在Oracle中,具有多个联接的查询执行花费更多时间

时间:2019-03-05 08:06:41

标签: sql oracle query-performance

我们正在尝试在Oracle数据库中执行查询。执行需要5秒。所有列均已编制索引。

select
       count(*)
from
    ehub_mbr_sds.ehub_sds_mbr a  
 join
    ehub_mbr_sds.ehub_sds_mbr_cntrct b 
        on a.ehub_mbr_id = b.ehub_mbr_id  
 join
    ehub_mbr_sds.ehub_sds_cntrct d 
        on b.cntrct_id = d.cntrct_id  
 JOIN
    EHUB_MBR_SDS.EHUB_SDS_CVRG c 
        ON b.EHUB_MBR_CNTRCT_ID= c.EHUB_MBR_CNTRCT_ID   
 JOIN
    EHUB_MBR_SDS.EHUB_SDS_ELGBLTY f 
        ON f.PROD_CD= c.PROD_CD  
 JOIN
    ehub_mbr_sds.ehub_sds_grp e 
        on d.ehub_grp_id = e.ehub_grp_id   
where
    a.sor_cd ='****' 
    AND e.GRP_ID='****' --need indexes for  GRPID
    AND c.sub_grp_id='*****'  
    and f.plan_type_cd in('***') 
    and CURRENT_TIMESTAMP > c.cvrg_efctv_dt 
    and CURRENT_TIMESTAMP > c.cvrg_trmntn_dt 
order by
    b.hcid;

任何指针都会有所帮助

3 个答案:

答案 0 :(得分:0)

发布说明计划。在此期间,请使用并行性重试查询,并在选择符前面加上提示。 I. E.

select /*+parallel*/...

通过获取带有或不带有提示的解释计划,确保并行工作正常。 (很可能您的服务器未配置为并行执行)

答案 1 :(得分:0)

删除顺序,以下是没有并行性的说明计划

Plan hash value: 2953621403

---------------------------------------------------------------------------------------------------------------------
| Id  | Operation                                  | Name                   | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                           |                        |     1 |   161 |    25   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE                            |                        |     1 |   161 |            |          |
|   2 |   NESTED LOOPS                             |                        |     1 |   161 |    25   (0)| 00:00:01 |
|   3 |    NESTED LOOPS                            |                        |    12 |   161 |    25   (0)| 00:00:01 |
|   4 |     NESTED LOOPS                           |                        |     1 |   147 |    13   (0)| 00:00:01 |
|   5 |      NESTED LOOPS                          |                        |     1 |   128 |    11   (0)| 00:00:01 |
|   6 |       NESTED LOOPS                         |                        |     1 |   108 |     9   (0)| 00:00:01 |
|   7 |        NESTED LOOPS                        |                        |     1 |    92 |     7   (0)| 00:00:01 |
|*  8 |         TABLE ACCESS BY INDEX ROWID BATCHED| EHUB_SDS_CVRG          |     1 |    53 |     5   (0)| 00:00:01 |
|*  9 |          INDEX RANGE SCAN                  | IX5_EHUB_SDS_CVRG      |     1 |       |     4   (0)| 00:00:01 |
|  10 |         TABLE ACCESS BY INDEX ROWID        | EHUB_SDS_MBR_CNTRCT    |     1 |    39 |     2   (0)| 00:00:01 |
|* 11 |          INDEX UNIQUE SCAN                 | PK_EHUB_SDS_MBR_CNTRCT |     1 |       |     1   (0)| 00:00:01 |
|* 12 |        TABLE ACCESS BY INDEX ROWID         | EHUB_SDS_CNTRCT        |     1 |    16 |     2   (0)| 00:00:01 |
|* 13 |         INDEX UNIQUE SCAN                  | PK_EHUB_SDS_CNTRCT     |     1 |       |     1   (0)| 00:00:01 |
|* 14 |       TABLE ACCESS BY INDEX ROWID          | EHUB_SDS_GRP           |     1 |    20 |     2   (0)| 00:00:01 |
|* 15 |        INDEX UNIQUE SCAN                   | PK_EHUB_SDS_GRP        |     1 |       |     1   (0)| 00:00:01 |
|* 16 |      TABLE ACCESS BY INDEX ROWID           | EHUB_SDS_MBR           |     1 |    19 |     2   (0)| 00:00:01 |
|* 17 |       INDEX UNIQUE SCAN                    | PK_EHUB_SDS_MBR        |     1 |       |     1   (0)| 00:00:01 |
|* 18 |     INDEX RANGE SCAN                       | IX3_EHUB_SDS_ELGBLTY   |    12 |       |     2   (0)| 00:00:01 |
|* 19 |    TABLE ACCESS BY INDEX ROWID             | EHUB_SDS_ELGBLTY       |     1 |    14 |    12   (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   8 - filter(SYS_EXTRACT_UTC(INTERNAL_FUNCTION("C"."CVRG_EFCTV_DT"))<SYS_EXTRACT_UTC(CURRENT_TIMESTAMP(6)) 
              AND SYS_EXTRACT_UTC(INTERNAL_FUNCTION("C"."CVRG_TRMNTN_DT"))<SYS_EXTRACT_UTC(CURRENT_TIMESTAMP(6)))
   9 - access("C"."SUB_GRP_ID"='*********')
  11 - access("B"."EHUB_MBR_CNTRCT_ID"="C"."EHUB_MBR_CNTRCT_ID")
  12 - filter("D"."EHUB_GRP_ID" IS NOT NULL)
  13 - access("B"."CNTRCT_ID"="D"."CNTRCT_ID")
  14 - filter("E"."GRP_ID"='*****')
  15 - access("D"."EHUB_GRP_ID"="E"."EHUB_GRP_ID")
  16 - filter("A"."SOR_CD"='*****')
  17 - access("A"."EHUB_MBR_ID"="B"."EHUB_MBR_ID")
  18 - access("F"."PROD_CD"="C"."PROD_CD")
  19 - filter("F"."PLAN_TYPE_CD"='*****')

Note
-----
   - dynamic statistics used: dynamic sampling (level=2)
   - this is an adaptive plan
   - 2 Sql Plan Directives used for this statement

}

