微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何优化 Oracle UNION ALL 的两个 3 秒查询,耗时超过 200 秒......即使使用 rownum

如何解决如何优化 Oracle UNION ALL 的两个 3 秒查询,耗时超过 200 秒......即使使用 rownum

我正在努力进一步优化以下查询。到目前为止,我已经在优化查询方面取得了很多成功,但现在我正在寻求其他人的帮助以寻求想法。感谢您的帮助。

以下查询需要 200 多秒才能完成,但构成“UNION ALL”的两个单独的 WITH 子句查询(receiving_1 和 receive_2)每个都需要不到 4 秒。

  • receiving_1 -- 3.4 秒内接收 58 次;成本 295(无 UNION)
  • receiving_2 -- 3.8 秒内收到 0 条记录;成本 295(无 UNION)
  • UNION ALL of 1+2 -- 58 recs in 203.1 secs;成本 300(UNION ALL)

我希望“rownum”能帮助优化“UNION ALL”,但它没有。此尝试基于 AskTom --> 文件 --> sqlTechniques.zip(61 到 72 之间)的注释

当你有两个分别以光速运行的查询时 但不是这样在一起 通常是一个混合的“CBO/RBO”问题 使用具有启动 CBO 的功能的 RBO Rownum 可以是一个临时修复,直到所有事情都成为 CBO

注意:避免此问题的一种优化是嵌入的替换参数或游标参数,它们极大地减少了查询中关键点的行数。但是,由于我需要针对只读数据库通过数据库链接运行此查询,因此此查询无法使用以下选项。

注意:为了用尽可能少的代码提供一个好的测试用例,下面的 sql(4,584 个字符,88 个换行符)是实际 sql(93,683 个字符,2,014 个换行符)的大大简化版本我正在开发中。最初的 sql 已经经过多轮优化,将运行时间从一个多小时缩短到 10 秒以下。这个最新的挑战是必须将 sql 重写为视图,而不是带有嵌入替换参数的 sql 文件。到目前为止,替换参数是优化的关键。我现在正在重构 sql 以用作 Oracle 11gR2 中的视图,以便通过来自 Oracle 19c 的数据库链接进行调用。显然,视图没有参数。查询视图时,驱动参数(账本、OU、期间)将是WHERE子句条件。

大图:正在开发的实际 sql 是 6 个共享大量重复代码的报表查询的合并。我的工作是将所有六个源报告查询转换为有效的摘录,以便导入新的数据库模式以进行协调。

