SELECT T1.DESCRIPTION,
T1.NAME,
T1.EXTERNALKEY,
T2.STATECODE
FROM TABLE1 T1, TABLE2 T2, TABLE3 T3
WHERE T1.CLASSID = 7040
AND T2.ID = T3.ID
AND T2.RECEIVERID = T1.ID
AND T1.OWNERID = (SELECT ID
FROM TABLE1
WHERE EXTERNALKEY = 'XXX')
MINUS
SELECT T1.DESCRIPTION,
T1.NAME,
T1.EXTERNALKEY,
T2.STATECODE
FROM TABLE3 T3, TABLE1 T1, TABLE2 T2
WHERE VALUE = 'XXXX' AND T3.ID = T1.ID;
您好。这是我的执行查询,需要很长时间。任何人都可以将其更改为优化的。谢谢你
答案 0 :(得分:1)
首先我会在表上放置适当的索引,理想情况下覆盖索引
答案 1 :(得分:0)
ALTER TABLE `TABLE1 ` ADD INDEX `index1` (`NAME`, `EXTERNALKEY`);
ALTER TABLE `TABLE1 ` ADD INDEX `index2` (`OWNERID`);
ALTER TABLE `TABLE2 ` ADD INDEX `index3` (`STATECODE`);
ALTER TABLE `TABLE2 ` ADD INDEX `index4` (`RECEIVERID`);
现在请注意查询的执行时间
答案 2 :(得分:0)
当然,如果没有执行计划,我们无法帮助你,但我看到你得到了什么
SELECT ID
FROM TABLE1
WHERE EXTERNALKEY = 'XXX'
我建议您使用WITH子句实现它,或者将ID添加到id为%type的任何plsql变量中,并在查询中使用它来代替您的语句。