你好,游客 登录 注册 搜索
背景:
阅读新闻

探索执行计划中filter的原理

[日期:2013-11-08] 来源:Linux社区  作者:stevendbaguo [字体:大 中 小]

filter下挂两个节点:

挂两个节点时,emp扫描了一次有14条记录,类似于nested loops, 而扫描如果是nested loop的话,则应该是14次,但是此处dept是3次。这是因为filter维护了一个hash table,如果有重复的记录可以减少扫描次数。此处由于emp中的deptno只有三个值,所以只扫描3次。

SQL> select /*+rule*/count(*) from emp
where not exists (select 1
from dept
where dept.dname = 'SALE'
and dept.deptno = emp.deptno);
COUNT(*)
----------
14

SQL> select * from table(dbms_xplan.display_cursor(null,null,'allstats last'));
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------
SQL_ID 0wjfqsm43j4z5, child number 0
-------------------------------------
select /*+rule*/count(*) from emp where not exists (select 1 from dept
where dept.dname = 'SALE' and dept.deptno = emp.deptno)
Plan hash value: 3536434453
------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | A-Rows | A-Time | Buffers |
------------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 |00:00:00.01 | 13 |
|* 2 | FILTER | | 1 | 14 |00:00:00.01 | 13 |
| 3 | TABLE ACCESS FULL | EMP | 1| 14 |00:00:00.01 | 7 |
|* 4 | TABLE ACCESS BY INDEX ROWID| DEPT | 3 | 0 |00:00:00.01 | 6 |
|* 5 | INDEX UNIQUE SCAN | PK_DEPT | 3 | 3 |00:00:00.01 | 3 |
------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter( IS NULL)
4 - filter("DEPT"."DNAME"='SALE')
5 - access("DEPT"."DEPTNO"=:B1)

filter下挂三个节点:

挂三个节点时,每当emp返回一条数据,都会驱动dept和bouns分别执行一次(注意的是在执行连接时每次只能两个表进行连接),由于filter使用了缓存技术,所以看到的dept只是扫描了3次,bonus扫描了14次。

SQL> select /*+rule*/count(*) from emp
where not exists (select 1
from dept
where dept.dname = 'SALE'
and dept.deptno = emp.deptno)
and not exists (select 1 from bonus where bonus.ename = emp.ename);
COUNT(*)
----------
14
SQL> select * from table(dbms_xplan.display_cursor(null,null,'allstats last'));
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 2wss1r100vqd9, child number 0
-------------------------------------
select /*+rule*/* from emp where not exists (select 1 from dept
where dept.dname = 'SALE' and dept.deptno = emp.deptno) and not
exists (select 1 from bonus where bonus.ename = emp.ename)
Plan hash value: 1445856646
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | A-Rows | A-Time | Buffers |
-----------------------------------------------------------------------------------------
|* 1 | FILTER | | 1 | 14 |00:00:00.01 | 56 |
| 2 | TABLE ACCESS FULL | EMP | 1 | 14 |00:00:00.01 | 8 |
|* 3 | TABLE ACCESS BY INDEX ROWID| DEPT | 3 | 0 |00:00:00.01 | 6 |
|* 4 | INDEX UNIQUE SCAN | PK_DEPT | 3 | 3 |00:00:00.01 | 3 |
|* 5 | TABLE ACCESS FULL | BONUS | 14 | 0 |00:00:00.01 | 42 |
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(( IS NULL AND IS NULL))
3 - filter("DEPT"."DNAME"='SALE')
4 - access("DEPT"."DEPTNO"=:B1)
5 - filter("BONUS"."ENAME"=:B1)

SQL> select count(*) from emp
where not exists (select 1
from dept
where dept.dname = 'SALE'
and dept.deptno = emp.deptno);
COUNT(*)
----------
14

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux
相关资讯       filter 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款