oracle谓词推进测试

可合并视图,不可合并视图,谓词推进测试
 create table t3 as select * from dba_tables;
 create table t4 as select * from dba_users;
 create table t5 as select * from dba_objects;


对于没有外连接的测试
SQL> select * from (select * from t3,t4 where t3.owner=t4.username order by table_name) v,t5 where v.owner=t5.owner and v.table_name=t5.object_name;


已选择1917行。




执行计划
----------------------------------------------------------
Plan hash value: 2774782749


-------------------------------------------------------------------------------------
| Id  | Operation            | Name | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |      |  1683 |  4805K|       |  1126   (1)| 00:00:14 |
|   1 |  SORT ORDER BY       |      |  1683 |  4805K|  6744K|  1126   (1)| 00:00:14 |
|*  2 |   HASH JOIN          |      |  1683 |  4805K|       |    97   (2)| 00:00:02 |
|   3 |    TABLE ACCESS FULL | T4   |    18 | 39168 |       |     3   (0)| 00:00:01 |
|*  4 |    HASH JOIN         |      |  1683 |  1229K|       |    94   (2)| 00:00:02 |
|   5 |     TABLE ACCESS FULL| T3   |  1683 |   889K|       |    20   (0)| 00:00:01 |
|   6 |     TABLE ACCESS FULL| T5   | 21334 |  4312K|       |    73   (0)| 00:00:01 |
-------------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------


   2 - access("T3"."OWNER"="T4"."USERNAME")
   4 - access("T3"."OWNER"="T5"."OWNER" AND
              "T3"."TABLE_NAME"="T5"."OBJECT_NAME")


Note
-----
   - dynamic sampling used for this statement (level=2)






对于左外连接的测试
 select * from (select * from t3,t4 where t3.owner=t4.username order by table_name) v,t5 where v.owner=t5.owner(+) and v.table_name=t5.object_name(+);




执行计划
----------------------------------------------------------
Plan hash value: 165444085


-------------------------------------------------------------------------------------
| Id  | Operation            | Name | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |      |  1683 |  4805K|       |  1126   (1)| 00:00:14 |
|   1 |  SORT ORDER BY       |      |  1683 |  4805K|  6744K|  1126   (1)| 00:00:14 |
|*  2 |   HASH JOIN          |      |  1683 |  4805K|       |    97   (2)| 00:00:02 |
|   3 |    TABLE ACCESS FULL | T4   |    18 | 39168 |       |     3   (0)| 00:00:01 |
|*  4 |    HASH JOIN OUTER   |      |  1683 |  1229K|       |    94   (2)| 00:00:02 |
|   5 |     TABLE ACCESS FULL| T3   |  1683 |   889K|       |    20   (0)| 00:00:01 |
|   6 |     TABLE ACCESS FULL| T5   | 21334 |  4312K|       |    73   (0)| 00:00:01 |
-------------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------


   2 - access("T3"."OWNER"="T4"."USERNAME")
   4 - access("T3"."OWNER"="T5"."OWNER"(+) AND
              "T3"."TABLE_NAME"="T5"."OBJECT_NAME"(+))


Note
-----
   - dynamic sampling used for this statement (level=2)






对于右外连接的测试
SQL> select * from (select * from t3,t4 where t3.owner=t4.username order by table_name) v,t5 where v.owner(+)=t5.owner and v.table_name(+)=t5.object_name;


已选择18515行。




执行计划
----------------------------------------------------------
Plan hash value: 3366092662


