关注我的微信公众号:pythonislover,领取python,大数据,SQL优化相关视频资料!~
Python大数据与SQL优化笔 QQ群:771686295
谓语推入,估计有很多人,对这个术语都听过,但是却迷迷糊糊,好像知道,但是想说却说不出。
下面我试试说一说。
首先我要把谓语推入分成两种:
1.常数值的谓语推入
2.连接键的谓语推入
下面我们一个一个来说
什么叫常数值的谓语推入
SQL> create view v_predicate_push as
select e.* , d.DNAME,d.LOC
from emp e inner join dept d
on e.DEPTNO = d.DEPTNO; 2 3 4
View created.
SQL> explain plan for
select * from v_predicate_push where EMPNO=7499;
2
Explained.
SQL> set linesize 100
SQL> SELECT * FROM TABLE(dbms_xplan.display);
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
Plan hash value: 2385808155
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 58 | 2 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | 1 | 58 | 2 (0)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 38 | 1 (0)| 00:00:01 |
|* 3 | INDEX UNIQUE SCAN | PK_EMP | 1 | | 0 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID| DEPT | 4 | 80 | 1 (0)| 00:00:01 |
|* 5 | INDEX UNIQUE SCAN | PK_DEPT | 1 | | 0 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("E"."EMPNO"=7499)
5 - access("E"."DEPTNO"="D"."DEPTNO")
18 rows selected.
SQL> create view v_predicate_push_1 as
select e.* , d.DNAME,d.LOC
from emp e inner join dept d
on e.DEPTNO = d.DEPTNO
union all
select e.* , d.DNAME,d.LOC
from emp e inner join dept d
on e.DEPTNO = d.DEPTNO; 2 3 4 5 6 7 8
View created.
SQL> explain plan for
select * from v_predicate_push_1 where EMPNO=7499; 2
Explained.
SQL> set linesize 400
SQL> SELECT * FROM TABLE(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------