Запрос курсора после перехода на Oracle 12c выполняется очень медленно - PullRequest
0 голосов
/ 25 октября 2019

После перехода с 11g на 12c запрос курсора базы данных Oracle внутри процедуры выполняется очень медленно, в то время как весь процесс занимает 11 минут, а в 11g - около 60-90 минут в 12c.

Я сделал некоторые наблюдениянапример, когда я помещаю жестко закодированные значения переменных в курсор, производительность становится нормальной, т.е. около 8 минут. Я могу видеть полное сканирование таблицы в v $ session_longops, пока около 25000k записей из курсора из 26500 записей не займет обычное время для его обработки, но послечто он застревает в нескольких разных записях (эти записи не согласованы) и занимает около 20 минут для каждой записи для извлечения, а в фоновом режиме полное сканирование таблицы происходит при длинных интервалах. Объясните, что план выглядит одинаково как в 11g, так и в 12c, но я не могу понять это снижение производительности.

Дайте мне знать, если кто-нибудь может помочь мне в этом, если потребуется какой-либо дополнительный вклад, тогда, пожалуйста, дайте мне знать.

Результаты запроса из 12c:

      26537 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 1805658626

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

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

| Id  | Operation                         | Name                   | Rows  | Byt

es | Cost (%CPU)| Time     |

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

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

|   0 | SELECT STATEMENT                  |                        |  2378 |   3

17K|   907K  (1)| 00:00:36 |

|   1 |  UNION-ALL                        |                        |       |
   |            |          |

|*  2 |   HASH JOIN RIGHT ANTI            |                        |  1271 |   1

83K|   306K  (1)| 00:00:12 |

|*  3 |    TABLE ACCESS FULL              | LEA_UNAPPLIED_TXN_DTL  |     1 |
13 |   348   (1)| 00:00:01 |

|   4 |    NESTED LOOPS                   |                        |  1271 |   1

67K|   305K  (1)| 00:00:12 |

|   5 |     NESTED LOOPS                  |                        |  1271 |   1

67K|   305K  (1)| 00:00:12 |

|   6 |      NESTED LOOPS                 |                        |  1271 |   1

39K|   303K  (1)| 00:00:12 |

|   7 |       NESTED LOOPS                |                        |  1271 |   1

17K|   300K  (1)| 00:00:12 |

|*  8 |        TABLE ACCESS FULL          | NBFC_TXN_ADVICE_DTL    |  1271 | 559

24 |   298K  (1)| 00:00:12 |

|   9 |        TABLE ACCESS BY INDEX ROWID| LEA_AGREEMENT_DTL      |     1 |
51 |     2   (0)| 00:00:01 |

|* 10 |         INDEX UNIQUE SCAN         | LEA_AGREEMENT_DTL_UQ   |     1 |
   |     1   (0)| 00:00:01 |

|  11 |       TABLE ACCESS BY INDEX ROWID | NBFC_CUSTOMER_M        |     1 |
17 |     2   (0)| 00:00:01 |

|* 12 |        INDEX UNIQUE SCAN          | NBFC_CUSTOMER_M_PK     |     1 |
   |     1   (0)| 00:00:01 |

|* 13 |      INDEX UNIQUE SCAN            | NBFC_CHEQUE_DTL_PK     |     1 |
   |     1   (0)| 00:00:01 |

|* 14 |     TABLE ACCESS BY INDEX ROWID   | NBFC_CHEQUE_DTL        |     1 |
23 |     2   (0)| 00:00:01 |

|  15 |   NESTED LOOPS                    |                        |  1101 |   1

33K|   302K  (1)| 00:00:12 |

|  16 |    NESTED LOOPS                   |                        |  1101 |   1

33K|   302K  (1)| 00:00:12 |

|  17 |     NESTED LOOPS                  |                        |  1101 |   1

15K|   300K  (1)| 00:00:12 |

|* 18 |      TABLE ACCESS FULL            | NBFC_TXN_ADVICE_DTL    |  1101 | 616

56 |   298K  (1)| 00:00:12 |

