查看性能与WITH性能

时间:2018-06-25 11:29:01

标签: sql oracle performance views

我有一个查询,可以从视图和更多表中进行选择。

当我按原样执行此查询时-性能很差。

当我使用视图的查询并使用iframe将其添加到外部查询中时,它的运行速度非常快。

我的测试表明,问题不在于视图的查询本身,而在于优化器将视图数据与其他数据结合在一起的方式。

对此问题的解释是什么?

由于30K个字符的限制,选择查询中缺少一些字段。

WITH CLAUSE

视图查询(性能不佳)

--View:
CREATE OR REPLACE VIEW DWH.CC_MC_VIEW AS
SELECT /*+ full(E) */
DISTINCT/* a lot of fields */
FROM dwh.t2002_merkazei_tamhir_cur a
LEFT JOIN dwh.allovdim b
ON a.oved_achrai_char = TO_CHAR(b.mis_oved)
AND a.company         = b.company
LEFT JOIN dwh.t2003_kodei_merkazei_tamhir h
ON h.year     = TO_CHAR(SYSDATE-28,'yyyy')
AND h.erech   = a.c01_agaf
AND h.company = A.company
AND h.amuda   = '01'
LEFT JOIN dwh.t2003_kodei_merkazei_tamhir g
ON g.erech    = a.c03_minhal_rb
AND g.amuda   = '03'
AND g.year    = TO_CHAR(SYSDATE-28,'yyyy')
AND g.company = A.company
LEFT JOIN DWH_COMPANIES E
ON A.COMPANY = E.COM_COMPANY_CODE
LEFT JOIN dwh.t2003_kodei_merkazei_tamhir d
ON d.erech    = a.c02_minhalhativa
AND d.amuda   = '02'
AND D.year    = TO_CHAR(SYSDATE-28,'yyyy')
AND A.COMPANY = D.COMPANY
LEFT JOIN dwh.allovdim c
ON d.oved_achrai = c.mis_oved
AND d.company    = c.company
LEFT JOIN DWH_COMPANIES F
ON D.COMPANY    = F.COM_COMPANY_CODE
WHERE KOD_SGIRA = 1;

说明视图计划(效果不佳)

