Oracle with as (hint inline materialize)
admin
2023-05-07 20:02:17
0
  1. 测试数据:

SQL> create table test1 as  select * from dba_objects;
Table created.
SQL> create table test2 as  select * from user_objects;
Table created.
SQL> create table test3 as  select * from dba_objects;
Table created.

收集统计信息:

BEGIN
  DBMS_STATS.GATHER_TABLE_STATS(ownname          => 'SCOTT',
                                tabname          => 'TEST1',
                                estimate_percent => 100,
                                method_opt       => 'for  columns owner size repeat',
                                no_invalidate    => FALSE,
                                degree           => 4,
                                granularity      => 'ALL',
                                cascade          => TRUE);
  END;
   /
PL/SQL procedure successfully completed.

SQL> with t as(select t1.* from test1 t1,test2 t2 where t1.object_id=t2.object_id) select * from t,test3 t3 where t.object_id=t3.object_id;

11 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 2878150729

-------------------------------------------------------------------------------------
| Id  | Operation	    | Name  | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |	    | 86999 |	 16M|	    |  1605   (1)| 00:00:20 |
|*  1 |  HASH JOIN	    |	    | 86999 |	 16M|	    |  1605   (1)| 00:00:20 |
|   2 |   TABLE ACCESS FULL | TEST2 |	 13 |	 65 |	    |	  3   (0)| 00:00:01 |
|*  3 |   HASH JOIN	    |	    | 86999 |	 16M|  9352K|  1602   (1)| 00:00:20 |
|   4 |    TABLE ACCESS FULL| TEST1 | 86997 |  8325K|	    |	347   (1)| 00:00:05 |
|   5 |    TABLE ACCESS FULL| TEST3 | 86999 |  8326K|	    |	347   (1)| 00:00:05 |
-------------------------------------------------------------------------------------

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

   1 - access("T1"."OBJECT_ID"="T2"."OBJECT_ID")
   3 - access("T1"."OBJECT_ID"="T3"."OBJECT_ID")


Statistics
----------------------------------------------------------
	  0  recursive calls
	  0  db block gets
       2491  consistent gets
       2484  physical reads
	  0  redo size
       3736  bytes sent via SQL*Net to client
	523  bytes received via SQL*Net from client
	  2  SQL*Net roundtrips to/from client
	  0  sorts (memory)
	  0  sorts (disk)
	 11  rows processed
	 

加 materialize hint,强制oracle生成临时表
SQL> with t as(select /*+ materialize */t1.* from test1 t1,test2 t2 where t1.object_id=t2.object_id) select * from t,test3 t3 where t.object_id=t3.object_id;

11 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 3288461629

----------------------------------------------------------------------------------------------------------------
| Id  | Operation		   | Name		       | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT	   |			       |   582M|   165G|       |  3963	(40)| 00:00:48 |
|   1 |  TEMP TABLE TRANSFORMATION |			       |       |       |       |	    |	       |
|   2 |   LOAD AS SELECT	   | SYS_TEMP_0FD9D661A_155646 |       |       |       |	    |	       |
|*  3 |    HASH JOIN		   |			       | 86997 |  8750K|       |   351	 (1)| 00:00:05 |
|   4 |     TABLE ACCESS FULL	   | TEST2		       |    13 |    65 |       |     3	 (0)| 00:00:01 |
|   5 |     TABLE ACCESS FULL	   | TEST1		       | 86997 |  8325K|       |   347	 (1)| 00:00:05 |
|*  6 |   HASH JOIN		   |			       |   582M|   165G|  9352K|  3613	(44)| 00:00:44 |
|   7 |    TABLE ACCESS FULL	   | TEST3		       | 86999 |  8326K|       |   347	 (1)| 00:00:05 |
|   8 |    VIEW 		   |			       | 86997 |    17M|       |   332	 (1)| 00:00:04 |
|   9 |     TABLE ACCESS FULL	   | SYS_TEMP_0FD9D661A_155646 | 86997 |  8750K|       |   332	 (1)| 00:00:04 |
----------------------------------------------------------------------------------------------------------------

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

   3 - access("T1"."OBJECT_ID"="T2"."OBJECT_ID")
   6 - access("T"."OBJECT_ID"="T3"."OBJECT_ID")


Statistics
----------------------------------------------------------
	 55  recursive calls
	  8  db block gets
       2525  consistent gets
       2485  physical reads
	656  redo size
       3736  bytes sent via SQL*Net to client
	523  bytes received via SQL*Net from client
	  2  SQL*Net roundtrips to/from client
	  3  sorts (memory)
	  0  sorts (disk)
	 11  rows processed

相关内容

热门资讯

武汉大学打开大门,以开放拆掉“... 澎湃新闻主笔 沈彬5月13日,武汉大学正式取消社会公众进校预约制度。公众无需任何预约,仅凭本人身份证...
中方很直白:对欧洲非常失望,把... 【文/观察者网 柳白】欧盟屡借“安全风险”和“产业振兴”之名,行保护主义与差别对待之实,遭中方明确回...
韩国赚大了,但大麻烦也来了 AI正在改变世界,但不得不说,最先被深刻重塑、掀起财富狂潮的,还是韩国。有些数据,说出来都不敢相信自...
以色列执政联盟提交提前解散议会... 以色列执政联盟主席奥菲尔·卡茨13日与联盟各派别领导人共同提交一项解散议会的议案,此举可能触发以色列...
内塔尼亚胡首次公开证实曾秘访,... 以色列总理办公室13日证实,以总理内塔尼亚胡在以色列对伊朗发动大规模军事行动期间曾秘密访问阿联酋,并...
1万个外资项目,看好这个县级市 在昆山高新区的沪士电子股份有限公司门口,运输建材的卡车与满载成品的物流货车交错而行。新厂房扩建与车间...
特朗普抵达酒店,车队驶过持续6... 美国总统特朗普车队于5月13日晚8点30分左右抵达位于北京东三环的下榻酒店。凤凰卫视驻北京记者在酒店...
少出国、少用油、少买金子,莫迪... 【文/观察者网 熊超然】上周末,印度总理莫迪呼吁民众在中东战争持续的这段时间里,未来一年内适度减少燃...
岛内“新地标”,沦为民进党“抢... 被视为岛内近年来最为重大的公共建设项目之一的新北市淡江大桥,于5月12日正式通车。然而,因民进党当局...
副秘书长在以色列机场遭扣留,联... 新华社联合国5月13日电 联合国秘书长副发言人哈克13日就联合国负责安全和安保事务的副秘书长吉勒·米...