当前位置: 代码迷 >> Sql Server >> in的效率太慢!解决思路
  详细解决方案

in的效率太慢!解决思路

热度:6   发布时间:2016-04-27 11:16:56.0
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 = 1union allselect * from table1 where id = 2union allselect * from table1 where id = 3union allselect * from table1 where id = 4union allselect * from table1 where id = 5union allselect * from table1 where id = 6union allselect * from table1 where id = 7union allselect * from table1 where id = 8union allselect * 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上有索引也是没用的,基本上无法优化.
  相关解决方案