with
gccs as ( 
select
       gcc.code_combination_id
    from apps.gl_code_combinations gcc
    where 1=1
      AND regexp_like(gcc.segment1,'^[0-9]{4}$') -- only include 4-digit numbers
      AND gcc.segment1 BETWEEN to_char('1500') and to_char('1504')
      AND regexp_like(gcc.segment3,'^[0-9]{4}$') -- only include 4-digit numbers
      AND (    gcc.segment3 BETWEEN to_char('5000') and to_char('5999')
            OR gcc.segment3 in ('6000','6002','6003','6004','6005','6006','6007','6008','6009','6010','6011','6012','6013','6014','6017','6018','6019','6020','6021','6022','6023','6024','6025','6026','6027','6028','6029','6030','6031','6032','6033','6034','6035','6036','6037','6038','6039','6040','6041','6042','6043','6044','6045','6046','6047','6048','6049','6050','6051','6052','6053','6054','6055','6056','6058','6060','6061','6062','6063','6064','6065','6066','6067','6068','6069','6070','6071','6072','6073','6074','6075','6076','6077','6084','6085','6086','6087','6088','6089','6090','6091','6092','6093','6094','6095','6096','6097','6098','6099','6100','6101','6102','6103','6104','6105','6106','6120','6121','6130','6131','6140','6150','6151','6155','6158','6162','6990','6991','6992','6993','6994','6995','6996','6997','6998'))
      AND regexp_like(gcc.segment6,'^[0-9]{4}$') -- only include 4-digit numbers
      AND gcc.segment6 BETWEEN to_char('3000') and to_char('4999')
) -- select count(*) code_combination_id from gccs;,base_query as (
    SELECT 
           gl.LEDGER_ID,hou.organization_id,gper.PERIOD_NAME,XAL.AE_HEADER_ID,XAL.AE_LINE_NUM,GJB.STATUS BATCH_STATUS,GJH.JE_CATEGORY,XAL.ACCOUNTING_CLASS_CODE,GJH.JE_SOURCE,GJH.JE_HEADER_ID,GJL.JE_LINE_NUM           
      FROM apps.gl_ledgers gl
            join apps.hr_operating_units         hou 
                on hou.set_of_books_id = gl.ledger_id
            join APPS.GL_JE_LInes               GJL 
                on exists (select null from gccs where gccs.CODE_COMBINATION_ID = GJL.CODE_COMBINATION_ID)
                   AND (nvl(gjl.stat_amount,0) <> 0 OR (NVL (gjl.accounted_dr,0) - NVL (gjl.accounted_cr,0)) <> 0)
            join APPS.GL_PERIODS                       gper
                on GJL.PERIOD_NAME = gper.PERIOD_NAME
            join APPS.GL_JE_HEADERS             GJH 
                on     GJH.JE_HEADER_ID = GJL.JE_HEADER_ID
                   AND GJH.PERIOD_NAME = gper.PERIOD_NAME
                   AND GJH.LEDGER_ID = gl.ledger_id
                   AND GJH.JE_SOURCE = 'Cost Management'
            join APPS.GL_JE_BATCHES             GJB 
                on GJB.JE_BATCH_ID = GJH.JE_BATCH_ID
            join APPS.GL_IMPORT_REFERENCES      GIR 
                on     GIR.JE_HEADER_ID = GJL.JE_HEADER_ID
                   AND GIR.JE_LINE_NUM = GJL.JE_LINE_NUM
            join APPS.XLA_AE_LInes              XAL 
                on     XAL.GL_SL_LINK_TABLE = GIR.GL_SL_LINK_TABLE
                   AND XAL.GL_SL_LINK_ID = GIR.GL_SL_LINK_ID
                   AND XAL.LEDGER_ID = gl.LEDGER_ID
),receiving_1 as (
        select  distinct 
                        bq.LEDGER_ID,bq.organization_id,bq.period_name,bq.AE_HEADER_ID,bq.AE_LINE_NUM
          FROM base_query bq
         WHERE bq.BATCH_STATUS = 'P'
           AND UPPER(bq.JE_CATEGORY) = UPPER('Receiving')
),receiving_2 as (
        select   distinct
                        bq.LEDGER_ID,bq.AE_LINE_NUM
          FROM base_query bq
         WHERE bq.ACCOUNTING_CLASS_CODE = 'INTRA'
           AND bq.BATCH_STATUS = 'P'
           AND UPPER(bq.JE_CATEGORY) = UPPER('Receiving')
),receiving_all as (
    -- the use of "rownum" below sometimes helps to optimize "union all",but does not help in this query
    select rownum,x.* from receiving_1 x            -- 58 recs in   3.4 secs cost 295 (no UNION)
    union all                                        -- 58 recs in 203.1 secs cost 300 (UNION ALL)
    select rownum,x.* from receiving_2 x            -- 0 recs in 3.8 secs cost 295 (no UNION)
)
select count(*) 
    from receiving_all 
    where ledger_id = 2021 
      and organization_id = 82 
      and period_name = 'SEP-2020';

用于接收_1 部分查询的 AUTOTRACE"

  COUNT(*)
----------
        58