(SELECT  ROUND(dwh.plm_docdelivery.RELEASEDDATE-dwh.plm_docdelivery.PROCESSSTARTDATE),
ROUND(sysdate         -dwh.plm_docdelivery.PROCESSSTARTDATE),
dwh.plm_docdelivery.*,
dwh.cc_mc_view.*,
dwh.plm_programs.*,
FROM    dwh.plm_docdelivery,
DWH.PLM_PROGRAMS,
dwh.cc_mc_view,
dwh.allovdim ENG_OWNER,
dwh.plm_last_rev
WHERE
(
dwh.plm_docdelivery.PROGRAMNUMBER=dwh.plm_programs.PROGRAMNUMBER
AND dwh.plm_docdelivery.COMPANY=dwh.plm_programs.COMPANY
AND dwh.plm_docdelivery.LOGISTICCOMPANY=dwh.plm_programs.LOGISTICCOMPANY
)
AND
(
dwh.plm_docdelivery.ENGOWNERID= ENG_OWNER.EMP_ID(+)
)
AND
(
dwh.cc_mc_view.MERKAZ_TAMHIR(+)=ENG_OWNER.MIS_TAMH
AND dwh.cc_mc_view.COMPANY(+)  =ENG_OWNER.COMPANY
)
AND
(
dwh.plm_last_rev.COMPANY=dwh.plm_docdelivery.COMPANY
AND dwh.plm_last_rev.LOGISTICCOMPANY=dwh.plm_docdelivery.LOGISTICCOMPANY
AND dwh.plm_last_rev.PROGRAMNUMBER=dwh.plm_docdelivery.PROGRAMNUMBER
AND dwh.plm_last_rev.DOCUMENT=dwh.plm_docdelivery.DOCUMENT
)
AND
(ENG_OWNER.COMPANY<>'SOL')
AND
(dwh.plm_docdelivery.PROGRAMNUMBER IN ('X395','X419','X422','X379','X454','X372','X308', 'X394','X426','X433','X423','X391','X391A','X393','X490','X510','X460','X466A','X466B', 'X466C','X448','T622','T610','X461','X470','X520','X436','X560','D308','X922B','X922','X435', 'X494','X402','X995SP','X493','X481','X990','T799')
AND
(dwh.plm_docdelivery.CDRLTYPE    <> 'SDRL'
OR dwh.plm_docdelivery.CDRLTYPE IS NULL)
AND dwh.plm_last_rev.LAST_REV = dwh.plm_docdelivery.DOCUMENTREVISION
AND((dwh.plm_docdelivery.AUTHORDATE <= '16-07-2017 00:00:00'
AND(dwh.plm_docdelivery.STATUS    IN ( '(Freeze)','(Released)' )
OR dwh.plm_docdelivery.STATUS IS NULL))
OR dwh.plm_docdelivery.RELEASEDDATE IS NOT NULL)
AND dwh.plm_programs.COMPANY IN ('ESL','TCL'))
MINUS
SELECT  ROUND(dwh.plm_docdelivery.RELEASEDDATE-dwh.plm_docdelivery.PROCESSSTARTDATE),
ROUND(sysdate         -dwh.plm_docdelivery.PROCESSSTARTDATE),
dwh.plm_docdelivery.STATUS,
dwh.plm_docdelivery.SIGNERSLEFT,
dwh.plm_docdelivery.RELEASEDDATE,
dwh.plm_docdelivery.PROGRAMNUMBER,
dwh.plm_programs.PROGRAMNAME,
dwh.cc_mc_view.MINHALHATIVA,
TO_CHAR(dwh.plm_docdelivery.PLANNEDVALUE)
||
dwh.plm_docdelivery.TIMEUNIT
||
' '
||
CASE
WHEN dwh.plm_docdelivery.PLANNEDRELATION='After'
THEN '+'
WHEN dwh.plm_docdelivery.PLANNEDRELATION='Before'
THEN '-'
ELSE ''
END
||
dwh.plm_docdelivery.CDRLGATENAME,
ENG_OWNER.MISHPAHA,
ENG_OWNER.MISHPAHA_ENG,
ENG_OWNER.PRATI,
ENG_OWNER.PRATI_ENG,
dwh.plm_docdelivery.ENGOWNERID,
dwh.plm_docdelivery.ENGDISCIPLINE,
dwh.cc_mc_view.ACHRAI_HATIVA_NAME,
dwh.cc_mc_view.OVED_ACHRAI_HATIVA_FULL,
dwh.cc_mc_view.ACHRAI_MT_NAME,
dwh.cc_mc_view.OVED_ACHRAI_MT_FULL,
dwh.plm_docdelivery.DOCUMENTREVISION,
dwh.plm_docdelivery.DOCUMENTNAME,
dwh.plm_docdelivery.DOCUMENT,
dwh.plm_docdelivery.DELIVERY,
dwh.plm_docdelivery.CURRENTUSER ,
dwh.cc_mc_view.MERKAZ_TAMHIR,
dwh.plm_docdelivery.CDRLTYPE,
dwh.plm_docdelivery.CDRL,
dwh.plm_docdelivery.AUTHORDATE,
dwh.plm_docdelivery.DOC_REV_CREATION_DATE,
dwh.plm_docdelivery.DELIVERY_CREATION_DATE,
dwh.plm_docdelivery.GATEORIGINALDATE,
dwh.plm_programs.STATUS_DATE,
dwh.plm_docdelivery.ProcedureName,
dwh.plm_last_rev.LAST_REV,
dwh.plm_programs.COMPANY
FROM    dwh.plm_docdelivery,
DWH.PLM_PROGRAMS,
dwh.cc_mc_view,
dwh.allovdim ENG_OWNER,
dwh.plm_last_rev
WHERE
(dwh.plm_docdelivery.PROGRAMNUMBER      =dwh.plm_programs.PROGRAMNUMBER
AND dwh.plm_docdelivery.COMPANY        =dwh.plm_programs.COMPANY
AND dwh.plm_docdelivery.LOGISTICCOMPANY=dwh.plm_programs.LOGISTICCOMPANY)
AND
(dwh.plm_docdelivery.ENGOWNERID= ENG_OWNER.EMP_ID(+))
AND
(dwh.cc_mc_view.MERKAZ_TAMHIR(+)=ENG_OWNER.MIS_TAMH
AND dwh.cc_mc_view.COMPANY(+)  =ENG_OWNER.COMPANY)
AND
(dwh.plm_last_rev.COMPANY            =dwh.plm_docdelivery.COMPANY
AND dwh.plm_last_rev.LOGISTICCOMPANY=dwh.plm_docdelivery.LOGISTICCOMPANY
AND dwh.plm_last_rev.PROGRAMNUMBER  =dwh.plm_docdelivery.PROGRAMNUMBER
AND dwh.plm_last_rev.DOCUMENT       =dwh.plm_docdelivery.DOCUMENT)
AND
(ENG_OWNER.COMPANY<>'SOL')
AND
(dwh.plm_docdelivery.PROGRAMNUMBER IN ('X395','X419','X422','X379','X454','X372','X308', 'X394','X426','X433','X423','X391','X391A','X393','X490','X510','X460','X466A','X466B', 'X466C','X448','T622','T610','X461','X470','X520','X436','X560','D308','X922B','X922','X435', 'X494','X402','X995SP','X493','X481','X990','T799')
AND dwh.plm_docdelivery.DELIVERY  IS NOT NULL
AND dwh.plm_docdelivery.DOCUMENT  IS NULL
AND dwh.plm_programs.COMPANY      IN ('CMP1','CMP2')))

