In “Every row in T3 can find a row either in T12 or T14.” , T3 should be T2. 连接条件写在WHERE里了.
原来的SQL还有很多条件,但关键是这段subquery写得太烂.一是nested subquery, 二是cartesian join.
改后的SQL:
select ...
from T1,T2,T3,T4
where ...
(EXISTS (SELECT 1 FROM T16, T14
WHERE (T16.NUM = 34) AND (T14.VID = T2.VID) AND (T14.IID = T2.IID) AND T16.CLL IN (T14.CLLCODE, -1))
OR
EXISTS (SELECT 1
FROM T16, T12 WHERE (T16.NUM = 34) AND (T12.VID = T2.VID) AND (T12.IID = T2.IID) AND T16.CLL IN (T12.CLLCODE, -1)))
实际上, 在上面的SQL里还是有cartesian join. 幸好developer痛定思痛, 把-1也去掉了 (在没违背原设计的情况下). 最后执行时间是0.5秒!
原来的SQL还有很多条件,但关键是这段subquery写得太烂.一是nested subquery, 二是cartesian join.
改后的SQL:
select ...
from T1,T2,T3,T4
where ...
(EXISTS (SELECT 1 FROM T16, T14
WHERE (T16.NUM = 34) AND (T14.VID = T2.VID) AND (T14.IID = T2.IID) AND T16.CLL IN (T14.CLLCODE, -1))
OR
EXISTS (SELECT 1
FROM T16, T12 WHERE (T16.NUM = 34) AND (T12.VID = T2.VID) AND (T12.IID = T2.IID) AND T16.CLL IN (T12.CLLCODE, -1)))
实际上, 在上面的SQL里还是有cartesian join. 幸好developer痛定思痛, 把-1也去掉了 (在没违背原设计的情况下). 最后执行时间是0.5秒!