?commit;
?delete event partition(C25_M2_S3)? where cycle_code=25 and cycle_month=2 and cycle_year=2015 and customer_id=5289835;
?commit;
?delete event partition(C25_M2_S4)? where cycle_code=25 and cycle_month=2 and cycle_year=2015 and customer_id=5289835;
?commit;
。。。。。。。
delete event partition(C25_M2_S20)? where cycle_code=25 and cycle_month=2 and cycle_year=2015 and customer_id=5289835;
?commit;
?delete /*+ full(rated_event) parallel(rated_event,16) */ event partition(C25_M2_S1)? where cycle_code=25 and cycle_month=2 and cycle_year=2015 and customer_id=5289835;
?commit;
事情到此一般就结束了,开发找到我,我们做了进一步的沟通,她根据我提供的脚本提出了一些问题,她从业务层面来做了确认,说数据只会在C25_M2_S8这个分区上,有了业务确认,调优的语句就更加简化了。
set linesize 200
set timing on
set time on
alter session force parallel dml parallel 16;
?delete event partition(C25_M2_S8)? where cycle_code=25 and cycle_month=2 and cycle_year=2015 and customer_id=5289835;
?commit;
查看执行计划,合理的走了全表扫描,因为分区中有1千多万的记录,删除900多万的数据,走全表扫描还是情理之中的。
Plan hash value: 1742190108
?----------------------------------------------------------------------------------------------------------------------------------
?| Id? | Operation? ? ? ? ? ? | Name? ? ? ? | Rows? | Bytes | Cost (%CPU)| Time? ? | Pstart| Pstop |? ? TQ? |IN-OUT| PQ Distrib |
?----------------------------------------------------------------------------------------------------------------------------------
?|? 0 | DELETE STATEMENT? ? ? |? ? ? ? ? ? |? 9115K|? 382M| 19351? (1)| 00:03:53 |? ? ? |? ? ? |? ? ? ? |? ? ? |? ? ? ? ? ? |
?|? 1 |? PX COORDINATOR? ? ? |? ? ? ? ? ? |? ? ? |? ? ? |? ? ? ? ? ? |? ? ? ? ? |? ? ? |? ? ? |? ? ? ? |? ? ? |? ? ? ? ? ? |
?|? 2 |? PX SEND QC (RANDOM) | :TQ10000? ? |? 9115K|? 382M| 19351? (1)| 00:03:53 |? ? ? |? ? ? |? Q1,00 | P->S | QC (RAND)? |
?|? 3 |? ? DELETE? ? ? ? ? ? |? ? ? EVENT |? ? ? |? ? ? |? ? ? ? ? ? |? ? ? ? ? |? ? ? |? ? ? |? Q1,00 | PCWP |? ? ? ? ? ? |
?|? 4 |? ? PX BLOCK ITERATOR |? ? ? ? ? ? |? 9115K|? 382M| 19351? (1)| 00:03:53 |? 248 |? 248 |? Q1,00 | PCWC |? ? ? ? ? ? |
?|*? 5 |? ? ? TABLE ACCESS FULL|? ? ? EVENT |? 9115K|? 382M| 19351? (1)| 00:03:53 |? 248 |? 248 |? Q1,00 | PCWP |? ? ? ? ? ? |
?----------------------------------------------------------------------------------------------------------------------------------
通过这个例子,我们可以看到原本索引扫描的执行计划看起来很好,但是执行效率却大打折扣,在分析了分区表的分区规则和数据分布情况之后,发现可以把原本700多个分区简化到20个,加上业务层面的确认,本来20个分区的删除可以简化到有一个特定的分区,性能调优在这个时候就是一个接力棒式的工作。问题经过一步一步的分析和确认,也变得清晰起来。