与parallel(4)一起解释计划

Plan hash value: 2232660988

--------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                                        | Name                   | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
--------------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                                 |                        |     1 |   161 |  2775   (1)| 00:00:01 |        |      |            |
|   1 |  SORT AGGREGATE                                  |                        |     1 |   161 |            |          |        |      |            |
|   2 |   PX COORDINATOR                                 |                        |       |       |            |          |        |      |            |
|   3 |    PX SEND QC (RANDOM)                           | :TQ10003               |     1 |   161 |            |          |  Q1,03 | P->S | QC (RAND)  |
|   4 |     SORT AGGREGATE                               |                        |     1 |   161 |            |          |  Q1,03 | PCWP |            |
|   5 |      NESTED LOOPS                                |                        |     1 |   161 |  2775   (1)| 00:00:01 |  Q1,03 | PCWP |            |
|   6 |       NESTED LOOPS                               |                        |    12 |   161 |  2775   (1)| 00:00:01 |  Q1,03 | PCWP |            |
|   7 |        NESTED LOOPS                              |                        |     1 |   147 |  2771   (1)| 00:00:01 |  Q1,03 | PCWP |            |
|   8 |         NESTED LOOPS                             |                        |     1 |   128 |  2771   (1)| 00:00:01 |  Q1,03 | PCWP |            |
|   9 |          NESTED LOOPS                            |                        |     1 |   108 |  2770   (1)| 00:00:01 |  Q1,03 | PCWP |            |
|  10 |           NESTED LOOPS                           |                        |     1 |    92 |  2770   (1)| 00:00:01 |  Q1,03 | PCWP |            |
|  11 |            BUFFER SORT                           |                        |       |       |            |          |  Q1,03 | PCWC |            |
|  12 |             PX RECEIVE                           |                        |       |       |            |          |  Q1,03 | PCWP |            |
|  13 |              PX SEND HASH                        | :TQ10001               |       |       |            |          |  Q1,01 | P->P | HASH       |
|* 14 |               TABLE ACCESS BY INDEX ROWID BATCHED| EHUB_SDS_CVRG          |     1 |    53 |  2769   (1)| 00:00:01 |  Q1,01 | PCWP |            |
|  15 |                BUFFER SORT                       |                        |       |       |            |          |  Q1,01 | PCWC |            |
|  16 |                 PX RECEIVE                       |                        |  3845 |       |     9   (0)| 00:00:01 |  Q1,01 | PCWP |            |
|  17 |                  PX SEND HASH (BLOCK ADDRESS)    | :TQ10000               |  3845 |       |     9   (0)| 00:00:01 |  Q1,00 | S->P | HASH (BLOCK|
|  18 |                   PX SELECTOR                    |                        |       |       |            |          |  Q1,00 | SCWC |            |
|* 19 |                    INDEX RANGE SCAN              | IX4_EHUB_SDS_CVRG      |  3845 |       |     9   (0)| 00:00:01 |  Q1,00 | SCWP |            |
|  20 |            TABLE ACCESS BY INDEX ROWID           | EHUB_SDS_MBR_CNTRCT    |     1 |    39 |     1   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 21 |             INDEX UNIQUE SCAN                    | PK_EHUB_SDS_MBR_CNTRCT |     1 |       |     0   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 22 |           TABLE ACCESS BY INDEX ROWID            | EHUB_SDS_CNTRCT        |     1 |    16 |     1   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 23 |            INDEX UNIQUE SCAN                     | PK_EHUB_SDS_CNTRCT     |     1 |       |     0   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 24 |          TABLE ACCESS BY INDEX ROWID             | EHUB_SDS_GRP           |     1 |    20 |     1   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 25 |           INDEX UNIQUE SCAN                      | PK_EHUB_SDS_GRP        |     1 |       |     0   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 26 |         TABLE ACCESS BY INDEX ROWID              | EHUB_SDS_MBR           |     1 |    19 |     1   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 27 |          INDEX UNIQUE SCAN                       | PK_EHUB_SDS_MBR        |     1 |       |     0   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 28 |        INDEX RANGE SCAN                          | IX3_EHUB_SDS_ELGBLTY   |    12 |       |     1   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 29 |       TABLE ACCESS BY INDEX ROWID                | EHUB_SDS_ELGBLTY       |  4279 | 59906 |     3   (0)| 00:00:01 |  Q1,03 | PCWP |            |
--------------------------------------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

  14 - filter(SYS_EXTRACT_UTC(INTERNAL_FUNCTION("C"."CVRG_EFCTV_DT"))<=SYS_EXTRACT_UTC(CURRENT_TIMESTAMP(6)) AND 
              SYS_EXTRACT_UTC(INTERNAL_FUNCTION("C"."CVRG_TRMNTN_DT"))>=SYS_EXTRACT_UTC(CURRENT_TIMESTAMP(6)))
  19 - access("C"."SUB_GRP_ID"='*****')
  21 - access("B"."EHUB_MBR_CNTRCT_ID"="C"."EHUB_MBR_CNTRCT_ID")
  22 - filter("D"."EHUB_GRP_ID" IS NOT NULL)
  23 - access("B"."CNTRCT_ID"="D"."*****")
  24 - filter("E"."GRP_ID"='****')
  25 - access("D"."EHUB_GRP_ID"="E"."****")
  26 - filter("A"."SOR_CD"='****')
  27 - access("A"."EHUB_MBR_ID"="B"."*******")
  28 - access("F"."PROD_CD"="C"."*****")
  29 - filter("F"."PLAN_TYPE_CD"='****')

Note
-----
   - dynamic statistics used: dynamic sampling (level=AUTO)
   - Degree of Parallelism is 4 because of hint
   - this is an adaptive plan

} 谁能给我们分析我不能运行诊断没有那些特权