带有WITH子句的变体(效果好)

Plan hash value: 822592127

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

| Id  | Operation| Name         | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT         |              |    57 | 52896 | 32848   (2)| 00:01:39 |
|   1 |  MINUS   |              |       |       |            |          |
|   2 |   SORT UNIQUE            |              |    57 | 26448 | 16424   (2)| 00:00:50 |
|   3 |    NESTED LOOPS OUTER    |              |    57 | 26448 | 16423   (2)| 00:00:50 |
|   4 |     NESTED LOOPS         |              |    20 |  5540 | 14146   (3)| 00:00:43 |
|*  5 |      HASH JOIN           |              |    20 |  4660 | 14106   (3)| 00:00:43 |
|*  6 |       TABLE ACCESS FULL  | PLM_LAST_REV |    50 |  1300 | 13959   (3)| 00:00:42 |
|   7 |       NESTED LOOPS       |              |   798 |   161K|   147   (2)| 00:00:01 |
|   8 |        NESTED LOOPS      |              |   798 |   161K|   147   (2)| 00:00:01 |
|*  9 |         TABLE ACCESS FULL| PLM_PROGRAMS |    44 |  1496 |    14   (8)| 00:00:01 |
|* 10 |         INDEX RANGE SCAN | IDX_DELIVERY_1               |     1 |       |     2   (0)| 00:00:01 |
|* 11 |        TABLE ACCESS BY INDEX ROWID       | PLM_DOCDELIVERY              |    18 |  3114 |     3   (0)| 00:00:01 |
|  12 |      TABLE ACCESS BY INDEX ROWID         | ALLOVDIM     |     1 |    44 |     2   (0)| 00:00:01 |
|* 13 |       INDEX RANGE SCAN   | ALLOVDIM_I_EMP_CMP           |     1 |       |     1   (0)| 00:00:01 |
|  14 |     VIEW PUSHED PREDICATE| CC_MC_VIEW   |     1 |   187 |   114   (2)| 00:00:01 |
|  15 |      SORT UNIQUE         |              |     1 |   217 |   114   (2)| 00:00:01 |
|* 16 |       FILTER             |              |       |       |            |          |
|  17 |        NESTED LOOPS OUTER|              |     1 |   217 |   113   (1)| 00:00:01 |
|  18 |         NESTED LOOPS OUTER               |              |     1 |   173 |    97   (2)| 00:00:01 |
|* 19 |          HASH JOIN OUTER |              |     1 |   167 |    96   (2)| 00:00:01 |
|  20 |           NESTED LOOPS OUTER             |              |     1 |   161 |    48   (0)| 00:00:01 |
|  21 |            NESTED LOOPS OUTER            |              |     1 |   117 |    46   (0)| 00:00:01 |
|  22 |             NESTED LOOPS OUTER           |              |     1 |    90 |    32   (0)| 00:00:01 |
|  23 |              NESTED LOOPS OUTER          |              |     1 |    65 |    18   (0)| 00:00:01 |
|* 24 |               TABLE ACCESS BY INDEX ROWID| T2002_MERKAZEI_TAMHIR_CUR    |     1 |    40 |     4   (0)| 00:00:01 |
|* 25 |INDEX RANGE SCAN          | T2002_MERKAZEI_TAMHIR_CUR_I1 |     3 |       |     1   (0)| 00:00:01 |
|  26 |               TABLE ACCESS BY INDEX ROWID| T2003_KODEI_MERKAZEI_TAMHIR  |     1 |    25 |    14   (0)| 00:00:01 |
|* 27 |INDEX RANGE SCAN          | T2003_K_MT97_Y_AE_I          |     1 |       |    13   (0)| 00:00:01 |
|  28 |              TABLE ACCESS BY INDEX ROWID | T2003_KODEI_MERKAZEI_TAMHIR  |     1 |    25 |    14   (0)| 00:00:01 |
|* 29 |               INDEX RANGE SCAN           | T2003_K_MT97_Y_AE_I          |     1 |       |    13   (0)| 00:00:01 |
|  30 |             TABLE ACCESS BY INDEX ROWID  | T2003_KODEI_MERKAZEI_TAMHIR  |     1 |    27 |    14   (0)| 00:00:01 |
|* 31 |              INDEX RANGE SCAN            | T2003_K_MT97_Y_AE_I          |     1 |       |    13   (0)| 00:00:01 |
|  32 |            TABLE ACCESS BY INDEX ROWID   | ALLOVDIM     |     1 |    44 |     2   (0)| 00:00:01 |
|* 33 |             INDEX RANGE SCAN             | ALLOVDIM_I_CMP_MIS           |     1 |       |     1   (0)| 00:00:01 |
|* 34 |           TABLE ACCESS FULL              | DWH_COMPANIES|     1 |     6 |    47   (0)| 00:00:01 |
|  35 |          TABLE ACCESS BY INDEX ROWID     | DWH_COMPANIES|     1 |     6 |     1   (0)| 00:00:01 |
|* 36 |           INDEX UNIQUE SCAN              | COMP_IDX1    |     1 |       |     0   (0)| 00:00:01 |
|  37 |         TABLE ACCESS BY INDEX ROWID      | ALLOVDIM     |     1 |    44 |    16   (0)| 00:00:01 |
|* 38 |          INDEX RANGE SCAN| ALLOVDIM_I_CMP_MIS           |     1 |       |    15   (0)| 00:00:01 |
|  39 |   SORT UNIQUE            |              |    57 | 26448 | 16424   (2)| 00:00:50 |
|  40 |    NESTED LOOPS OUTER    |              |    57 | 26448 | 16423   (2)| 00:00:50 |
|  41 |     NESTED LOOPS         |              |    20 |  5540 | 14145   (3)| 00:00:43 |
|* 42 |      HASH JOIN           |              |    20 |  4660 | 14105   (3)| 00:00:43 |
|* 43 |       TABLE ACCESS FULL  | PLM_LAST_REV |    50 |  1300 | 13959   (3)| 00:00:42 |
|  44 |       NESTED LOOPS       |              |    64 | 13248 |   146   (1)| 00:00:01 |
|  45 |        NESTED LOOPS      |              |    64 | 13248 |   146   (1)| 00:00:01 |
|* 46 |         TABLE ACCESS FULL| PLM_PROGRAMS |    44 |  1496 |    14   (8)| 00:00:01 |
|* 47 |         INDEX RANGE SCAN | IDX_DELIVERY_1               |     1 |       |     2   (0)| 00:00:01 |
|* 48 |        TABLE ACCESS BY INDEX ROWID       | PLM_DOCDELIVERY              |     1 |   173 |     3   (0)| 00:00:01 |
|  49 |      TABLE ACCESS BY INDEX ROWID         | ALLOVDIM     |     1 |    44 |     2   (0)| 00:00:01 |
|* 50 |       INDEX RANGE SCAN   | ALLOVDIM_I_EMP_CMP           |     1 |       |     1   (0)| 00:00:01 |
|  51 |     VIEW PUSHED PREDICATE| CC_MC_VIEW   |     1 |   187 |   114   (2)| 00:00:01 |
|  52 |      SORT UNIQUE         |              |     1 |   217 |   114   (2)| 00:00:01 |
|* 53 |       FILTER             |              |       |       |            |          |
|  54 |        NESTED LOOPS OUTER|              |     1 |   217 |   113   (1)| 00:00:01 |
|  55 |         NESTED LOOPS OUTER               |              |     1 |   173 |    97   (2)| 00:00:01 |
|* 56 |          HASH JOIN OUTER |              |     1 |   167 |    96   (2)| 00:00:01 |
|  57 |           NESTED LOOPS OUTER             |              |     1 |   161 |    48   (0)| 00:00:01 |
|  58 |            NESTED LOOPS OUTER            |              |     1 |   117 |    46   (0)| 00:00:01 |
|  59 |             NESTED LOOPS OUTER           |              |     1 |    90 |    32   (0)| 00:00:01 |
|  60 |              NESTED LOOPS OUTER          |              |     1 |    65 |    18   (0)| 00:00:01 |
|* 61 |               TABLE ACCESS BY INDEX ROWID| T2002_MERKAZEI_TAMHIR_CUR    |     1 |    40 |     4   (0)| 00:00:01 |
|* 62 |INDEX RANGE SCAN          | T2002_MERKAZEI_TAMHIR_CUR_I1 |     3 |       |     1   (0)| 00:00:01 |
|  63 |               TABLE ACCESS BY INDEX ROWID| T2003_KODEI_MERKAZEI_TAMHIR  |     1 |    25 |    14   (0)| 00:00:01 |
|* 64 |INDEX RANGE SCAN          | T2003_K_MT97_Y_AE_I          |     1 |       |    13   (0)| 00:00:01 |
|  65 |              TABLE ACCESS BY INDEX ROWID | T2003_KODEI_MERKAZEI_TAMHIR  |     1 |    25 |    14   (0)| 00:00:01 |
|* 66 |               INDEX RANGE SCAN           | T2003_K_MT97_Y_AE_I          |     1 |       |    13   (0)| 00:00:01 |
|  67 |             TABLE ACCESS BY INDEX ROWID  | T2003_KODEI_MERKAZEI_TAMHIR  |     1 |    27 |    14   (0)| 00:00:01 |
|* 68 |              INDEX RANGE SCAN            | T2003_K_MT97_Y_AE_I          |     1 |       |    13   (0)| 00:00:01 |
|  69 |            TABLE ACCESS BY INDEX ROWID   | ALLOVDIM     |     1 |    44 |     2   (0)| 00:00:01 |
|* 70 |             INDEX RANGE SCAN             | ALLOVDIM_I_CMP_MIS           |     1 |       |     1   (0)| 00:00:01 |
|* 71 |           TABLE ACCESS FULL              | DWH_COMPANIES|     1 |     6 |    47   (0)| 00:00:01 |
|  72 |          TABLE ACCESS BY INDEX ROWID     | DWH_COMPANIES|     1 |     6 |     1   (0)| 00:00:01 |
|* 73 |           INDEX UNIQUE SCAN              | COMP_IDX1    |     1 |       |     0   (0)| 00:00:01 |
|  74 |         TABLE ACCESS BY INDEX ROWID      | ALLOVDIM     |     1 |    44 |    16   (0)| 00:00:01 |
|* 75 |          INDEX RANGE SCAN| ALLOVDIM_I_CMP_MIS           |     1 |       |    15   (0)| 00:00:01 |

