我不是专家SQL用户所以我看到了一些优化以下SQL的建议。
SELECT pm.name, pm.WTPARTNUMBER
FROM WTPARTMASTER pm, WTPART pt, CHECKOUTLINK clink
WHERE pt.IDA2A2 = clink.CLASSNAMEKEYROLEBOBJECTREF
AND pm.WTPARTMASTER
IN (
SELECT master.WTPARTNUMBER
FROM WTPARTMASTER master
WHERE master.IDA2A2
NOT IN (
SELECT ulink.IDA3B5
FROM WTPARTUSAGELINK ulink, wtpart part
WHERE part.IDA3E2ITERATIONINFO = 1
AND ulink.CLASSNAMEKEYROLEAOBJECTREF = part.IDA2A2
)
AND master.WTPARTNUMBER LIKE '%-R'
)
AND pm.WTPARTNUMBER LIKE '%-R'
ORDER BY pm.WTPARTNUMBER;
第一个内部选择返回大约60K的数字,这些数字将用于外部查询IN。
有没有办法可以执行第一个内部查询并在外部IN运算符中使用该结果?
或优化查询的任何其他方式?
提前致谢。
答案 0 :(得分:1)
这很慢:
where somefield not in
(
select somefield
etc
)
这更快:
where somefield in
(
select somefield
from etc
where the conditions match the outer query
minus
select somefield
from etc
where the conditions match the outer query
and you want to exclude them
)
)