【发布时间】:2015-09-17 09:35:47
【问题描述】:
目前我们有一个工作查询,它从一个大型分区表中进行选择以进行处理。该表按每日范围进行分区,1 个分区中有 1 天的数据。
查询是:
SELECT /*+parallel(auto)*/ a.*
FROM TBL_EXCLUDED a
WHERE (not exists(
select 1 from C_HISTORY history
inner join C_MATRIX_EXT ext on ext.from_type = (CASE WHEN UPPER(history.TYPE_CD)<>'B' THEN 'C' ELSE 'B' END) and ext.from_channel = history.channel
where history.mid= a.mid
and ext.to_channel = a.channel and ext.to_type = (CASE WHEN UPPER(a.TYPE_CD)<>'B' THEN 'C' ELSE 'B' END)
and history.channel_sent_dt>=TRUNC (SYSDATE-ext.duration+1)
and history.channel_sent_dt<=TRUNC (SYSDATE)+1
) )
解释计划有点长,所以我只会展示带分区的部分。请注意PARTITION_START 是1 和PARTITION_STOP 是KEY
现在,如果我更改从固定日期搜索的条件,而不是从 sysdate 派生,成本将会改变:
SELECT /*+parallel(auto)*/ a.*
FROM TBL_EXCLUDED a
WHERE (not exists(
select 1 from C_HISTORY history
inner join C_MATRIX_EXT ext on ext.from_type = (CASE WHEN UPPER(history.TYPE_CD)<>'B' THEN 'C' ELSE 'B' END) and ext.from_channel = history.channel
where history.mid= a.mid
and ext.to_channel = a.channel and ext.to_type = (CASE WHEN UPPER(a.TYPE_CD)<>'B' THEN 'C' ELSE 'B' END)
and history.channel_sent_dt>=TRUNC ( TO_DATE('10-09-2015','dd-mm-yy') )
and history.channel_sent_dt<=TRUNC ( TO_DATE('17-09-2015','dd-mm-yy') )+1
) )
实际执行会与此计划不同吗?另外,虽然在sysdate 的查询中成本很高,但实际执行会少得多,因为它应该只能从目标分区中进行选择?
最后,使用第二种查询范围分区表而不是第一种查询会有实际好处吗?
感谢大家的回复和指导,谢谢。
【问题讨论】:
标签: oracle partitioning sql-execution-plan