解释WITH子句的计划

with CC as
(SELECT /*+full(E) */  
DISTINCT/* a lot of fields */
FROM dwh.t2002_merkazei_tamhir_cur a
LEFT JOIN dwh.allovdim b
ON a.oved_achrai_char = TO_CHAR(b.mis_oved)
AND a.company         = b.company
LEFT JOIN dwh.t2003_kodei_merkazei_tamhir h
ON h.year     = TO_CHAR(SYSDATE-28,'yyyy')
AND h.erech   = a.c01_agaf
AND h.company = A.company
AND h.amuda   = '01'
LEFT JOIN dwh.t2003_kodei_merkazei_tamhir g
ON g.erech    = a.c03_minhal_rb
AND g.amuda   = '03'
AND g.year    = TO_CHAR(SYSDATE-28,'yyyy')
AND g.company = A.company
LEFT JOIN DWH_COMPANIES E
ON A.COMPANY = E.COM_COMPANY_CODE
LEFT JOIN dwh.t2003_kodei_merkazei_tamhir d
ON d.erech    = a.c02_minhalhativa
AND d.amuda   = '02'
AND D.year    = TO_CHAR(SYSDATE-28,'yyyy')
AND A.COMPANY = D.COMPANY
LEFT JOIN dwh.allovdim c
ON d.oved_achrai = c.mis_oved
AND d.company    = c.company
LEFT JOIN DWH_COMPANIES F
on D.COMPANY    = F.COM_COMPANY_CODE
WHERE KOD_SGIRA = 1
)
(
SELECT  ROUND(dwh.plm_docdelivery.RELEASEDDATE-dwh.plm_docdelivery.PROCESSSTARTDATE),
ROUND(sysdate         -dwh.plm_docdelivery.PROCESSSTARTDATE),
dwh.plm_docdelivery.*,
dwh.cc_mc_view.*,
dwh.plm_programs.*,
FROM dwh.plm_docdelivery,
DWH.PLM_PROGRAMS,
cc,
dwh.allovdim ENG_OWNER,
dwh.plm_last_rev
WHERE
(
dwh.plm_docdelivery.PROGRAMNUMBER=dwh.plm_programs.PROGRAMNUMBER
AND dwh.plm_docdelivery.COMPANY=dwh.plm_programs.COMPANY
AND dwh.plm_docdelivery.LOGISTICCOMPANY=dwh.plm_programs.LOGISTICCOMPANY
)
AND
(dwh.plm_docdelivery.ENGOWNERID= ENG_OWNER.EMP_ID(+))
AND
(cc.MERKAZ_TAMHIR(+)=ENG_OWNER.MIS_TAMH
AND cc.COMPANY(+)  =ENG_OWNER.COMPANY)
AND
(dwh.plm_last_rev.COMPANY            =dwh.plm_docdelivery.COMPANY
AND dwh.plm_last_rev.LOGISTICCOMPANY=dwh.plm_docdelivery.LOGISTICCOMPANY
AND dwh.plm_last_rev.PROGRAMNUMBER  =dwh.plm_docdelivery.PROGRAMNUMBER
AND dwh.plm_last_rev.DOCUMENT       =dwh.plm_docdelivery.DOCUMENT)
AND
(ENG_OWNER.COMPANY<>'SOL')
AND
(dwh.plm_docdelivery.PROGRAMNUMBER IN ('X395','X419','X422','X379','X454','X372','X308', 'X394','X426','X433','X423','X391','X391A','X393','X490','X510','X460','X466A','X466B', 'X466C','X448','T622','T610','X461','X470','X520','X436','X560','D308','X922B','X922','X435', 'X494','X402','X995SP','X493','X481','X990','T799')
AND
(dwh.plm_docdelivery.CDRLTYPE    <> 'SDRL'
OR dwh.plm_docdelivery.CDRLTYPE IS NULL)
AND dwh.plm_last_rev.LAST_REV = dwh.plm_docdelivery.DOCUMENTREVISION
AND((dwh.plm_docdelivery.AUTHORDATE <= '16-07-2017 00:00:00'
AND(dwh.plm_docdelivery.STATUS    IN ( '(Freeze)','(Released)' )
OR dwh.plm_docdelivery.STATUS IS NULL))
OR dwh.plm_docdelivery.RELEASEDDATE IS NOT NULL)
AND dwh.plm_programs.COMPANY IN ('ESL','TCL'))
MINUS
SELECT ROUND(dwh.plm_docdelivery.RELEASEDDATE-dwh.plm_docdelivery.PROCESSSTARTDATE),
ROUND(sysdate-dwh.plm_docdelivery.PROCESSSTARTDATE),
dwh.plm_docdelivery.STATUS,
dwh.plm_docdelivery.SIGNERSLEFT,
dwh.plm_docdelivery.RELEASEDDATE,
dwh.plm_docdelivery.PROGRAMNUMBER,
dwh.plm_programs.PROGRAMNAME,
cc.MINHALHATIVA,
TO_CHAR(dwh.plm_docdelivery.PLANNEDVALUE)
||
dwh.plm_docdelivery.TIMEUNIT
||
' '
||
CASE
WHEN dwh.plm_docdelivery.PLANNEDRELATION='After'
THEN '+'
WHEN dwh.plm_docdelivery.PLANNEDRELATION='Before'
THEN '-'
ELSE ''
END
||
dwh.plm_docdelivery.CDRLGATENAME,
ENG_OWNER.MISHPAHA,
ENG_OWNER.MISHPAHA_ENG,
ENG_OWNER.PRATI,
ENG_OWNER.PRATI_ENG,
dwh.plm_docdelivery.ENGOWNERID,
dwh.plm_docdelivery.ENGDISCIPLINE,
cc.ACHRAI_HATIVA_NAME,
cc.OVED_ACHRAI_HATIVA_FULL,
cc.ACHRAI_MT_NAME,
cc.OVED_ACHRAI_MT_FULL,
dwh.plm_docdelivery.DOCUMENTREVISION,
dwh.plm_docdelivery.DOCUMENTNAME,
dwh.plm_docdelivery.DOCUMENT,
dwh.plm_docdelivery.DELIVERY,
dwh.plm_docdelivery.CURRENTUSER ,
cc.MERKAZ_TAMHIR,
dwh.plm_docdelivery.CDRLTYPE,
dwh.plm_docdelivery.CDRL,
dwh.plm_docdelivery.AUTHORDATE,
dwh.plm_docdelivery.DOC_REV_CREATION_DATE,
dwh.plm_docdelivery.DELIVERY_CREATION_DATE,
dwh.plm_docdelivery.GATEORIGINALDATE,
dwh.plm_programs.STATUS_DATE,
dwh.plm_docdelivery.ProcedureName,
dwh.plm_last_rev.LAST_REV,
dwh.plm_programs.COMPANY
FROM dwh.plm_docdelivery,DWH.PLM_PROGRAMS,cc,dwh.allovdim ENG_OWNER,dwh.plm_last_rev
WHERE(dwh.plm_docdelivery.PROGRAMNUMBER=dwh.plm_programs.PROGRAMNUMBER
AND dwh.plm_docdelivery.COMPANY=dwh.plm_programs.COMPANY
AND dwh.plm_docdelivery.LOGISTICCOMPANY=dwh.plm_programs.LOGISTICCOMPANY)
AND(dwh.plm_docdelivery.ENGOWNERID=ENG_OWNER.EMP_ID(+))
AND(cc.MERKAZ_TAMHIR(+)=ENG_OWNER.MIS_TAMH
AND cc.COMPANY(+)=ENG_OWNER.COMPANY)
AND(dwh.plm_last_rev.COMPANY=dwh.plm_docdelivery.COMPANY
AND dwh.plm_last_rev.LOGISTICCOMPANY=dwh.plm_docdelivery.LOGISTICCOMPANY
AND dwh.plm_last_rev.PROGRAMNUMBER=dwh.plm_docdelivery.PROGRAMNUMBER
AND dwh.plm_last_rev.DOCUMENT=dwh.plm_docdelivery.DOCUMENT)
AND(ENG_OWNER.COMPANY<>'SOL')
AND(dwh.plm_docdelivery.PROGRAMNUMBER IN ('X395','X419','X422','X379','X454','X372','X308', 'X394','X426','X433','X423','X391','X391A','X393','X490','X510','X460','X466A','X466B', 'X466C','X448','T622','T610','X461','X470','X520','X436','X560','D308','X922B','X922','X435', 'X494','X402','X995SP','X493','X481','X990','T799')
AND dwh.plm_docdelivery.DELIVERY IS NOT NULL
AND dwh.plm_docdelivery.DOCUMENT IS NULL
AND dwh.plm_programs.COMPANY IN ('CMP1','CMP2'))); 

