그림 4-7
{section}
{column:width=50}
SQL> ALTER SYSTEM FLUSH SHARED_POOL;
시스템이 변경되었습니다.
{column}
{column:width=50}{column}
{section}
{section}
{column:width=50}
SQL> SELECT /* cursor_test */
2 empno, ename, job, sal, deptno
3 FROM emp
4 WHERE empno = 7369
5 ;
EMPNO ENAME JOB SAL DEPTNO
---------- -------------------- ------------------ ---------- ----------
7369 SMITH CLERK 800 20
SQL> SELECT sql_id
2 , parse_calls
3 , loads
4 , executions
5 , invalidations
6 , DECODE(SIGN(invalidations), 1, (loads - invalidations), 0) reloads
7 FROM v$sql
8 WHERE sql_text LIKE '%cursor_test%'
9 AND sql_text NOT LIKE '%V$SQL%'
10 ;
SQL_ID PARSE_CALLS LOADS EXECUTIONS INVALIDATIONS RELOADS
-------------------------- ----------- ---------- ---------- ------------- ----------
9v6cbm9canuj8 1 1 1 0 0
SQL> SELECT /* cursor_test */
2 empno, ename, job, sal, deptno
3 FROM emp
4 WHERE empno = 7369
5 ;
EMPNO ENAME JOB SAL DEPTNO
---------- -------------------- ------------------ ---------- ----------
7369 SMITH CLERK 800 20
SQL> SELECT /* cursor_test */
2 empno, ename, job, sal, deptno
3 FROM emp
4 WHERE empno = 7369
5 ;
EMPNO ENAME JOB SAL DEPTNO
---------- -------------------- ------------------ ---------- ----------
7369 SMITH CLERK 800 20
SQL> SELECT sql_id
2 , parse_calls
3 , loads
4 , executions
5 , invalidations
6 , DECODE(SIGN(invalidations), 1, (loads - invalidations), 0) reloads
7 FROM v$sql
8 WHERE sql_text LIKE '%cursor_test%'
9 AND sql_text NOT LIKE '%V$SQL%'
10 ;
SQL_ID PARSE_CALLS LOADS EXECUTIONS INVALIDATIONS RELOADS
-------------------------- ----------- ---------- ---------- ------------- ----------
9v6cbm9canuj8 3 1 3 0 0
{column}
{column:width=50}{column}
{section}
SQL> disconn
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production에서 분리되었습니다.
SQL> conn scott/tiger
연결되었습니다.
SQL> SELECT /* cursor_test */
2 empno, ename, job, sal, deptno
3 FROM emp
4 WHERE empno = 7369
5 ;
EMPNO ENAME JOB SAL DEPTNO
---------- -------------------- ------------------ ---------- ----------
7369 SMITH CLERK 800 20
SQL> SELECT sql_id
2 , parse_calls
3 , loads
4 , executions
5 , invalidations
6 , DECODE(SIGN(invalidations), 1, (loads - invalidations), 0) reloads
7 FROM v$sql
8 WHERE sql_text LIKE '%cursor_test%'
9 AND sql_text NOT LIKE '%V$SQL%'
10 ;
SQL_ID PARSE_CALLS LOADS EXECUTIONS INVALIDATIONS RELOADS
-------------------------- ----------- ---------- ---------- ------------- ----------
9v6cbm9canuj8 4 1 4 0 0
{column}
{column:width=50}{column}
{section}
SQL> BEGIN
2 DBMS_STATS.GATHER_TABLE_STATS
3 ( ownname => USER
4 , tabname => 'EMP'
5 , no_invalidate => FALSE
6 );
7 END;
8 /
PL/SQL 처리가 정상적으로 완료되었습니다.
SQL> SELECT sql_id
2 , parse_calls
3 , loads
4 , executions
5 , invalidations
6 , DECODE(SIGN(invalidations), 1, (loads - invalidations), 0) reloads
7 FROM v$sql
8 WHERE sql_text LIKE '%cursor_test%'
9 AND sql_text NOT LIKE '%V$SQL%'
10 ;
선택된 레코드가 없습니다.
SQL> SELECT /* cursor_test */
2 empno, ename, job, sal, deptno
3 FROM emp
4 WHERE empno = 7369
5 ;
EMPNO ENAME JOB SAL DEPTNO
---------- -------------------- ------------------ ---------- ----------
7369 SMITH CLERK 800 20
SQL> SELECT sql_id
2 , parse_calls
3 , loads
4 , executions
5 , invalidations
6 , DECODE(SIGN(invalidations), 1, (loads - invalidations), 0) reloads
7 FROM v$sql
8 WHERE sql_text LIKE '%cursor_test%'
9 AND sql_text NOT LIKE '%V$SQL%'
10 ;
SQL_ID PARSE_CALLS LOADS EXECUTIONS INVALIDATIONS RELOADS
-------------------------- ----------- ---------- ---------- ------------- ----------
9v6cbm9canuj8 1 2 1 1 1
{column}
{column:width=50}{column}
{section}
SQL> SELECT * FROM emp;
SQL> SELECT sql_id
2 , version_count
3 , optimizer_mode
4 , address
5 , hash_value
6 FROM v$sqlarea
7 WHERE sql_text LIKE '%SELECT * FROM emp%'
8 AND sql_text NOT LIKE '%V$SQL%'
9 ;
SQL_ID VERSION_COUNT OPTIMIZER_MODE ADDRESS HASH_VALUE
------------- ------------- -------------- -------- ----------
4u5074pdutxzs 2 ALL_ROWS 2FF85AF4 1538062328
SQL> SELECT sql_id
2 , child_number
3 , optimizer_mode
4 , address
5 , hash_value
6 , parsing_user_id
7 FROM v$sql
8 WHERE sql_text LIKE '%SELECT * FROM emp%'
9 AND sql_text NOT LIKE '%V$SQL%'
10 ;
SQL_ID CHILD_NUMBER OPTIMIZER_MODE ADDRESS HASH_VALUE PARSING_USER_ID
------------- ------------ -------------- -------- ---------- ---------------
4u5074pdutxzs 0 ALL_ROWS 2FF85AF4 1538062328 33
4u5074pdutxzs 1 ALL_ROWS 2FF85AF4 1538062328 36
SQL> SELECT * FROM dual;
SQL> SELECT sql_id
2 , version_count
3 , optimizer_mode
4 , address
5 , hash_value
6 FROM v$sqlarea
7 WHERE sql_text LIKE '%SELECT * FROM dual%'
8 AND sql_text NOT LIKE '%V$SQL%'
9 ;
SQL_ID VERSION_COUNT OPTIMIZER_MODE ADDRESS HASH_VALUE
------------- ------------- -------------- -------- ----------
3vjxpmhhzngu4 2 ALL_ROWS 2FF5EDA4 570048324
SQL> SELECT sql_id
2 , child_number
3 , optimizer_mode
4 , address
5 , hash_value
6 , parsing_user_id
7 FROM v$sql
8 WHERE sql_text LIKE '%SELECT * FROM dual%'
9 AND sql_text NOT LIKE '%V$SQL%'
10 ;
SQL_ID CHILD_NUMBER OPTIMIZER_MODE ADDRESS HASH_VALUE PARSING_USER_ID
------------- ------------ -------------- -------- ---------- ---------------
3vjxpmhhzngu4 1 ALL_ROWS 2FF5EDA4 570048324 36
{column}
{column:width=50}{column}
{section}
SQL> ALTER SESSION SET OPTIMIZER_MODE='FIRST_ROWS';
SQL> SELECT * FROM emp;
SQL> SELECT sql_id
2 , child_number
3 , child_address
4 , optimizer_mode_mismatch
5 , optimizer_mismatch
6 , auth_check_mismatch
7 , translation_mismatch
8 FROM v$sql_shared_cursor
9 WHERE sql_id = '4u5074pdutxzs'
10 ;
SQL_ID CHILD_NUMBER CHILD_AD OP OP AU TR
-------------------------- ------------ -------- -- -- -- --
4u5074pdutxzs 0 335BFBEC N N N N
4u5074pdutxzs 1 2FFC2AB8 N N Y Y
4u5074pdutxzs 2 2FFCE6B4 Y N N N
{column}
{column:width=50}{column}
{section}
SQL> CREATE TABLE t(c VARCHAR2(4000));
SQL> ALTER SYSTEM FLUSH SHARED_POOL;
SQL> DECLARE
2 l_cnt NUMBER;
3 l_child_cnt NUMBER;
4 l_prev_child_cnt NUMBER;
5 l_bind_value VARCHAR2(4000);
6 l_sql_id VARCHAR2(13);
7 BEGIN
8 l_prev_child_cnt := 0;
9
10 FOR c IN 1..4000
11 LOOP
12 l_bind_value := LPAD('A', c, '0');
13
14 SELECT COUNT(*)
15 INTO l_cnt
16 FROM t
17 WHERE c = l_bind_value
18 ;
19
20 -- 맨 처음에만 sql_id를 찾아 출력
21 IF c = 1 THEN
22 SELECT prev_sql_id
23 INTO l_sql_id
24 FROM v$session
25 WHERE sid = USERENV('SID')
26 AND username IS NOT NULL
27 AND prev_hash_value <> 0
28 ;
29
30 DBMS_OUTPUT.PUT_LINE('SQL_ID --> ' || l_sql_id);
31 END IF;
32
33 SELECT COUNT(*)
34 INTO l_child_cnt
35 FROM v$sql
36 WHERE sql_id = l_sql_id
37 ;
38
39 IF l_prev_child_cnt < l_child_cnt THEN -- 새 Child 커서가 생길 때마다
40 DBMS_OUTPUT.PUT_LINE(c);
41 l_prev_child_cnt := l_child_cnt;
42 END IF;
43 END LOOP;
44 END;
45 /
SQL_ID --> f6qwn8zavty07
1
PL/SQL 처리가 정상적으로 완료되었습니다.
SQL> SELECT * FROM v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
{column}
{column:width=50}{column}
{section}