日期:2014-05-17  浏览次数:20564 次

in的效率太慢!
select * from table1 where id in(1,2,3,4,5,6,7,8,9)
怎么才能提高效率呢?不用in?不会,求指教。

------解决方案--------------------
SQL code
--id 列上有索引的情况下

select * from table1 where id = 1
union all
select * from table1 where id = 2
union all
select * from table1 where id = 3
union all
select * from table1 where id = 4
union all
select * from table1 where id = 5
union all
select * from table1 where id = 6
union all
select * from table1 where id = 7
union all
select * from table1 where id = 8
union all
select * from table1 where id = 9

------解决方案--------------------
探讨
select * from table1 where id in(1,2,3,4,5,6,7,8,9)
怎么才能提高效率呢?不用in?不会,求指教。

------解决方案--------------------
还是另外建立一个码表 然后JOIN比较快。
------解决方案--------------------
得看数据发布的情况,

如table1总记录数10万,id in(1,2,3,4,5,6,7,8,9)的记录有9.9万.
此时即使id上有索引也是没用的,基本上无法优化.