-- 0. Oracle Version
SELECT *
FROM V$VERSION
;
BANNER
------------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
NLSRTL Version 10.2.0.3.0 - Production
;
-- 1. 샘플 데이터 생성
DROP TABLE XSOFT_T;
CREATE TABLE XSOFT_T AS
SELECT DECODE(LENGTH(LEVEL), 1, 1,
2, 2,
3, 3) FLAG
FROM DUAL
CONNECT BY LEVEL <= 999
;
-- 2. 통계정보 생성
-- 히스토그램 없이 통계정보 생성
BEGIN
DBMS_STATS.GATHER_TABLE_STATS(USER,
'XSOFT_T',
METHOD_OPT => 'FOR ALL COLUMNS SIZE SKEWONLY');
END;
/
-- 3. bind peeking 활성화
-- 1) 바인드 변수 선언
VAR B1 NUMBER;
EXEC :B1 := 3;
-- 2) STATISTICS_LEVEL 활성화
ALTER SESSION SET STATISTICS_LEVEL = ALL ;
-- 3) 분포도가 낮은 값 3으로 먼저 Peeking
SELECT /*+ OPT_PARAM('_OPTIM_PEEK_USER_BINDS' 'TRUE') */
*
FROM XSOFT_T
WHERE FLAG = :B1
;
-- 4) V$SQL에서 SQL_ID 확인
SELECT SUBSTR(SQL_TEXT, 1, 30),
SQL_ID,
CHILD_NUMBER
FROM V$SQL
WHERE UPPER(SQL_TEXT) LIKE '%XSOFT_T%'
ORDER BY FIRST_LOAD_TIME DESC
;
SUBSTR(SQL_TEXT,1,30) SQL_ID CHILD_NUMBER
------------------------------ ------------- ------------
SELECT SUBSTR(SQL_TEXT, 1, 30) 56bqkx2bgmvfc 0
SELECT SUBSTR(SQL_TEXT, 1, 30) 46dmyzrsppa3a 0
SELECT SUBSTR(SQL_TEXT, 1, 30) 46dmyzrsppa3a 1
SELECT SUBSTR(SQL_TEXT, 1, 20) b3qmfm55u7trs 0
SELECT SUBSTR(SQL_TEXT, 1, 20) atu0kk85um7v1 0
SELECT SQL_TEXT, SQL_FU 5hx6usvks1r75 0
SELECT SQL_TEXT, SQL_FU 5hx6usvks1r75 1
SELECT /*+ OPT_PARAM('_OPTIM_P 35x0sx3dxtt5r 0
EXPLAIN PLAN FOR SELECT /*+ OP bfa0u88cz3n78 0
select /*+ no_parallel(t) no_p 8zw3fzkk0gvwc 0
select substrb(dump(val,16,0,3 4agz0p1vt39fw 0
select /*+ no_parallel(t) no_ 2gckc3xgdabky 0
BEGIN DBMS_STATS.GATHER_TA 4qt4pb05pwh74 0
SELECT topology FROM SDO_T 997gattrj5nag 0
*/
-- 5) Runtime Plan 확인
SELECT * FROM TABLE (DBMS_XPLAN.DISPLAY_CURSOR('35x0sx3dxtt5r',NULL,'ADVANCED ALLSTATS COST LAST'));
-----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
-----------------------------------------------------------------------------------------------------------------------
|* 1 | TABLE ACCESS FULL| XSOFT_T | 1 | 333 | 999 | 3 (0)| 00:00:01 | 900 |00:00:00.01 | 64 |
-----------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / XSOFT_T@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('10.2.0.3')
OPT_PARAM('_b_tree_bitmap_plans' 'false')
OPT_PARAM('_fast_full_scan_enabled' 'false')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$1" "XSOFT_T"@"SEL$1")
END_OUTLINE_DATA
*/
;
-- 6) 분포도가 높은 값 1 사용
VAR B1 NUMBER;
EXEC :B1 := 1;
SELECT /*+ OPT_PARAM('_OPTIM_PEEK_USER_BINDS' 'TRUE') */
*
FROM XSOFT_T
WHERE FLAG = :B1
;
-- 7) V$SQL에서 SQL_ID 확인
SELECT SUBSTR(SQL_TEXT, 1, 30),
SQL_ID,
CHILD_NUMBER
FROM V$SQL
WHERE UPPER(SQL_TEXT) LIKE '%XSOFT_T%'
ORDER BY FIRST_LOAD_TIME DESC
;
SUBSTR(SQL_TEXT,1,30) SQL_ID CHILD_NUMBER
------------------------------ ------------- ------------
SELECT SUBSTR(SQL_TEXT, 1, 30) 56bqkx2bgmvfc 0
SELECT SUBSTR(SQL_TEXT, 1, 30) 46dmyzrsppa3a 0
SELECT SUBSTR(SQL_TEXT, 1, 30) 46dmyzrsppa3a 1
SELECT SUBSTR(SQL_TEXT, 1, 20) b3qmfm55u7trs 0
SELECT SUBSTR(SQL_TEXT, 1, 20) atu0kk85um7v1 0
SELECT SQL_TEXT, SQL_FU 5hx6usvks1r75 0
SELECT SQL_TEXT, SQL_FU 5hx6usvks1r75 1
SELECT /*+ OPT_PARAM('_OPTIM_P 35x0sx3dxtt5r 0
EXPLAIN PLAN FOR SELECT /*+ OP bfa0u88cz3n78 0
select /*+ no_parallel(t) no_p 8zw3fzkk0gvwc 0
select substrb(dump(val,16,0,3 4agz0p1vt39fw 0
select /*+ no_parallel(t) no_ 2gckc3xgdabky 0
BEGIN DBMS_STATS.GATHER_TA 4qt4pb05pwh74 0
SELECT topology FROM SDO_T 997gattrj5nag 0
*/
-- 8) Runtime Plan 확인
SELECT * FROM TABLE (DBMS_XPLAN.DISPLAY_CURSOR('35x0sx3dxtt5r',NULL,'ADVANCED ALLSTATS COST LAST'));
-----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
-----------------------------------------------------------------------------------------------------------------------
|* 1 | TABLE ACCESS FULL| XSOFT_T | 1 | 333 | 999 | 3 (0)| 00:00:01 | 9 |00:00:00.01 | 5 |
-----------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / XSOFT_T@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('10.2.0.3')
OPT_PARAM('_b_tree_bitmap_plans' 'false')
OPT_PARAM('_fast_full_scan_enabled' 'false')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$1" "XSOFT_T"@"SEL$1")
END_OUTLINE_DATA
*/
-- 9) STATISTICS_LEVEL 비활성화
ALTER SESSION SET STATISTICS_LEVEL = TYPICAL ;
Property | Descriotion |
---|---|
Parameter type | String |
Syntax | CURSOR_SHARING = ( SIMILAR , EXACT , FORCE ) |
Default value | EXACT |
Modifiable | ALTER SESSION, ALTER SYSTEM |
Basic | No |
SELECT T1.V1,
T2.V1
FROM T1,
T2
WHERE T1.N2 = 99
AND T1.N1 = T2.N1
;
- 강좌 URL : http://www.gurubee.net/lecture/4414
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.