本文发表在 rolia.net 枫下论坛select ...
from T1,T2,T3,T4
where ...
EXISTS(SELECT
1
FROM T16
WHERE (T16.NUM = 34) AND
(EXISTS(SELECT 1
FROM T14
WHERE (T14.VID = T2.VID) AND (T14.IID = T2.IID) AND
T16.CLL IN (T14.CLLCODE, -1))
OR
EXISTS(SELECT 1
FROM T12
WHERE (T12.VID = T2.VID) AND (T12.IID = T2.IID) AND
((T16.CLL = T12.CLLCODE) OR (T16.CLL = -1)))
)
)
Without subquery, it returns 500 rows. T16 has 10 million rows, T12 has 25k rows, T14 has 200k rows.
There is a foreign key relationshipt between T12 and T16, T12 is the child.
Same as T14 and T16, T14 is the child.
Every row in T3 can find a row either in T12 or T14.
-1 is a rare value in T16.CLL. 34 is a frequent value in T16.NUM.
Without query rewrite, it requires 15 minutes to finish, after query rewrite, 16 seconds.更多精彩文章及讨论,请光临枫下论坛 rolia.net
from T1,T2,T3,T4
where ...
EXISTS(SELECT
1
FROM T16
WHERE (T16.NUM = 34) AND
(EXISTS(SELECT 1
FROM T14
WHERE (T14.VID = T2.VID) AND (T14.IID = T2.IID) AND
T16.CLL IN (T14.CLLCODE, -1))
OR
EXISTS(SELECT 1
FROM T12
WHERE (T12.VID = T2.VID) AND (T12.IID = T2.IID) AND
((T16.CLL = T12.CLLCODE) OR (T16.CLL = -1)))
)
)
Without subquery, it returns 500 rows. T16 has 10 million rows, T12 has 25k rows, T14 has 200k rows.
There is a foreign key relationshipt between T12 and T16, T12 is the child.
Same as T14 and T16, T14 is the child.
Every row in T3 can find a row either in T12 or T14.
-1 is a rare value in T16.CLL. 34 is a frequent value in T16.NUM.
Without query rewrite, it requires 15 minutes to finish, after query rewrite, 16 seconds.更多精彩文章及讨论,请光临枫下论坛 rolia.net