SQL> select /*+ gather_plan_statistics */ empno, ename, sal, hiredate
2 , (select d.dname from dept d where d.deptno = e.deptno ) dname
3 from emp e
4 where sal >= 2000;
SQL> select * from table( dbms_xplan.display_cursor( null, null, 'ALLSTATS LAST'));
-------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
-------------------------------------------------------------------------------------------------
| 1 | TABLE ACCESS BY INDEX ROWID| DEPT | 3 | 1 | 3 |00:00:00.01 | 5 |
|* 2 | INDEX UNIQUE SCAN | PK_DEPT | 3 | 1 | 3 |00:00:00.01 | 2 |
|* 3 | TABLE ACCESS FULL | EMP | 1 | 11 | 6 |00:00:00.01 | 8 |
-------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("D"."DEPTNO"=:B1)
3 - filter("SAL">=2000)
select /*+ gather_plan_statistics ordered use_nl(d)*/
e.empno, e.ename, e.sal, e.hiredate, d.dname
from emp e, dept d
where d.deptno(+) = e.deptno
and e.sal >= 2000;
SQL> select * from table( dbms_xplan.display_cursor( null, null, 'ALLSTATS LAST'));
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
--------------------------------------------------------------------------------------------------
| 1 | NESTED LOOPS OUTER | | 1 | 11 | 6 |00:00:00.01 | 16 |
|* 2 | TABLE ACCESS FULL | EMP | 1 | 11 | 6 |00:00:00.01 | 8 |
| 3 | TABLE ACCESS BY INDEX ROWID| DEPT | 6 | 1 | 6 |00:00:00.01 | 8 |
|* 4 | INDEX UNIQUE SCAN | PK_DEPT | 6 | 1 | 6 |00:00:00.01 | 2 |
--------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("E"."SAL">=2000)
4 - access("D"."DEPTNO"="E"."DEPTNO")
select empno, ename, sal, hiredate
, (select d.dname -> 출력값 : d.dname
from dept d
where d.deptno = e.empno -> 입력값 : e.empno
)
from emp e
where sal >= 2000
SQL> CREATE TABLE T_code AS
2 SELECT ROWNUM code, CHR(ROWNUM + 64) NAME FROM DUAL
3 CONNECT BY LEVEL <= 1000
SQL> CREATE INDEX IDX_T_code_PK ON T_code(code,NAME);
SQL> ALTER TABLE T_code ADD CONSTRAINT IDX_T_code_PK PRIMARY KEY(code);
SQL> CREATE TABLE T AS
2 SELECT ROWNUM NO, CEIL(ROWNUM/1000) code FROM DUAL
3 CONNECT BY LEVEL <= 1000000;
SQL> CREATE INDEX IDX_T_01 ON T( code);
SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS(USER, 'T');
SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS(USER, 'T_code');
CREATE or REPLACE FUNCTION GET_NAME(IN_code INT)
RETURN VARCHAR
IS
RET_NAME T_code.NAME%TYPE;
BEGIN
SELECT NAME
INTO RET_NAME
FROM T_code WHERE code = IN_code;
RETURN RET_NAME;
END;
/
SQL> SELECT /*+ gather_plan_statistics*/COUNT(T)
2 FROM (
3 SELECT GET_NAME(code) AS T
4 FROM T)
5 ;
COUNT(T)
----------
1000000
SQL> select * from table( dbms_xplan.display_cursor( null, null, 'ALLSTATS LAST'));
-------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
-------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:17.42 | 2003K|
| 2 | TABLE ACCESS FULL| T | 1 | 994K| 1000K|00:00:00.01 | 1925 |
-------------------------------------------------------------------------------------
SQL> SELECT /*+ gather_plan_statistics*/COUNT(T)
2 FROM (
3 SELECT (SELECT GET_NAME(code) FROM DUAL) AS T
4 FROM T)
5 ;
COUNT(T)
----------
1000000
SQL> select * from table( dbms_xplan.display_cursor( null, null, 'ALLSTATS LAST'));
-------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
-------------------------------------------------------------------------------------
| 1 | FAST DUAL | | 1000 | 1 | 1000 |00:00:00.01 | 0 |
| 2 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:00.18 | 3927 |
| 3 | TABLE ACCESS FULL| T | 1 | 994K| 1000K|00:00:00.01 | 1925 |
-------------------------------------------------------------------------------------
SQL> select /*+gather_plan_statistics*/d.deptno, d.dname, avg_sal, min_sal, max_sal
2 from dept d
3 ,(select deptno, avg(sal) avg_sal, min(sal) min_sal, max(sal) max_sal
4 from emp group by deptno) e
5 where e.deptno(+) = d.deptno
6 and d.loc = 'CHICAGO';
DEPTNO DNAME AVG_SAL MIN_SAL MAX_SAL
---------- -------------- ---------- ---------- ----------
30 SALES 1566.66667 950 2850
SQL> select * from table( dbms_xplan.display_cursor( null, null, 'ALLSTATS LAST'));
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | OMem | 1Mem | Us
----------------------------------------------------------------------------------------------------
| 1 | HASH GROUP BY | | 1 | 1 | 1 |00:00:00.01 | 3 | | | |
| 2 | MERGE JOIN OUTER | | 1 | 5 | 6 |00:00:00.01 | 3 | | | |
|* 3 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 | 1 | 1 |00:00:00.01 | 2 | | | |
| 4 | INDEX FULL SCAN | PK_DEPT | 1 | 4 | 4 |00:00:00.01 | 1 | | | |
|* 5 | SORT JOIN | | 1 | 14 | 6 |00:00:00.01 | 1 | 2048 | 2048 | 2048 (0)|
| 6 | INDEX FULL SCAN | EMP_X01 | 1 | 14 | 14 |00:00:00.01 | 1 | | | |
----------------------------------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
3 - filter("D"."LOC"='CHICAGO')
5 - access("DEPTNO"="D"."DEPTNO")
filter("DEPTNO"="D"."DEPTNO")
select d.deptno, d.dname
,(select avg(sal), min(sal), max(sal) from emp where deptno = d.deptno)
from dept d
where d.loc = 'CHICAGO';
SQL> select /*+gather_plan_statistics*/d.deptno, d.dname
2 ,(select avg(sal) from emp where deptno = d.deptno) avg_sal
3 ,(select min(sal) from emp where deptno = d.deptno) min_sal
4 ,(select max(sal) from emp where deptno = d.deptno) max_sal
5 from dept d
6 where d.loc = 'CHICAGO';
DEPTNO DNAME AVG_SAL MIN_SAL MAX_SAL
---------- -------------- ---------- ---------- ----------
30 SALES 1566.66667 950 2850
SQL> select * from table( dbms_xplan.display_cursor( null, null, 'ALLSTATS LAST'));
---------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:00.01 | 1 |
|* 2 | INDEX RANGE SCAN| EMP_X01 | 1 | 5 | 6 |00:00:00.01 | 1 |
| 3 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:00.01 | 1 |
|* 4 | INDEX RANGE SCAN| EMP_X01 | 1 | 5 | 6 |00:00:00.01 | 1 |
| 5 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:00.01 | 1 |
|* 6 | INDEX RANGE SCAN| EMP_X01 | 1 | 5 | 6 |00:00:00.01 | 1 |
|* 7 | TABLE ACCESS FULL| DEPT | 1 | 1 | 1 |00:00:00.01 | 8 |
---------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("DEPTNO"=:B1)
4 - access("DEPTNO"=:B1)
6 - access("DEPTNO"=:B1)
7 - filter("D"."LOC"='CHICAGO')
SQL> SELECT /*+ GATHER_PLAN_STATISTICS */
2 DEPTNO
3 , DNAME
4 , TO_NUMBER(SUBSTR(SAL, 1, 7)) AVG_SAL
5 , TO_NUMBER(SUBSTR(SAL, 8, 7)) MIN_SAL
6 , TO_NUMBER(SUBSTR(SAL, 15)) MAX_SAL
7 FROM (SELECT D.DEPTNO, D.DNAME
8 , (SELECT LPAD(AVG(SAL), 7)||LPAD(MIN(SAL),7)||MAX(SAL)
9 FROM EMP
10 WHERE DEPTNO = D.DEPTNO) SAL
11 FROM DEPT D
12 WHERE D.LOC = 'CHICAGO'
13 )
14 ;
DEPTNO DNAME AVG_SAL MIN_SAL MAX_SAL
---------- -------------- ---------- ---------- ----------
30 SALES 1566.66 950 2850
SQL> select * from table( dbms_xplan.display_cursor( null, null, 'ALLSTATS LAST'));
---------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
---------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:00.01 | 1 |
|* 2 | INDEX RANGE SCAN| EMP_X01 | 1 | 5 | 6 |00:00:00.01 | 1 |
|* 3 | TABLE ACCESS FULL| DEPT | 1 | 1 | 1 |00:00:00.01 | 8 |
---------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("DEPTNO"=:B1)
3 - filter("D"."LOC"='CHICAGO')
SQL> CREATE OR REPLACE TYPE SAL_TYPE AS OBJECT
2 (AVG_SAL NUMBER, MIN_SAL NUMBER, MAX_SAL NUMBER)
3 /
유형이 생성되었습니다.
SQL> SELECT /*+ GATHER_PLAN_STATISTICS */DEPTNO, DNAME
2 , A.SAL.AVG_SAL, A.SAL.MIN_SAL, A.SAL.MAX_SAL
3 FROM (SELECT D.DEPTNO, D.DNAME
4 , (SELECT SAL_TYPE(AVG(SAL), MIN(SAL), MAX(SAL) )
5 FROM EMP WHERE DEPTNO = D.DEPTNO) SAL
6 FROM DEPT D WHERE D.LOC = 'CHICAGO')A
7 ;
DEPTNO DNAME SAL.AVG_SAL SAL.MIN_SAL SAL.MAX_SAL
---------- -------------- ----------- ----------- -----------
30 SALES 1566.66667 950 2850
SQL> select * from table( dbms_xplan.display_cursor( null, null, 'ALLSTATS LAST'));
---------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
---------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:00.01 | 1 |
|* 2 | INDEX RANGE SCAN| EMP_X01 | 1 | 5 | 6 |00:00:00.01 | 1 |
|* 3 | TABLE ACCESS FULL| DEPT | 1 | 1 | 1 |00:00:00.01 | 8 |
---------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("DEPTNO"=:B1)
3 - filter("D"."LOC"='CHICAGO')
- 강좌 URL : http://www.gurubee.net/lecture/3271
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.