Выполнение запроса с несколькими объединениями занимает больше времени в оракуле - PullRequest
0 голосов
/ 05 марта 2019

Мы пытаемся выполнить запрос в Oracle db.Это занимает 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 голосов
/ 06 марта 2019

Удален порядок, ниже приведен план объяснения без параллелизма

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

}

При параллельном (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

} Может кто-нибудь датьнам анализ на это я не могу запустить диагностический донот не имеют эти привилегии

0 голосов
/ 06 марта 2019
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 |            |
0 голосов
/ 05 марта 2019

Опубликовать план объяснения.В то же время, попробуйте запрос, используя параллелизм с подсказкой перед вашим выбором.IE

select /*+parallel*/...

Убедитесь, что параллелизм работает, взяв план объяснения с подсказкой и без нее.(Возможно, ваш сервер не настроен для параллельного выполнения)

...