DROP TABLE "ORDER" PURGE
DROP TABLE DEPT PURGE
CREATE TABLE "ORDER" AS
SELECT LEVEL SEQNO
, TO_CHAR( ( SYSDATE - 100 ) - 1 / 1440 / ( 60 / ( 1000001 - LEVEL )), 'YYYYMMDDHH24MISS' ) ORDDATE
, TO_CHAR( TRUNC( dbms_random.value( 1,12 ) ), 'FM0009' ) SALDEPTNO
FROM DUAL
CONNECT BY LEVEL <= 1000000
CREATE TABLE DEPT AS
SELECT TO_CHAR( LEVEL, 'FM0009' ) DEPTNO
, '부서'|| TO_CHAR( LEVEL, 'FM0009' ) AS DEPTNAME
, TRUNC( dbms_random.value( 1,4 ) ) TYPE1
FROM DUAL
CONNECT BY LEVEL <= 12
CREATE INDEX ORDDATE_INDEX ON "ORDER"( ORDDATE )
CREATE INDEX ORDDATE_INDEX_01 ON "ORDER"( ORDDATE, SALDEPTNO )
CREATE UNIQUE INDEX DEPT_PK ON DEPT ( DEPTNO )
SQL> SELECT *
2 FROM (SELECT *
3 FROM "ORDER"
4 ORDER BY SEQNO ASC
5 )
6 WHERE ROWNUM <= 10;
SEQNO ORDDATE SALDE
---------- -------------- -----
1 20110616073831 0001
2 20110616073832 0008
3 20110616073833 0002
4 20110616073834 0007
5 20110616073835 0005
6 20110616073836 0001
7 20110616073837 0010
8 20110616073838 0011
9 20110616073839 0006
10 20110616073840 0007
10 개의 행이 선택되었습니다.
SQL> SELECT SUBSTR( ORDDATE, 1,8 ), MAX(SEQNO), COUNT(*)
2 FROM "ORDER"
3 GROUP BY SUBSTR( ORDDATE, 1,8 )
4 ORDER BY MAX(SEQNO);
SUBSTR(ORDDATE,1 MAX(SEQNO) COUNT(*)
---------------- ---------- ----------
20110616 58889 58889
20110617 145289 86400
20110618 231689 86400
20110619 318089 86400
20110620 404489 86400
20110621 490889 86400
20110622 577289 86400
20110623 663689 86400
20110624 750089 86400
20110625 836489 86400
20110626 922889 86400
SUBSTR(ORDDATE,1 MAX(SEQNO) COUNT(*)
---------------- ---------- ----------
20110627 1000000 77111
12 개의 행이 선택되었습니다.
SQL> SELECT * FROM DEPT
2 ;
DEPTN DEPTNAME TYPE1
----- --------- ----------
0001 부서0001 3
0002 부서0002 2
0003 부서0003 1
0004 부서0004 1
0005 부서0005 2
0006 부서0006 3
0007 부서0007 3
0008 부서0008 3
0009 부서0009 3
0010 부서0010 3
0011 부서0011 3
DEPTN DEPTNAME TYPE1
----- --------- ----------
0012 부서0012 2
12 개의 행이 선택되었습니다.
SQL> SELECT /*+ gather_plan_statistics */ COUNT(*)
2 FROM "ORDER" X
3 WHERE ORDDATE LIKE '20110621%'
4 AND EXISTS ( SELECT 'O'
5 FROM DEPT Y
6 WHERE Y.DEPTNO = X.SALDEPTNO
7 AND Y.TYPE1 = 1 );
COUNT(*)
----------
15832
SQL> @XPLAN
---------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads | OMem | 1Mem | Used-Mem |
---------------------------------------------------------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:00.11 | 757 | 374 | | | |
| 2 | NESTED LOOPS | | 1 | 17623 | 15832 |00:00:00.19 | 757 | 374 | | | |
| 3 | SORT UNIQUE | | 1 | 2 | 2 |00:00:00.01 | 3 | 0 | 9216 | 9216 | 8192 (0)|
|* 4 | TABLE ACCESS FULL| DEPT | 1 | 2 | 2 |00:00:00.01 | 3 | 0 | | | |
|* 5 | INDEX RANGE SCAN | ORDDATE_INDEX_01 | 2 | 8812 | 15832 |00:00:00.13 | 754 | 374 | | | |
---------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter("Y"."TYPE1"=1)
5 - access("ORDDATE" LIKE '20110621%' AND "Y"."DEPTNO"="X"."SALDEPTNO")
filter(("ORDDATE" LIKE '20110621%' AND "Y"."DEPTNO"="X"."SALDEPTNO"))
SQL> SELECT /*+ gather_plan_statistics INDEX( X ORDDATE_INDEX ) */ COUNT(*)
2 FROM "ORDER" X
3 WHERE ORDDATE LIKE '20110621%'
4 AND EXISTS ( SELECT /*+ NO_UNNEST NO_PUSH_SUBQ */ 'O'
5 FROM DEPT Y
6 WHERE Y.DEPTNO = X.SALDEPTNO
7 AND Y.TYPE1 = 1 );
COUNT(*)
----------
15832
SQL> @XPLAN
------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads |
------------------------------------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:00.15 | 697 | 313 |
|* 2 | FILTER | | 1 | | 15832 |00:00:00.21 | 697 | 313 |
| 3 | TABLE ACCESS BY INDEX ROWID| ORDER | 1 | 96928 | 86400 |00:00:00.95 | 675 | 313 |
|* 4 | INDEX RANGE SCAN | ORDDATE_INDEX | 1 | 96928 | 86400 |00:00:00.26 | 316 | 313 |
|* 5 | TABLE ACCESS BY INDEX ROWID| DEPT | 11 | 1 | 2 |00:00:00.01 | 22 | 0 |
|* 6 | INDEX UNIQUE SCAN | DEPT_PK | 11 | 1 | 11 |00:00:00.01 | 11 | 0 |
------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter( IS NOT NULL)
4 - access("ORDDATE" LIKE '20110621%')
filter("ORDDATE" LIKE '20110621%')
5 - filter("Y"."TYPE1"=1)
6 - access("Y"."DEPTNO"=:B1)
SQL> SELECT /*+ gather_plan_statistics INDEX( X ORDDATE_INDEX ) */ COUNT(*)
2 FROM "ORDER" X
3 WHERE ORDDATE LIKE '20110621%'
4 AND EXISTS ( SELECT /*+ NL_SJ */ 'O'
5 FROM DEPT Y
6 WHERE Y.DEPTNO = X.SALDEPTNO
7 AND Y.TYPE1 = 1 );
COUNT(*)
----------
15832
SQL> @xplan
---------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
---------------------------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:00.12 | 688 |
| 2 | NESTED LOOPS SEMI | | 1 | 709 | 15832 |00:00:00.17 | 688 |
| 3 | TABLE ACCESS BY INDEX ROWID| ORDER | 1 | 3899 | 86400 |00:00:00.61 | 675 |
|* 4 | INDEX RANGE SCAN | ORDDATE_INDEX | 1 | 3899 | 86400 |00:00:00.26 | 316 |
|* 5 | TABLE ACCESS BY INDEX ROWID| DEPT | 11 | 1 | 2 |00:00:00.01 | 13 |
|* 6 | INDEX UNIQUE SCAN | DEPT_PK | 11 | 1 | 11 |00:00:00.01 | 2 |
---------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("ORDDATE" LIKE '20110621%')
filter("ORDDATE" LIKE '20110621%')
5 - filter("Y"."TYPE1"=1)
6 - access("Y"."DEPTNO"="X"."SALDEPTNO")
SQL> SELECT /*+ gather_plan_statistics INDEX( X ORDDATE_INDEX ) */ *
2 FROM "ORDER" X
3 WHERE ORDDATE LIKE '20110621%'
4 AND ROWNUM <= 50
5 ORDER BY ORDDATE ASC;
SEQNO ORDDATE SALDE
---------- -------------- -----
404490 20110621000000 0008
404491 20110621000001 0007
404492 20110621000002 0002
404493 20110621000003 0004
404494 20110621000004 0005
404495 20110621000005 0001
404496 20110621000006 0002
404497 20110621000007 0008
404498 20110621000008 0007
404499 20110621000009 0011
404500 20110621000010 0009
SEQNO ORDDATE SALDE
---------- -------------- -----
404501 20110621000011 0010
404502 20110621000012 0008
404503 20110621000013 0007
404504 20110621000014 0003
404505 20110621000015 0003
404506 20110621000016 0006
404507 20110621000017 0011
404508 20110621000018 0009
404509 20110621000019 0009
404510 20110621000020 0004
404511 20110621000021 0004
SEQNO ORDDATE SALDE
---------- -------------- -----
404512 20110621000022 0004
404513 20110621000023 0008
404514 20110621000024 0002
404515 20110621000025 0001
404516 20110621000026 0006
404517 20110621000027 0004
404518 20110621000028 0001
404519 20110621000029 0009
404520 20110621000030 0003
404521 20110621000031 0011
404522 20110621000032 0010
SEQNO ORDDATE SALDE
---------- -------------- -----
404523 20110621000033 0002
404524 20110621000034 0001
404525 20110621000035 0011
404526 20110621000036 0007
404527 20110621000037 0008
404528 20110621000038 0009
404529 20110621000039 0011
404530 20110621000040 0004
404531 20110621000041 0003
404532 20110621000042 0009
404533 20110621000043 0010
SEQNO ORDDATE SALDE
---------- -------------- -----
404534 20110621000044 0001
404535 20110621000045 0003
404536 20110621000046 0008
404537 20110621000047 0008
404538 20110621000048 0003
404539 20110621000049 0007
50 개의 행이 선택되었습니다.
SQL> SELECT /*+ gather_plan_statistics INDEX( X ORDDATE_INDEX ) */ DISTINCT SALDEPTNO
2 FROM "ORDER" X
3 WHERE ORDDATE LIKE '20110621%' ;
SALDE
-----
0008
0010
0009
0001
0011
0006
0005
0007
0002
0004
0003
11 개의 행이 선택되었습니다.
SQL> select ksppinm name,
2 ksppstvl value,
3 decode(bitand(ksppiflg/256,1),1,'true','false') ses_modifiable,
4 decode(bitand(ksppiflg/65536,3),1,'immediate',2,'deferred',3,'immediate','false') sys_modifiable,
5 ksppdesc description
6 from sys.x$ksppi i, sys.x$ksppcv v
7 where i.indx = v.indx
8 and i.ksppinm like '%_query_execution_cache_max_size%';
NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SES_M SYS_MODIF
----- ---------
DESCRIPTION
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
_query_execution_cache_max_size
65536 <--
true deferred
max size of query execution cache
SQL> SELECT /*+ gather_plan_statistics INDEX( X ORDDATE_INDEX_01 ) */ COUNT(*)
2 FROM "ORDER" X
3 WHERE ORDDATE LIKE '20110621%'
4 AND EXISTS ( SELECT /*+ NO_UNNEST NO_PUSH_SUBQ */ 'O'
5 FROM DEPT Y
6 WHERE Y.DEPTNO = X.SALDEPTNO
7 AND Y.TYPE1 = 1 );
COUNT(*)
----------
15832
SQL> @XPLAN
---------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads |
---------------------------------------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:00.10 | 399 | 3 |
|* 2 | FILTER | | 1 | | 15832 |00:00:00.16 | 399 | 3 |
|* 3 | INDEX RANGE SCAN | ORDDATE_INDEX_01 | 1 | 3899 | 86400 |00:00:00.26 | 377 | 3 |
|* 4 | TABLE ACCESS BY INDEX ROWID| DEPT | 11 | 1 | 2 |00:00:00.01 | 22 | 0 |
|* 5 | INDEX UNIQUE SCAN | DEPT_PK | 11 | 1 | 11 |00:00:00.01 | 11 | 0 |
---------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter( IS NOT NULL)
3 - access("ORDDATE" LIKE '20110621%')
filter("ORDDATE" LIKE '20110621%')
4 - filter("Y"."TYPE1"=1)
5 - access("Y"."DEPTNO"=:B1)
SQL> SELECT /*+ gather_plan_statistics INDEX( X ORDDATE_INDEX_01 ) */ COUNT(*)
2 FROM "ORDER" X
3 WHERE ORDDATE LIKE '20110621%'
4 AND EXISTS ( SELECT /*+ NL_SJ */ 'O'
5 FROM DEPT Y
6 WHERE Y.DEPTNO = X.SALDEPTNO
7 AND Y.TYPE1 = 1 );
COUNT(*)
----------
15832
SQL> @XPLAN
------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
------------------------------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:00.08 | 390 |
| 2 | NESTED LOOPS SEMI | | 1 | 709 | 15832 |00:00:00.13 | 390 |
|* 3 | INDEX RANGE SCAN | ORDDATE_INDEX_01 | 1 | 3899 | 86400 |00:00:00.26 | 377 |
|* 4 | TABLE ACCESS BY INDEX ROWID| DEPT | 11 | 1 | 2 |00:00:00.01 | 13 |
|* 5 | INDEX UNIQUE SCAN | DEPT_PK | 11 | 1 | 11 |00:00:00.01 | 2 |
------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("ORDDATE" LIKE '20110621%')
filter("ORDDATE" LIKE '20110621%')
4 - filter("Y"."TYPE1"=1)
5 - access("Y"."DEPTNO"="X"."SALDEPTNO")
- 강좌 URL : http://www.gurubee.net/lecture/4454
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.