答案 2 :(得分:0)

SYS_EXTRACT_UTC(INTERNAL_FUNCTION("C"."CVRG_TRMNTN_DT"))<SYS_EXTRACT_UTC(CURRENT_TIMESTAMP(6)))
   - 4 Sql Plan Directives used for this statement
   - Degree of Parallelism is 4 because of hint
   - dynamic statistics used: dynamic sampling (level=4)
   - this is an adaptive plan
  14 - filter(SYS_EXTRACT_UTC(INTERNAL_FUNCTION("C"."CVRG_EFCTV_DT"))<SYS_EXTRACT_UTC(CURRENT_TIMESTAMP(6)) AND 
  19 - access("C"."SUB_GRP_ID"='****')
  21 - access("B"."EHUB_MBR_CNTRCT_ID"="C"."EHUB_MBR_CNTRCT_ID")
  22 - filter("D"."EHUB_GRP_ID" IS NOT NULL)
  23 - access("B"."CNTRCT_ID"="D"."****")
  24 - filter("E"."GRP_ID"='****')
  25 - access("E"."EHUB_GRP_ID"="D"."*****")
  26 - filter("A"."SOR_CD"='***')
  27 - access("A"."EHUB_MBR_ID"="B"."*****")
  28 - access("F"."PROD_CD"="C"."*****")
  29 - filter("F"."PLAN_TYPE_CD"='****')
--------------------------------------------------------------------------------------------------------------------------------------------------------
Note
Plan hash value: 2232660988
Predicate Information (identified by operation id):
|   0 | SELECT STATEMENT                                 |                        |     1 |   161 |  2775   (1)| 00:00:01 |        |      |            |
|   1 |  SORT AGGREGATE                                  |                        |     1 |   161 |            |          |        |      |            |
|   2 |   PX COORDINATOR                                 |                        |       |       |            |          |        |      |            |
|   3 |    PX SEND QC (RANDOM)                           | :TQ10003               |     1 |   161 |            |          |  Q1,03 | P->S | QC (RAND)  |
|   4 |     SORT AGGREGATE                               |                        |     1 |   161 |            |          |  Q1,03 | PCWP |            |
|   5 |      NESTED LOOPS                                |                        |     1 |   161 |  2775   (1)| 00:00:01 |  Q1,03 | PCWP |            |
|   6 |       NESTED LOOPS                               |                        |    12 |   161 |  2775   (1)| 00:00:01 |  Q1,03 | PCWP |            |
|   7 |        NESTED LOOPS                              |                        |     1 |   147 |  2771   (1)| 00:00:01 |  Q1,03 | PCWP |            |
|   8 |         NESTED LOOPS                             |                        |     1 |   128 |  2771   (1)| 00:00:01 |  Q1,03 | PCWP |            |
|   9 |          NESTED LOOPS                            |                        |     1 |   108 |  2770   (1)| 00:00:01 |  Q1,03 | PCWP |            |
|  10 |           NESTED LOOPS                           |                        |     1 |    92 |  2770   (1)| 00:00:01 |  Q1,03 | PCWP |            |
|  11 |            BUFFER SORT                           |                        |       |       |            |          |  Q1,03 | PCWC |            |
|  12 |             PX RECEIVE                           |                        |       |       |            |          |  Q1,03 | PCWP |            |
|  13 |              PX SEND HASH                        | :TQ10001               |       |       |            |          |  Q1,01 | P->P | HASH       |
|  15 |                BUFFER SORT                       |                        |       |       |            |          |  Q1,01 | PCWC |            |
|  16 |                 PX RECEIVE                       |                        |  3845 |       |     9   (0)| 00:00:01 |  Q1,01 | PCWP |            |
|  17 |                  PX SEND HASH (BLOCK ADDRESS)    | :TQ10000               |  3845 |       |     9   (0)| 00:00:01 |  Q1,00 | S->P | HASH (BLOCK|
|  18 |                   PX SELECTOR                    |                        |       |       |            |          |  Q1,00 | SCWC |            |
|  20 |            TABLE ACCESS BY INDEX ROWID           | EHUB_SDS_MBR_CNTRCT    |     1 |    39 |     1   (0)| 00:00:01 |  Q1,03 | PCWP |            |
| Id  | Operation                                        | Name                   | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
|* 14 |               TABLE ACCESS BY INDEX ROWID BATCHED| EHUB_SDS_CVRG          |     1 |    53 |  2769   (1)| 00:00:01 |  Q1,01 | PCWP |            |
|* 19 |                    INDEX RANGE SCAN              | IX4_EHUB_SDS_CVRG      |  3845 |       |     9   (0)| 00:00:01 |  Q1,00 | SCWP |            |
|* 21 |             INDEX UNIQUE SCAN                    | PK_EHUB_SDS_MBR_CNTRCT |     1 |       |     0   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 22 |           TABLE ACCESS BY INDEX ROWID            | EHUB_SDS_CNTRCT        |     1 |    16 |     1   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 23 |            INDEX UNIQUE SCAN                     | PK_EHUB_SDS_CNTRCT     |     1 |       |     0   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 24 |          TABLE ACCESS BY INDEX ROWID             | EHUB_SDS_GRP           |     1 |    20 |     1   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 25 |           INDEX UNIQUE SCAN                      | PK_EHUB_SDS_GRP        |     1 |       |     0   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 26 |         TABLE ACCESS BY INDEX ROWID              | EHUB_SDS_MBR           |     1 |    19 |     1   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 27 |          INDEX UNIQUE SCAN                       | PK_EHUB_SDS_MBR        |     1 |       |     0   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 28 |        INDEX RANGE SCAN                          | IX3_EHUB_SDS_ELGBLTY   |    12 |       |     1   (0)| 00:00:01 |  Q1,03 | PCWP |            |
|* 29 |       TABLE ACCESS BY INDEX ROWID                | EHUB_SDS_ELGBLTY       |   990 | 13860 |     3   (0)| 00:00:01 |  Q1,03 | PCWP |            |