{section}
{column:width=50}
C:\Users\sunshiny>sqlplus scott/tiger
SQL*Plus: Release 11.2.0.1.0 Production on 수 4월 13 22:25:32 2011
Copyright (c) 1982, 2010, Oracle. All rights reserved.
다음에 접속됨:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> CREATE TABLE t1(c1 INT, c2 CHAR(10), c3 INT);
테이블이 생성되었습니다.
SQL> CREATE TABLE t2(c1 INT, c2 CHAR(10), c3 INT);
테이블이 생성되었습니다.
SQL> CREATE TABLE t3(c1 INT, c2 CHAR(10), c3 INT);
테이블이 생성되었습니다.
SQL> CREATE INDEX t1_n1 ON t1(c1);
인덱스가 생성되었습니다.
SQL> CREATE INDEX t2_n1 ON t2(c1);
인덱스가 생성되었습니다.
SQL> CREATE INDEX t3_n1 ON t3(c1);
인덱스가 생성되었습니다.
SQL> ALTER SESSION SET "_optimizer_cost_based_transformation" = off;
세션이 변경되었습니다.
SQL> ALTER SESSION SET "_optimizer_push_pred_cost_based" = false;
세션이 변경되었습니다.
SQL> INSERT INTO t1
2 SELECT level c1 -- 유일값(1~10000)
3 , 'dummy' c2 -- 동일값('dummy')
4 , MOD(level, 10) + 1 c3 -- 10개값(1~10)
5 FROM dual
6 CONNECT BY level <= 10000
7 ;
10000 개의 행이 만들어졌습니다.
SQL> INSERT INTO t2
2 SELECT level
3 , 'dummy'
4 , MOD(level, 10) + 1
5 FROM dual
6 CONNECT BY level <= 1000
7 ;
1000 개의 행이 만들어졌습니다.
SQL> INSERT INTO t3
2 SELECT level
3 , 'dummy'
4 , MOD(level, 10) + 1
5 FROM dual
6 CONNECT BY level <= 100
7 ;
100 개의 행이 만들어졌습니다.
SQL> COMMIT;
커밋이 완료되었습니다.
SQL> EXEC dbms_stats.gather_table_stats(user, 'T1');
PL/SQL 처리가 정상적으로 완료되었습니다.
SQL> EXEC dbms_stats.gather_table_stats(user, 'T2');
PL/SQL 처리가 정상적으로 완료되었습니다.
SQL> EXEC dbms_stats.gather_table_stats(user, 'T3');
PL/SQL 처리가 정상적으로 완료되었습니다.
SQL> SELECT COUNT(*)
2 FROM (SELECT /*+ gather_plan_statistics */
3 t1.c1, t1.c2
4 FROM t1
5 WHERE
6 t1.c1 IN (SELECT ROWNUM FROM t2)
7 )
8 ;
{column}
{column:width=50}
{column}
{section}
{section}
{column:width=50}
SQL> SELECT * FROM TABLE(dbms_xplan.display_cursor(null,null,'allstats cost last'));
SQL_ID f0cpgyqcch33j, child number 0
-------------------------------------
SELECT COUNT(*) FROM (SELECT /*+ gather_plan_statistics */ t1.c1,
t1.c2 FROM t1 WHERE t1.c1 IN (SELECT ROWNUM FROM t2) )
Plan hash value: 2572059326
-------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
-------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 12 (100)| 1 |00:00:00.03 | 32 | | | |
| 1 | SORT AGGREGATE | | 1 | 1 | | 1 |00:00:00.03 | 32 | | | |
|* 2 | HASH JOIN | | 1 | 1000 | 12 (17)| 1000 |00:00:00.03 | 32 | 1066K| 1066K| 1205K (0)|
| 3 | VIEW | VW_NSO_1 | 1 | 1000 | 4 (25)| 1000 |00:00:00.01 | 7 | | | |
| 4 | HASH UNIQUE | | 1 | 1000 | 4 (25)| 1000 |00:00:00.01 | 7 | 1037K| 1037K| 1262K (0)|
| 5 | COUNT | | 1 | | | 1000 |00:00:00.01 | 7 | | | |
| 6 | TABLE ACCESS FULL| T2 | 1 | 1000 | 3 (0)| 1000 |00:00:00.01 | 7 | | | |
| 7 | INDEX FAST FULL SCAN| T1_N1 | 1 | 10000 | 7 (0)| 10000 |00:00:00.01 | 25 | | | |
-------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("T1"."C1"="ROWNUM")
{column}
{column:width=50}
{column}
{section}
{section}
{column:width=50}
SQL> SELECT COUNT(*)
2 FROM (SELECT /*+ gather_plan_statistics */
3 t1.c1, t1.c2
4 FROM
5 t1
6 WHERE
7 t1.c1 IN (SELECT /*+ no_unnest */ ROWNUM FROM t2)
8 )
9 ;
SQL> SELECT * FROM TABLE(dbms_xplan.display_cursor(null,null,'allstats cost last'));
SQL_ID a4f96mbz2gbv0, child number 0
-------------------------------------
SELECT COUNT(*) FROM (SELECT /*+ gather_plan_statistics */ t1.c1, t1.c2
FROM t1
WHERE t1.c1 IN (SELECT /*+ no_unnest */
ROWNUM FROM t2) )
Plan hash value: 2881437346
-----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers |
-----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 10014 (100)| 1 |00:00:13.47 | 68883 |
| 1 | SORT AGGREGATE | | 1 | 1 | | 1 |00:00:13.47 | 68883 |
|* 2 | FILTER | | 1 | | | 1000 |00:00:13.47 | 68883 |
| 3 | TABLE ACCESS FULL | T1 | 1 | 10000 | 11 (0)| 10000 |00:00:00.01 | 38 |
|* 4 | FILTER | | 10000 | | | 1000 |00:00:13.44 | 68845 |
| 5 | COUNT | | 10000 | | | 9500K|00:00:10.06 | 68845 |
| 6 | TABLE ACCESS FULL| T2 | 10000 | 1 | 2 (0)| 9500K|00:00:05.99 | 68845 |
-----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter( IS NOT NULL)
4 - filter(ROWNUM=:B1)
{column}
{column:width=50}
{column}
{section}
{section}
{column:width=50}
SELECT /*+ gather_plan_statistics */
t1.c1, t1.c2
FROM
t1
WHERE
t1.c1 IN (SELECT c1 FROM t2
UNION ALL
SELECT c1 FROM t3)
;
{column}
{column:width=50}
{column}
{section}
{section}
{column:width=50}
SQL> SELECT * FROM TABLE(dbms_xplan.display_cursor(null,null,'allstats cost last'));
SQL_ID 7nx65u3p79p0g, child number 0
-------------------------------------
SELECT /*+ gather_plan_statistics */ t1.c1, t1.c2 FROM t1 WHERE t1.c1 IN (SELECT c1 FROM t2
UNION ALL
SELECT c1 FROM t3)
Plan hash value:3011680408
------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 18 (100)| 1000 |00:00:00.03 | 119 | | | |
|* 1 | HASH JOIN | | 1 | 1100 | 18 (6)| 1000 |00:00:00.03 | 119 | 1066K| 1066K| 1194K (0)|
| 2 | VIEW | VW_NSO_1 | 1 | 1100 | 6 (0)| 1000 |00:00:00.01 | 14 | | | |
| 3 | HASH UNIQUE | | 1 | 1100 | 6 (50)| 1000 |00:00:00.01 | 14 | 1037K| 1037K| 1260K (0)|
| 4 | UNION-ALL | | 1 | | | 1100 |00:00:00.01 | 14 | | | |
| 5 | TABLE ACCESS FULL| T2 | 1 | 1000 | 3 (0)| 1000 |00:00:00.01 | 7 | | | |
| 6 | TABLE ACCESS FULL| T3 | 1 | 100 | 3 (0)| 100 |00:00:00.01 | 7 | | | |
| 7 | TABLE ACCESS FULL | T1 | 1 | 10000 | 11 (0)| 10000 |00:00:00.01 | 105 | | | |
------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("T1"."C1"="C1")
{column}
{column:width=50}
{column}
{section}
{section}
{column:width=50}
SELECT /*+ gather_plan_statistics */
t1.c1, t1.c2
FROM
t1
WHERE
t1.c1 IN (SELECT c1 FROM t2
UNION ALL
SELECT c1 FROM t3)
AND t1.c1 BETWEEN 1 AND 100
;
{column}
{column:width=50}
{column}
{section}
{section}
{column:width=50}
SQL> SELECT * FROM TABLE(dbms_xplan.display_cursor(null,null,'allstats cost last'));
SQL_ID 5bxtkwx5p35s4, child number 0
-------------------------------------
SELECT /*+ gather_plan_statistics */ t1.c1, t1.c2 FROM t1 WHERE t1.c1 IN (SELECT c1 FROM t2
UNION ALL
SELECT c1 FROM t3)
AND t1.c1 BETWEEN 1 AND 100
Plan hash value: 4050798339
-------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
-------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 7 (100)| 100 |00:00:00.01 | 6 | | | |
|* 1 | HASH JOIN | | 1 | 2 | 7 (15)| 100 |00:00:00.01 | 6 | 870K| 870K| 1195K (0)|
| 2 | TABLE ACCESS BY INDEX ROWID| T1 | 1 | 100 | 3 (0)| 100 |00:00:00.01 | 3 | | | |
|* 3 | INDEX RANGE SCAN | T1_N1 | 1 | 100 | 2 (0)| 100 |00:00:00.01 | 2 | | | |
| 4 | VIEW | VW_NSO_1 | 1 | 200 | 3 (0)| 100 |00:00:00.01 | 3 | | | |
| 5 | HASH UNIQUE | | 1 | 200 | 3 (34)| 100 |00:00:00.01 | 3 | 1067K| 1067K| 1259K (0)|
| 6 | UNION-ALL | | 1 | | | 200 |00:00:00.01 | 3 | | | |
|* 7 | INDEX RANGE SCAN | T2_N1 | 1 | 100 | 2 (0)| 100 |00:00:00.01 | 2 | | | |
|* 8 | INDEX RANGE SCAN | T3_N1 | 1 | 100 | 1 (0)| 100 |00:00:00.01 | 1 | | | |
-------------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("T1"."C1"="C1")
3 - access("T1"."C1">=1 AND "T1"."C1"<=100)
7 - access("C1">=1 AND "C1"<=100)
8 - access("C1">=1 AND "C1"<=100)
{column}
{column:width=50}
{column}
{section}
{section}
{column:width=50}
SELECT /*+ gather_plan_statistics opt_param('_remove_aggr_subquery','false') */
t1.c1, t2.c2
FROM
t1, t2
WHERE
t1.c1 = t2.c1 AND
t2.c2 = (SELECT MAX(c2) FROM t2 s WHERE s.c1 = t1.c1)
;
{column}
{column:width=50}
{column}
{section}
{section}
{column:width=50}
SQL> SELECT * FROM TABLE(dbms_xplan.display_cursor(null,null,'allstats cost last'));
SQL_ID b9v83r4pgzcs5, child number 0
-------------------------------------
SELECT /*+ gather_plan_statistics
opt_param('_remove_aggr_subquery','false') */ t1.c1, t2.c2 FROM t1, t2
WHERE t1.c1 = t2.c1 AND t2.c2 = (SELECT MAX(c2) FROM t2 s WHERE s.c1 = t1.c1)
Plan hash value: 2760822941
------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 15 (100)| 1000 |00:00:00.03 | 106 | | | |
|* 1 | HASH JOIN | | 1 | 1000 | 15 (14)| 1000 |00:00:00.03 | 106 | 870K| 870K| 1223K (0)|
| 2 | TABLE ACCESS FULL | T2 | 1 | 1000 | 3 (0)| 1000 |00:00:00.01 | 7 | | | |
|* 3 | HASH JOIN | | 1 | 1000 | 12 (17)| 1000 |00:00:00.02 | 99 | 870K| 870K| 1198K (0)|
| 4 | VIEW | VW_SQ_1 | 1 | 1000 | 4 (25)| 1000 |00:00:00.01 | 7 | | | |
| 5 | HASH GROUP BY | | 1 | 1000 | 4 (25)| 1000 |00:00:00.01 | 7 | 848K| 848K| 1218K (0)|
| 6 | TABLE ACCESS FULL | T2 | 1 | 1000 | 3 (0)| 1000 |00:00:00.01 | 7 | | | |
| 7 | INDEX FAST FULL SCAN| T1_N1 | 1 | 10000 | 7 (0)| 10000 |00:00:00.01 | 92 | | | |
------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("T1"."C1"="T2"."C1" AND "T2"."C2"="MAX(C2)")
3 - access("ITEM_1"="T1"."C1")
{column}
{column:width=50}
{column}
{section}
{section}
{column:width=50}
SELECT /*+ gather_plan_statistics opt_param('_remove_aggr_subquery','true') */
t1.c1, t2.c2
FROM
t1, t2
WHERE
t1.c1 = t2.c1 AND
t2.c2 = (SELECT MAX(c2) FROM t2 s WHERE s.c1 = t1.c1)
;
SQL> SELECT * FROM TABLE(dbms_xplan.display_cursor(null,null,'allstats cost last'));
SQL_ID 4akhckc977yd0, child number 0
-------------------------------------
SELECT /*+ gather_plan_statistics
opt_param('_remove_aggr_subquery','true') */ t1.c1, t2.c2 FROM t1, t2
WHERE t1.c1 = t2.c1 AND t2.c2 = (SELECT MAX(c2) FROM t2 s WHERE s.c1 = t1.c1)
Plan hash value: 3825390570
--------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
--------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 12 (100)| 1000 |00:00:00.03 | 32 | | | |
|* 1 | VIEW | VW_WIF_1 | 1 | 1000 | 12 (17)| 1000 |00:00:00.03 | 32 | | | |
| 2 | WINDOW SORT | | 1 | 1000 | 12 (17)| 1000 |00:00:00.03 | 32 | 55296 | 55296 |49152(0)|
|* 3 | HASH JOIN | | 1 | 1000 | 11 (10)| 1000 |00:00:00.02 | 32 | 804K| 804K| 1229K(0)|
| 4 | TABLE ACCESS FULL | T2 | 1 | 1000 | 3 (0)| 1000 |00:00:00.01 | 7 | | |
| 5 | INDEX FAST FULL SCAN| T1_N1 | 1 | 10000 | 7 (0)| 10000 |00:00:00.01 | 25 | | | |
--------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("VW_COL_3" IS NOT NULL)
3 - access("T1"."C1"="T2"."C1")
{column}
{column:width=50}
{column}
{section}
SELECT * FROM TABLE(dbms_xplan.display_cursor(null,null,'ALL allstats cost last'));
{section}
{column:width=50}
SQL> SELECT * FROM TABLE(dbms_xplan.display_cursor(null,null,'all allstats cost last'));
SQL_ID 4akhckc977yd0, child number 0
-------------------------------------
SELECT /*+ gather_plan_statistics
opt_param('_remove_aggr_subquery','true') */ t1.c1, t2.c2 FROM t1, t2
WHERE t1.c1 = t2.c1 AND t2.c2 = (SELECT MAX(c2) FROM t2 s WHERE s.c1 = t1.c1)
Plan hash value: 3825390570
---------------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
---------------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 12 (100)| | 1000 |00:00:00.03 | 32 | | | |
|* 1 | VIEW | VW_WIF_1 | 1 | 1000 | 37000 | 12 (17)| 00:00:01 | 1000 |00:00:00.03 | 32 | | | |
| 2 | WINDOW SORT | | 1 | 1000 | 22000 | 12 (17)| 00:00:01 | 1000 |00:00:00.03 | 32 | 55296 | 55296 |49152 (0)|
|* 3 | HASH JOIN | | 1 | 1000 | 22000 | 11 (10)| 00:00:01 | 1000 |00:00:00.02 | 32 | 804K| 804K| 1215K (0)|
| 4 | TABLE ACCESS FULL | T2 | 1 | 1000 | 18000 | 3 (0)| 00:00:01 | 1000 |00:00:00.01 | 7 | | | |
| 5 | INDEX FAST FULL SCAN| T1_N1 | 1 | 10000 | 40000 | 7 (0)| 00:00:01 | 10000 |00:00:00.01 | 25 | | | |
---------------------------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$4F4DF0AE / VW_WIF_1@SEL$F79C84EE
2 - SEL$4F4DF0AE
4 - SEL$4F4DF0AE / T2@SEL$1
5 - SEL$4F4DF0AE / T1@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("VW_COL_3" IS NOT NULL)
3 - access("T1"."C1"="T2"."C1")
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - "ITEM_1"[NUMBER,22], "ITEM_2"[CHARACTER,10], "VW_COL_3"[ROWID,10]
2 - (#keys=1) "T2"."C1"[NUMBER,22], "T2"."C2"[CHARACTER,10], "T1"."C1"[NUMBER,22], ROWID[ROWID,10],
MAX("C2") OVER ( PARTITION BY "S"."C1")[10]
3 - (#keys=1) "T2"."C1"[NUMBER,22], "T1"."C1"[NUMBER,22], ROWID[ROWID,10], "T2"."C2"[CHARACTER,10]
4 - ROWID[ROWID,10], "T2"."C1"[NUMBER,22], "T2"."C2"[CHARACTER,10]
5 - "T1"."C1"[NUMBER,22]
{column}
{column:width=50}
{column}
{section}