![]() | 1 ipconfiger 2013-06-14 23:11:12 +08:00 ![]() MySql下in查致索引失,然後就成了全表描,如果表大,那就定了很慢。 in 子查的情貌似可以match索引,但是你,定了了。 如果in的容不是很多的,可以用union 代替in。 化sql最大的技巧就是 一右的感按 ^_^ |
![]() | 2 VYSE 2013-06-15 02:39:58 +08:00 ![]() 你可以EXPLAIN看下有没有使用INDEX,现在的QUERY OPTIMIZER已经很智能去处理是否使用INDEX(有时一遍扫表效率更高)。 见官方文档: Each table index is queried, and the best index is used unless the optimizer believes that it is more efficient to use a table scan. At one time, a scan was used based on whether the best index spanned more than 30% of the table, but a fixed percentage no longer determines the choice between using an index or a scan. The optimizer now is more complex and bases its estimate on additional factors such as table size, number of rows, and I/O block size. 如果一定要使用INDEX,在TABLE后面加上FORCE INDEX (names_index,memos_index)。 你这种情况相信MYSQL比盲目优化来的好,EXPLAIN还能参考语句效率。 另可试试拆成俩进行JOIN取代AND看看时间 |
![]() | 3 banxi1988 OP @ipconfiger mysql下的子查询的in其实会优化成exists子句,不会丢失索引。 in的内容不多,平均10来条。union使用请明示。谢谢。 |
4 2269195609 2013-06-15 13:04:07 +08:00 若用等值连接查询呢,将后面两个列表组合成表, |