Oracle:复杂查询作为查询运行速度非常快,因为查看

时间:2016-01-14 16:45:29

标签: oracle performance indexing views

我有一个基于UNION ALL的几个SELECT的View,每个都使用UNPIVOT,对于特定情况,在查询View时运行速度非常慢,但在查询基础查询时非常快。

以下是View上查询的解释计划:

select * from MY_SLOW_VIEW where SourceID='1234567890';

Slow View

与基础查询的解释计划相比:

select * from (select ... ) where SourceID='1234567890';

Fast Query

现在看起来像使用View时索引不起作用。 我已经尝试在各个选项中添加INDEX提示,这些选择是联合所有,但没有效果。

(SourceID是显示为String的几个表中的oid。)

这是代码(释义):

    CREATE OR REPLACE FORCE VIEW "MY_SLOW_VIEW" (
      "SOURCEID", 
      "ACTIONPARAMETERKEY", 
      "ACTIONPARAMETERVALUE", 
      "UPDDAT") 

    AS

    SELECT 
       cast(sourceid as varchar2(50)) as sourceid,
       actionparameterkey,
       actionparametervalue, 
       upddat  

    FROM (

    (   SELECT 
            sourceid,
            actionparameterkey,
            to_char(actionparametervalue) as actionparametervalue, 
            upddat
        FROM 
        (   select 
                table1.oid as sourceid, 
                table1.upddat as upddat,  
                to_char(table1.status) as status, 
                to_char(table1.typ) as typ,     
            from table1)
            UNPIVOT (actionparametervalue for actionparameterkey in (
                    typ as 'policyType', 
                    status as 'policyStatus')
        )
    )

    UNION ALL

    (   SELECT 
            sourceid,
            actionparameterkey,
            to_char(actionparametervalue) as actionparametervalue, 
            upddat
        FROM 
        (   select 
                table2.oid as sourceid, 
                table2.upddat as upddat,  
                to_char(table2.productKey) as productKey, 
                to_char(table2.contractID) as contractId,     
            from table2)
        UNPIVOT (actionparametervalue for actionparameterkey in (
                    productKey as 'productKey', 
                    contractId as 'contractId')
        )
    )

    UNION ALL

            [snip]

    )

是否有任何提示作为如何使索引在视图中工作,或任何其他关于问题可能是什么的提示?

由于

[编辑 - 按照kordirko的建议添加计划表输出]

首先..原始查询

