mysql>select/* twGetTermTotalCount 127.0.0.1 */count(*)AS amount from smw_ids where smw_namespace between 1000 and 2000 and smw_namespace mod 2=0;
+---------+
| amount |
+---------+
| 1271240 |
+---------+
1 row inset(1.94 sec)
EXPLAIN信息如下:
mysql> explain select/* twGetTermTotalCount 127.0.0.1 */count(*)AS amount from smw_ids where smw_namespace between 1000 and 2000 and smw_namespace mod 2=0;
mysql> explain select/* twGetTermTotalCount 127.0.0.1 */count(*)AS amount from smw_ids IGNORE INDEX(idx_smw_sortkey)where smw_namespace between 1000 and 2000 and smw_namespace mod 2=0;
mysql>select/* twGetTermTotalCount 127.0.0.1 */count(*)AS amount from smw_ids IGNORE INDEX(idx_smw_sortkey)where smw_namespace between 1000 and 2000 and smw_namespace mod 2=0;
+---------+
| amount |
+---------+
| 1271208 |
+---------+
1 row inset(0.77 sec)
mysql 自己的優(yōu)化器某些時(shí)候還是不那么“聰明的”,優(yōu)化的時(shí)候要多思考。