Welcome to Oracle PL SQL Performance Tuning and Optimization. At Oracle PL SQL Performance Tuning and Optimization talk about SQL Tuning - NOT EXISTS versus NOT IN

Wednesday, July 11

SQL Tuning - NOT EXISTS versus NOT IN

SQL Tuning - NOT EXISTS versus NOT IN - 
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

Copyright © 2013 Oracle PL SQL Performance Tuning and Optimization | Oracle PL SQL Performance Tuning and Optimization