文章目录
explain extended
配合 show warnings
可以查看优化器优化后的结果;
mysql> explain extended select * from tb_limit_test where id <=10;
+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+
| 1 | SIMPLE | tb_limit_test | range | PRIMARY | PRIMARY | 8 | NULL | 11 | 100.00 | Using where |
+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings\G
*************************** 1. row ***************************
Level: Note
Code: 1003
Message: select `test`.`tb_limit_test`.`id` AS `id`,
`test`.`tb_limit_test`.`key` AS `key`,`test`.`tb_limit_test`.`value` AS `value`
from `test`.`tb_limit_test` where (`test`.`tb_limit_test`.`id` <= 10)
1 row in set (0.00 sec)
mysql> explain extended select * from tb_limit_test where 1=1 and id <=10;
+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+
| 1 | SIMPLE | tb_limit_test | range | PRIMARY | PRIMARY | 8 | NULL | 11 | 100.00 | Using where |
+
1 row in set, 1 warning (0.01 sec)
mysql> show warnings\G
*************************** 1. row ***************************
Level: Note
Code: 1003
Message: select `test`.`tb_limit_test`.`id` AS `id`,
`test`.`tb_limit_test`.`key` AS `key`,`test`.`tb_limit_test`.`value` AS `value`
from `test`.`tb_limit_test` where (`test`.`tb_limit_test`.`id` <= 10)
1 row in set (0.00 sec)