메모리 소트 (IN MEORY SORT) : 전체 데이터 정렬을 메모리 내에서 완료.
디스크 소트 (TO-DISK SORT) : 메모리에서 정렬을 완료 못해 TEMP 디스크 공간 까지 사용하는 경우. (EXTERNAL SORT)
Optimal sort : 소트 포러에이션이 메모리 내에서 정렬.
Onepass sort : 정렬 대상 집합이 디스크에 한번만 쓰임.
Multipass sort : 정렬 대상 집합이 디스크에 여러번 쓰임.
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
1002 consistent gets
0 physical reads
0 redo size
435 bytes sent via SQL*Net to client
415 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory) <<
1 sorts (disk) <<
1 rows processed
Trace Event
direct path write temp
direct path read temp
SORT_AREA_REAINED_SIZE : 데이터 정렬을 끝내고 나서 집합결과를 모두 Fetch 할 때 까지 Sort Area 사이즈.
workarea_size_policy = auto 인 경우. (9i이후 True default)
SQL> SELECT /*+ gather_plan_statistics monitor */ SUM(SAL), MAX(SAL), MIN(SAL)
2 FROM SCOTT.EMP
3 ;
Execution Plan
----------------------------------------------------------
Plan hash value: 2083865914
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 | 828 (2)| 00:00:10 |
| 1 | SORT AGGREGATE | | 1 | 2 | | |
| 2 | TABLE ACCESS FULL| EMP | 1000K| 1953K| 828 (2)| 00:00:10 |
---------------------------------------------------------------------------
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
2913 consistent gets
2906 physical reads
0 redo size
567 bytes sent via SQL*Net to client
415 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
*정렬된 결과집합을 얻고자 할 때 나타남
SELECT /*+ gather_plan_statistics monitor */ *
FROM SCOTT.EMP
ORDER BY SAL DESC
;
-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1000K| 20M| | 7477 (1)| 00:01:30 |
| 1 | SORT ORDER BY | | 1000K| 20M| 42M| 7477 (1)| 00:01:30 |
| 2 | TABLE ACCESS FULL| EMP | 1000K| 20M| | 829 (2)| 00:00:10 |
-----------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
2913 consistent gets
2906 physical reads
0 redo size
17231057 bytes sent via SQL*Net to client
415324 bytes received via SQL*Net from client
37721 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
565786 rows processed
-- Sort Group by : Sort 알고리즘 이용하여 그룹별 집계를 수행할 때 발생. (/*+ USE_HASH_AGGREGATION */)
SQL> SELECT /*+ OPT_PARAM('_GBY_HASH_AGGREGATION_ENABLED', 'FALSE') */
2 DEPTNO,
3 JOB,
4 SUM(SAL),
5 MAX(SAL),
6 MIN(SAL)
7 FROM SCOTT.EMP
8 GROUP BY DEPTNO, JOB;
Execution Plan
----------------------------------------------------------
Plan hash value: 15469362
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 11 | 66 | 863 (6)| 00:00:11 |
| 1 | SORT GROUP BY | | 11 | 66 | 863 (6)| 00:00:11 |
| 2 | TABLE ACCESS FULL| EMP | 1000K| 5859K| 829 (2)| 00:00:10 |
---------------------------------------------------------------------------
-- HASH Group by : Hash 알고리즘 이용하여 그룹별 집계를 수행할 때 발생
SQL> SELECT /*+ gather_plan_statistics monitor */
2 DEPTNO,
3 JOB,
4 SUM(SAL),
5 MAX(SAL),
6 MIN(SAL)
7 FROM SCOTT.EMP
8 GROUP BY DEPTNO, JOB;
Execution Plan
----------------------------------------------------------
Plan hash value: 4067220884
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 11 | 66 | 863 (6)| 00:00:11 |
| 1 | HASH GROUP BY | | 11 | 66 | 863 (6)| 00:00:11 |
| 2 | TABLE ACCESS FULL| EMP | 1000K| 5859K| 829 (2)| 00:00:10 |
---------------------------------------------------------------------------
SQL> select /*+ ordered use_nl(depts) */ * from scott.emp
where deptno in (select /*+ unnest */ deptno from scott.depts);
~
14 개의 행이 선택되었습니다.
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 490 | 834 (2)| 00:00:11 |
|* 1 | HASH JOIN | | 14 | 490 | 834 (2)| 00:00:11 |
| 2 | SORT UNIQUE | | 6 | 78 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| DEPTS | 6 | 78 | 3 (0)| 00:00:01 |
|* 4 | TABLE ACCESS FULL | EMP | 14 | 308 | 830 (2)| 00:00:10 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("DEPTNO"="DEPTNO")
4 - filter("DEPTNO" IS NOT NULL)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
2917 consistent gets
2906 physical reads
0 redo size
1414 bytes sent via SQL*Net to client
415 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
14 rows processed
SQL> SELECT /*+ ORDERED USE_MERGE(E D) */ *
2 FROM scott.EMP E, scott.DEPT D
3 WHERE E.DEPTNO = D.DEPTNO
4 ;
14 개의 행이 선택되었습니다.
Execution Plan
Id | Operation | Name | Rows | Bytes | Cost (%CPU) | Time |
0 | SELECT STATEMENT | 14 | 546 | 835 (2) | 00:00:11 | |
1 | MERGE JOIN | 14 | 546 | 835 (2) | 00:00:11 | |
2 | SORT JOIN | 14 | 308 | 831 (2) | 00:00:10 | |
| TABLE ACCESS FULL | EMP | 14 | 308 | 830 (2) | 00:00:10 |
| SORT JOIN | 6 | 102 | 4 (25) | 00:00:01 | |
5 | TABLE ACCESS FULL | DEPT | 6 | 102 | 3 (0) | 00:00:01 |
Predicate Information (identified by operation id):
3 - filter("E"."DEPTNO" IS NOT NULL)
4 - access("E"."DEPTNO"="D"."DEPTNO")
filter("E"."DEPTNO"="D"."DEPTNO")
Statistics
h6. #Window Sort
{code :xml}