"PLAN_TABLE_OUTPUT"
"Plan hash value: 2498531538"
" "
"----------------------------------------------------------------------------------------------------------------------"
"| Id  | Operation                             | Name                         | Rows  | Bytes | Cost (%CPU)| Time     |"
"----------------------------------------------------------------------------------------------------------------------"
"|   0 | SELECT STATEMENT                      |                              |     6 |   624 |    81   (7)| 00:00:01 |"
"|   1 |  VIEW                                 |                              |     6 |   624 |    81   (7)| 00:00:01 |"
"|   2 |   UNION-ALL                           |                              |       |       |            |          |"
"|   3 |    HASH UNIQUE                        |                              |     1 |    79 |    36   (3)| 00:00:01 |"
"|*  4 |     VIEW                              |                              |    21 |  1659 |    35   (0)| 00:00:01 |"
"|   5 |      UNPIVOT                          |                              |       |       |            |          |"
"|   6 |       NESTED LOOPS                    |                              |     3 |   498 |     5   (0)| 00:00:01 |"
"|   7 |        NESTED LOOPS                   |                              |     3 |   498 |     5   (0)| 00:00:01 |"
"|   8 |         NESTED LOOPS                  |                              |     3 |   378 |     4   (0)| 00:00:01 |"
"|   9 |          NESTED LOOPS                 |                              |     3 |   339 |     3   (0)| 00:00:01 |"
"|  10 |           NESTED LOOPS                |                              |     1 |    99 |     2   (0)| 00:00:01 |"
"|  11 |            TABLE ACCESS BY INDEX ROWID| PLANANSCHLUSS                |     1 |    46 |     1   (0)| 00:00:01 |"
"|* 12 |             INDEX UNIQUE SCAN         | SYS_C0012952                 |     1 |       |     1   (0)| 00:00:01 |"
"|  13 |            TABLE ACCESS BY INDEX ROWID| ANSCHLUSS                    |     1 |    53 |     1   (0)| 00:00:01 |"
"|* 14 |             INDEX UNIQUE SCAN         | SYS_C0012832                 |     1 |       |     1   (0)| 00:00:01 |"
"|  15 |           TABLE ACCESS BY INDEX ROWID | VERSICHERTER                 |     3 |    42 |     1   (0)| 00:00:01 |"
"|* 16 |            INDEX RANGE SCAN           | IX6_VERSICHERTER             |     3 |       |     1   (0)| 00:00:01 |"
"|* 17 |          TABLE ACCESS BY INDEX ROWID  | PARTNERROLLE                 |     1 |    13 |     1   (0)| 00:00:01 |"
"|* 18 |           INDEX UNIQUE SCAN           | SYS_C0012947                 |     1 |       |     1   (0)| 00:00:01 |"
"|* 19 |         INDEX RANGE SCAN              | IX5_NATPERSON                |     1 |       |     1   (0)| 00:00:01 |"
"|  20 |        TABLE ACCESS BY INDEX ROWID    | NATPERSON                    |     1 |    40 |     1   (0)| 00:00:01 |"
"|  21 |    NESTED LOOPS                       |                              |     1 |    24 |     4   (0)| 00:00:01 |"
"|  22 |     NESTED LOOPS                      |                              |     1 |    24 |     4   (0)| 00:00:01 |"
"|* 23 |      TABLE ACCESS FULL                | INVESTITION                  |     1 |    14 |     3   (0)| 00:00:01 |"
"|* 24 |      INDEX UNIQUE SCAN                | INVESTITION_AUFTRAG_PK       |     1 |       |     1   (0)| 00:00:01 |"
"|* 25 |     TABLE ACCESS BY INDEX ROWID       | INVESTITION_AUFTRAG          |     1 |    10 |     1   (0)| 00:00:01 |"
"|* 26 |    FILTER                             |                              |       |       |            |          |"
"|* 27 |     TABLE ACCESS BY INDEX ROWID       | PLANANSCHLUSS                |     1 |    40 |     1   (0)| 00:00:01 |"
"|* 28 |      INDEX UNIQUE SCAN                | SYS_C0012952                 |     1 |       |     1   (0)| 00:00:01 |"
"|* 29 |     TABLE ACCESS BY INDEX ROWID       | PLANANSCHLUSS                |     1 |    37 |     1   (0)| 00:00:01 |"
"|* 30 |      INDEX RANGE SCAN                 | IX5_PLA_VERSICHERTERID       |     1 |       |     1   (0)| 00:00:01 |"
"|  31 |    HASH UNIQUE                        |                              |     2 |    98 |     5  (20)| 00:00:01 |"
"|* 32 |     VIEW                              |                              |     2 |    98 |     4   (0)| 00:00:01 |"
"|  33 |      UNPIVOT                          |                              |       |       |            |          |"
"|* 34 |       FILTER                          |                              |       |       |            |          |"
"|  35 |        NESTED LOOPS OUTER             |                              |     1 |    75 |     2   (0)| 00:00:01 |"
"|* 36 |         TABLE ACCESS BY INDEX ROWID   | MUTBELEG_AKTIVE_STAND        |     1 |    34 |     1   (0)| 00:00:01 |"
"|* 37 |          INDEX RANGE SCAN             | IX1_MUTB_A_PLAFKOID_CALCDATE |    10 |       |     1   (0)| 00:00:01 |"
"|* 38 |         TABLE ACCESS BY INDEX ROWID   | MUTBELEG_AKTIVE_STAND        |     1 |    41 |     1   (0)| 00:00:01 |"
"|* 39 |          INDEX RANGE SCAN             | IX1_MUTB_A_PLAFKOID_CALCDATE |    10 |       |     1   (0)| 00:00:01 |"
"|  40 |    HASH UNIQUE                        |                              |     1 |    79 |    31   (4)| 00:00:01 |"
"|* 41 |     VIEW                              |                              |     6 |   474 |    30   (0)| 00:00:01 |"
"|  42 |      UNPIVOT                          |                              |       |       |            |          |"
"|  43 |       NESTED LOOPS                    |                              |     1 |   159 |     5   (0)| 00:00:01 |"
"|  44 |        NESTED LOOPS                   |                              |     1 |   119 |     4   (0)| 00:00:01 |"
"|  45 |         NESTED LOOPS                  |                              |     1 |   106 |     3   (0)| 00:00:01 |"
"|  46 |          NESTED LOOPS                 |                              |     1 |    90 |     2   (0)| 00:00:01 |"
"|  47 |           TABLE ACCESS BY INDEX ROWID | RV_POLICE                    |     1 |    37 |     1   (0)| 00:00:01 |"
"|* 48 |            INDEX UNIQUE SCAN          | PK_RV_POLICE                 |     1 |       |     1   (0)| 00:00:01 |"
"|  49 |           TABLE ACCESS BY INDEX ROWID | ANSCHLUSS                    |     1 |    53 |     1   (0)| 00:00:01 |"
"|* 50 |            INDEX UNIQUE SCAN          | SYS_C0012832                 |     1 |       |     1   (0)| 00:00:01 |"
"|  51 |          TABLE ACCESS BY INDEX ROWID  | RV_LEISTUNGSFALL             |     1 |    16 |     1   (0)| 00:00:01 |"
"|* 52 |           INDEX UNIQUE SCAN           | PK_RV_LEISTUNGSFALL          |     1 |       |     1   (0)| 00:00:01 |"
"|* 53 |         TABLE ACCESS BY INDEX ROWID   | PARTNERROLLE                 |     1 |    13 |     1   (0)| 00:00:01 |"
"|* 54 |          INDEX UNIQUE SCAN            | SYS_C0012947                 |     1 |       |     1   (0)| 00:00:01 |"
"|  55 |        TABLE ACCESS BY INDEX ROWID    | NATPERSON                    |     1 |    40 |     1   (0)| 00:00:01 |"
"|* 56 |         INDEX RANGE SCAN              | IX5_NATPERSON                |     1 |       |     1   (0)| 00:00:01 |"
"|* 57 |    VIEW                               |                              |     1 |    91 |     2  (50)| 00:00:01 |"
"|* 58 |     TABLE ACCESS BY INDEX ROWID       | RV_LEISTUNGBASIS             |     1 |    42 |     1   (0)| 00:00:01 |"
"|* 59 |      INDEX RANGE SCAN                 | IX1_RV_LEISTUNGBASIS         |     1 |       |     1   (0)| 00:00:01 |"
"|  60 |     HASH UNIQUE                       |                              |     1 |    35 |     2  (50)| 00:00:01 |"
"|  61 |      TABLE ACCESS BY INDEX ROWID      | RV_LEISTUNGBASIS             |     1 |    35 |     1   (0)| 00:00:01 |"
"|* 62 |       INDEX RANGE SCAN                | IX1_RV_LEISTUNGBASIS         |     1 |       |     1   (0)| 00:00:01 |"
"----------------------------------------------------------------------------------------------------------------------"
" "
"Predicate Information (identified by operation id):"
"---------------------------------------------------"
" "
"   4 - filter(""unpivot_view_069"".""ACTIONPARAMETERVALUE"" IS NOT NULL)"
"  12 - access(""PA"".""OID""=3505032127)"
"  14 - access(""PA"".""ANSCHLUSSFKOID""=""A"".""OID"")"
"  16 - access(""PA"".""VERSICHERTERFKID""=""V"".""ID"")"
"  17 - filter(""PR"".""NATPERSONFKID"" IS NOT NULL)"
"  18 - access(""V"".""ROLLEVERSICHERTERFKOID""=""PR"".""OID"")"
"  19 - access(""PR"".""NATPERSONFKID""=""NP"".""ID"")"
"  23 - filter(""INV"".""PLANANSCHLUSSFKOID""=:B1)"
"  24 - access(""INV"".""AUFTRAGFKOID""=""INV_AUF"".""OID"")"
"  25 - filter(""INV_AUF"".""ISBESTAETIG""=0)"
"  26 - filter(CASE  WHEN  EXISTS (SELECT 0 FROM ""PLANANSCHLUSS"" ""PA2"" WHERE ""PA2"".""VERSICHERTERFKID""=:B1 AND "
"              ""PA2"".""ANSCHLUSSFKOID""=:B2 AND NVL(""PA2"".""UPDDAT"",""PA2"".""CREDAT"")>NVL(:B3,:B4)) THEN 0 ELSE 1 END =1)"
"  27 - filter(""PA"".""ISIVA""=1)"
"  28 - access(""PA"".""OID""=3505032127)"
"       filter(CASE  WHEN  EXISTS (SELECT 0 FROM ""INVESTITION_AUFTRAG"" ""INV_AUF"",""INVESTITION"" ""INV"" WHERE "
"              ""INV"".""PLANANSCHLUSSFKOID""=:B1 AND ""INV"".""AUFTRAGFKOID""=""INV_AUF"".""OID"" AND ""INV_AUF"".""ISBESTAETIG""=0) THEN "
"              '1' ELSE '0' END  IS NOT NULL)"
"  29 - filter(""PA2"".""ANSCHLUSSFKOID""=:B1 AND NVL(""PA2"".""UPDDAT"",""PA2"".""CREDAT"")>NVL(:B2,:B3))"
"  30 - access(""PA2"".""VERSICHERTERFKID""=:B1)"
"  32 - filter(""unpivot_view_079"".""ACTIONPARAMETERVALUE"" IS NOT NULL)"
"  34 - filter(""MAS2"".""OID"" IS NULL)"
"  36 - filter(""MAS"".""ISTAKTUELLSTER""=1 AND CASE NVL(""MAS"".""PRODUKTSUBCD"",""MAS"".""PRODUKTCD"") WHEN 'na' THEN "
"              ""MAS"".""PRODUKTCD"" ELSE NVL(""MAS"".""PRODUKTSUBCD"",""MAS"".""PRODUKTCD"") END  IS NOT NULL)"
"  37 - access(""MAS"".""PLANANSCHLUSSFKOID""=3505032127)"
"  38 - filter(""MAS2"".""ISTAKTUELLSTER""(+)=1 AND ""MAS2"".""CREDAT""(+)>""MAS"".""CREDAT"" AND "
"              NVL(""MAS2"".""PLANMERKMALCD2""(+),'ERWP')=NVL(""MAS"".""PLANMERKMALCD2"",'ERWP') AND CASE "
"              NVL(""MAS"".""PRODUKTSUBCD"",""MAS"".""PRODUKTCD"") WHEN 'na' THEN ""MAS"".""PRODUKTCD"" ELSE "
"              NVL(""MAS"".""PRODUKTSUBCD"",""MAS"".""PRODUKTCD"") END =CASE NVL(""MAS2"".""PRODUKTSUBCD""(+),""MAS2"".""PRODUKTCD""(+)) "
"              WHEN 'na' THEN ""MAS2"".""PRODUKTCD""(+) ELSE NVL(""MAS2"".""PRODUKTSUBCD""(+),""MAS2"".""PRODUKTCD""(+)) END )"
"  39 - access(""MAS2"".""PLANANSCHLUSSFKOID""(+)=3505032127)"
"  41 - filter(""unpivot_view_111"".""ACTIONPARAMETERVALUE"" IS NOT NULL)"
"  48 - access(""POL"".""OID""=3505032127)"
"  50 - access(""POL"".""X_ANSCHLUSSFKOID""=""A"".""OID"")"
"  52 - access(""POL"".""RV_LEISTUNGSFALLFKOID""=""LF"".""OID"")"
"  53 - filter(""PR"".""NATPERSONFKID"" IS NOT NULL)"
"  54 - access(""LF"".""ROLLERENTNERFKOID""=""PR"".""OID"")"
"  56 - access(""PR"".""NATPERSONFKID""=""NP"".""ID"")"
"  57 - filter(""from$_subquery$_028"".""ISTAKTUELLSTER""=1)"
"  58 - filter(""RV2"".""LEISTUNGCD""=:B1 AND NVL(""RV2"".""UPDDAT"",""RV2"".""CREDAT"")>NVL(:B2,:B3))"
"  59 - access(""RV2"".""RV_POLICEFKOID""=:B1)"
"  62 - access(""RV"".""RV_POLICEFKOID""=3505032127)"

