How to make this query fast? [message #132102] |
Wed, 10 August 2005 18:19 |
oracle_user_2005
Messages: 6 Registered: August 2005
|
Junior Member |
|
|
This is my first post to your forum. Presently this query takes 3 minutes 14 secs to come back with 100 rows if I give it a bind variable of 100 :endrow. Can someone please suggest me an alternate way to write this to make it faster or some hint.
select *
FROM
(
SELECT
*
FROM
(
SELECT
INNER.*,
ROWNUM
AS QUERY_ROWNUM
FROM
(
SELECT --+
COUNT(*) OVER() AS TOTAL_ROWS,
NVL(MT.TRNSF_FL, 'N') AS TRNSF_FL,
MT.MASS_TRNSF_INDVL_PK,
IND.INDVL_PK,
IND.LAST_NM,
IND.FIRST_NM,
IND.MID_NM,
IFA.ORG_PK,
IFA.RR_FL,
IFA.IAR_FL,
IFA.BACK_OFC_FL
FROM
INDVL IND,
INDVL_FIRM_ASCTN IFA,
(
SELECT
MTI.MASS_TRNSF_INDVL_PK,
MTI.INDVL_PK,
MTI.TRNSF_FL
FROM
MASS_TRNSF_PRDSR MTP,
MASS_TRNSF_INDVL MTI
WHERE
MTP.MASS_TRNSF_PK = :i_MASS_TRNSF_PK AND
MTP.ORG_PK = :i_ORG_PK AND
MTP.MASS_TRNSF_PRDSR_PK = MTI.MASS_TRNSF_PRDSR_PK
) MT
WHERE
IND.LAST_NM LIKE :l_STARTS_WITH AND
IFA.ORG_PK = :i_ORG_PK AND
IFA.INDVL_FIRM_ST_CD = 'ACTIVE' AND
IFA.PAGE_2_FL = 'N' AND
(IFA.RR_FL = 'Y' OR
IFA.BACK_OFC_FL = 'Y' ) AND
IFA.INDVL_PK = IND.INDVL_PK AND
MT.INDVL_PK (+) = IND.INDVL_PK
ORDER BY
IND.LAST_NM,
IND.FIRST_NM,
IND.MID_NM
) INNER
WHERE
ROWNUM <= :EndRow
) OUTER
WHERE
OUTER.QUERY_ROWNUM >= :StartRow
) B
This is the explain plan:
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=CHOOSE 24 21
VIEW 24 2 K 21
COUNT STOPKEY
VIEW 24 2 K 21
WINDOW SORT 24 1 K 21
HASH JOIN OUTER 24 1 K 21
NESTED LOOPS 24 1 K 18
TABLE ACCESS BY INDEX ROWID CRDMAIN.INDVL_FIRM_ASCTN 24 576 9
INDEX RANGE SCAN CRDMAIN.XIE2INDVL_FIRM_ASCTN 63 3
TABLE ACCESS BY INDEX ROWID CRDMAIN.INDVL 1 27 1
INDEX UNIQUE SCAN CRDMAIN.XPKINDVL 1 1
VIEW 1 13 2
TABLE ACCESS BY INDEX ROWID CRDMAIN.MASS_TRNSF_INDVL 81 1 K 1
NESTED LOOPS 1 31 2
TABLE ACCESS BY INDEX ROWID CRDMAIN.MASS_TRNSF_PRDSR 1 14 1
INDEX RANGE SCAN CRDMAIN.XIF1MASS_TRNSF_PRDSR 1 1
INDEX RANGE SCAN CRDMAIN.XIF1MASS_TRNSF_INDVL 81
|
|
|
|
|
|
Re: How to make this query fast? [message #132270 is a reply to message #132263] |
Thu, 11 August 2005 11:35 |
oracle_user_2005
Messages: 6 Registered: August 2005
|
Junior Member |
|
|
Mahesh,
Thank You for your reply. For my requirement I do need an outer join with MT.INDVL_PK (+)=IND.INDVL_PK. Can you suggest me a workaround to avoid the outer hash join? I am submitting the query and explain plan within [code] now.
Thank You
select
*
FROM
(
SELECT
*
FROM
(
SELECT
INNER.*,
ROWNUM
AS QUERY_ROWNUM
FROM
(
SELECT
COUNT(*) OVER() AS TOTAL_ROWS,
NVL(MT.TRNSF_FL, 'N') AS TRNSF_FL,
MT.MASS_TRNSF_INDVL_PK,
IND.INDVL_PK,
IND.LAST_NM,
IND.FIRST_NM,
IND.MID_NM,
IFA.ORG_PK,
IFA.RR_FL,
IFA.IAR_FL,
IFA.BACK_OFC_FL
FROM
INDVL IND,
INDVL_FIRM_ASCTN IFA,
(
SELECT
MTI.MASS_TRNSF_INDVL_PK,
MTI.INDVL_PK,
MTI.TRNSF_FL
FROM
MASS_TRNSF_PRDSR MTP,
MASS_TRNSF_INDVL MTI
WHERE
MTP.MASS_TRNSF_PK = :i_MASS_TRNSF_PK AND
MTP.ORG_PK = :i_ORG_PK AND
MTP.MASS_TRNSF_PRDSR_PK = MTI.MASS_TRNSF_PRDSR_PK
) MT
WHERE
IND.LAST_NM LIKE :l_STARTS_WITH AND
IFA.ORG_PK = :i_ORG_PK AND
IFA.INDVL_FIRM_ST_CD = 'ACTIVE' AND
IFA.PAGE_2_FL = 'N' AND
(IFA.RR_FL = 'Y' OR
IFA.BACK_OFC_FL = 'Y' ) AND
IFA.INDVL_PK = IND.INDVL_PK AND
MT.INDVL_PK (+) = IND.INDVL_PK
ORDER BY
IND.LAST_NM,
IND.FIRST_NM,
IND.MID_NM
) INNER
WHERE
ROWNUM <= :EndRow
) OUTER
WHERE
OUTER.QUERY_ROWNUM >= :StartRow
) B
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=CHOOSE 24 21
VIEW 24 2 K 21
COUNT STOPKEY
VIEW 24 2 K 21
WINDOW SORT 24 1 K 21
HASH JOIN OUTER 24 1 K 21
NESTED LOOPS 24 1 K 18
TABLE ACCESS BY INDEX ROWID CRDMAIN.INDVL_FIRM_ASCTN 24 576 9
INDEX RANGE SCAN CRDMAIN.XIE2INDVL_FIRM_ASCTN 63 3
TABLE ACCESS BY INDEX ROWID CRDMAIN.INDVL 1 27 1
INDEX UNIQUE SCAN CRDMAIN.XPKINDVL 1 1
VIEW 1 13 2
TABLE ACCESS BY INDEX ROWID CRDMAIN.MASS_TRNSF_INDVL 81 1 K 1
NESTED LOOPS 1 31 2
TABLE ACCESS BY INDEX ROWID CRDMAIN.MASS_TRNSF_PRDSR 1 14 1
INDEX RANGE SCAN CRDMAIN.XIF1MASS_TRNSF_PRDSR 1 1
INDEX RANGE SCAN CRDMAIN.XIF1MASS_TRNSF_INDVL 81
|
|
|
Re: How to make this query fast? [message #132276 is a reply to message #132270] |
Thu, 11 August 2005 12:55 |
oracle_user_2005
Messages: 6 Registered: August 2005
|
Junior Member |
|
|
Mahesh,
You were absolutely right. When I remove the outer join , the query becomes extremely fast. But I do need the outer join as per the requirements. Here is the explain plan when I remove the outer join. Can you suggest me any hint or a new way to write this query so I can mimic this plan:
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=CHOOSE 1 4
VIEW 1 116 4
COUNT STOPKEY
VIEW 1 103 4
WINDOW SORT 1 82 4
TABLE ACCESS BY INDEX ROWID CRDMAIN.INDVL_FIRM_ASCTN 1 24 1
NESTED LOOPS 1 82 4
NESTED LOOPS 1 58 3
NESTED LOOPS 1 31 2
TABLE ACCESS BY INDEX ROWID CRDMAIN.MASS_TRNSF_PRDSR 1 14 1
INDEX RANGE SCAN CRDMAIN.XIF1MASS_TRNSF_PRDSR 1 1
TABLE ACCESS BY INDEX ROWID CRDMAIN.MASS_TRNSF_INDVL 81 1 K 1
INDEX RANGE SCAN CRDMAIN.XIF1MASS_TRNSF_INDVL 81
TABLE ACCESS BY INDEX ROWID CRDMAIN.INDVL 1 27 1
INDEX UNIQUE SCAN CRDMAIN.XPKINDVL 1 1
INDEX RANGE SCAN CRDMAIN.XPKINDVL_FIRM_ASCTN 1 2
|
|
|
|
|
|
|
Re: How to make this query fast? [message #133131 is a reply to message #132371] |
Wed, 17 August 2005 15:36 |
oracle_user_2005
Messages: 6 Registered: August 2005
|
Junior Member |
|
|
Mahesh,
When I run the query by adding a hint ( --+ FULL(MTP) )to the inline view MT and I comment out count over () and order by the query comes back in 1 sec. I am still working on sending you the trace file output.
If this gives your some new insight please let me know.
Here is the query:
SELECT *
FROM
(
SELECT
*
FROM
(
SELECT
INNER.*,
ROWNUM
AS QUERY_ROWNUM
FROM
(
SELECT --+
--COUNT(*) OVER() AS TOTAL_ROWS,
NVL(MT.TRNSF_FL, 'N') AS TRNSF_FL,
MT.MASS_TRNSF_INDVL_PK,
IND.INDVL_PK,
IND.LAST_NM,
IND.FIRST_NM,
IND.MID_NM,
IFA.ORG_PK,
IFA.RR_FL,
IFA.IAR_FL,
IFA.BACK_OFC_FL
FROM
INDVL IND,
INDVL_FIRM_ASCTN IFA,
(
SELECT --+ FULL( MTP )
MTI.MASS_TRNSF_INDVL_PK,
MTI.INDVL_PK,
MTI.TRNSF_FL
FROM
MASS_TRNSF_PRDSR MTP,
MASS_TRNSF_INDVL MTI
WHERE
MTP.MASS_TRNSF_PK = :i_MASS_TRNSF_PK AND
MTP.ORG_PK = :i_ORG_PK AND
MTP.MASS_TRNSF_PRDSR_PK = MTI.MASS_TRNSF_PRDSR_PK
) MT
WHERE
IFA.ORG_PK = :i_ORG_PK AND
IFA.INDVL_FIRM_ST_CD = 'ACTIVE' AND
IFA.PAGE_2_FL = 'N' AND
( IFA.RR_FL = 'Y' OR
IFA.BACK_OFC_FL = 'Y' ) AND
IFA.INDVL_PK = IND.INDVL_PK AND
MT.INDVL_PK (+) = IND.INDVL_PK
-- ORDER BY
-- IND.LAST_NM,
-- IND.FIRST_NM,
-- IND.MID_NM
) INNER
WHERE
ROWNUM <= :EndRow
) OUTER
WHERE
OUTER.QUERY_ROWNUM >= :StartRow
) B
Here is the explain plan:
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=CHOOSE 24 23
VIEW 24 2 K 23
COUNT STOPKEY
NESTED LOOPS OUTER 24 1 K 23
NESTED LOOPS 24 1 K 18
TABLE ACCESS BY INDEX ROWID CRDMAIN.INDVL_FIRM_ASCTN 24 576 9
INDEX RANGE SCAN CRDMAIN.XIE2INDVL_FIRM_ASCTN 63 3
TABLE ACCESS BY INDEX ROWID CRDMAIN.INDVL 1 27 1
INDEX UNIQUE SCAN CRDMAIN.XPKINDVL 1 1
VIEW PUSHED PREDICATE 1 13 1
TABLE ACCESS BY INDEX ROWID CRDMAIN.MASS_TRNSF_INDVL 1 17 1
NESTED LOOPS 1 31 5
TABLE ACCESS FULL CRDMAIN.MASS_TRNSF_PRDSR 1 14 4
INDEX RANGE SCAN CRDMAIN.XIF1MASS_TRNSF_INDVL 81
|
|
|