These two terms in the Predicate Information section indicate when the data source is reduced. Simply, access means only retrieve those records meeting the condition and ignore others. Filter means *after* you already got the data, go through them all and keep those meeting the condition and throw away the others.

access: 直接获取那些满足条件的数据,抛弃其他不满足的数据
filter: 你已经有了一些数据,对这些已经有的数据应用filter,得到满足filter的数据。

http://www.itpub.net/forum.php?mod=viewthread&tid=1766289

一:简要说明

在查看执行计划的信息中,经常会看到两个谓词filter和access,它们的区别是什么,理解了这两个词对我们解读Oracle的执行计划信息会有所帮助。

简单说,执行计划如果显示是access,就表示这个谓词条件的值将会影响数据的访问路径(表还是索引),而filter表示谓词条件的值并不会影响数据访问路径,只起到过滤的作用。

二:举例说明
SQL> create table zhou_t (x int , y int );
表已创建。
SQL> set autotrace trace exp;
SQL> select /*+rule*/ * from zhou_t where x=5;
执行计划
----------------------------------------------------------
Plan hash value: 1395150869
------------------------------------
| Id | Operation | Name |
------------------------------------
| 0 | SELECT STATEMENT | |
|* 1 | TABLE ACCESS FULL| ZHOU_T |
------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("X"=5)
Note
-----
- rule based optimizer used (consider using cbo)

因为表zhou_t没有创建索引,执行计划没有选择数据访问路径的余地,谓词条件在这里只是起到数据过滤的作用,所以使用了filter

如果在表上创建了索引呢?

SQL> create index zhou_t_idx on zhou_t(x,y);
索引已创建。
SQL> select /*+rule*/ * from zhou_t where x=5;
执行计划
----------------------------------------------------------
Plan hash value: 42197324
---------------------------------------
| Id | Operation | Name |
---------------------------------------
| 0 | SELECT STATEMENT | |
|* 1 | INDEX RANGE SCAN| ZHOU_T_IDX |
---------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("X"=5)
Note
-----
- rule based optimizer used (consider using cbo)

从上面可以看到,谓词条件影响到数据访问的路径------选择了索引,所以用access

http://zuoren110.blog.163.com/blog/static/617563201201331427675/

SQL> create table t
  2  as select rownum r,object_name
  3  from dba_objects
  4  /
Table created.
SQL> create index t_idx on t(r);
Index created.
SQL> execute dbms_stats.gather_table_stats(user,'t',cascade=>true)
PL/SQL procedure successfully completed.
SQL> set autotrace traceonly explain
SQL> select * from t
  2  where r = 10000;