|  19 |      TABLE ACCESS BY INDEX ROWID  | LEA_AGREEMENT_DTL      |     1 |
51 |     2   (0)| 00:00:01 |

|* 20 |       INDEX UNIQUE SCAN           | LEA_AGREEMENT_DTL_UQ   |     1 |
   |     1   (0)| 00:00:01 |

|* 21 |     INDEX UNIQUE SCAN             | NBFC_CUSTOMER_M_PK     |     1 |
   |     1   (0)| 00:00:01 |

|  22 |    TABLE ACCESS BY INDEX ROWID    | NBFC_CUSTOMER_M        |     1 |
17 |     2   (0)| 00:00:01 |

|  23 |   NESTED LOOPS                    |                        |     6 |   8

22 |   298K  (1)| 00:00:12 |

|  24 |    NESTED LOOPS                   |                        |     6 |   8

22 |   298K  (1)| 00:00:12 |

|  25 |     NESTED LOOPS ANTI             |                        |     6 |   7

20 |   298K  (1)| 00:00:12 |

|  26 |      NESTED LOOPS                 |                        |     6 |   6

42 |   298K  (1)| 00:00:12 |

|* 27 |       TABLE ACCESS FULL           | NBFC_TXN_ADVICE_DTL    |     6 |   3

36 |   298K  (1)| 00:00:12 |

|  28 |       TABLE ACCESS BY INDEX ROWID | LEA_AGREEMENT_DTL      |     1 |
51 |     2   (0)| 00:00:01 |

|* 29 |        INDEX UNIQUE SCAN          | LEA_AGREEMENT_DTL_UQ   |     1 |
   |     1   (0)| 00:00:01 |

|* 30 |      TABLE ACCESS BY INDEX ROWID  | LEA_TERMINATION_DTL    |     1 |
13 |     1   (0)| 00:00:01 |

|* 31 |       INDEX UNIQUE SCAN           | LEA_TERMINATION_DTL_PK |     1 |
   |     0   (0)| 00:00:01 |

|* 32 |     INDEX UNIQUE SCAN             | NBFC_CUSTOMER_M_PK     |     1 |
   |     1   (0)| 00:00:01 |

