Oracle SQL:Optimizer没有选择最佳方式?

时间:2015-08-17 21:49:50

标签: oracle optimization

每个单独的查询执行时间不到10秒。

但是当我将这些查询加在一起时,通过使用IN关键字和列表,优化程序会创建一个奇怪的解释计划,并且查询需要很长时间(想想小时)。

我已经包含了以下查询。 我是否必须强制进行某种索引?

查询1:

select row_number() over (partition by  t1.COLUMN_1, t1.COLUMN_2, t1.COLUMN_3 order by t1.RSLT_DT desc) rn, 
      t1.COLUMN_1,
      t1.RSLT_DT,
      t1.COLUMN_2,
      t1.COLUMN_3,
      t1.MY_SCORE
      from MY_DB.MY_TABLE t1
      where t1.COLUMN_3 in ('FACT_1','FACT_0') 
      and t1.COLUMN_1 
      in ('33162046') 
      and MY_SCORE > 0;

Plan hash value: 3324896092

------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                | 70545 |  4202K|       |  7545K (40)| 37:43:34 |       |       |
|   1 |  WINDOW SORT                        |                | 70545 |  4202K|  5312K|  7545K (40)| 37:43:34 |       |       |
|   2 |   PARTITION RANGE ALL               |                | 70545 |  4202K|       |  7544K (40)| 37:43:26 |     1 |1048575|
|*  3 |    TABLE ACCESS BY LOCAL INDEX ROWID| MY_TABLE     | 70545 |  4202K|       |  7544K (40)| 37:43:26 |     1 |1048575|
|   4 |     BITMAP CONVERSION TO ROWIDS     |                |       |       |       |            |          |       |       |
|   5 |      BITMAP AND                     |                |       |       |       |            |          |       |       |
|   6 |       BITMAP OR                     |                |       |       |       |            |          |       |       |
|*  7 |        BITMAP INDEX SINGLE VALUE    | MY_TABLE_X27 |       |       |       |            |          |     1 |1048575|
|*  8 |        BITMAP INDEX SINGLE VALUE    | MY_TABLE_X27 |       |       |       |            |          |     1 |1048575|
|   9 |       BITMAP MERGE                  |                |       |       |       |            |          |       |       |
|* 10 |        BITMAP INDEX RANGE SCAN      | MY_TABLE_X21 |       |       |       |            |          |     1 |1048575|
------------------------------------------------------------------------------------------------------------------------------

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

   3 - filter("MY_SCORE">0)
   7 - access("T1"."COLUMN_3"='FACT_0')
   8 - access("T1"."COLUMN_3"='FACT_1')
  10 - access("T1"."COLUMN_1"=33162046)
       filter("T1"."COLUMN_1"=33162046)

查询2:

select row_number() over (partition by  t1.COLUMN_1, t1.COLUMN_2, t1.COLUMN_3 order by t1.RSLT_DT desc) rn, 
          t1.COLUMN_1,
          t1.RSLT_DT,
          t1.COLUMN_2,
          t1.COLUMN_3,
          t1.MY_SCORE
          from MY_DB.MY_TABLE t1
          where t1.COLUMN_3 in ('FACT_1','FACT_0') 
          and t1.COLUMN_1 
          in ('33162047')
          and MY_SCORE > 0;


Plan hash value: 3324896092

------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                | 70545 |  4202K|       |  7545K (40)| 37:43:34 |       |       |
|   1 |  WINDOW SORT                        |                | 70545 |  4202K|  5312K|  7545K (40)| 37:43:34 |       |       |
|   2 |   PARTITION RANGE ALL               |                | 70545 |  4202K|       |  7544K (40)| 37:43:26 |     1 |1048575|
|*  3 |    TABLE ACCESS BY LOCAL INDEX ROWID| MY_TABLE     | 70545 |  4202K|       |  7544K (40)| 37:43:26 |     1 |1048575|
|   4 |     BITMAP CONVERSION TO ROWIDS     |                |       |       |       |            |          |       |       |
|   5 |      BITMAP AND                     |                |       |       |       |            |          |       |       |
|   6 |       BITMAP OR                     |                |       |       |       |            |          |       |       |
|*  7 |        BITMAP INDEX SINGLE VALUE    | MY_TABLE_X27 |       |       |       |            |          |     1 |1048575|
|*  8 |        BITMAP INDEX SINGLE VALUE    | MY_TABLE_X27 |       |       |       |            |          |     1 |1048575|
|   9 |       BITMAP MERGE                  |                |       |       |       |            |          |       |       |
|* 10 |        BITMAP INDEX RANGE SCAN      | MY_TABLE_X21 |       |       |       |            |          |     1 |1048575|
------------------------------------------------------------------------------------------------------------------------------

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

   3 - filter("MY_SCORE">0)
   7 - access("T1"."COLUMN_3"='FACT_0')
   8 - access("T1"."COLUMN_3"='FACT_1')
  10 - access("T1"."COLUMN_1"=33162047)
       filter("T1"."COLUMN_1"=33162047)

加入查询:

select row_number() over (partition by  t1.COLUMN_1, t1.COLUMN_2, t1.COLUMN_3 order by t1.RSLT_DT desc) rn, 
      t1.COLUMN_1,
      t1.RSLT_DT,
      t1.COLUMN_2,
      t1.COLUMN_3,
      t1.MY_SCORE
      from MY_DB.MY_TABLE t1
      where t1.COLUMN_3 in ('FACT_1','FACT_0') 
      and t1.COLUMN_1 
      in ('33162046','33162047') 
      and MY_SCORE > 0;

Plan hash value: 2547923189

-------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                            | Name           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
-------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                     |                | 70545 |  4202K|       |    11M  (1)| 59:28:46 |       |       |
|   1 |  WINDOW SORT                         |                | 70545 |  4202K|  5312K|    11M  (1)| 59:28:46 |       |       |
|   2 |   PARTITION RANGE ALL                |                | 70545 |  4202K|       |    11M  (1)| 59:28:38 |     1 |1048575|
|   3 |    INLIST ITERATOR                   |                |       |       |       |            |          |       |       |
|*  4 |     TABLE ACCESS BY LOCAL INDEX ROWID| MY_TABLE     | 70545 |  4202K|       |    11M  (1)| 59:28:38 |     1 |1048575|
|   5 |      BITMAP CONVERSION TO ROWIDS     |                |       |       |       |            |          |       |       |
|*  6 |       BITMAP INDEX SINGLE VALUE      | MY_TABLE_X27 |       |       |       |            |          |     1 |1048575|
-------------------------------------------------------------------------------------------------------------------------------

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

   4 - filter(("T1"."COLUMN_1"=33162046 OR "T1"."COLUMN_1"=33162047) AND "MY_SCORE">0)
   6 - access("T1"."COLUMN_3"='FACT_0' OR "T1"."COLUMN_3"='FACT_1')

0 个答案:

没有答案
相关问题