Execution Plan
----------------------------------------------------------
Plan hash value: 470836197
-------------------------------------------------------------------------------------
| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |       |     1 |    30 |     2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| T     |     1 |    30 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | T_IDX |     1 |       |     1   (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
 2 - access("R"=10000)
使用的谓词是access ,访问的是索引,然后通过rowid 直接取出select结果。
SQL> select * from t
  2  where r > 10000 and r < 50000
  3  /
Execution Plan
----------------------------------------------------------
Plan hash value: 1601196873
--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      | 40001 |  1171K|    88   (2)| 00:00:02 |
|*  1 |  TABLE ACCESS FULL| T    | 40001 |  1171K|    88   (2)| 00:00:02 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter("R"<50000 AND "R">10000)
使用的谓词是filter 使用的是全表扫描,过滤掉不需要的行。
SQL> select r from t
  2  where r > 10000
  3  /
Execution Plan
----------------------------------------------------------
Plan hash value: 3163761342
------------------------------------------------------------------------------
| Id  | Operation            | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |       | 55631 |   271K|    42   (3)| 00:00:01 |
|*  1 |  INDEX FAST FULL SCAN| T_IDX | 55631 |   271K|    42   (3)| 00:00:01 |
------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter("R">10000)
这里的执行计划,就有点意思了,使用的是索引扫描(index fast full scan),
但是没有通过access 指出。可见oracle 决定使用索引扫描,并不一定要通过
access 来告诉我们。在这里r 可以完全通过读取索引来获得所需要的列值,并且
需要检索索引中的大部分key,所以oracle 决定使用index fast full scan,这种
访问索引的方式会通过multiblocks read 方式读取索引的 bocks,返回的结果集
是未经排序的,并且因为读取了所以的index blocks ,所以需要对index blocks
中的index keys 进行过滤。
SQL> create table emp
  2  as select employee_id,first_name,last_name
  3  from hr.employees;
Table created.
SQL> create index emp_idx on emp(employee_id,last_name);
Index created.
SQL> exec dbms_stats.gather_table_stats(user,'emp',cascade=>true)
PL/SQL procedure successfully completed.
SQL> select employee_id,last_name
  2  from emp
  3  where employee_id < 200 and last_name = 'King'
  4  /
Execution Plan
----------------------------------------------------------
Plan hash value: 3087982339
----------------------------------------------------------------------------
| Id  | Operation        | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------
|   0 | SELECT STATEMENT |         |     2 |    24 |     1   (0)| 00:00:01 |
|*  1 |  INDEX RANGE SCAN| EMP_IDX |     2 |    24 |     1   (0)| 00:00:01 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - access("LAST_NAME"='King' AND "EMPLOYEE_ID"<200)
       filter("LAST_NAME"='King')
我上面这个例子也比较有意思,我们在前面创建了一个复合索引,并且在where 子句中
使用了索引中的列。oracle 会根据where 条件通过访问复合索引中的列是否满足employee_id < 200
如果满足再根据条件filter 过滤出last_name = 'King' 的index Key。
小结:通过上面的列子,虽然例子不是很经典,但是我觉得已经可以说明。
1、如果oracle 决定使用 index 来获得结果集,不需要使用access 谓词告诉我们,我(oracle)使用了index.
2、通过index 访问数据,也有可能需要用到filter 的。

http://blog.csdn.net/kkdelta/article/details/7938653

oracle_执行计划_谓词信息和数据获取(access and filter区别) (转)的更多相关文章

  1. SQL Server 执行计划利用统计信息对数据行的预估原理二(为什么复合索引列顺序会影响到执行计划对数据行的预估)

    本文出处:http://www.cnblogs.com/wy123/p/6008477.html 关于统计信息对数据行数做预估,之前写过对非相关列(单独或者单独的索引列)进行预估时候的算法,参考这里. ...

  2. Oracle执行计划与统计信息的一些总结

    [日期:2011-08-05]来源:Linux社区  作者:wangshengfeng1986211[字体:大 中 小] 2010-07-01 15:03 1.SET AUTOTRACE ON EXP ...

  3. sqlplus中显示sql执行计划和统计信息

    31 ,32 , 33 ,34  keywords : oracle  storage  structure 最详细讲解: 1:doc 1   logical  storage structure 2 ...

  4. 为准确生成执行计划更新统计信息-analyze与dbms_stats

    如果我们想让CBO利用合理利用数据的统计信息,正确判断执行任何SQL查询时的最快途径,需要及时的使用analyze命令或者dbms_stats重新统计数据的统计信息. 例如索引跳跃式扫描(INDEX ...

  5. SQL Server 执行计划利用统计信息对数据行的预估原理以及SQL Server 2014中预估策略的改变

    前提  本文仅讨论SQL Server查询时, 对于非复合统计信息,也即每个字段的统计信息只包含当前列的数据分布的情况下, 在用多个字段进行组合查询的时候,如何根据统计信息去预估行数的. 利用不同字段 ...

  6. 当执行计划中出现BITMAP CONVERSION TO ROWIDS关键字时,需要注意了。

    前言 前些天优化了一些耗费buffers较多的SQL,但系统CPU降低的效果不明显,于是又拉了awr报告,查看了SQL ordered by Gets排名前列的SQL. 分析 SQL代码: selec ...

  7. MySQL统计信息以及执行计划预估方式初探

    数据库中的统计信息在不同(精确)程度上描述了表中数据的分布情况,执行计划通过统计信息获取符合查询条件的数据大小(行数),来指导执行计划的生成.在以Oracle和SQLServer为代表的商业数据库,和 ...

  8. sql-查看执行计划的方法

    sql执行计划:把SQL语句拆分为每个的操作步骤组合,按照一定的顺序执行得出结果,查看并看懂执行计划是调优的关键步骤 查看执行计划的方法 DBMS_XPLAN包 sql*plus AUTO trace ...

  9. [z]Oracle性能优化-读懂执行计划

    http://blog.csdn.net/lifetragedy/article/details/51320192 Oracle的执行计划   得到执行计划的方式       Autotrace例子 ...

随机推荐

  1. PyCharm4注册码

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 name : newasp == ...

  2. LinearLayout增加divider分割线

    在android3.0及后面的版本在LinearLayout里增加了个分割线 1 2 android:divider="@drawable/shape"<!--分割线图片-- ...

  3. URL重写:RewriteCond指令与RewriteRule 指令格式(转)

    Rewirte主要的功能就是实现URL的跳转和隐藏真实地址,基于Perl语言的正则表达式规范.平时帮助我们实现拟静态,拟目录,域名跳转,防止盗链等.本文将针对mod_rewrite和URL匹配的技术细 ...

  4. BaseAdapter以及对ListView的优化(转)

    背景 对于ListView.GridView.Gallery.Spinner等等,它是它们的适配器,直接继承自接口类Adapter的,使用BaseAdapter时需要重写很多方法,其中最重要的当属ge ...

  5. POJ 3449 Geometric Shapes (求正方形的另外两点)

    Geometric Shapes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1470   Accepted: 622 D ...

  6. codevs 1047 邮票面值设计

    /* 开始没啥好的思路 暴力吧 T的太严重 加了k>n的特判 结果没数据…..然后又暴力生成了几组答案 打表 然而有没有数据 华丽的爆零了 正解 回溯+DP 回溯生成k数组 然后DP找最优解更新 ...

  7. jq之简单表单验证

    <body> <form method="post" action=""> <div class="int"& ...

  8. 面试题——分析从输入url到页面返回的过程(或者查询返回过程)

    1. You enter a URL into the browser(输入一个url地址) 2.The browser looks up the IP address for the domain ...

  9. C#敏感关键词过滤代码

    System.Text.StringBuilder sb = new System.Text.StringBuilder(text.Length);             string filter ...

  10. scn转换为十进制