--------------------------------------------------------------------------------------
| Id  | Operation             | Name | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT      |      | 21334 |    59M|       |  1492   (1)| 00:00:18 |
|*  1 |  HASH JOIN RIGHT OUTER|      | 21334 |    59M|  4488K|  1492   (1)| 00:00:18 |
|   2 |   VIEW                |      |  1683 |  4465K|       |   979   (1)| 00:00:12 |
|   3 |    SORT ORDER BY      |      |  1683 |  4465K|  6744K|   979   (1)| 00:00:12 |
|*  4 |     HASH JOIN         |      |  1683 |  4465K|       |    24   (5)| 00:00:01 |
|   5 |      TABLE ACCESS FULL| T4   |    18 | 39168 |       |     3   (0)| 00:00:01 |
|   6 |      TABLE ACCESS FULL| T3   |  1683 |   889K|       |    20   (0)| 00:00:01 |
|   7 |   TABLE ACCESS FULL   | T5   | 21334 |  4312K|       |    73   (0)| 00:00:01 |
--------------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------


   1 - access("V"."OWNER"(+)="T5"."OWNER" AND
              "V"."TABLE_NAME"(+)="T5"."OBJECT_NAME")
   4 - access("T3"."OWNER"="T4"."USERNAME")


Note
-----
   - dynamic sampling used for this statement (level=2)


看到对于右外连接的这种情况,视图没有合并


对于rownum伪劣的情况
SQL> select * from (select * from t3,t4 where t3.owner=t4.username order by table_name) v,t5 where v.owner=t5.owner and v.table_name=t5.object_name and rownum<1
0;


已选择9行。




执行计划
----------------------------------------------------------
Plan hash value: 87499378


---------------------------------------------------------------------------------------
| Id  | Operation              | Name | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |      |     9 | 26316 |       |   649   (1)| 00:00:08 |
|*  1 |  COUNT STOPKEY         |      |       |       |       |            |          |
|   2 |   NESTED LOOPS         |      |     9 | 26316 |       |   649   (1)| 00:00:08 |
|   3 |    VIEW                |      |  1683 |  4465K|       |     6   (0)| 00:00:01 |
|   4 |     SORT ORDER BY      |      |  1683 |  4465K|  6744K|   979   (1)| 00:00:12 |
|*  5 |      HASH JOIN         |      |  1683 |  4465K|       |    24   (5)| 00:00:01 |
|   6 |       TABLE ACCESS FULL| T4   |    18 | 39168 |       |     3   (0)| 00:00:01 |
|   7 |       TABLE ACCESS FULL| T3   |  1683 |   889K|       |    20   (0)| 00:00:01 |
|*  8 |    TABLE ACCESS FULL   | T5   |     1 |   207 |       |    71   (0)| 00:00:01 |
---------------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------


   1 - filter(ROWNUM<10)
   5 - access("T3"."OWNER"="T4"."USERNAME")
   8 - filter("V"."OWNER"="T5"."OWNER" AND "V"."TABLE_NAME"="T5"."OBJECT_NAME")


Note
-----
   - dynamic sampling used for this statement (level=2)
看到在不包含外连接的情况下,在有伪劣的情况下,视图也是没有合并的。






-----在视图无法合并的情况下使用push_pred,进行谓词推进
SQL> select * from (select /*+push_pred*/ * from t3,t4 where t3.owner=t4.username order by table_name) v,t5 where v.owner(+)=t5.owner and v.table_name(+)=t5.obj
ect_name and rownum<=10;


已选择10行。




执行计划
----------------------------------------------------------
Plan hash value: 857520502


---------------------------------------------------------------------------------
| Id  | Operation                | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------
|   0 | SELECT STATEMENT         |      |    10 | 29090 |   501K  (3)| 01:40:23 |
|*  1 |  COUNT STOPKEY           |      |       |       |            |          |
|   2 |   NESTED LOOPS OUTER     |      | 21334 |    59M|   501K  (3)| 01:40:23 |
|   3 |    TABLE ACCESS FULL     | T5   | 21334 |  4312K|     2   (0)| 00:00:01 |
|   4 |    VIEW PUSHED PREDICATE |      |     1 |  2702 |    24   (5)| 00:00:01 |
|*  5 |     HASH JOIN            |      |     1 |  2717 |    24   (5)| 00:00:01 |
|*  6 |      TABLE ACCESS FULL   | T4   |     1 |  2176 |     3   (0)| 00:00:01 |
|*  7 |      TABLE ACCESS FULL   | T3   |     1 |   541 |    20   (0)| 00:00:01 |
---------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------


   1 - filter(ROWNUM<=10)
   5 - access("T3"."OWNER"="T4"."USERNAME")
   6 - filter("T4"."USERNAME"="T5"."OWNER")
   7 - filter("T3"."TABLE_NAME"="T5"."OBJECT_NAME" AND
              "T3"."OWNER"="T5"."OWNER")


