分区表有非常多优点,以大化小,一小化了,加上并行的使用,在loap中能往往能提高几十倍甚至几百倍的效果。

当然表设计得不好也会适得其反。效果比普通表跟糟糕。
为了更好的使用分区表,这里看一下分区表的运行计划。
PARTITION RANGE ALL:扫描全部分区
PARTITION RANGE ITERATOR:扫描多个分区,小于全部个分区数量
PARTITION RANGE SINGLE:扫描单一的分区
KEY,表示运行时才知道哪个分区 看到keywordALL的时候就要注意了,扫描的是全部分区。 写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 |
----------------------------------------------------------------------------------------------- --KEY,表示运行时才知道哪个分区
SQL> explain plan for select * from t1 where created>=sysdate-1;
-------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
-------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 947 | 163K| 33 (16)| 00:00:01 | | |
| 1 | PARTITION RANGE ITERATOR| | 947 | 163K| 33 (16)| 00:00:01 | KEY | 13 |
|* 2 | TABLE ACCESS FULL | T1 | 947 | 163K| 33 (16)| 00:00:01 | KEY | 13 |
------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 2 - filter("CREATED">=SYSDATE@!-1) SQL> variable x varchar2;
SQL> explain plan for select * from t1 where created>=to_date(:x,'yyyymmdd');
-------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
-------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2099 | 362K| 107 (2)| 00:00:02 | | |
| 1 | PARTITION RANGE ITERATOR| | 2099 | 362K| 107 (2)| 00:00:02 | KEY | 13 |
|* 2 | TABLE ACCESS FULL | T1 | 2099 | 362K| 107 (2)| 00:00:02 | KEY | 13 |
------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 2 - filter("CREATED">=TO_DATE(:X,'yyyymmdd'))

oracle分区表运行计划的更多相关文章

  1. 使用hint优化Oracle的运行计划 以及 SQL Tune Advisor的使用

    背景: 某表忽然出现查询很缓慢的情况.cost 100+ 秒以上:严重影响生产. 原SQL: explain plan for select * from ( select ID id,RET_NO ...

  2. [Oracle] 获取运行计划的各方法总结

    总的结论: 一.获取运行计划的6种方法(具体步骤已经在每一个样例的开头凝视部分说明了): 1. explain plan for获取:  2. set autotrace on .  3. stati ...

  3. 查询oracle sql运行计划,一个非常重要的观点--dba_hist_sql_plan

    该文章的作者给予了极大的帮助长老枯荣,为了表达我的谢意. 这适用于oracle db版本号oracle 10g或者更高的版本号. 之所以说这种看法是非常重要的,因为观点是有之一awrsqrpt报告没有 ...

  4. Oracle 11g 递归+ exists运行计划的改变

    有一个递归查询在10g上执行非常快,但在11g上执行不出来. SQL> select * from v$version; BANNER ----------------------------- ...

  5. Oracle rownum影响运行计划

    今天调优一条SQL语句,因为SQL比較复杂,用autotrace非常难一眼看出哪里出了问题,直接上10046. SELECT AB.* FROM (SELECT A.*, rownum RN FROM ...

  6. 深入学习Oracle分区表及分区索引

    关于分区表和分区索引(About Partitioned Tables and Indexes)对于10gR2而言,基本上可以分成几类: •       Range(范围)分区 •       Has ...

  7. 运行计划之误区,为什么COST非常小,SQL却跑得非常慢?

    转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/38321477 2014.7.31就晚20:30 My Oracle Support组猫大师 ...

  8. 性能-发挥ORACLE分区表

    ORACLE分区表发挥性能 http://www.cnblogs.com/zwl715/p/3962837.html 1.1 分区表PARTITION table 在ORACLE里如果遇到特别大的表, ...

  9. 【ORACLE】记录通过执行Oracle的执行计划查询SQL脚本中的效率问题

    记录通过执行Oracle的执行计划查询SQL脚本中的效率问题   问题现象: STARiBOSS5.8.1R2版本中,河北对帐JOB执行时,无法生成发票对帐文件.   首先,Quartz表达式培植的启 ...

随机推荐

  1. 运行yum报错Error: Cannot retrieve metalink for reposit

    http://www.netpc.com.cn/593.html 运行yum报错Error: Cannot retrieve metalink for reposit 今天给Centos通过rpm - ...

  2. vs2008中使用gdi+的设置

    vs2008中使用gdi+ 1.新建一个mfc工程 2.在stdafx.h文件中加入以下几行语句: #include <gdiplus.h>                //#pragm ...

  3. 与众不同 windows phone (13) - Background Task(后台任务)之后台文件传输(上传和下载)

    原文:与众不同 windows phone (13) - Background Task(后台任务)之后台文件传输(上传和下载) [索引页][源码下载] 与众不同 windows phone (13) ...

  4. 与众不同 windows phone (6) - Isolated Storage(独立存储)

    原文:与众不同 windows phone (6) - Isolated Storage(独立存储) [索引页][源码下载] 与众不同 windows phone (6) - Isolated Sto ...

  5. mysqldump --flush-logs

    <pre name="code" class="html"><pre name="code" class="ht ...

  6. python中的中文编码

    我现在编写python代码,有一些内容需要用中文编写,例如注释,一些其它的东西 默认python是不支持中文的,包括两个方面不支持,一是文件编码默认是ansi的,二是虚拟机运行解析脚本时也是非utf的 ...

  7. 新发现QWindow

    http://doc.qt.io/qt-5/qwindow.html#details 不知道该什么时候使用它?

  8. 引用类中的enum

    引用类中的enum 引用类中的enum,需要加类的域class_name::value_in_enum_name 点击(此处)折叠或打开 #include <stdio.h> #inclu ...

  9. [Android学习笔记]SeekBar的使用

    一.SeekBar滑动条的使用 xml声明: <SeekBar android:id="@+id/seekbar" android:layout_width="20 ...

  10. hdu4496 D-City

    D-City Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total Submis ...