MySQL等于比大于等

时间:2015-01-01 03:58:01

标签: mysql sql indexing

我的MySQL数据库存在一个奇怪的问题。以下查询在0.003秒内运行:

SELECT * FROM `post` where `thread_id` > 12117484 and `index` > -1 limit 1;

如果我更改第二个>到= =,查询没有完成(它运行超过一分钟):

SELECT * FROM `post` where `thread_id` > 12117484 and `index` = 0 limit 1;

值得注意的是,第一个查询的结果为index = 0。我知道命名专栏index的形式不好......但它是我已经获得的数据库。这是第二个查询的MySQL解释:

+----+-------------+-------+-------+---------------------+---------------------+---------+------+------+------------------------------------+
| id | select_type | table | type  | possible_keys       | key                 | key_len | ref  | rows | Extra                              |
+----+-------------+-------+-------+---------------------+---------------------+---------+------+------+------------------------------------+
|  1 | SIMPLE      | post  | range | post_thread_id_idx1 | post_thread_id_idx1 | 5       | NULL |    1 | Using index condition; Using where |
+----+-------------+-------+-------+---------------------+---------------------+---------+------+------+------------------------------------+

0 个答案:

没有答案