|  33 |    TABLE ACCESS BY INDEX ROWID    | NBFC_CUSTOMER_M        |     1 |
17 |     2   (0)| 00:00:01 |

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

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


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

   2 - access("H"."CHEQUEID"="C"."CHEQUEID")
   3 - filter("H"."AUTHID" IS NULL)
   8 - filter("A"."CHEQUEID" IS NOT NULL AND "A"."TXNTYPE"='E' AND "A"."ADVICETY

PE"='P' AND

              "A"."ADVICEAMT">NVL("A"."TXNADJUSTEDAMT",0)+NVL("A"."AMTINPROCESS"

,0) AND "A"."BPTYPE"='LS' AND

              NVL("A"."STATUS",'A')='A' AND "A"."MODULEID"='LEA' AND NVL("A"."MC

_STATUS",'A')='A')

  10 - access("A"."CASEID"="B"."AGREEMENTID")
  12 - access("D"."CUSTOMERID"="B"."LESSEEID")
  13 - access("C"."CHEQUEID"="A"."CHEQUEID")
  14 - filter("C"."STATUS"='C' AND "C"."MC_STATUS"='A')
  18 - filter("A"."ADVICETYPE"='P' AND INSTR(',110486,110487,110666,58,500,572,4

30,111352,27,431,100

              164,68,510,511,370,260,103,',','||TO_CHAR("CHARGEID")||',')=0 AND
              "A"."ADVICEAMT">NVL("A"."TXNADJUSTEDAMT",0)+NVL("A"."AMTINPROCESS"

,0) AND "A"."BPTYPE"='LS' AND

              "A"."TXNTYPE"<>'E' AND "A"."TXNTYPE"<>'T' AND NVL("A"."STATUS",'A'

)='A' AND "A"."MODULEID"='LEA'

              AND NVL("A"."MC_STATUS",'A')='A')
  20 - access("A"."CASEID"="B"."AGREEMENTID")
  21 - access("B"."LESSEEID"="D"."CUSTOMERID")
  27 - filter("A"."TXNTYPE"='T' AND "A"."ADVICETYPE"='P' AND
              INSTR(',110486,110487,110666,58,500,572,430,111352,27,431,100164,6

8,510,511,370,260,103,',','||TO_CH

              AR("CHARGEID")||',')=0 AND "A"."ADVICEAMT">NVL("A"."TXNADJUSTEDAMT

",0)+NVL("A"."AMTINPROCESS",0)

              AND "A"."BPTYPE"='LS' AND NVL("A"."STATUS",'A')='A' AND "A"."MODUL

EID"='LEA' AND

              NVL("A"."MC_STATUS",'A')='A')
  29 - access("A"."CASEID"="B"."AGREEMENTID")
  30 - filter("H"."AUTHORIZEDON" IS NULL)
  31 - access("H"."AGREEMENTID"="B"."AGREEMENTID")
  32 - access("B"."LESSEEID"="D"."CUSTOMERID")


Statistics
----------------------------------------------------------
         30  recursive calls
          0  db block gets
    3507495  consistent gets
    3292158  physical reads
        360  redo size
    1535583  bytes sent via SQL*Net to client
      20011  bytes received via SQL*Net from client
       1771  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
      26537  rows processed





Explain plan from 11g
----------------------------------------------------------------------------------------------------
| Id  | Operation                         | Name                      | Rows  | Bytes | Cost (%CPU)|
----------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                  |                           |  2405 |   331K|  1107K  (1)|
|   1 |  UNION-ALL                        |                           |       |       |            |
|   2 |   NESTED LOOPS                    |                           |   353 | 56833 |   367K  (1)|
|   3 |    NESTED LOOPS                   |                           |   353 | 56833 |   367K  (1)|
|   4 |     NESTED LOOPS                  |                           |   353 | 49420 |   367K  (1)|
|   5 |      NESTED LOOPS ANTI            |                           |   353 | 27181 |   366K  (1)|
|   6 |       NESTED LOOPS                |                           |   353 | 22592 |   366K  (1)|
|*  7 |        TABLE ACCESS FULL          | NBFC_TXN_ADVICE_DTL       |   353 | 14473 |   365K  (1)|
|*  8 |        TABLE ACCESS BY INDEX ROWID| NBFC_CHEQUE_DTL           |     1 |    23 |     2   (0)|
|*  9 |         INDEX UNIQUE SCAN         | NBFC_CHEQUE_DTL_PK        |     1 |       |     1   (0)|
|* 10 |       TABLE ACCESS BY INDEX ROWID | LEA_UNAPPLIED_TXN_DTL     |     1 |    13 |     1   (0)|
|* 11 |        INDEX RANGE SCAN           | LEA_UNAPPLIED_TXN_DTL_IDX |     1 |       |     0   (0)|
|  12 |      TABLE ACCESS BY INDEX ROWID  | LEA_AGREEMENT_DTL         |     1 |    63 |     2   (0)|
|* 13 |       INDEX UNIQUE SCAN           | LEA_AGREEMENT_DTL_UQ      |     1 |       |     1   (0)|
|* 14 |     INDEX UNIQUE SCAN             | NBFC_CUSTOMER_M_PK        |     1 |       |     1   (0)|
|  15 |    TABLE ACCESS BY INDEX ROWID    | NBFC_CUSTOMER_M           |     1 |    21 |     2   (0)|
|  16 |   NESTED LOOPS                    |                           |  1977 |   264K|   373K  (1)|
|  17 |    NESTED LOOPS                   |                           |  1977 |   264K|   373K  (1)|
|  18 |     NESTED LOOPS                  |                           |  1977 |   223K|   369K  (1)|
|* 19 |      TABLE ACCESS FULL            | NBFC_TXN_ADVICE_DTL       |  1977 |   102K|   365K  (1)|
|  20 |      TABLE ACCESS BY INDEX ROWID  | LEA_AGREEMENT_DTL         |     1 |    63 |     2   (0)|
|* 21 |       INDEX UNIQUE SCAN           | LEA_AGREEMENT_DTL_UQ      |     1 |       |     1   (0)|
|* 22 |     INDEX UNIQUE SCAN             | NBFC_CUSTOMER_M_PK        |     1 |       |     1   (0)|
|  23 |    TABLE ACCESS BY INDEX ROWID    | NBFC_CUSTOMER_M           |     1 |    21 |     2   (0)|
|  24 |   NESTED LOOPS                    |                           |    75 | 11325 |   366K  (1)|
|  25 |    NESTED LOOPS                   |                           |    75 | 11325 |   366K  (1)|
|  26 |     NESTED LOOPS ANTI             |                           |    75 |  9750 |   366K  (1)|
|  27 |      NESTED LOOPS                 |                           |    75 |  8700 |   365K  (1)|
|* 28 |       TABLE ACCESS FULL           | NBFC_TXN_ADVICE_DTL       |    75 |  3975 |   365K  (1)|
|  29 |       TABLE ACCESS BY INDEX ROWID | LEA_AGREEMENT_DTL         |     1 |    63 |     2   (0)|
|* 30 |        INDEX UNIQUE SCAN          | LEA_AGREEMENT_DTL_UQ      |     1 |       |     1   (0)|
|* 31 |      TABLE ACCESS BY INDEX ROWID  | LEA_TERMINATION_DTL       |     1 |    14 |     2   (0)|
|* 32 |       INDEX UNIQUE SCAN           | LEA_TERMINATION_DTL_PK    |     1 |       |     1   (0)|
|* 33 |     INDEX UNIQUE SCAN             | NBFC_CUSTOMER_M_PK        |     1 |       |     1   (0)|
|  34 |    TABLE ACCESS BY INDEX ROWID    | NBFC_CUSTOMER_M           |     1 |    21 |     2   (0)|
----------------------------------------------------------------------------------------------------

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

   7 - filter("A"."CHEQUEID" IS NOT NULL AND "A"."TXNTYPE"='E' AND "A"."ADVICETYPE"='P' AND 
              "A"."ADVICEAMT">NVL("A"."TXNADJUSTEDAMT",0)+NVL("A"."AMTINPROCESS",0) AND "A"."BPTYPE"='LS' 
              AND NVL("A"."STATUS",'A')='A' AND "A"."MODULEID"='LEA' AND NVL("A"."MC_STATUS",'A')='A')
   8 - filter("C"."STATUS"='C' AND "C"."MC_STATUS"='A')
   9 - access("C"."CHEQUEID"="A"."CHEQUEID")
  10 - filter("H"."AUTHID" IS NULL)
  11 - access("H"."CHEQUEID"="C"."CHEQUEID")
  13 - access("A"."CASEID"="B"."AGREEMENTID")
  14 - access("D"."CUSTOMERID"="B"."LESSEEID")
  19 - filter("A"."ADVICETYPE"='P' AND INSTR(',110486,110487,110666,58,500,572,430,111352,27
              ,431,100164,68,510,511,370,260,103,',','||TO_CHAR("CHARGEID")||',')=0 AND 
              "A"."ADVICEAMT">NVL("A"."TXNADJUSTEDAMT",0)+NVL("A"."AMTINPROCESS",0) AND "A"."BPTYPE"='LS' 
              AND "A"."TXNTYPE"<>'E' AND "A"."TXNTYPE"<>'T' AND NVL("A"."STATUS",'A')='A' AND 
              "A"."MODULEID"='LEA' AND NVL("A"."MC_STATUS",'A')='A')
  21 - access("A"."CASEID"="B"."AGREEMENTID")
  22 - access("B"."LESSEEID"="D"."CUSTOMERID")
  28 - filter("A"."TXNTYPE"='T' AND "A"."ADVICETYPE"='P' AND 
              INSTR(',110486,110487,110666,58,500,572,430,111352,27,431,100164,68,510,511,370,260,103,',',
              '||TO_CHAR("CHARGEID")||',')=0 AND "A"."ADVICEAMT">NVL("A"."TXNADJUSTEDAMT",0)+NVL("A"."AMTI
              NPROCESS",0) AND "A"."BPTYPE"='LS' AND NVL("A"."STATUS",'A')='A' AND "A"."MODULEID"='LEA' 
              AND NVL("A"."MC_STATUS",'A')='A')
  30 - access("A"."CASEID"="B"."AGREEMENTID")
  31 - filter("H"."AUTHORIZEDON" IS NULL)
  32 - access("H"."AGREEMENTID"="B"."AGREEMENTID")
  33 - access("B"."LESSEEID"="D"."CUSTOMERID")

Note
-----
   - 'PLAN_TABLE' is old version

   =================================================================================================

   Explain plan from 12c


-------------------------------------------------------------------------------------------------
| Id  | Operation                         | Name                   | Rows  | Bytes | Cost (%CPU)|
-------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                  |                        |  2378 |   317K|   907K  (1)|
|   1 |  UNION-ALL                        |                        |       |       |            |
|*  2 |   HASH JOIN RIGHT ANTI            |                        |  1271 |   183K|   306K  (1)|
|*  3 |    TABLE ACCESS FULL              | LEA_UNAPPLIED_TXN_DTL  |     1 |    13 |   348   (1)|
|   4 |    NESTED LOOPS                   |                        |  1271 |   167K|   305K  (1)|
|   5 |     NESTED LOOPS                  |                        |  1271 |   167K|   305K  (1)|
|   6 |      NESTED LOOPS                 |                        |  1271 |   139K|   303K  (1)|
|   7 |       NESTED LOOPS                |                        |  1271 |   117K|   300K  (1)|
|*  8 |        TABLE ACCESS FULL          | NBFC_TXN_ADVICE_DTL    |  1271 | 55924 |   298K  (1)|
|   9 |        TABLE ACCESS BY INDEX ROWID| LEA_AGREEMENT_DTL      |     1 |    51 |     2   (0)|
|* 10 |         INDEX UNIQUE SCAN         | LEA_AGREEMENT_DTL_UQ   |     1 |       |     1   (0)|
|  11 |       TABLE ACCESS BY INDEX ROWID | NBFC_CUSTOMER_M        |     1 |    17 |     2   (0)|
|* 12 |        INDEX UNIQUE SCAN          | NBFC_CUSTOMER_M_PK     |     1 |       |     1   (0)|
|* 13 |      INDEX UNIQUE SCAN            | NBFC_CHEQUE_DTL_PK     |     1 |       |     1   (0)|
|* 14 |     TABLE ACCESS BY INDEX ROWID   | NBFC_CHEQUE_DTL        |     1 |    23 |     2   (0)|
|  15 |   NESTED LOOPS                    |                        |  1101 |   133K|   302K  (1)|
|  16 |    NESTED LOOPS                   |                        |  1101 |   133K|   302K  (1)|
|  17 |     NESTED LOOPS                  |                        |  1101 |   115K|   300K  (1)|
|* 18 |      TABLE ACCESS FULL            | NBFC_TXN_ADVICE_DTL    |  1101 | 61656 |   298K  (1)|
|  19 |      TABLE ACCESS BY INDEX ROWID  | LEA_AGREEMENT_DTL      |     1 |    51 |     2   (0)|
|* 20 |       INDEX UNIQUE SCAN           | LEA_AGREEMENT_DTL_UQ   |     1 |       |     1   (0)|
|* 21 |     INDEX UNIQUE SCAN             | NBFC_CUSTOMER_M_PK     |     1 |       |     1   (0)|
|  22 |    TABLE ACCESS BY INDEX ROWID    | NBFC_CUSTOMER_M        |     1 |    17 |     2   (0)|
|  23 |   NESTED LOOPS                    |                        |     6 |   822 |   298K  (1)|
|  24 |    NESTED LOOPS                   |                        |     6 |   822 |   298K  (1)|
|  25 |     NESTED LOOPS ANTI             |                        |     6 |   720 |   298K  (1)|
|  26 |      NESTED LOOPS                 |                        |     6 |   642 |   298K  (1)|
|* 27 |       TABLE ACCESS FULL           | NBFC_TXN_ADVICE_DTL    |     6 |   336 |   298K  (1)|
|  28 |       TABLE ACCESS BY INDEX ROWID | LEA_AGREEMENT_DTL      |     1 |    51 |     2   (0)|
|* 29 |        INDEX UNIQUE SCAN          | LEA_AGREEMENT_DTL_UQ   |     1 |       |     1   (0)|
|* 30 |      TABLE ACCESS BY INDEX ROWID  | LEA_TERMINATION_DTL    |     1 |    13 |     1   (0)|
|* 31 |       INDEX UNIQUE SCAN           | LEA_TERMINATION_DTL_PK |     1 |       |     0   (0)|
|* 32 |     INDEX UNIQUE SCAN             | NBFC_CUSTOMER_M_PK     |     1 |       |     1   (0)|
|  33 |    TABLE ACCESS BY INDEX ROWID    | NBFC_CUSTOMER_M        |     1 |    17 |     2   (0)|
-------------------------------------------------------------------------------------------------

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

   2 - access("H"."CHEQUEID"="C"."CHEQUEID")
   3 - filter("H"."AUTHID" IS NULL)
   8 - filter("A"."CHEQUEID" IS NOT NULL AND "A"."TXNTYPE"='E' AND "A"."ADVICETYPE"='P' 
              AND "A"."ADVICEAMT">NVL("A"."TXNADJUSTEDAMT",0)+NVL("A"."AMTINPROCESS",0) AND 
              "A"."BPTYPE"='LS' AND NVL("A"."STATUS",'A')='A' AND "A"."MODULEID"='LEA' AND 
              NVL("A"."MC_STATUS",'A')='A')
  10 - access("A"."CASEID"="B"."AGREEMENTID")
  12 - access("D"."CUSTOMERID"="B"."LESSEEID")
  13 - access("C"."CHEQUEID"="A"."CHEQUEID")
  14 - filter("C"."STATUS"='C' AND "C"."MC_STATUS"='A')
  18 - filter("A"."ADVICETYPE"='P' AND INSTR(',110486,110487,110666,58,500,572,430,111352
              ,27,431,100164,68,510,511,370,260,103,',','||TO_CHAR("CHARGEID")||',')=0 AND 
              "A"."ADVICEAMT">NVL("A"."TXNADJUSTEDAMT",0)+NVL("A"."AMTINPROCESS",0) AND 
              "A"."BPTYPE"='LS' AND "A"."TXNTYPE"<>'E' AND "A"."TXNTYPE"<>'T' AND 
              NVL("A"."STATUS",'A')='A' AND "A"."MODULEID"='LEA' AND NVL("A"."MC_STATUS",'A')='A')
  20 - access("A"."CASEID"="B"."AGREEMENTID")
  21 - access("B"."LESSEEID"="D"."CUSTOMERID")
  27 - filter("A"."TXNTYPE"='T' AND "A"."ADVICETYPE"='P' AND 
              INSTR(',110486,110487,110666,58,500,572,430,111352,27,431,100164,68,510,511,370,260,103,'
              ,','||TO_CHAR("CHARGEID")||',')=0 AND "A"."ADVICEAMT">NVL("A"."TXNADJUSTEDAMT",0)+NVL("A"
              ."AMTINPROCESS",0) AND "A"."BPTYPE"='LS' AND NVL("A"."STATUS",'A')='A' AND 
              "A"."MODULEID"='LEA' AND NVL("A"."MC_STATUS",'A')='A')
  29 - access("A"."CASEID"="B"."AGREEMENTID")
  30 - filter("H"."AUTHORIZEDON" IS NULL)
  31 - access("H"."AGREEMENTID"="B"."AGREEMENTID")
  32 - access("B"."LESSEEID"="D"."CUSTOMERID")

Note
-----
   - 'PLAN_TABLE' is old version
...