第二个..查看视图

"PLAN_TABLE_OUTPUT"
"Plan hash value: 2116722895"
" "
"----------------------------------------------------------------------------------------------------------------------"
"| Id  | Operation                             | Name                         | Rows  | Bytes | Cost (%CPU)| Time     |"
"----------------------------------------------------------------------------------------------------------------------"
"|   0 | SELECT STATEMENT                      |                              |     6 |   624 |   199K  (1)| 00:39:50 |"
"|   1 |  VIEW                                 |                              |     6 |   624 |   199K  (1)| 00:39:50 |"
"|   2 |   UNION-ALL                           |                              |       |       |            |          |"
"|   3 |    HASH UNIQUE                        |                              |     1 |    79 | 20007   (1)| 00:04:01 |"
"|*  4 |     VIEW                              |                              |    21 |  1659 | 20006   (1)| 00:04:01 |"
"|   5 |      UNPIVOT                          |                              |       |       |            |          |"
"|   6 |       NESTED LOOPS                    |                              |     3 |   498 |  2858   (1)| 00:00:35 |"
"|   7 |        NESTED LOOPS                   |                              |     3 |   498 |  2858   (1)| 00:00:35 |"
"|   8 |         NESTED LOOPS                  |                              |     3 |   378 |  2857   (1)| 00:00:35 |"
"|   9 |          NESTED LOOPS                 |                              |     3 |   339 |  2856   (1)| 00:00:35 |"
"|  10 |           NESTED LOOPS                |                              |     1 |    99 |  2855   (1)| 00:00:35 |"
"|* 11 |            TABLE ACCESS FULL          | PLANANSCHLUSS                |     1 |    46 |  2854   (1)| 00:00:35 |"
"|  12 |            TABLE ACCESS BY INDEX ROWID| ANSCHLUSS                    |     1 |    53 |     1   (0)| 00:00:01 |"
"|* 13 |             INDEX UNIQUE SCAN         | SYS_C0012832                 |     1 |       |     1   (0)| 00:00:01 |"
"|  14 |           TABLE ACCESS BY INDEX ROWID | VERSICHERTER                 |     3 |    42 |     1   (0)| 00:00:01 |"
"|* 15 |            INDEX RANGE SCAN           | IX6_VERSICHERTER             |     3 |       |     1   (0)| 00:00:01 |"
"|* 16 |          TABLE ACCESS BY INDEX ROWID  | PARTNERROLLE                 |     1 |    13 |     1   (0)| 00:00:01 |"
"|* 17 |           INDEX UNIQUE SCAN           | SYS_C0012947                 |     1 |       |     1   (0)| 00:00:01 |"
"|* 18 |         INDEX RANGE SCAN              | IX5_NATPERSON                |     1 |       |     1   (0)| 00:00:01 |"
"|  19 |        TABLE ACCESS BY INDEX ROWID    | NATPERSON                    |     1 |    40 |     1   (0)| 00:00:01 |"
"|  20 |    NESTED LOOPS                       |                              |     1 |    24 |     4   (0)| 00:00:01 |"
"|  21 |     NESTED LOOPS                      |                              |     1 |    24 |     4   (0)| 00:00:01 |"
"|* 22 |      TABLE ACCESS FULL                | INVESTITION                  |     1 |    14 |     3   (0)| 00:00:01 |"
"|* 23 |      INDEX UNIQUE SCAN                | INVESTITION_AUFTRAG_PK       |     1 |       |     1   (0)| 00:00:01 |"
"|* 24 |     TABLE ACCESS BY INDEX ROWID       | INVESTITION_AUFTRAG          |     1 |    10 |     1   (0)| 00:00:01 |"
"|  25 |    HASH UNIQUE                        |                              |     1 |    40 |  2865   (1)| 00:00:35 |"
"|* 26 |     FILTER                            |                              |       |       |            |          |"
"|* 27 |      TABLE ACCESS FULL                | PLANANSCHLUSS                |     1 |    40 |  2859   (1)| 00:00:35 |"
"|* 28 |      TABLE ACCESS BY INDEX ROWID      | PLANANSCHLUSS                |     1 |    37 |     1   (0)| 00:00:01 |"
"|* 29 |       INDEX RANGE SCAN                | IX5_PLA_VERSICHERTERID       |     1 |       |     1   (0)| 00:00:01 |"
"|  30 |    HASH UNIQUE                        |                              |     2 |    98 |   173K  (1)| 00:34:43 |"
"|* 31 |     VIEW                              |                              |     2 |    98 |   173K  (1)| 00:34:43 |"
"|  32 |      UNPIVOT                          |                              |       |       |            |          |"
"|* 33 |       FILTER                          |                              |       |       |            |          |"
"|  34 |        NESTED LOOPS OUTER             |                              |     1 |    75 | 86771   (1)| 00:17:22 |"
"|* 35 |         TABLE ACCESS BY INDEX ROWID   | MUTBELEG_AKTIVE_STAND        |     1 |    34 | 86770   (1)| 00:17:22 |"
"|* 36 |          INDEX RANGE SCAN             | IX5_MUTB_A_ISTAKTUELLSTER    |  2381K|       |   590   (1)| 00:00:08 |"
"|* 37 |         TABLE ACCESS BY INDEX ROWID   | MUTBELEG_AKTIVE_STAND        | 23817 |   953K|     1   (0)| 00:00:01 |"
"|* 38 |          INDEX RANGE SCAN             | IX1_MUTB_A_PLAFKOID_CALCDATE |    10 |       |     1   (0)| 00:00:01 |"
"|  39 |    HASH UNIQUE                        |                              |     1 |    79 |  2330   (1)| 00:00:28 |"
"|* 40 |     VIEW                              |                              |     6 |   474 |  2329   (1)| 00:00:28 |"
"|  41 |      UNPIVOT                          |                              |       |       |            |          |"
"|  42 |       NESTED LOOPS                    |                              |     1 |   159 |   388   (1)| 00:00:05 |"
"|  43 |        NESTED LOOPS                   |                              |     1 |   159 |   388   (1)| 00:00:05 |"
"|  44 |         NESTED LOOPS                  |                              |     1 |   119 |   387   (1)| 00:00:05 |"
"|  45 |          NESTED LOOPS                 |                              |     1 |    66 |   386   (1)| 00:00:05 |"
"|  46 |           NESTED LOOPS                |                              |     1 |    53 |   385   (1)| 00:00:05 |"
"|* 47 |            TABLE ACCESS FULL          | RV_POLICE                    |     1 |    37 |   384   (1)| 00:00:05 |"
"|  48 |            TABLE ACCESS BY INDEX ROWID| RV_LEISTUNGSFALL             |     1 |    16 |     1   (0)| 00:00:01 |"
"|* 49 |             INDEX UNIQUE SCAN         | PK_RV_LEISTUNGSFALL          |     1 |       |     1   (0)| 00:00:01 |"
"|* 50 |           TABLE ACCESS BY INDEX ROWID | PARTNERROLLE                 |     1 |    13 |     1   (0)| 00:00:01 |"
"|* 51 |            INDEX UNIQUE SCAN          | SYS_C0012947                 |     1 |       |     1   (0)| 00:00:01 |"
"|  52 |          TABLE ACCESS BY INDEX ROWID  | ANSCHLUSS                    |     1 |    53 |     1   (0)| 00:00:01 |"
"|* 53 |           INDEX UNIQUE SCAN           | SYS_C0012832                 |     1 |       |     1   (0)| 00:00:01 |"
"|* 54 |         INDEX RANGE SCAN              | IX5_NATPERSON                |     1 |       |     1   (0)| 00:00:01 |"
"|  55 |        TABLE ACCESS BY INDEX ROWID    | NATPERSON                    |     1 |    40 |     1   (0)| 00:00:01 |"
"|* 56 |    VIEW                               |                              |     1 |    91 |   385   (1)| 00:00:05 |"
"|* 57 |     TABLE ACCESS BY INDEX ROWID       | RV_LEISTUNGBASIS             |     1 |    42 |     1   (0)| 00:00:01 |"
"|* 58 |      INDEX RANGE SCAN                 | IX1_RV_LEISTUNGBASIS         |     1 |       |     1   (0)| 00:00:01 |"
"|  59 |     HASH UNIQUE                       |                              |     1 |    35 |   385   (1)| 00:00:05 |"
"|* 60 |      TABLE ACCESS FULL                | RV_LEISTUNGBASIS             |     1 |    35 |   384   (1)| 00:00:05 |"
"----------------------------------------------------------------------------------------------------------------------"
" "
"Predicate Information (identified by operation id):"
"---------------------------------------------------"
" "
"   4 - filter(""unpivot_view_070"".""ACTIONPARAMETERVALUE"" IS NOT NULL)"
"  11 - filter(CAST(""PA"".""OID"" AS varchar2(50))='3505032127')"
"  13 - access(""PA"".""ANSCHLUSSFKOID""=""A"".""OID"")"
"  15 - access(""PA"".""VERSICHERTERFKID""=""V"".""ID"")"
"  16 - filter(""PR"".""NATPERSONFKID"" IS NOT NULL)"
"  17 - access(""V"".""ROLLEVERSICHERTERFKOID""=""PR"".""OID"")"
"  18 - access(""PR"".""NATPERSONFKID""=""NP"".""ID"")"
"  22 - filter(""INV"".""PLANANSCHLUSSFKOID""=:B1)"
"  23 - access(""INV"".""AUFTRAGFKOID""=""INV_AUF"".""OID"")"
"  24 - filter(""INV_AUF"".""ISBESTAETIG""=0)"
"  26 - filter(CASE  WHEN  EXISTS (SELECT 0 FROM SL_PAV_BEST.""INVESTITION_AUFTRAG"" "
"              ""INV_AUF"",SL_PAV_BEST.""INVESTITION"" ""INV"" WHERE ""INV"".""PLANANSCHLUSSFKOID""=:B1 AND "
"              ""INV"".""AUFTRAGFKOID""=""INV_AUF"".""OID"" AND ""INV_AUF"".""ISBESTAETIG""=0) THEN '1' ELSE '0' END  IS NOT NULL AND "
"              CASE  WHEN  EXISTS (SELECT 0 FROM SL_PAV_BEST.""PLANANSCHLUSS"" ""PA2"" WHERE ""PA2"".""VERSICHERTERFKID""=:B2 AND "
"              ""PA2"".""ANSCHLUSSFKOID""=:B3 AND NVL(""PA2"".""UPDDAT"",""PA2"".""CREDAT"")>NVL(:B4,:B5)) THEN 0 ELSE 1 END =1)"
"  27 - filter(""PA"".""ISIVA""=1 AND CAST(""PA"".""OID"" AS varchar2(50))='3505032127')"
"  28 - filter(""PA2"".""ANSCHLUSSFKOID""=:B1 AND NVL(""PA2"".""UPDDAT"",""PA2"".""CREDAT"")>NVL(:B2,:B3))"
"  29 - access(""PA2"".""VERSICHERTERFKID""=:B1)"
"  31 - filter(""unpivot_view_080"".""ACTIONPARAMETERVALUE"" IS NOT NULL)"
"  33 - filter(""MAS2"".""OID"" IS NULL)"
"  35 - filter(CAST(""MAS"".""PLANANSCHLUSSFKOID"" AS varchar2(50))='3505032127' AND CASE "
"              NVL(""MAS"".""PRODUKTSUBCD"",""MAS"".""PRODUKTCD"") WHEN 'na' THEN ""MAS"".""PRODUKTCD"" ELSE "
"              NVL(""MAS"".""PRODUKTSUBCD"",""MAS"".""PRODUKTCD"") END  IS NOT NULL)"
"  36 - access(""MAS"".""ISTAKTUELLSTER""=1)"
"  37 - filter(""MAS2"".""ISTAKTUELLSTER""(+)=1 AND ""MAS2"".""CREDAT""(+)>""MAS"".""CREDAT"" AND "
"              NVL(""MAS2"".""PLANMERKMALCD2""(+),'ERWP')=NVL(""MAS"".""PLANMERKMALCD2"",'ERWP') AND CASE "
"              NVL(""MAS"".""PRODUKTSUBCD"",""MAS"".""PRODUKTCD"") WHEN 'na' THEN ""MAS"".""PRODUKTCD"" ELSE "
"              NVL(""MAS"".""PRODUKTSUBCD"",""MAS"".""PRODUKTCD"") END =CASE NVL(""MAS2"".""PRODUKTSUBCD""(+),""MAS2"".""PRODUKTCD""(+)) "
"              WHEN 'na' THEN ""MAS2"".""PRODUKTCD""(+) ELSE NVL(""MAS2"".""PRODUKTSUBCD""(+),""MAS2"".""PRODUKTCD""(+)) END )"
"  38 - access(""MAS2"".""PLANANSCHLUSSFKOID""(+)=""MAS"".""PLANANSCHLUSSFKOID"")"
"  40 - filter(""unpivot_view_112"".""ACTIONPARAMETERVALUE"" IS NOT NULL)"
"  47 - filter(CAST(""POL"".""OID"" AS varchar2(50))='3505032127')"
"  49 - access(""POL"".""RV_LEISTUNGSFALLFKOID""=""LF"".""OID"")"
"  50 - filter(""PR"".""NATPERSONFKID"" IS NOT NULL)"
"  51 - access(""LF"".""ROLLERENTNERFKOID""=""PR"".""OID"")"
"  53 - access(""POL"".""X_ANSCHLUSSFKOID""=""A"".""OID"")"
"  54 - access(""PR"".""NATPERSONFKID""=""NP"".""ID"")"
"  56 - filter(""from$_subquery$_029"".""ISTAKTUELLSTER""=1)"
"  57 - filter(""RV2"".""LEISTUNGCD""=:B1 AND NVL(""RV2"".""UPDDAT"",""RV2"".""CREDAT"")>NVL(:B2,:B3))"
"  58 - access(""RV2"".""RV_POLICEFKOID""=:B1)"
"  60 - filter(CAST(""RV"".""RV_POLICEFKOID"" AS varchar2(50))='3505032127')"