Execution Plan
----------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                                     | Name                           | Rows  | Bytes | Cost (%cpu)| Pstart| Pstop |
-------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                              |                                |     1 |    35 |   295   (1)|       |       |
|   1 |  SORT AGGREGATE                               |                                |     1 |    35 |            |       |       |
|   2 |   VIEW                                        |                                |     1 |    35 |   295   (1)|       |       |
|   3 |    COUNT                                      |                                |       |       |            |       |       |
|   4 |     VIEW                                      |                                |     1 |    35 |   295   (1)|       |       |
|   5 |      HASH UNIQUE                              |                                |     1 |   266 |   295   (1)|       |       |
|   6 |       nesTED LOOPS                            |                                |     1 |   266 |   294   (1)|       |       |
|   7 |        nesTED LOOPS                           |                                |     1 |   266 |   294   (1)|       |       |
|   8 |         nesTED LOOPS                          |                                |     1 |   237 |   236   (1)|       |       |
|   9 |          nesTED LOOPS                         |                                |     1 |   214 |   178   (1)|       |       |
|  10 |           nesTED LOOPS                        |                                |     1 |   207 |   176   (1)|       |       |
|  11 |            nesTED LOOPS                       |                                |     1 |   183 |   176   (1)|       |       |
|  12 |             nesTED LOOPS                      |                                |     1 |   152 |   173   (1)|       |       |
|  13 |              nesTED LOOPS                     |                                |     1 |   148 |   173   (1)|       |       |
|  14 |               nesTED LOOPS                    |                                |     1 |   123 |   172   (1)|       |       |
|  15 |                nesTED LOOPS                   |                                |     1 |   101 |   169   (1)|       |       |
|  16 |                 nesTED LOOPS                  |                                |     1 |    97 |   169   (1)|       |       |
|  17 |                  nesTED LOOPS                 |                                |     1 |    53 |   167   (1)|       |       |
|  18 |                   SORT UNIQUE                 |                                |     1 |    21 |    22   (0)|       |       |
|  19 |                    TABLE ACCESS BY INDEX ROWID| GL_CODE_COMBINATIONS           |     1 |    21 |    22   (0)|       |       |
|  20 |                     INDEX RANGE SCAN          | GL_CODE_COMBINATIONS_N1        |   117 |       |     8   (0)|       |       |
|  21 |                   TABLE ACCESS BY INDEX ROWID | GL_JE_LInes                    |    16 |   512 |   144   (0)|       |       |
|  22 |                    INDEX RANGE SCAN           | GL_JE_LInes_N1                 |   319 |       |     4   (0)|       |       |
|  23 |                  TABLE ACCESS BY INDEX ROWID  | GL_JE_HEADERS                  |     1 |    44 |     2   (0)|       |       |
|  24 |                   INDEX UNIQUE SCAN           | GL_JE_HEADERS_U1               |     1 |       |     1   (0)|       |       |
|  25 |                 INDEX UNIQUE SCAN             | GL_LEDGERS_U2                  |     1 |     4 |     0   (0)|       |       |
|  26 |                TABLE ACCESS BY INDEX ROWID    | HR_ORGANIZATION_informatION    |     1 |    22 |     3   (0)|       |       |
|  27 |                 INDEX RANGE SCAN              | HR_ORGANIZATION_informatIO_FK1 |    30 |       |     1   (0)|       |       |
|  28 |               INDEX RANGE SCAN                | GL_PERIODS_U1                  |     1 |    25 |     1   (0)|       |       |
|  29 |              INDEX UNIQUE SCAN                | HR_ORGANIZATION_UNITS_PK       |     1 |     4 |     0   (0)|       |       |
|  30 |             TABLE ACCESS BY INDEX ROWID       | HR_ORGANIZATION_informatION    |     1 |    31 |     3   (0)|       |       |
|  31 |              INDEX RANGE SCAN                 | HR_ORGANIZATION_informatIO_FK2 |     2 |       |     1   (0)|       |       |
|  32 |            INDEX UNIQUE SCAN                  | HR_ALL_ORGANIZATION_UNTS_TL_PK |     1 |    24 |     0   (0)|       |       |
|  33 |           TABLE ACCESS BY INDEX ROWID         | GL_JE_BATCHES                  |     1 |     7 |     2   (0)|       |       |
|  34 |            INDEX UNIQUE SCAN                  | GL_JE_BATCHES_U1               |     1 |       |     1   (0)|       |       |
|  35 |          TABLE ACCESS BY INDEX ROWID          | GL_IMPORT_REFERENCES           |   105 |  2415 |    58   (0)|       |       |
|  36 |           INDEX RANGE SCAN                    | GL_IMPORT_REFERENCES_N1        |   105 |       |     3   (0)|       |       |
|  37 |         PARTITION LIST ALL                    |                                |     1 |       |    57   (0)|     1 |    19 |
|  38 |          INDEX RANGE SCAN                     | XLA_AE_LInes_N4                |     1 |       |    57   (0)|     1 |    19 |
|  39 |        TABLE ACCESS BY LOCAL INDEX ROWID      | XLA_AE_LInes                   |     1 |    29 |    58   (0)|     1 |     1 |
-------------------------------------------------------------------------------------------------------------------------------------

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


Statistics
----------------------------------------------------------
         99  recursive calls
          0  db block gets
    3500320  consistent gets
          0  physical reads
        116  redo size
        346  bytes sent via sql*Net to client
       4388  bytes received via sql*Net from client
          2  sql*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
          1  rows processed

用于接收_2 部分查询的 AUTOTRACE:

  COUNT(*)
----------
        0


