Oracle分区表执行计划

php中文网
发布: 2016-06-07 16:08:02
原创
1180人浏览过

Oracle分区表有很多好处,以大化小,一小化了,加上并行的使用,在loap中能往往能提高几十倍甚至几百倍的效果。当然表设计得不好

oracle分区表有很多好处,以大化小,一小化了,加上并行的使用,在loap中能往往能提高几十倍甚至几百倍的效果。当然表设计得不好也会适得其反,效果比普通表跟糟糕。
为了更好的使用分区表,这里看一下分区表的执行计划。
partition range all:扫描所有分区
partition range iterator:扫描多个分区,小于所有个分区数量
partition range single:扫描单一的分区
key,表示执行时才知道哪个分区

看到关键字ALL的时候就要注意了,扫描的是全部分区。写sql的时候在where条件中能充分利用分区字段来限制的话最好,这样能起到分区裁剪的作用,没必要的分区就不用扫描了。

SQL> create table t1
  2  partition by range(created)(
  3  partition p1 values less than (to_date('20140101','yyyymmdd')),
  4  partition p2 values less than (to_date('20140201','yyyymmdd')),
  5  partition p3 values less than (to_date('20140301','yyyymmdd')),
  6  partition p4 values less than (to_date('20140401','yyyymmdd')),
  7  partition p5 values less than (to_date('20140501','yyyymmdd')),
  8  partition p6 values less than (to_date('20140601','yyyymmdd')),
  9  partition p7 values less than (to_date('20140701','yyyymmdd')),
 10  partition p8 values less than (to_date('20140801','yyyymmdd')),
 11  partition p9 values less than (to_date('20140901','yyyymmdd')),
 12  partition p10 values less than (to_date('20141001','yyyymmdd')),
 13  partition p11 values less than (to_date('20141101','yyyymmdd')),
 14  partition p12 values less than (to_date('20141201','yyyymmdd')),
 15  partition p13 values less than (maxvalue)
 16  )
 17  as select * from dba_objects where created>=to_date('20131001','yyyymmdd');
 
--PARTITION RANGE ALL:扫描所有分区
SQL> explain plan for select count(*) from t1;
-------------------------------------------------------------------------------------
| Id  | Operation            | Name | Rows  | Cost (%CPU)| Time    | Pstart| Pstop |
-------------------------------------------------------------------------------------
|  0 | SELECT STATEMENT    |      |    1 |  106  (1)| 00:00:02 |      |      |
|  1 |  SORT AGGREGATE      |      |    1 |            |          |      |      |
|  2 |  PARTITION RANGE ALL|      | 41973 |  106  (1)| 00:00:02 |    1 |    13 |
|  3 |    TABLE ACCESS FULL | T1  | 41973 |  106  (1)| 00:00:02 |    1 |    13 |
-------------------------------------------------------------------------------------

--PARTITION RANGE ITERATOR:扫描多个分区,,小于所有个分区数量
SQL> explain plan for select * from t1 where created>=to_date('20141101','yyyymmdd');
-------------------------------------------------------------------------------------------------
| Id  | Operation                | Name | Rows  | Bytes | Cost (%CPU)| Time    | Pstart| Pstop |
-------------------------------------------------------------------------------------------------
|  0 | SELECT STATEMENT        |      | 13121 |  2267K|    39  (6)| 00:00:01 |      |      |
|  1 |  PARTITION RANGE ITERATOR|      | 13121 |  2267K|    39  (6)| 00:00:01 |    12 |    13 |
|*  2 |  TABLE ACCESS FULL      | T1  | 13121 |  2267K|    39  (6)| 00:00:01 |    12 |    13 |
-------------------------------------------------------------------------------------------------

 

--PARTITION RANGE SINGLE:扫描单一的分区
SQL> explain plan for select * from t1 where created>=to_date('20141217','yyyymmdd');
-----------------------------------------------------------------------------------------------
| Id  | Operation              | Name | Rows  | Bytes | Cost (%CPU)| Time    | Pstart| Pstop |
-----------------------------------------------------------------------------------------------
|  0 | SELECT STATEMENT      |      |  947 |  163K|    28  (0)| 00:00:01 |      |      |
|  1 |  PARTITION RANGE SINGLE|      |  947 |  163K|    28  (0)| 00:00:01 |    13 |    13 |
|*  2 |  TABLE ACCESS FULL    | T1  |  947 |  163K|    28  (0)| 00:00:01 |    13 |    13 |
-----------------------------------------------------------------------------------------------

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号