1 nested Loops join -- 如果不加hint,则走的是hash join(已测试,过程略)
set autotrace traceonly
select /*+ leading(t1) use_nl(t2)*/ * from t1,t2 where t1.id=t2.t1_id and t1.n=9;
ZBB@test>select /*+ leading(t1) use_nl(t2)*/ * from t1,t2 where t1.id=t2.t1_id and t1.n=9;
Execution Plan
----------------------------------------------------------
Plan hash value: 1967407726
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4069 | 276 (1)| 00:00:01 |
| 1 | NESTED LOOPS | | 1 | 4069 | 276 (1)| 00:00:01 |
|* 2 | TABLE ACCESS FULL| T1 | 1 | 2028 | 3 (0)| 00:00:01 |
|* 3 | TABLE ACCESS FULL| T2 | 1 | 2041 | 273 (1)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("T1"."N"=9)
3 - filter("T1"."ID"="T2"."T1_ID")
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
7 recursive calls
0 db block gets
1098 consistent gets
0 physical reads
0 redo size
1031 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)
1 rows processed
ZBB@test>
-- 从上面的执行结果来看,并没有排序,sorts都是0
2 hash join
select /*+ leading(t1) use_hash(t2)*/ * from t1,t2 where t1.id=t2.t1_id and t1.n=9;
ZBB@test>select /*+ leading(t1) use_hash(t2)*/ * from t1,t2 where t1.id=t2.t1_id and t1.n=9;
Execution Plan
----------------------------------------------------------
Plan hash value: 1838229974
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4069 | 276 (1)| 00:00:01 |
|* 1 | HASH JOIN | | 1 | 4069 | 276 (1)| 00:00:01 |
|* 2 | TABLE ACCESS FULL| T1 | 1 | 2028 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| T2 | 111K| 217M| 273 (1)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("T1"."ID"="T2"."T1_ID")
2 - filter("T1"."N"=9)
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
1013 consistent gets
0 physical reads
0 redo size
1031 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)
1 rows processed
ZBB@test>
-- 从上面的执行结果来看,也没有排序,sorts是0
3 merge sort join
select /*+ leading(t1) use_merge(t2)*/ * from t1,t2 where t1.id=t2.t1_id and t1.n=9;
ZBB@test>select /*+ leading(t1) use_merge(t2)*/ * from t1,t2 where t1.id=t2.t1_id and t1.n=9;
Execution Plan
----------------------------------------------------------
Plan hash value: 412793182
------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4069 | | 47920 (1)| 00:00:11 |
| 1 | MERGE JOIN | | 1 | 4069 | | 47920 (1)| 00:00:11 |
| 2 | SORT JOIN | | 1 | 2028 | | 4 (25)| 00:00:01 |
|* 3 | TABLE ACCESS FULL| T1 | 1 | 2028 | | 3 (0)| 00:00:01 |
|* 4 | SORT JOIN | | 111K| 217M| 582M| 47916 (1)| 00:00:11 |
| 5 | TABLE ACCESS FULL| T2 | 111K| 217M| | 273 (1)| 00:00:01 |
------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter("T1"."N"=9)
4 - access("T1"."ID"="T2"."T1_ID")
filter("T1"."ID"="T2"."T1_ID")
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
7 recursive calls
0 db block gets
1096 consistent gets
0 physical reads
0 redo size
1031 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
1 rows processed
ZBB@test>
ZBB@test>select /*+ leading(t2) use_merge(t1)*/ * from t1,t2 where t1.id=t2.t1_id and t1.n=9;
Execution Plan
----------------------------------------------------------
Plan hash value: 1792967693
------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4069 | | 47920 (1)| 00:00:11 |
| 1 | MERGE JOIN | | 1 | 4069 | | 47920 (1)| 00:00:11 |
| 2 | SORT JOIN | | 111K| 217M| 582M| 47916 (1)| 00:00:11 |
| 3 | TABLE ACCESS FULL| T2 | 111K| 217M| | 273 (1)| 00:00:01 |
|* 4 | SORT JOIN | | 1 | 2028 | | 4 (25)| 00:00:01 |
|* 5 | TABLE ACCESS FULL| T1 | 1 | 2028 | | 3 (0)| 00:00:01 |
------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("T1"."ID"="T2"."T1_ID")
filter("T1"."ID"="T2"."T1_ID")
5 - filter("T1"."N"=9)
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
7 recursive calls
0 db block gets
1096 consistent gets
0 physical reads
0 redo size
1031 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
1 rows processed
ZBB@test>
-- 从上面的执行结果来看,进行了排序 。
end