Execution Plan
----------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                                     | Name                           | Rows  | Bytes | Cost (%cpu)| Pstart| Pstop |
-------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                              |                                |     1 |    35 |   295   (1)|       |       |
|   1 |  SORT AGGREGATE                               |                                |     1 |    35 |            |       |       |
|   2 |   VIEW                                        |                                |     1 |    35 |   295   (1)|       |       |
|   3 |    COUNT                                      |                                |       |       |            |       |       |
|   4 |     VIEW                                      |                                |     1 |    35 |   295   (1)|       |       |
|   5 |      HASH UNIQUE                              |                                |     1 |   279 |   295   (1)|       |       |
|   6 |       nesTED LOOPS                            |                                |     1 |   279 |   294   (1)|       |       |
|   7 |        nesTED LOOPS                           |                                |     1 |   279 |   294   (1)|       |       |
|   8 |         nesTED LOOPS                          |                                |     1 |   272 |   292   (1)|       |       |
|   9 |          nesTED LOOPS                         |                                |     1 |   230 |   234   (1)|       |       |
|  10 |           nesTED LOOPS                        |                                |     1 |   207 |   176   (1)|       |       |
|  11 |            nesTED LOOPS                       |                                |     1 |   183 |   176   (1)|       |       |
|  12 |             nesTED LOOPS                      |                                |     1 |   152 |   173   (1)|       |       |
|  13 |              nesTED LOOPS                     |                                |     1 |   148 |   173   (1)|       |       |
|  14 |               nesTED LOOPS                    |                                |     1 |   126 |   170   (1)|       |       |
|  15 |                nesTED LOOPS                   |                                |     1 |   122 |   170   (1)|       |       |
|  16 |                 nesTED LOOPS                  |                                |     1 |    97 |   169   (1)|       |       |
|  17 |                  nesTED LOOPS                 |                                |     1 |    53 |   167   (1)|       |       |
|  18 |                   SORT UNIQUE                 |                                |     1 |    21 |    22   (0)|       |       |
|  19 |                    TABLE ACCESS BY INDEX ROWID| GL_CODE_COMBINATIONS           |     1 |    21 |    22   (0)|       |       |
|  20 |                     INDEX RANGE SCAN          | GL_CODE_COMBINATIONS_N1        |   117 |       |     8   (0)|       |       |
|  21 |                   TABLE ACCESS BY INDEX ROWID | GL_JE_LInes                    |    16 |   512 |   144   (0)|       |       |
|  22 |                    INDEX RANGE SCAN           | GL_JE_LInes_N1                 |   319 |       |     4   (0)|       |       |
|  23 |                  TABLE ACCESS BY INDEX ROWID  | GL_JE_HEADERS                  |     1 |    44 |     2   (0)|       |       |
|  24 |                   INDEX UNIQUE SCAN           | GL_JE_HEADERS_U1               |     1 |       |     1   (0)|       |       |
|  25 |                 INDEX RANGE SCAN              | GL_PERIODS_U1                  |     1 |    25 |     1   (0)|       |       |
|  26 |                INDEX UNIQUE SCAN              | GL_LEDGERS_U2                  |     1 |     4 |     0   (0)|       |       |
|  27 |               TABLE ACCESS BY INDEX ROWID     | HR_ORGANIZATION_informatION    |     1 |    22 |     3   (0)|       |       |
|  28 |                INDEX RANGE SCAN               | HR_ORGANIZATION_informatIO_FK1 |    30 |       |     1   (0)|       |       |
|  29 |              INDEX UNIQUE SCAN                | HR_ORGANIZATION_UNITS_PK       |     1 |     4 |     0   (0)|       |       |
|  30 |             TABLE ACCESS BY INDEX ROWID       | HR_ORGANIZATION_informatION    |     1 |    31 |     3   (0)|       |       |
|  31 |              INDEX RANGE SCAN                 | HR_ORGANIZATION_informatIO_FK2 |     2 |       |     1   (0)|       |       |
|  32 |            INDEX UNIQUE SCAN                  | HR_ALL_ORGANIZATION_UNTS_TL_PK |     1 |    24 |     0   (0)|       |       |
|  33 |           TABLE ACCESS BY INDEX ROWID         | GL_IMPORT_REFERENCES           |   105 |  2415 |    58   (0)|       |       |
|  34 |            INDEX RANGE SCAN                   | GL_IMPORT_REFERENCES_N1        |   105 |       |     3   (0)|       |       |
|  35 |          PARTITION LIST ALL                   |                                |     1 |    42 |    58   (0)|     1 |    19 |
|  36 |           TABLE ACCESS BY LOCAL INDEX ROWID   | XLA_AE_LInes                   |     1 |    42 |    58   (0)|     1 |    19 |
|  37 |            INDEX RANGE SCAN                   | XLA_AE_LInes_N4                |     1 |       |    57   (0)|     1 |    19 |
|  38 |         INDEX UNIQUE SCAN                     | GL_JE_BATCHES_U1               |     1 |       |     1   (0)|       |       |
|  39 |        TABLE ACCESS BY INDEX ROWID            | GL_JE_BATCHES                  |     1 |     7 |     2   (0)|       |       |
-------------------------------------------------------------------------------------------------------------------------------------

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


