h*******7 发帖数: 14 | 1 现在是通过另外的某个文件读取了一部分ID,然后
SELECT * FROM x_table WHERE x_table.ID IN (....)
当ID集合比较大的时候(几万~几十万),发现效率非常低,请问有什么优化的方式么
? |
n****f 发帖数: 905 | 2 check the indexes in two tables first. we have over 10 million rows and can
do that quickly. |
h*******7 发帖数: 14 | 3 谢谢回复~
查询表的主键是有做索引的。
IN后面不是另外一个表,是别的程序抛过来的一些ID,也不连续。。。 |
n****f 发帖数: 905 | 4 What is the detail about the "是别的程序抛过来的一些ID,也不连续。。。"
There are many ways to fix this issue.
if this is a run-time query, you may use the partition table in the main
table....
【在 h*******7 的大作中提到】 : 谢谢回复~ : 查询表的主键是有做索引的。 : IN后面不是另外一个表,是别的程序抛过来的一些ID,也不连续。。。
|
m*****y 发帖数: 229 | 5 exist or join would be better if id indexed in both. |
p***c 发帖数: 5202 | 6 正解:不要in,哪怕做个table variable,temp table
把ID insert进去
再join都比这强 |