Home » RDBMS Server » Performance Tuning » Tuning query having not exists clause. (Oracle Database 10g Release 10.2.0.4.0 - 64bit Production.)
Tuning query having not exists clause. [message #452458] Thu, 22 April 2010 04:36 Go to next message
Gangaprasad
Messages: 7
Registered: April 2010
Location: India
Junior Member
I need help in tuning below mentioned query.
number of records in each table as below.
b_acct_recv : 8L
b_acct_recv_sub : 8L
b_accrual : 4.5L
b_amortization : 2.5L
By intention to remove FULL table scan on b_acct_recv_sub table.
b_acct_recv_sub table is having index on link_num but same is not using.
 QUERY :
    INSERT INTO B_TRB112
      (COUNTRY_CODE,
      LEG_VEH,
      BOFF_CODE,
      REF_NUM,
      SEQ_NUM,
      SERIAL_NUM,
      CHARGE_TYPE,
      CHARGE_CCY,
      RECV_STATUS,
      POSTING_DATE,
      LINK_NUM,
      SUPPRESS_TRACER,
      LAST_TRACER_DATE,
      NEXT_TRACER_DATE,
      AGE)
		SELECT
         B_ACCT_RECV.COUNTRY_CODE,
         B_ACCT_RECV.LEG_VEH,
         B_ACCT_RECV.BOFF_CODE,
         B_ACCT_RECV.REF_NUM,
         B_ACCT_RECV.SEQ_NUM,
         B_ACCT_RECV.SERIAL_NUM,
         B_ACCT_RECV.CHARGE_TYPE,
         B_ACCT_RECV.TXN_CCY,
         B_ACCT_RECV.RECV_STATUS,
         B_ACCT_RECV.POSTING_DATE,
         B_ACCT_RECV.LINK_NUM,
         B_ACCT_RECV.SUPPRESS_TRACER,
         B_ACCT_RECV.LAST_TRACER_DATE,
         B_ACCT_RECV.NEXT_TRACER_DATE,
         TRUNC(TO_DATE('20120501000000','YYYYMMDDHH24MISS'))
         -  TRUNC(B_ACCT_RECV.POSTING_DATE)
         FROM B_ACCT_RECV
         WHERE
            B_ACCT_RECV.COUNTRY_CODE = 'US' and
            B_ACCT_RECV.LEG_VEH = 'CNA' and
            TRUNC(B_ACCT_RECV.POSTING_DATE)
              <= TRUNC(TO_DATE('20120501000000', 'YYYYMMDDHH24MISS')) and
            (B_ACCT_RECV.RECV_STATUS = 'OST' or
            B_ACCT_RECV.RECV_STATUS =  'ACT' or
            B_ACCT_RECV.RECV_STATUS =  'PPD') and
            not EXISTS (SELECT A.REF_NUM FROM B_ACCRUAL A WHERE B_ACCT_RECV.REF_NUM = A.REF_NUM
                                                          AND B_ACCT_RECV.CHARGE_TYPE = A.CHARGE_TYPE) and
            not EXISTS (SELECT A.REF_NUM FROM B_AMORTIZATION A WHERE B_ACCT_RECV.REF_NUM = A.REF_NUM
                                                          AND B_ACCT_RECV.CHARGE_TYPE = A.CHARGE_TYPE) and
            B_ACCT_RECV.COUNTRY_STATE = 'A' and
            B_ACCT_RECV.LEG_VEH_STATE = 'A' and
            NOT EXISTS (select x.link_num from B_ACCT_RECV_SUB x
                        where  x.link_num  = B_ACCT_RECV.link_num and
                               x.recv_type = 'COF' ) ;

  Explain Plan
   0      INSERT STATEMENT Optimizer=ALL_ROWS (Cost=2553 Card=1 Bytes=
          101)

   1    0   NESTED LOOPS (ANTI) (Cost=2553 Card=1 Bytes=101)
   2    1     NESTED LOOPS (ANTI) (Cost=2551 Card=1 Bytes=84)
   3    2       HASH JOIN (RIGHT ANTI) (Cost=2549 Card=1 Bytes=67)
   4    3         TABLE ACCESS (FULL) OF 'B_ACCT_RECV_SUB' (TABLE) (Cost=1737 Card=3749 Bytes=33741)

   5    3         INLIST ITERATOR
   6    5           TABLE ACCESS (BY INDEX ROWID) OF 'B_ACCT_RECV' (TABLE) (Cost=812 Card=1284 Bytes=74472)

   7    6             INDEX (RANGE SCAN) OF 'B_ACCT_RECV_INDX' (INDEX) (Cost=82 Card=25682)

   8    2       TABLE ACCESS (BY INDEX ROWID) OF 'B_ACCRUAL' (TABLE) (Cost=2 Card=1 Bytes=17)

   9    8         INDEX (RANGE SCAN) OF 'B_IDX_ACCRUAL_01' (INDEX) (Cost=1 Card=1)

  10    1     TABLE ACCESS (BY INDEX ROWID) OF 'B_AMORTIZATION' (TABLE) (Cost=2 Card=1 Bytes=17)

  11   10       INDEX (RANGE SCAN) OF 'B_IDX_AMORTIZATION_01' (INDEX)(Cost=1 Card=1)

Re: Tuning query having not exists clause. [message #452460 is a reply to message #452458] Thu, 22 April 2010 04:45 Go to previous messageGo to next message
cookiemonster
Messages: 13958
Registered: September 2008
Location: Rainy Manchester
Senior Member
Try adding an index to B_ACCT_RECV_SUB on (link_num, recv_type)
Re: Tuning query having not exists clause. [message #452463 is a reply to message #452460] Thu, 22 April 2010 04:51 Go to previous messageGo to next message
Gangaprasad
Messages: 7
Registered: April 2010
Location: India
Junior Member
Requirement not to add any additional index.
Just we need to tune sql query only.
Re: Tuning query having not exists clause. [message #452466 is a reply to message #452458] Thu, 22 April 2010 04:55 Go to previous message
cookiemonster
Messages: 13958
Registered: September 2008
Location: Rainy Manchester
Senior Member
Are your stats upto date?
If they are then oracle is probably ignoring the index for reason. You can try adding a hint to the sub-query to make it use your index but it might well slow the query down.
Previous Topic: Tune sql query
Next Topic: DBMS SQL TUNE Problem
Goto Forum:
  


Current Time: Mon Nov 25 15:09:59 CST 2024