Statistics
----------------------------------------------------------
         99  recursive calls
          0  db block gets
    3451912  consistent gets
          0  physical reads
          0  redo size
        345  bytes sent via sql*Net to client
       4385  bytes received via sql*Net from client
          2  sql*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
          1  rows processed

AUTOTRACE for UNION ALL 包含 request_1 和 request_2 的完整查询

  COUNT(*)
----------
        58


Execution Plan
----------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                                  | Name                           | Rows  | Bytes | Cost (%cpu)| Pstart| Pstop |
----------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                           |                                |     1 |    35 |   300   (1)|       |       |
|   1 |  TEMP TABLE TRANSFORMATION                 |                                |       |       |            |       |       |
|   2 |   LOAD AS SELECT                           | SYS_TEMP_0FD9D6767_FC3F7B00    |       |       |            |       |       |
|   3 |    nesTED LOOPS                            |                                |     1 |   279 |   294   (1)|       |       |
|   4 |     nesTED LOOPS                           |                                |     1 |   279 |   294   (1)|       |       |
|   5 |      nesTED LOOPS                          |                                |     1 |   237 |   236   (1)|       |       |
|   6 |       nesTED LOOPS                         |                                |     1 |   214 |   178   (1)|       |       |
|   7 |        nesTED LOOPS                        |                                |     1 |   207 |   176   (1)|       |       |
|   8 |         nesTED LOOPS                       |                                |     1 |   183 |   176   (1)|       |       |
|   9 |          nesTED LOOPS                      |                                |     1 |   152 |   173   (1)|       |       |
|  10 |           nesTED LOOPS                     |                                |     1 |   148 |   173   (1)|       |       |
|  11 |            nesTED LOOPS                    |                                |     1 |   126 |   170   (1)|       |       |
|  12 |             nesTED LOOPS                   |                                |     1 |   122 |   170   (1)|       |       |
|  13 |              nesTED LOOPS                  |                                |     1 |    78 |   168   (1)|       |       |
|  14 |               nesTED LOOPS                 |                                |     1 |    53 |   167   (1)|       |       |
|  15 |                SORT UNIQUE                 |                                |     1 |    21 |    22   (0)|       |       |
|  16 |                 TABLE ACCESS BY INDEX ROWID| GL_CODE_COMBINATIONS           |     1 |    21 |    22   (0)|       |       |
|  17 |                  INDEX RANGE SCAN          | GL_CODE_COMBINATIONS_N1        |   117 |       |     8   (0)|       |       |
|  18 |                TABLE ACCESS BY INDEX ROWID | GL_JE_LInes                    |    16 |   512 |   144   (0)|       |       |
|  19 |                 INDEX RANGE SCAN           | GL_JE_LInes_N1                 |   319 |       |     4   (0)|       |       |
|  20 |               INDEX RANGE SCAN             | GL_PERIODS_U1                  |     1 |    25 |     1   (0)|       |       |
|  21 |              TABLE ACCESS BY INDEX ROWID   | GL_JE_HEADERS                  |     1 |    44 |     2   (0)|       |       |
|  22 |               INDEX UNIQUE SCAN            | GL_JE_HEADERS_U1               |     1 |       |     1   (0)|       |       |
|  23 |             INDEX UNIQUE SCAN              | GL_LEDGERS_U2                  |     1 |     4 |     0   (0)|       |       |
|  24 |            TABLE ACCESS BY INDEX ROWID     | HR_ORGANIZATION_informatION    |     1 |    22 |     3   (0)|       |       |
|  25 |             INDEX RANGE SCAN               | HR_ORGANIZATION_informatIO_FK1 |    30 |       |     1   (0)|       |       |
|  26 |           INDEX UNIQUE SCAN                | HR_ORGANIZATION_UNITS_PK       |     1 |     4 |     0   (0)|       |       |
|  27 |          TABLE ACCESS BY INDEX ROWID       | HR_ORGANIZATION_informatION    |     1 |    31 |     3   (0)|       |       |
|  28 |           INDEX RANGE SCAN                 | HR_ORGANIZATION_informatIO_FK2 |     2 |       |     1   (0)|       |       |
|  29 |         INDEX UNIQUE SCAN                  | HR_ALL_ORGANIZATION_UNTS_TL_PK |     1 |    24 |     0   (0)|       |       |
|  30 |        TABLE ACCESS BY INDEX ROWID         | GL_JE_BATCHES                  |     1 |     7 |     2   (0)|       |       |
|  31 |         INDEX UNIQUE SCAN                  | GL_JE_BATCHES_U1               |     1 |       |     1   (0)|       |       |
|  32 |       TABLE ACCESS BY INDEX ROWID          | GL_IMPORT_REFERENCES           |   105 |  2415 |    58   (0)|       |       |
|  33 |        INDEX RANGE SCAN                    | GL_IMPORT_REFERENCES_N1        |   105 |       |     3   (0)|       |       |
|  34 |      PARTITION LIST ALL                    |                                |     1 |       |    57   (0)|     1 |    19 |
|  35 |       INDEX RANGE SCAN                     | XLA_AE_LInes_N4                |     1 |       |    57   (0)|     1 |    19 |
|  36 |     TABLE ACCESS BY LOCAL INDEX ROWID      | XLA_AE_LInes                   |     1 |    42 |    58   (0)|     1 |     1 |
|  37 |   SORT AGGREGATE                           |                                |     1 |    35 |            |       |       |
|  38 |    VIEW                                    |                                |     2 |    70 |     6  (34)|       |       |
|  39 |     UNION-ALL                              |                                |       |       |            |       |       |
|  40 |      COUNT                                 |                                |       |       |            |       |       |
|  41 |       VIEW                                 |                                |     1 |    35 |     3  (34)|       |       |
|  42 |        HASH UNIQUE                         |                                |     1 |    44 |     3  (34)|       |       |
|  43 |         VIEW                               |                                |     1 |    44 |     2   (0)|       |       |
|  44 |          TABLE ACCESS FULL                 | SYS_TEMP_0FD9D6767_FC3F7B00    |     1 |    74 |     2   (0)|       |       |
|  45 |      COUNT                                 |                                |       |       |            |       |       |
|  46 |       VIEW                                 |                                |     1 |    35 |     3  (34)|       |       |
|  47 |        HASH UNIQUE                         |                                |     1 |    61 |     3  (34)|       |       |
|  48 |         VIEW                               |                                |     1 |    61 |     2   (0)|       |       |
|  49 |          TABLE ACCESS FULL                 | SYS_TEMP_0FD9D6767_FC3F7B00    |     1 |    74 |     2   (0)|       |       |
----------------------------------------------------------------------------------------------------------------------------------

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