2 个答案:

答案 0 :(得分:3)

  

“一般来说,我想知道为什么视图和视图之间有区别”

在调优中有非常普遍适用的规则。通常情况取决于具体情况。因此,您的情况相关,关键是第二个解释计划中的这一步骤:

TEMP TABLE TRANSFORMATION            

基本上,调优连接表和视图的查询非常困难,因为优化器无法真正确定视图将返回多少行。就像这里所做的那样,这通常会导致一个糟糕的计划。如果您查看第一个计划,则优化器选择了VIEW PUSHED PREDICATE。这意味着它将为其他表中的每一行查询一次视图。两次,因为有了MINUS运算符。由于优化器将谓词推入视图查询(ENG_OWNER.MIS_TAMH, ENG_OWNER.COMPANY)中,因此它使用了一系列嵌套循环来执行视图的查询。对于大表,这可能是一项昂贵的操作。

因此,通过WITH子句,优化器可以查看一个查询中的所有表,并可以决定将子查询结果集具体化为临时表。临时表并不总是有效的,因为它们涉及到临时表空间的写入和读取,而且许多DBA都不会费心去适当地配置其表空间。但是,实现的最大优点是视图查询仅执行一次,并且(只要结果集足够小)读取一次并保存在内存中。

由于实现似乎可行,您可以使用提示。

