ORACLE执行计划(7)---采用TRUNC(SYSDATE)-1方法 无法确定分区
转自 http://blog.csdn.net/zengmuansha/article/details/7492826
在看分区的执行计划当中 说明字段有各种不同的分区操作其中有两个
PARTITION RANGE ITERATOR
PARTITION RANGE single
ITERATOR的成本高于SINGLE 好像ITERATOR是跨分区,当没有跨多个分区似的
还有个PARTITION RANGE ITERATOR ALL 这就是访问所有分区.
不管怎么样,不太喜欢PARTITION RANGE ITERATOR
select PROVCODE,AREACODE,to_char(CREATETIME,'yyyymmdd')
from sms_mms_send_his
where status = 100
and CREATETIME >= trunc(sysdate)-1
and CREATETIME < trunc(sysdate)
SELECT STATEMENT REMOTE, GOAL = ALL_ROWS Depth=0 Operation=SELECT STATEMENT Cost=20295 CPU cost=3824735837 IO cost=20128
FILTER Depth=1 Operation=FILTER Filter predicates=TRUNC(SYSDATE@!)-1<TRUNC(SYSDATE@!)
PARTITION RANGE ITERATOR Depth=2 Operation=PARTITION RANGE Cost=20295 CPU cost=3824735837 IO cost=20128
TABLE ACCESS FULL Depth=3 Operation=TABLE ACCESS Cost=20295 Filter predicates="STATUS"=100 AND "CREATETIME">=TRUNC(SYSDATE@!)-1 AND "CREATETIME"<TRUNC(SYSDATE@!) CPU cost=3824735837 IO cost=20128
如果我指定分区的话
select PROVCODE,AREACODE,to_char(CREATETIME,'yyyymmdd')
from sms_mms_send_his_info partition(SMS_MMS_SEND_HIS_INFO_201210421)
where status = 100
SELECT STATEMENT, GOAL = ALL_ROWS Depth=0 Operation=SELECT STATEMENT Cost=2 CPU cost=7121 IO cost=2
PARTITION RANGE SINGLE Depth=1 Operation=PARTITION RANGE Cost=2 CPU cost=7121 IO cost=2
TABLE ACCESS FULL Depth=2 Operation=TABLE ACCESS Cost=2 Filter predicates="STATUS"=100 CPU cost=7121 IO cost=2
从执行计划上来看 ITERATOR 高于 SINGLE 而且createtime是分区关键字 而它去不是ACCESS谓词,就是定位的谓词条件,反而变成了过滤条件.
为了避免这样情况出现
and CREATETIME >= trunc(sysdate)-1
and CREATETIME < trunc(sysdate)
改成
and CREATETIME >= to_date('','yyyymmdd')
and CREATETIME < to_date('','yyyymmdd')
方式
外加/*+full()*/ 提示 避免它走分区本地索引. 虽然我们的DBA说trunc(sysdate)实际执行的时候不跨分区,还是把控制权掌握自己手上好
小小菜鸟一枚