Note
-----
   - dynamic sampling used for this statement (level=2)




SQL> select * from (select /*+push_pred*/ * from t3,t4 where t3.owner=t4.username order by table_name) v,t5 where v.owner(+)=t5.owner and v.table_name(+)=t5.obj
ect_name;


已选择18515行。




执行计划
----------------------------------------------------------
Plan hash value: 1963531859


--------------------------------------------------------------------------------
| Id  | Operation               | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------
|   0 | SELECT STATEMENT        |      | 21334 |    59M|   501K  (3)| 01:40:24 |
|   1 |  NESTED LOOPS OUTER     |      | 21334 |    59M|   501K  (3)| 01:40:24 |
|   2 |   TABLE ACCESS FULL     | T5   | 21334 |  4312K|    73   (0)| 00:00:01 |
|   3 |   VIEW PUSHED PREDICATE |      |     1 |  2702 |    24   (5)| 00:00:01 |
|*  4 |    HASH JOIN            |      |     1 |  2717 |    24   (5)| 00:00:01 |
|*  5 |     TABLE ACCESS FULL   | T4   |     1 |  2176 |     3   (0)| 00:00:01 |
|*  6 |     TABLE ACCESS FULL   | T3   |     1 |   541 |    20   (0)| 00:00:01 |
--------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------


   4 - access("T3"."OWNER"="T4"."USERNAME")
   5 - filter("T4"."USERNAME"="T5"."OWNER")
   6 - filter("T3"."TABLE_NAME"="T5"."OBJECT_NAME" AND
              "T3"."OWNER"="T5"."OWNER")


Note
-----
   - dynamic sampling used for this statement (level=2)
-----在不包含外连接的情况下,即时有rownum伪劣,也是无法谓词推进的


SQL> select * from (select /*+push_pred*/ * from t3,t4 where t3.owner=t4.username order by table_name) v,t5 where v.owner=t5.owner and v.table_name=t5.object_na
me and rownum<=10;


已选择10行。




执行计划
----------------------------------------------------------
Plan hash value: 87499378


---------------------------------------------------------------------------------------
| Id  | Operation              | Name | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |      |    10 | 29240 |       |   792   (1)| 00:00:10 |
|*  1 |  COUNT STOPKEY         |      |       |       |       |            |          |
|   2 |   NESTED LOOPS         |      |    11 | 32164 |       |   792   (1)| 00:00:10 |
|   3 |    VIEW                |      |  1683 |  4465K|       |     7   (0)| 00:00:01 |
|   4 |     SORT ORDER BY      |      |  1683 |  4465K|  6744K|   979   (1)| 00:00:12 |
|*  5 |      HASH JOIN         |      |  1683 |  4465K|       |    24   (5)| 00:00:01 |
|   6 |       TABLE ACCESS FULL| T4   |    18 | 39168 |       |     3   (0)| 00:00:01 |
|   7 |       TABLE ACCESS FULL| T3   |  1683 |   889K|       |    20   (0)| 00:00:01 |
|*  8 |    TABLE ACCESS FULL   | T5   |     1 |   207 |       |    71   (0)| 00:00:01 |
---------------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------


   1 - filter(ROWNUM<=10)
   5 - access("T3"."OWNER"="T4"."USERNAME")
   8 - filter("V"."OWNER"="T5"."OWNER" AND "V"."TABLE_NAME"="T5"."OBJECT_NAME")


Note



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值