选择一个分区,但优化器使用分区列表全部

时间:2017-02-14 05:58:40

标签: sql performance oracle11g sql-execution-plan

我有这样的查询:

select *   from P2P_TST2.kh4rqolog t  where t.kh4ldat472 between to_date('20170121120001', 'YYYYMMDDHH24MISS') and
   to_date('20170121130101', 'YYYYMMDDHH24MISS')

和表测试分区日复一日。我在查询中选择了一个分区,但优化器在执行计划中使用了所有分区列表。为什么?

我的表定义:

create table KH4RQOLOG
(
   ...
  kh4stdat472     DATE,
  kh4ldat472      DATE,
  ...     
)
partition by range (KH4LDAT472)
subpartition by list (KH4DBINSTID000)
(
  partition SYS_P2898 values less than (TO_DATE(' 2016-12-06 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace KISHTBS
    pctfree 10
    initrans 1
    maxtrans 255
  (  ...    ),
.
.
  partition SYS_P5433 values less than (TO_DATE(' 2017-01-20 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace KISHTBS
  ... (   ...  ),
  partition SYS_P5509 values less than (TO_DATE(' 2017-01-21 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace KISHTBS
    ... (   ...  ),
  partition SYS_P5548 values less than (TO_DATE(' 2017-01-22 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace KISHTBS
    ... (   ...  ),
 . 
 . 
   partition SYS_P6556 values less than (TO_DATE(' 2017-02-07 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace KISHTBS
      ... (   ...  ),
);
-- Create/Recreate indexes 
create index ESH_KHCHID472 on KH4RQOLOG (KH4BTCHID472)
  local;
create index IDX_RQIN on KH4RQOLOG (KH4RECID470)
  local;
create index PK_KH4RQOLOG on KH4RQOLOG (KH4RECID472)
  local;

并且执行计划是:

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 1161379669
--------------------------------------------------------------------------------
| Id  | Operation              | Name      | Rows  | Bytes | Cost (%CPU)| Time
--------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |           | 75186 |    24M| 23967   (1)| 00:04:
|   1 |  PARTITION RANGE SINGLE|           | 75186 |    24M| 23967   (1)| 00:04:
|   2 |   PARTITION LIST ALL   |           | 75186 |    24M| 23967   (1)| 00:04:
|*  3 |    TABLE ACCESS FULL   | KH4RQOLOG | 75186 |    24M| 23967   (1)| 00:04:
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   3 - filter("T"."KH4LDAT472">=TO_DATE(' 2017-01-21 12:00:01', 'syyyy-mm-dd hh2
              AND "T"."KH4LDAT472"<=TO_DATE(' 2017-01-21 13:01:01', 'syyyy-mm-dd
16 rows selected

1 个答案:

答案 0 :(得分:1)

您的执行计划看起来是正确的。您正在寻找一天内的数据,因此您拥有PARTITION RANGE SINGLE运营商。由于您的子分区列上没有谓词,因此您有一个PARTITION LIST ALL运算符。