목차
1. 소트와 성능
2. 데이터 모댈 측면에서의 검토
3. 소트가 발생하지 않도록 SQL 작성
4. 인텍스를 이용한 소트 연산 대체
5. 소트 영역을 적게 사용하도록 SQL 작성
6. 소트 영역 크기 조정
구분 | 설명 |
---|---|
메모리(In-Memory) 소트 | 전체 데이터의 정렬 작업을 할당받은 소트 영역 내에 서 완료하는 것을 말하며, 'Internal Sort' 또는 'Optimal Sort'라고 함. |
디스크(To-Disk) 소트 | 할당받은 소트 영역 내에서 정렬을 완료하지 못해 디스크 공간까지 사용하는 경우를 말하며, 'External Sort' 라고 함. 디스크에 임시 저장했다가 다시 읽는 작업을 반복한 횟수에 따라 디스크 소트를 다음 두 가지로 구분함. * Onepass Sort : 정렬 대상 집합을 디스크에 한 번만 기록 * Multipass Sort : 정렬 대상 집합을 디스크에 여러 번 기록 |
SELECT SUM(SAL),
MAX(SAL),
MIN(SAL)
FROM EMP
;
-- Oracle
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4 | 5 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 4 | | |
| 2 | TABLE ACCESS FULL| EMP | 14 | 56 | 5 (0)| 00:00:01 |
---------------------------------------------------------------------------
;
-- SQL Server
StmtText
-----------------------------------------------------------------------------------------------
|--Compute Scalar(DEFINE:([Expr1004]=CASE WHEN [Exprl014]=(O) THEN NULL ELSE [Expr1015] END))
|--Stream Aggregate(DEFINE: )
|--Table Scan(OBJECT:([SQLPRO].[dbo].[emp]))
SELECT *
FROM EMP
ORDER BY SAL DESC
;
-- Oracle
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 532 | 6 (17)| 00:00:01 |
| 1 | SORT ORDER BY | | 14 | 532 | 6 (17)| 00:00:01 |
| 2 | TABLE ACCESS FULL| EMP | 14 | 532 | 5 (0)| 00:00:01 |
---------------------------------------------------------------------------
;
-- SQL Server
StmtText
--------------------------------------------------------------------------------
|--Sort(ORDER BY: ([SQLPRO].[dbo].[emp].[sal] DESC))
|--Table Scan(OBJECT:([SQLPRO].[dbo].[emp]))
-- Check Oracle Version
SELECT *
FROM V$VERSION
;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
;
-- Check Hidden parameter
NAME VALUE DEF_YN DESCRIPTION
------------------------------ ------ ------- ---------------------------------------------------
_gby_hash_aggregation_enabled TRUE TRUE ENABLE group-by and aggregation using hash scheme
;
-- Sort Group by
SELECT /*+ OPT_PARAM('_GBY_HASH_AGGREGATION_ENABLED', 'FALSE') */
DEPTNO,
JOB,
SUM(SAL),
MAX(SAL),
MIN(SAL)
FROM EMP
GROUP BY DEPTNO,
JOB
;
-- Oracle
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 11 | 165 | 6 (17)| 00:00:01 |
| 1 | SORT GROUP BY | | 11 | 165 | 6 (17)| 00:00:01 |
| 2 | TABLE ACCESS FULL| EMP | 14 | 210 | 5 (0)| 00:00:01 |
---------------------------------------------------------------------------
;
-- SQL Server
StmtText
-----------------------------------------------------------------------------------------------
|--Compute Scalar(DEFINE:([Expr1004]=CASE WHEN [Expr1014]=(O) THEN NULL ELSE [Exprl0l5] END))
|--Stream Aggregate(GROUP BY: )
|--Sort(ORDER BY:([SQLPRO].[dbo].[emp].[deptno] ASC, [SQLPRO].[dbo].[emp].[job] ASC))
|--Table Scan(OBJECT: ([SQLPRO].[dbo].[emp]))
SELECT /*+ USE_HASH_AGGREGATION */
DEPTNO,
JOB,
SUM(SAL),
MAX(SAL),
MIN(SAL)
FROM EMP
GROUP BY DEPTNO,
JOB
;
-- Oracle
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 11 | 165 | 6 (17)| 00:00:01 |
| 1 | HASH GROUP BY | | 11 | 165 | 6 (17)| 00:00:01 |
| 2 | TABLE ACCESS FULL| EMP | 14 | 210 | 5 (0)| 00:00:01 |
---------------------------------------------------------------------------
;
SELECT DISTINCT DEPTNO
FROM EMP
ORDER BY DEPTNO
;
-- Oracle
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3 | 9 | 7 (29)| 00:00:01 |
| 1 | SORT UNIQUE | | 3 | 9 | 6 (17)| 00:00:01 |
| 2 | TABLE ACCESS FULL| EMP | 14 | 42 | 5 (0)| 00:00:01 |
---------------------------------------------------------------------------
;
-- SQL Server
StmtText
-----------------------------------------------------------------------------------
|--Sort(DISTINCT ORDER BY: ([SQLPRO].[dbo].[emp].[deptno] ASC))
|--Table Scan(OBJECT: ([SQLPRO].[dbo].[emp]))
-- Oracle
SELECT /*+ ORDERED USE_MERGE(E D) */
*
FROM EMP E,
DEPT D
WHERE E.DEPTNO = D.DEPTNO
;
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 812 | 8 (13)| 00:00:01 |
| 1 | MERGE JOIN | | 14 | 812 | 8 (13)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| EMP | 14 | 532 | 2 (0)| 00:00:01 |
| 3 | INDEX FULL SCAN | EMP_N1 | 14 | | 1 (0)| 00:00:01 |
|* 4 | SORT JOIN | | 4 | 80 | 6 (17)| 00:00:01 |
| 5 | TABLE ACCESS FULL | DEPT | 4 | 80 | 5 (0)| 00:00:01 |
---------------------------------------------------------------------------------------
;
-- SQL Server
SELECT *
FROM EMP E,
DEPT D
WHERE E.DEPTNO = D.DEPTNO
OPTION (FORCE ORDER, MERGE JOIN)
;
StmtText
-----------------------------------------------------------------------------------
|--Merge Join(Inner Join, MANY-TO-MANY MERGE: )
|--Sort(ORDER BY:([e].[deptno] ASC))
|--Table Scan(OBJECT: ([SQLPRO].[dbo].[emp] AS [e)))
|--Sort(ORDER BY:'([d].[deptno] ASC))
|--Table Scan(OBJECT:([SQLPRO].[dbo].[dept] AS [d]))
SELECT EMPNO,
ENAME,
JOB,
MGR,
SAL,
ROW_NUMBER() OVER(ORDER BY HIREDATE)
FROM EMP
;
-- Oracle
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 476 | 6 (17)| 00:00:01 |
| 1 | WINDOW SORT | | 14 | 476 | 6 (17)| 00:00:01 |
| 2 | TABLE ACCESS FULL| EMP | 14 | 476 | 5 (0)| 00:00:01 |
---------------------------------------------------------------------------
;
-- SQL Server
StmtText
---------------------------------------------------------------------------
| --Sequence Project(DEFINE: ([Exprl004] =row number))
|-- Compute Scalar(DEFINE: ([Expr1006] = (1)))
|--Segment
|--Sort(ORDER BY: ([SQLPRO].[dbo].[emp].[hiredate] ASC))
|--Table Scan(OBJECT: ([SQLPRO].[dbo].[emp]))
SELECT 과금.고객ID,
과금.상품ID,
과금.과금액,
가입상품.가입일시
FROM 과금,
(SELECT 고객ID,
상품ID,
MIN(가입일시) 가입일시
FROM 고객별상품라인
GROUP BY 고객 ID,
상품ID
) 가입상품
WHERE 과금.고객 ID(+) = 가입상품.고객ID
AND 과금.상품ID(+) = 가입상품.상품ID
AND 과금.과금연월(+) = :YYYYMM
SELECT 과금.고객ID,
과금.상품ID,
과금.과금액,
가입상품.가입일시
FROM 과금,
가입상품
WHERE 과금.고객ID(+) = 가입상품.고객ID
AND 괴금.상품ID(+) = 가입상품.상품ID
AND 과금.과금연월(+) = :YYYYMM
SELECT EMPNO,
JOB,
MGR
FROM EMP
WHERE DEPTNO = 10
UNION
SELECT EMPNO,
JOB,
MGR
FROM EMP
WHERE DEPTNO = 20
;
-- Oracle
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 190 | 6 (67)| 00:00:01 |
| 1 | SORT UNIQUE | | 10 | 190 | 6 (67)| 00:00:01 |
| 2 | UNION-ALL | | | | | |
| 3 | TABLE ACCESS BY INDEX ROWID| EMP | 5 | 95 | 2 (0)| 00:00:01 |
|* 4 | INDEX RANGE SCAN | EMP_N1 | 5 | | 1 (0)| 00:00:01 |
| 5 | TABLE ACCESS BY INDEX ROWID| EMP | 5 | 95 | 2 (0)| 00:00:01 |
|* 6 | INDEX RANGE SCAN | EMP_N1 | 5 | | 1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------
;
-- SQL Server
StmtText
-----------------------------------------------------------------------------------------
|--Sort(mSTINCT ORDER BY:([Unionl008] ASC, [Union1009] ASC, [Unionl010] ASC))
|--Concatenation
|--Nested Loops(Inner Join, OUTER REFERENCES:([Bmk1000]))
| |--Index Seek(OBJECT:([SQLPRO].[dbo].[emp].[emp_deptjdx]), SEEK:([deptno]=(10.)))
| |--RID Lookup(OBJECT:([SQLPRO].[dbo].[emp]), SEEK:([Bmk1000]=[BmklOOO]))
|--Nested Loops(Inner Join, OUTER REFERENCES:([Bmkl004]))
|--Index Seek(OBJECT:([SQLPROJ.[dbo].[emp].[emp_deptjdx]), SEEK:( deptno]=(20.)))
| -- RID Lookup( OBJECT: ([SQLPRO].[dbo].[emp]), SEEK:([Bmk1004] [Bmkl004]))
SELECT EMPNO,
JOB,
MGR
FROM EMP
WHERE DEPTNO = 10
UNION ALL
SELECT EMPNO,
JOB,
MGR
FROM EMP
WHERE DEPTNO = 20
;
-- Oracle
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 190 | 4 (50)| 00:00:01 |
| 1 | UNION-ALL | | | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| EMP | 5 | 95 | 2 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | EMP_N1 | 5 | | 1 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID| EMP | 5 | 95 | 2 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | EMP_N1 | 5 | | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------------
;
-- SQL Server
StmtText
------------------------------------------------------------------------------------------
|--Concatenation
|--Nested Loops(Inner Join, OUTER REFERENCES:([Bmk1000)))
| |--Index Seek(OBJECT:([SQLPRO].[dbo].[emp].[emp_depUdx]), SEEK:([deptno]=(10,)))
| |--RID Lookup(OBJECT: ([SQLPRO].[dbo].[emp]), SEEK:([Bmk1000] =[Bmk1000)))
|--Nested Loops(Inner Join, OUTER REFERENCES:([Bmk1004)))
|--Index Seek(OBJECT: ([SQLPRO].[dbo].[emp].[emp_depUdx]), SEEK: ([deptno]=(20.)))
|--RID Lookup(OBjECT:([SQLPRO].[dbo].[emp]), SEEK:([Bmk1004]=[Bmk1004)))
SELECT DISTINCT 과금연월
FROM 과금
WHERE 과금연월 <= :YYYYMM
AND 지역 LIKE :REG 11 '%'
;
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 4 27.65 98.38 32648 1586208 0 35
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 6 27.65 98.38 32648 1586208 0 35
Rows Row Source Operation
------- -----------------------------------------------------------------------
35 HASH UNIQUE (cr=1586208 pr=32648 pw=O time=98704640 us)
9845517 PARTITION RANGE ITERATOR PARTITION: 1 KEY (cr=1586208 pr=32648
9845517 TABLE ACCESS FULL 과금 (cr=1586208 pr=32648 pw=O time=70155864 us)
SELECT 연월
FROM 연월테이블 A
WHERE 연월 <= :YYYYMM
AND EXISTS (SELECT 'x'
FROM 과금
WHERE 과금연월 A. 연월
AND 지 역 LIKE :REG 11 '%')
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 4 0.00 0.01 0 82 0 35
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 6 0.00 0.01 0 82 0 35
Rows Row Source Operation
---- ------------------------------------------------------------------------------
35 NESTED LOOPS SEMI (cr=82 pr=O pw=O time=19568 us)
36 TABLE ACCESS FULL 연월테이블 (cr=6 pr=O pw=O t ime=557 us)
35 PARTITION RANGE ITERATOR PARTITION: KEY KEY (cr=76 pr=O pw=O time=853 us)
35 INDEX RANGE SCAN 과금_N1 (cr=76 pr=O pw=O time=683 us)
DECLARE
l_cnt NUMBER;
BEGIN
SELECT COUNT(*)
INTO l_cnt
FROM MEMBER
WHERE MEMB_CLS = '1'
AND BIRTH_YYYY <= '1950';
IF l_cnt > 0 THEN
DBMS_OUTPUT.PUT_LINE('exists');
ELSE
DBMS_OUTPUT.PUT_LINE('not exists');
END IF;
END;
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.000 0.000 0 0 0 0
Execute 1 0.000 0.000 0 0 0 0
Fetch 2 0.172 17.561 4742 26112 0 1
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 4 0.172 17.561 4742 26112 0 1
Rows Row Source Operation
---- ------------------------------------------------------------------------------
0 STATEMENT
1 SORT AGGREGATE (cr=26112 pr=4742 pw=O time=17561372 us)
29184 TABLE ACCESS BY INDEX ROWID MEMBER (cr=26112 pr=4742 pw=O time=30885229 us)
33952 INDEX RANGE SCAN MEMBER_IDX01 (cr=105 pr=105 pw=O time=2042777 us)
-- Oracle
DECLARE
l_cnt NUMBER;
BEGIN
SELECT 1
INTO l_cnt
FROM MEMBER
WHERE MEMB_CLS = '1'
AND BIRTH_YYYY <= '1950'
AND ROWNUM <= 1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('not exists');
END;
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.000 0.000 0 0 0 0
Execute 1 0.000 0.000 0 0 0 0
Fetch 2 0.000 0.000 0 3 0 1
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 4 0.000 0.000 0 3 0 1
Rows Row Source Operation
---- ------------------------------------------------------------------------------
0 STATEMENT
1 COUNT STOPKEY (cr=3 pr=O pw=O time=54 us)
1 TABLE ACCESS BY INDEX ROWID MEMBER (cr=3 pr=O pw=O time=46 us)
1 INDEX RANGE SCAN MEMBER_IDX01 (cr=2 pr=O pw=O time=26 us)
;
-- SQL Server
DECLARE @cnt INT
SELECT @cnt = COUNT(*)
WHERE EXISTS (SELECT 'x'
FROM MEMBER
WHERE MEMB_CLS = '1'
AND BIRTH_YYYY <= '1950')
IF @cnt > 0
PRINT 'exists'
ELSE
PRINT 'not exists'
-- ORDER BY 절의 컬럼이 인덱스에 없을 경우
SELECT *
FROM EMP
WHERE DEPTNO = 10
ORDER BY JOB
;
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 | 190 | 3 (34)| 00:00:01 |
| 1 | SORT ORDER BY | | 5 | 190 | 3 (34)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| EMP | 5 | 190 | 2 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | EMP_N1 | 5 | | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------------
;
-- ORDER BY 절 컬럼이 인덱스에 있을 경우
CREATE INDEX APPS.EMP_N3 ON APPS.EMP (DEPTNO, JOB);
SELECT *
FROM EMP
WHERE DEPTNO = 10
ORDER BY JOB
;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 | 190 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 5 | 190 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | EMP_N3 | 5 | | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------------
-- 일반 컬럼 사용 시
SELECT /*+ NO_USE_HASH_AGGREGATION */
JOB,
SUM(SAL),
COUNT(*)
FROM EMP
GROUP BY JOB
;
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 | 60 | 6 (17)| 00:00:01 |
| 1 | SORT GROUP BY | | 5 | 60 | 6 (17)| 00:00:01 |
| 2 | TABLE ACCESS FULL| EMP | 14 | 168 | 5 (0)| 00:00:01 |
---------------------------------------------------------------------------
;
-- 인덱스 컬럼 사용 시
SELECT /*+ NO_USE_HASH_AGGREGATION */
EMPNO,
SUM(SAL),
COUNT(*)
FROM EMP E
GROUP BY EMPNO
;
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 112 | 2 (0)| 00:00:01 |
| 1 | SORT GROUP BY NOSORT | | 14 | 112 | 2 (0)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| EMP | 14 | 112 | 2 (0)| 00:00:01 |
| 3 | INDEX FULL SCAN | EMP_U1 | 14 | | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------------
SELECT MAX(JOB)
FROM EMP E
WHERE DEPTNO = :1
;
-- Oracle
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 11 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 11 | | |
| 2 | FIRST ROW | | 1 | 11 | 1 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN (MIN/MAX)| EMP_N3 | 1 | 11 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------------
-- SQL Server
StmtText
------------------------------------------------------------------------------------------------
|--Stream Aggregate(DEFINE: ([Expr1004) =MAX([SQLPRO).[dbo].[emp].[empno))))
|--Top(TOP EXPRESSION:((l)))
|-- Index Seek(OBJECT: ([SQLPRO].[dbo].[주문].[주문_PK)), SEEK:( .... .. ) ORDERED BACKWARD)
-- SQL_1
SELECT LPAD(상품번호, 30) || LPAD(상품명, 30) || LPAD(고객ID, 10) ||
LPAD(고객명, 20) || TO_CHAR(주문일시, 'YYYYMMDD HH24:MI:SS')
FROM 주문상품
WHERE 주문일시 BETWEEN :START
AND :END
ORDER BY 상품번호
;
-- SQL_2
SELECT LPAD(상품번호, 30) || LPAD(상품명, 30) || LPAD(고객ID, 10) ||
LPAD(고객명, 20) || TO_CHAR(주문일시, 'YYYYMMDD HH24:MI:SS')
FROM (SELECT 상품번호,
상품명,
고객ID,
고객명,
주문일시
FROM 주문상품
WHERE 주문일시 BETWEEN :START
AND :END
ORDER BY 상품번호
)
;
-- SQL_1(SQL Server)
SELECT TOP 10 거래일시, 체결건수, 체결수량, 거래대금
FROM 시간별종목거 래
WHERE 종목코드 = 'KR123456'
AND 거래일시 = '20080304'
;
-- SQL_2(DB2)
SELECT 거래일시, 체결건수, 체결수량, 거래대금
FROM 시간별종목거래
WHERE 종목코드 = 'KR123456'
AND 거래일시 = '20080304'
ORDER BY 거래일시
FETCH FIRST 10 ROWS ONLY
;
-- SQL_3(Oracle)
SELECT *
FROM (SELECT 거래일시, 체결건수, 체결수량, 거래대금
FROM 시간별종목거래
WHERE 종목코드 = 'KR123456'
AND 거래일시 = '20080304'
ORDER BY 거래일시
WHERE ROWNUM <= 10
;
Execution Plan
--------------------------------------------------------------------
SELECT STATEMENT Optimizer=ALL_ROWS
o COUNT (STOPKEY)
1 VIEW
2 TABLE ACCESS (BY INDEX ROWID) OF '시간별종목거래' (TABLE)
3 INDEX (RANGE SCAN) OF '시간별종목거래_PK' (INDEX (UNIQUE))
SELECT *
FROM (SELECT ROWNUM NO,
거래일시,
체결건수,
체결수량,
거래대금
FROM (SELECT 거래일시,
체결건수,
체결수량,
거래대금
FROM 시간별종목거래
WHERE 종목코드 = 'KR123456'
AND 거래일시 >= '20080304'
ORDER BY 거래일시
)
WHERE ROWNUM <= 100
)
WHERE NO BETWEEN 91 AND 100
SELECT *
FROM (SELECT ROWNUM NO,
거래일시,
체결건수,
체결수량,
거래대금
FROM (SELECT 거래일시,
체결건수,
체결수량,
거래대금
FROM 시간별종목거래
WHERE 종목코드 = 'KR123456'
AND 거래일시 >= '20080304'
ORDER BY 거래일시
)
)
WHERE NO BETWEEN 91 AND 100
SELECT 고객ID,
변경순번,
전화번호,
주소,
자녀수,
직업,
고객등급
FROM (SELECT 고객ID 변경순번,
MAX(변정순번) OVER(PARTITION BY 고객ID) 마지막변경순번,
전화번호,
주소,
자녀수,
직업,
고객등급
FROM 고객변경이력)
WHERE 변갱순번 = 마지막변청순번
SELECT 고객ID,
변경순번,
전화번호,
주소,
자녀수,
직업,
고객등급
FROM (SELECT 고객ID 변경순번,
RANK() OVER(PARTITION BY 고객ID ORDER BY 변경순번) RNUM
전화번호,
주소,
자녀수,
직업,
고객등급
FROM 고객변경이력)
WHERE RNUM = 1
alter session set sort area size 1048576;
alter session set workarea_size_policy manual;
alter session set sort area size 10485760;