1 个答案:

答案 0 :(得分:1)

比较两个计划中的这些行:
上层计划 - 谓词信息:

"  12 - access(""PA"".""OID""=3505032127)"
"  28 - access(""PA"".""OID""=3505032127)"
"  48 - access(""POL"".""OID""=3505032127)"
"  62 - access(""RV"".""RV_POLICEFKOID""=3505032127)"

和底部计划 - 视图:

"  11 - filter(CAST(""PA"".""OID"" AS varchar2(50))='3505032127')"
"  27 - filter(""PA"".""ISIVA""=1 AND CAST(""PA"".""OID"" AS varchar2(50))='3505032127')"
"  35 - filter(CAST(""MAS"".""PLANANSCHLUSSFKOID"" AS varchar2(50))='3505032127' AND CASE "
"  47 - filter(CAST(""POL"".""OID"" AS varchar2(50))='3505032127')"
"  60 - filter(CAST(""RV"".""RV_POLICEFKOID"" AS varchar2(50))='3505032127')"

如果不查看确切的视图定义,很难说,但是此视图中有一些内容强制将表列转换为varchar2,从而阻止视图使用索引,而原始查询使用直接数{{ 1}}(不是varchar)。

您可以尝试在查询中使用数字文字:

3505032127

而不是varchar2 literal

select * from MY_SLOW_VIEW where SourceID=1234567890;

编辑---------

对不起,我在视图定义中没有注意到这一点:

select * from MY_SLOW_VIEW where SourceID='1234567890';

这是错误的根源。删除 SELECT cast(sourceid as varchar2(50)) as sourceid, 到varchar的强制转换,这可以改进查询。