In subquery statements such as the following, the NOT IN clause causes an internal sort. Replacing the NOT IN with an indexed NOT EXISTS can be very beneficial. Study the following example:
SELECT . . .
FROM emp
WHERE dept_no NOT IN ( SELECT dept_no
FROM dept
WHERE dept_cat = 'A');
To improve performance, replace this code with:
SELECT . . .
FROM emp E
WHERE NOT EXISTS ( SELECT X'
FROM dept
WHERE dept_no = E.dept_no
AND dept_cat = 'A' );
0 comments:
Post a Comment