我有以下查询,我想调整,因为查询需要更多时间来运行。请帮帮我。
select info_id
from info_table
where info_id not in (select info_id
from some_table
where info_id is not null)
AND rownum <= 1000 ;
内部查询返回数百万行,因此存在问题。
答案 0 :(得分:1)
select info_id
from info_table e
where not exists (select 'x' from some_table where info_id = e.info_id);
这将避免内部排序或合并,应该更快
您甚至可以尝试外连接
select info_id
from info_table e LEFT OUTER JOIN some_table d
ON e.info_id= d.info_id
WHERE d.dept_no is not null;
答案 1 :(得分:0)
SELECT info_id
FROM info_table
LEFT OUTER JOIN some_table ON info_table.info_id = some_table.info_id
WHERE some_table.info_id IS NULL