Query Transformation

download Query Transformation

of 20

  • date post

    27-Oct-2014
  • Category

    Documents

  • view

    22
  • download

    4

Embed Size (px)

Transcript of Query Transformation

Query Transformation

Author Creation Date 2010-02-04 Last Updated Version Copyright(C) 2004 Goodus Inc. All Rights Reserved

Version

()

Query TransformationContents

1.

QUERY TRANSFORMATION ? ......................................................................................... 3 1.1. 1.2. QUERY TRANSFORMATION ...............................................................................3 OPTIMIZER QUERY TRANSFORMATION ? ...........................................4

2.

ORACLE OPTIMIZER ............................................................................................................. 5 2.1. OPTIMIZER ................................................................................................5 2.1.1. 2.1.2. 2.1.3. .................................................................................................................. 5 (Estimator) ................................................................................................. 6 (Plan Generator) ................................................................................ 6

3.

Transformation ............................................................................................................ 6 3.1. ViewMerging ................................................... ! . 3.1.1. 3.1.2. 3.2. 3.2.1. 3.2.2. 3.2.3. 3.3. 3.3.1. 3.3.2. 3.4. 3.4.1. ViewMerge case 1 ...................................................................................................... 6 ViewMerge case 2 ...................................................................................................... 8 Predicate Push Case 1 ................................................................................................ 9 Predicate Push Case 2 .............................................................................................. 10 Predicate Push Case 3 .............................................................................................. 12 SubQuery Unnesting case 1 ..................................................................................... 14 SubQuery Unnesting case 2 ..................................................................................... 16 SubQuery Pushing case 1 ........................................................................................ 18

Predicate Push ................................................ ! .

SubQuery Unnesting ....................................... ! .

SubQuery Pushing ........................................... ! .

4.

CostBasedQueryTransformation .......................................................................... 19

- 2

Query Transformation DB . RAC RDBMS SQLTuning . ORACLE OPTIMIZER QUERY TRANSFORMATION .

1.

QUERY TRANSFORMATION?

QUERY TRANSFORMATION OPTIMIZER Hard Parsing Query Query . Tuning QUERY TRANSFORMATION Query OPTIMIZER QUERYBLOCK . QUERY TRANSFORMATION A Between 1 and 100 A>=1 and A TBA_C -> TBA_B . SubQuery UnNesting Access Table . - 15

Query Transformation TAB_A SubQuery TABLE TAB_C SEMI JOIN . TAB_A.colA=1 TAB_B TAB_C PredicateInformation .

3.3.2. SubQuery Unnesting case 2 CASE SELECT A.CRD_NO , ............................ C.RESD_NO AS RESD_NO FROM CRD_AFTISS A , CRD_MASTER B , MBR_MASTER C , JON_JONCRD D , MBR_MBRETC E WHERE AND AND AND AND AND A.PGM_ID = :1 A.CRD_ISSU_DY BETWEEN :2 AND :3 A.MANUF_FG IN ('N','F') A.PGM_ID = B.PGM_ID D.WORK_FG = :6 A.CRD_NO NOT IN (SELECT CRD_NO FROM WHERE AND AND CRD_REMAKE REG_DY BETWEEN to_char(to_date(:7, 'YYYYMMDD') - 3, 'YYYYMMDD') and :8 REGR_ID IN ('ARS','IVR') PGM_ID = :9 )

.................................

SubQuery UnNesting .

- 16

Query Transformation

SubQuery . FILTER . MainQuery SubQuery Filtering . ANSI NL JOIN .

- 17

Query Transformation3.4. SUBQUERY PUSHING

SubQuery View Merge ROWNUM, DISTINCT, GROUP BY, SET OPERATOR Subquery Unnesting . OPTIMIZER SubQuery Table Main Query table Driving . subquery Pushing .

3.4.1. SubQuery Pushing case 1 SAMPL TABLE COLA

TAB_A TAB_C .SELECT A.colA,C.colA,A.colC,C.colC FROM TAB_A A,TAB_C C WHERE A.colA=C.colA AND A.colA IN (SELECT /*+ NO_UNNEST NO_PUSH_SUBQ */ B.colA FROM TAB_B B WHERE colA=1 GROUP BY B.colA) AND A.ColA=1

colA TAB_A TAB_C JOIN TAB_B SUBQUERY SQL . SubQuery UnNesting Query ?

-----------------------------------------------------------------------------------------------| Id | Operation | Name | E-Rows | Cost (%CPU)| A-Rows | Buffers |

-----------------------------------------------------------------------------------------------|* 1 | FILTER HASH JOIN | | | | | | 1260 | 1 | 1 | 1260 | | 1 | 125 | 1 1 117 2 1 115 | (5)| (0)| (0)| (5)| | (0)| (0)| 682 | 682 | 1 | 1 | 682 | 1 | 1 | 63 | 549 | 547 | 3 | 2 | 544 | 2 | 2 | 2 |

|* 2 | | |* |* |* | |* 3 | 4 | 5 | 6 | 7 | 8 |

TABLE ACCESS BY INDEX ROWID| TAB_A INDEX RANGE SCAN TABLE ACCESS FULL FILTER SORT GROUP BY NOSORT INDEX RANGE SCAN

| IDX_TABA_COLA | | TAB_C | | | | |

| IDX_TABB_COLA |

- 18

Query Transformation-----------------------------------------------------------------------------------------------Predicate Information (identified by operation id): --------------------------------------------------1 - filter( IS NOT NULL) 2 - access("A"."COLA"="C"."COLA") 4 - access("A"."COLA"=1) 5 - filter("C"."COLA"=1) 6 - filter("B"."COLA"=:B1) 8 - access("COLA"=1)

TAB_A TAB_C HASH JOIN SubQuery FILTER . OPTIMIZER TAB_C TAB_B ResultSet TAB_A TBA_B .

----------------------------------------------------------------------------------------------| Id | Operation | Name | E-Rows | Cost (%CPU)| A-Rows | Buffers |

----------------------------------------------------------------------------------------------|* | |* |* | |* |* 1 | 2 | 3 | 4 | 5 | 6 | 7 | HASH JOIN | | | 63 | 1 | 1 | | 1 | 125 | 1260 | 1 1 115 117 2 1 (5)| (0)| (0)| | (0)| (0)| (5)| 682 | 1 | 1 | 1 | 1 | 63 | 682 | 549 | 5 | 4 | 2 | 2 | 2 | 544 |

TABLE ACCESS BY INDEX ROWID| TAB_A INDEX RANGE SCAN FILTER SORT GROUP BY NOSORT INDEX RANGE SCAN TABLE ACCESS FULL

| IDX_TABA_COLA | | | | |

| IDX_TABB_COLA | | TAB_C |

-----------------------------------------------------------------------------------------------

SubQuery TAB_B TAB_A TAB_C JOIN TAB_A . OPTIMIZER SUBQUERY ACCESS .

4.

CostBasedQueryTransformation

QueryTransformation . QueryTransformation . 10046 trace . QT . . QT - 19

Query Transformation. . QT . ? oracle 9i 10g . "_OPTIMIZER_push_pred_cost_based Hidden Parameter . DEFAULT VALUE 9i FALSE 10g TRUE . Hidden QueryTransformation COST (TRUE), RULE (FALSE) . 9i CBO QT RULE . QueryTransformation QT / QT . 10g QT COST , QT . 10g QT ? . QT . QUERY TRANSFORMATION . QUERY TRANSFORMATION . SQL-Tuning QUERY TRANSFORMAION . QT Tuning .

- 20