在索引列中检查非0的最快方法是什么,使用:
WHERE column != 0
Run Code Online (Sandbox Code Playgroud)
要么
WHERE column > 0
Run Code Online (Sandbox Code Playgroud)
使用索引列可以更好地完成上述工作之一,还是在速度方面它们几乎相同?
我在〜650k行表上做了这个,column列被索引了.似乎存在细微差别,确实> 0更快.这两个查询在两个相同的数据库上运行,因此没有缓存可能会影响执行时间.
explain
select * from table where column > 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE table range column column 5 \N 4736 Using where
Execution Time : 00:00:00:005
explain
select * from table where column != 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE table range column column 5 \N 4746 Using where
Execution Time : 00:00:00:012
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6605 次 |
| 最近记录: |