Oracle performance optimization --NOT EXISTS instead LEFT JOIN performance increase 649 times!

SQL uses a NOT EXISTS way, the result is difficult to perform very slowly.

Script is as follows:

select count(1) from (

SELECT /*+ full(t) */

     t.*

      FROM cpe_demands_t t

      LEFT JOIN cpe_items_i_t i

        ON t.demand_item = i.item_code

     WHERE t.demand_id IS NOT NULL

       AND t.batch_id = 51115  -- 入参

       AND t.max_bom_level = 3  -- 入参

       AND NOT EXISTS (SELECT /*+ parallel(kk, 10) */

             1

              FROM iscp_atp.cpe_pegging_t kk

             WHERE kk.batch_id = 51115

               AND kk.max_bom_level = 3

               AND kk.demand_id = t.demand_id)

       AND t.demand_date >= SYSDATE -7 * 7 -- 入参

       AND t.demand_date < SYSDATE + 1 * 7 -- 入参

       )

LEFT JOIN instead of the way, performance significantly. The same amount of data, NOT EXISTS manner takes 422 seconds,

Oracle performance optimization --NOT EXISTS instead LEFT JOIN performance increase 649 times!

The LEFT JOIN way takes only 0.65 seconds, 649 times performance increase!

Oracle performance optimization --NOT EXISTS instead LEFT JOIN performance increase 649 times!

The optimized script is as follows:

select count(1) from (

select * from (

SELECT /*+ full(t) */

     t.*

      FROM cpe_demands_t t

      LEFT JOIN cpe_items_i_t i

        ON t.demand_item = i.item_code

     WHERE t.demand_id IS NOT NULL

       AND t.batch_id = 51115  -- 入参

       AND t.max_bom_level = 3  -- 入参

       AND t.demand_date >= SYSDATE -7 * 7 -- 入参

       AND t.demand_date < SYSDATE + 1 * 7 -- 入参

       ) tt left join

       cpe_pegging_t kk

       on kk.demand_id = tt.demand_id

             WHERE kk.demand_id  is null

       )

Author: waylau

Guess you like

Origin blog.51cto.com/14753584/2479937