Tuning query having not exists clause. [message #452458] |
Thu, 22 April 2010 04:36 |
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)
|
|
|
|
|
|