Statistics
----------------------------------------------------------
        766  recursive calls
      83076  db block gets
  270487689  consistent gets
      81660  physical reads
        676  redo size
        346  bytes sent via sql*Net to client
       4582  bytes received via sql*Net from client
          2  sql*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
          1  rows processed

解决方法

由于我不知道底层表、它们的结构和它们的数据,我只能猜测。话虽如此,我会尝试以下操作(不知道这些步骤是否有帮助!):

  1. receiving_all

    中删除 rownum
  2. 将主查询中的 where 子句添加到 receiving_all 中的每个子查询。优化器可能会推断出这一点,但我不确定。

  3. union all 中的 union 更改为 receiving_all,并从 distinctreceiving_1 中删除 receiving_2

  4. receiving_2 似乎包含在 receiving_2 中?

  5. 如果 4. 不是这种情况,我会将两者合并为一个带有 WHERE UPPER(bq.JE_CATEGORY) = UPPER('Receiving') AND ( (<conditions for 1>) OR (<conditions for 2>) )

    的查询
  6. 如果可以避免 UPPER(bq.JE_CATEGORY),我会尝试。函数阻止索引访问。

  7. 如果您可以创建表,我会将 gccs 的值展开到两个表中,一个用于 segment_1,另一个用于 segment_2

  8. 如果 7. 不是一个选项,我会将提示 select /*+ materialize */ gcc.code_combination_id 添加到 gcc

我很想知道哪个建议有任何积极影响...

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。