代替从视图中获取整个查询的WITH子句

with CC_MC_VIEW  as (select /*+ materialize  */ 
                     from dwh.CC_MC_VIEW )
select ...

答案 1 :(得分:1)

通常在Oracle上应该没有区别。 With子句可以是INLINEed或MATERIALIZEd。查看文档,了解如何使用这些提示。同样,可以修改将VIEW“嵌入”执行计划的方式。查看文档和搜索参数complex_view_merging / simple_view_merging。

您能做的最好的就是比较两者的执行计划。没有看到他们,没有人可以帮助您。从理论上讲,如果两种情况下Oracle优化器应返回相同的结果,则应生成相同的执行计划。

更新:在第二种情况下,视图已进行了材料化(请参见TEMP TABLE TRANSFORMATION)。 Oracle将VIEW查询上的内容存储到TEMP表空间中,并将其用于进一步的联接。从理论上讲,这应该比内联(第一种情况)要慢。

如@William INLINE / MATERIALIZE提示所指出的

尚未正式记录。 不幸的是,其他参数也没有记载。 尝试使用sqlplus(不是SqlDeveloper)4x执行慢查询,并通过设置(全部4种组合/ true / false)更改CBO参数

alter session set "_complex_view_merging"=true;
alter session set "_simple_view_merging"=true;

看看会发生什么。并且可能值得尝试从VIEW定义中删除FULL提示。您永远不会知道您将如何使用该视图,将使用哪些谓词,因此可能不需要表DWH_COMPANIES上的“ FULL TABLE SCAN”。