此查询在700 ms内执行:
SELECT pcl.COL1,
pcl.COL2,
pcl.COL3,
pcl.COL4,
(SELECT cc.COL5
FROM T3 cc
JOIN T4 cvp
ON cvp.COL10 = cc.COL10
AND cvp.COL2 = pcl.COL2) AS COL10,
pp.COL11
FROM T1 ba
JOIN T2 pcl
ON pcl.COL1 = ba.COL1
AND (pcl.COL2 = ba.COL2 OR ba.COL2 = 0)
JOIN T5 pscl
ON pscl.COL2 = pcl.COL2
AND pscl.COL4 <> 3
AND (pscl.COL6 = ba.COL6 OR ba.COL6 = 'ALL')
LEFT JOIN T6 bba
ON bba.COL7 = ba.COL7
LEFT JOIN T7 bsa
ON bsa.COL7 = ba.COL7
LEFT JOIN T8 pp
ON pp.COL1 = pcl.COL1
WHERE (ba.COL8 = 617617 OR bsa.COL8 = 617617 OR bba.COL9 = 617617)
问题是:
(ba.COL8 = 617617 OR bsa.COL8 = 617617 OR bba.COL9 = 617617)
COL 8和COL 9有索引。如果我保持3个条件中的任何一个,那么它需要30 ms来执行。如果我保留其中两个,那么执行需要300 ms。但我需要他们三个。如何改进/重写我的SELECT?
1条答案
按热度按时间ivqmmu1c1#
您没有使用
bba
或bsa
表,除非将其用作筛选器,因此您可以从使用JOIN
s更改为使用EXISTS
: