2

いくつかのテーブルに基づいてレポートを生成すると、そのうちのいくつかは非常に巨大 (10 億以上のレコード) で、一部はかなり小さい (100 レコード) で、17 分かかります。しかし、where句に条件を追加すると、1時間以上実行され始めました。

table1 には 10 億以上のレコードがあり、追加された条件は "and line_ind in ('Y', '*')" です。問題は、CBO が結合の結果セットから検索できるのに、なぜ全テーブル スキャンを行うのかということです。順序付けられたヒントは役に立たないようで、この選択をより速く実行する方法を考えています.?

テーブルのレコード数は次のとおりです

table1(a) 1,234,432,435
table2(b) 1,234,432,435
table3(c) 900
table4(d) 602,364,856
table5(e) 80
table6(f) 50
table7(g) 264,938,373
table8(h) 14,827



SELECT DISTINCT c_cd,
                  ci_nbr,
                  c.s_id1,
                  d.d_cd,
                  SUM (CASE WHEN (D_CD = 'MAILED') THEN 1 ELSE 0 END) AS MAILED
    FROM table1 a
         LEFT OUTER JOIN table2 b ON (a.o_id = b.o_id AND a.co_sid = b.co_sid)
         INNER JOIN table3 c
            ON c.c_sid = a.c_sid AND c.c_cd IN ('CC364', 'CC552')
         INNER JOIN table4 c ON a.sc_sid = c.sc_sid
         INNER JOIN table5 d ON d.d_SID = b.d_SID
         INNER JOIN table6 e ON e.cc_sid = b.cc_sid
         INNER JOIN table7 f ON f.ci_sid = b.ci_sid
         INNER JOIN table8 g ON g.dt_sid = a.dt_sid
GROUP BY dt_cd,
         c_nbr,
         c.s_id1,
         d.d_cd
 where dt_cd in ('c6543-010114','c5653-010514') and line_ind in ('Y', '*') and c_nbr='728246'

計画の説明

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                                         | Name                           | E-Rows |E-Bytes| Cost (%CPU)| E-Time   | Pstart| Pstop |    TQ  |IN-OUT| PQ Distrib |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                                  |                                |    811 |   296K|   304K  (3)| 01:11:02 |       |       |        |      |            |
|   1 |  PX COORDINATOR                                   |                                |        |       |            |          |       |       |        |      |            |
|   2 |   PX SEND QC (RANDOM)                             | :TQ10009                       |    811 |   296K|   304K  (3)| 01:11:02 |       |       |  Q1,09 | P->S | QC (RAND)  |
|   3 |    HASH GROUP BY                                  |                                |    811 |   296K|   304K  (3)| 01:11:02 |       |       |  Q1,09 | PCWP |            |
|   4 |     PX RECEIVE                                    |                                |    811 |   296K|   304K  (3)| 01:11:02 |       |       |  Q1,09 | PCWP |            |
|   5 |      PX SEND HASH                                 | :TQ10008                       |    811 |   296K|   304K  (3)| 01:11:02 |       |       |  Q1,08 | P->P | HASH       |
|   6 |       HASH GROUP BY                               |                                |    811 |   296K|   304K  (3)| 01:11:02 |       |       |  Q1,08 | PCWP |            |
|*  7 |        HASH JOIN                                  |                                |    811 |   296K|   304K  (3)| 01:11:02 |       |       |  Q1,08 | PCWP |            |
|   8 |         PX RECEIVE                                |                                |    802 |   278K|   277K  (4)| 01:04:39 |       |       |  Q1,08 | PCWP |            |
|   9 |          PX SEND BROADCAST                        | :TQ10007                       |    802 |   278K|   277K  (4)| 01:04:39 |       |       |  Q1,07 | P->P | BROADCAST  |
|* 10 |           HASH JOIN                               |                                |    802 |   278K|   277K  (4)| 01:04:39 |       |       |  Q1,07 | PCWP |            |
|  11 |            PX RECEIVE                             |                                |    802 |   177K|   225K  (4)| 00:52:44 |       |       |  Q1,07 | PCWP |            |
|  12 |             PX SEND BROADCAST                     | :TQ10006                       |    802 |   177K|   225K  (4)| 00:52:44 |       |       |  Q1,06 | P->P | BROADCAST  |
|* 13 |              HASH JOIN BUFFERED                   |                                |    802 |   177K|   225K  (4)| 00:52:44 |       |       |  Q1,06 | PCWP |            |
|  14 |               PX RECEIVE                          |                                |     96 |  4800 |     2   (0)| 00:00:01 |       |       |  Q1,06 | PCWP |            |
|  15 |                PX SEND BROADCAST                  | :TQ10004                       |     96 |  4800 |     2   (0)| 00:00:01 |       |       |  Q1,04 | P->P | BROADCAST  |
|  16 |                 PX BLOCK ITERATOR                 |                                |     96 |  4800 |     2   (0)| 00:00:01 |       |       |  Q1,04 | PCWC |            |
|  17 |                  TABLE ACCESS STORAGE FULL        | TABLE5                         |     96 |  4800 |     2   (0)| 00:00:01 |       |       |  Q1,04 | PCWP |            |
|* 18 |               HASH JOIN                           |                                |    802 |   138K|   225K  (4)| 00:52:44 |       |       |  Q1,06 | PCWP |            |
|  19 |                BUFFER SORT                        |                                |        |       |            |          |       |       |  Q1,06 | PCWC |            |
|  20 |                 PX RECEIVE                        |                                |     51 |   561 |     5   (0)| 00:00:01 |       |       |  Q1,06 | PCWP |            |
|  21 |                  PX SEND HASH                     | :TQ10000                       |     51 |   561 |     5   (0)| 00:00:01 |       |       |        | S->P | HASH       |
|  22 |                   TABLE ACCESS STORAGE FULL       | TABLE6                         |     51 |   561 |     5   (0)| 00:00:01 |       |       |        |      |            |
|  23 |                PX RECEIVE                         |                                |    802 |   130K|   225K  (4)| 00:52:44 |       |       |  Q1,06 | PCWP |            |
|  24 |                 PX SEND HASH                      | :TQ10005                       |    802 |   130K|   225K  (4)| 00:52:44 |       |       |  Q1,05 | P->P | HASH       |
|* 25 |                  HASH JOIN                        |                                |    802 |   130K|   225K  (4)| 00:52:44 |       |       |  Q1,05 | PCWP |            |
|  26 |                   PX RECEIVE                      |                                |    802 |   101K|   104K  (5)| 00:24:25 |       |       |  Q1,05 | PCWP |            |
|  27 |                    PX SEND BROADCAST              | :TQ10003                       |    802 |   101K|   104K  (5)| 00:24:25 |       |       |  Q1,03 | P->P | BROADCAST  |
|* 28 |                     HASH JOIN                     |                                |    802 |   101K|   104K  (5)| 00:24:25 |       |       |  Q1,03 | PCWP |            |
|  29 |                      PX RECEIVE                   |                                |      2 |    24 |    17   (0)| 00:00:01 |       |       |  Q1,03 | PCWP |            |
|  30 |                       PX SEND BROADCAST           | :TQ10001                       |      2 |    24 |    17   (0)| 00:00:01 |       |       |  Q1,01 | P->P | BROADCAST  |
|  31 |                        PX BLOCK ITERATOR          |                                |      2 |    24 |    17   (0)| 00:00:01 |       |       |  Q1,01 | PCWC |            |
|* 32 |                         TABLE ACCESS STORAGE FULL | TABLE3                         |      2 |    24 |    17   (0)| 00:00:01 |       |       |  Q1,01 | PCWP |            |
|* 33 |                      HASH JOIN                    |                                |  68190 |  7857K|   104K  (5)| 00:24:25 |       |       |  Q1,03 | PCWP |            |
|  34 |                       PX RECEIVE                  |                                |      2 |    34 |   276   (0)| 00:00:04 |       |       |  Q1,03 | PCWP |            |
|  35 |                        PX SEND BROADCAST          | :TQ10002                       |      2 |    34 |   276   (0)| 00:00:04 |       |       |  Q1,02 | P->P | BROADCAST  |
|  36 |                         PX BLOCK ITERATOR         |                                |      2 |    34 |   276   (0)| 00:00:04 |       |       |  Q1,02 | PCWC |            |
|* 37 |                          TABLE ACCESS STORAGE FULL| TABLE8                         |      2 |    34 |   276   (0)| 00:00:04 |       |       |  Q1,02 | PCWP |            |
|  38 |                       PX BLOCK ITERATOR           |                                |     22M|  2177M|   104K  (5)| 00:24:21 |     1 |1048575|  Q1,03 | PCWC |            |
|* 39 |                        TABLE ACCESS STORAGE FULL  | TABLE1                         |     22M|  2177M|   104K  (5)| 00:24:21 |     1 |1048575|  Q1,03 | PCWP |            |
|  40 |                   PX BLOCK ITERATOR               |                                |    969M|    32G|   121K  (3)| 00:28:15 |     1 |1048575|  Q1,05 | PCWC |            |
|* 41 |                    TABLE ACCESS STORAGE FULL      | TABLE2                         |    969M|    32G|   121K  (3)| 00:28:15 |     1 |1048575|  Q1,05 | PCWP |            |
|  42 |            PX BLOCK ITERATOR                      |                                |    398M|    47G| 50955   (1)| 00:11:54 |       |       |  Q1,07 | PCWC |            |
|  43 |             TABLE ACCESS STORAGE FULL             | TABLE7                         |    398M|    47G| 50955   (1)| 00:11:54 |       |       |  Q1,07 | PCWP |            |
|  44 |         PX BLOCK ITERATOR                         |                                |    589M|    10G| 27170   (2)| 00:06:21 |     1 |    13 |  Q1,08 | PCWC |            |
|  45 |          TABLE ACCESS STORAGE FULL                | TABLE4                         |    589M|    10G| 27170   (2)| 00:06:21 |     1 |    13 |  Q1,08 | PCWP |            |
4

1 に答える 1