使用索引的技巧知识点

1、尽量使用union代替or,减少merge index,因为mysql的merge index可能很白痴。
2、尽量使用in代替or,or的时间复杂度是o(n),而in是log(n)。不过in最好不要超过200个参数。
3、避免负向查询(not, !=,<>,!<,!>,not exists, not in, not like)和%前缀,因为mysql索引是B+ Tree结构,这样会无法使用索引。
4、使用order by null可以阻止group by 排序。
5、mysql中数值列与字符对比,两者会转成双精度,字符列与数值比较,字符列会转成数值,并且无法使用索引

posted @ 2013-01-09 16:21  luffy_zhong  阅读(155)  评论(0编辑  收藏  举报