0
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;

Hi. This is my execution query and it takes very large time. Can anyone changed this to optimized one. Thank u

4

3 回答 3

1

首先我会在表上放置适当的索引,理想情况下覆盖索引

于 2012-08-30T10:43:54.147 回答
0

如果没有执行计划,我们当然无法帮助你,但我看到你得到了什么

SELECT ID
FROM TABLE1
WHERE EXTERNALKEY = 'XXX'

我建议您使用 WITH 子句将其具体化,或者使用 id%type 将 ID 放入任何 plsql 变量中,并在查询中使用它来代替您的语句。

于 2012-08-30T12:34:10.913 回答
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`);

现在记下查询的执行时间

于 2012-08-30T11:14:05.710 回答