2009년 2월 17일 화요일

V$SQL / V$SQL_WORKAREA

V$SQL

V$SQL lists statistics on shared SQL areas without the GROUP BY clause and contains one row for each child of the original SQL text entered. Statistics displayed in V$SQL are normally updated at the end of query execution. However, for long running queries, they are updated every 5 seconds. This makes it easy to see the impact of long running SQL statements while they are still in progress.

ColumnDatatypeDescription
SQL_TEXTVARCHAR2(1000)First thousand characters of the SQL text for the current cursor
SQL_FULLTEXTCLOBFull text for the SQL statement exposed as a CLOB column. The full text of a SQL statement can be retrieved using this column instead of joining with the V$SQLTEXT dynamic performance view.
SQL_IDVARCHAR2(13)SQL identifier of the parent cursor in the library cache
SHARABLE_MEMNUMBERAmount of shared memory used by the child cursor (in bytes)
PERSISTENT_MEMNUMBERFixed amount of memory used for the lifetime of the child cursor (in bytes)
RUNTIME_MEMNUMBERFixed amount of memory required during the execution of the child cursor
SORTSNUMBERNumber of sorts that were done for the child cursor
LOADED_VERSIONSNUMBERIndicates whether the context heap is loaded (1) or not (0)
OPEN_VERSIONSNUMBERIndicates whether the child cursor is locked (1) or not (0)
USERS_OPENINGNUMBERNumber of users executing the statement
FETCHESNUMBERNumber of fetches associated with the SQL statement
EXECUTIONSNUMBERNumber of executions that took place on this object since it was brought into the library cache
PX_SERVERS_EXECUTIONSNUMBERTotal number of executions performed by parallel execution servers (0 when the statement has never been executed in parallel)
END_OF_FETCH_COUNTNUMBERNumber of times this cursor was fully executed since the cursor was brought into the library cache. The value of this statistic is not incremented when the cursor is partially executed, either because it failed during the execution or because only the first few rows produced by this cursor are fetched before the cursor is closed or re-executed. By definition, the value of the END_OF_FETCH_COUNTcolumn should be less or equal to the value of the EXECUTIONS column.
USERS_EXECUTINGNUMBERNumber of users executing the statement
LOADSNUMBERNumber of times the object was either loaded or reloaded
FIRST_LOAD_TIMEVARCHAR2(19)Timestamp of the parent creation time
INVALIDATIONSNUMBERNumber of times this child cursor has been invalidated
PARSE_CALLSNUMBERNumber of parse calls for this child cursor
DISK_READSNUMBERNumber of disk reads for this child cursor
DIRECT_WRITESNUMBERNumber of direct writes for this child cursor
BUFFER_GETSNUMBERNumber of buffer gets for this child cursor
APPLICATION_WAIT_TIMENUMBERApplication wait time (in microseconds)
CONCURRENCY_WAIT_TIMENUMBERConcurrency wait time (in microseconds)
CLUSTER_WAIT_TIMENUMBERCluster wait time (in microseconds)
USER_IO_WAIT_TIMENUMBERUser I/O Wait Time (in microseconds)
PLSQL_EXEC_TIMENUMBERPL/SQL execution time (in microseconds)
JAVA_EXEC_TIMENUMBERJava execution time (in microseconds)
ROWS_PROCESSEDNUMBERTotal number of rows the parsed SQL statement returns
COMMAND_TYPENUMBEROracle command type definition
OPTIMIZER_MODEVARCHAR2(10)Mode under which the SQL statement was executed
OPTIMIZER_COSTNUMBERCost of this query given by the optimizer
OPTIMIZER_ENVRAW(2000)Optimizer environment
OPTIMIZER_ENV_HASH_VALUENUMBERHash value for the optimizer environment
PARSING_USER_IDNUMBERUser ID of the user who originally built this child cursor
PARSING_SCHEMA_IDNUMBERSchema ID that was used to originally build this child cursor
PARSING_SCHEMA_NAMEVARCHAR2(30)Schema name that was used to originally build this child cursor
KEPT_VERSIONSNUMBERIndicates whether this child cursor has been marked to be kept pinned in the cache using theDBMS_SHARED_POOL package
ADDRESSRAW(4 | 8)Address of the handle to the parent for this cursor
TYPE_CHK_HEAPRAW(4)Descriptor of the type check heap for this child cursor
HASH_VALUENUMBERHash value of the parent statement in the library cache
OLD_HASH_VALUENUMBEROld SQL hash value
PLAN_HASH_VALUENUMBERNumeric representation of the SQL plan for this cursor. Comparing one PLAN_HASH_VALUE to another easily identifies whether or not two plans are the same (rather than comparing the two plans line by line).
CHILD_NUMBERNUMBERNumber of this child cursor
SERVICEVARCHAR2(64)Service name
SERVICE_HASHNUMBERHash value for the name listed in the SERVICEcolumn
MODULEVARCHAR2(64)Contains the name of the module that was executing at the time that the SQL statement was first parsed, which is set by calling DBMS_APPLICATION_INFO.SET_MODULE
MODULE_HASHNUMBERHash value of the module listed in the MODULE column
ACTIONVARCHAR2(64)Contains the name of the action that was executing at the time that the SQL statement was first parsed, which is set by calling DBMS_APPLICATION_INFO.SET_ACTION
ACTION_HASHNUMBERHash value of the action listed in the ACTION column
SERIALIZABLE_ABORTSNUMBERNumber of times the transaction failed to serialize, producing ORA-08177 errors, per cursor
OUTLINE_CATEGORYVARCHAR2(64)If an outline was applied during construction of the cursor, then this column displays the category of that outline. Otherwise the column is left blank.
CPU_TIMENUMBERCPU time (in microseconds) used by this cursor for parsing, executing, and fetching
ELAPSED_TIMENUMBERElapsed time (in microseconds) used by this cursor for parsing, executing, and fetching
OUTLINE_SIDNUMBEROutline session identifier
CHILD_ADDRESSRAW(4 | 8)Address of the child cursor
SQLTYPENUMBERDenotes the version of the SQL language used for this statement
REMOTEVARCHAR2(1)Indicates whether the cursor is remote mapped (Y) or not (N)
OBJECT_STATUSVARCHAR2(19)Status of the cursor:
  • VALID - Valid, authorized without errors

  • VALID_AUTH_ERROR - Valid, authorized with authorization errors

  • VALID_COMPILE_ERROR - Valid, authorized with compilation errors

  • VALID_UNAUTH - Valid, unauthorized

  • INVALID_UNAUTH - Invalid, unauthorized

  • INVALID - Invalid, unauthorized but keep the timestamp

LITERAL_HASH_VALUENUMBERHash value of the literals which are replaced with system-generated bind variables and are to be matched, when CURSOR_SHARING is used. This is not the hash value for the SQL statement. IfCURSOR_SHARING is not used, then the value is 0.
LAST_LOAD_TIMEVARCHAR2(19)Time at which the query plan was loaded into the library cache
IS_OBSOLETEVARCHAR2(1)Indicates whether the cursor has become obsolete (Y) or not (N). This can happen if the number of child cursors is too large.
IS_BIND_SENSITIVEVARCHAR2(1)Indicates whether the cursor is bind sensitive (Y) or not (N). A query is considered bind-sensitive if the optimizer peeked at one of its bind variable values when computing predicate selectivities and where a change in a bind variable value may cause the optimizer to generate a different plan.
IS_BIND_AWAREVARCHAR2(1)Indicates whether the cursor is bind aware (Y) or not (N). A query is considered bind-aware if it has been marked to use extended cursor sharing. The query would already have been marked as bind-sensitive.
IS_SHAREABLEVARCHAR2(1)Indicates whether the cursor can be shared (Y) or not (N)
CHILD_LATCHNUMBERChild latch number that is protecting the cursor. This column is obsolete and maintained for backward compatibility.
SQL_PROFILEVARCHAR2(64)SQL profile used for this statement, if any
SQL_PATCHVARCHAR2(30)SQL patch used for this statement, if any
SQL_PLAN_BASELINEVARCHAR2(30)SQL plan baseline used for this statement, if any
PROGRAM_IDNUMBERProgram identifier
PROGRAM_LINE#NUMBERProgram line number
EXACT_MATCHING_SIGNATURENUMBERSignature calculated on the normalized SQL text. The normalization includes the removal of white space and the uppercasing of all non-literal strings.
FORCE_MATCHING_SIGNATURENUMBERSignature used when the CURSOR_SHARING parameter is set to FORCE
LAST_ACTIVE_TIMEDATETIme at which the query plan was last active
BIND_DATARAW(2000)Bind data
TYPECHECK_MEMNUMBER???

V$SQL_WORKAREA

V$SQL_WORKAREA displays information about work areas used by SQL cursors. Each SQL statement stored in the shared pool has one or more child cursors that are listed in the V$SQL view. V$SQL_WORKAREA lists all work areas needed by these child cursors; V$SQL_WORKAREA can be joined with V$SQLAREA on (ADDRESSHASH_VALUE) and with V$SQL on (ADDRESSHASH_VALUECHILD_NUMBER).

You can use this view to find out answers to the following questions:

  • What are the top 10 work areas that require the most cache area?
  • For work areas allocated in AUTO mode, what percentage of work areas are running using maximum memory?
ColumnDatatypeDescription
ADDRESSRAW(4 | 8)Address of the parent cursor handle
HASH_VALUENUMBERHash value of the parent statement in the library cache. Two columns PARENT_HANDLE andHASH_VALUE can be used to join with V$SQLAREA to locate the parent cursor.
SQL_IDVARCHAR2(13)SQL identifier of the parent statement in the library cache
CHILD_NUMBERNUMBERNumber of the child cursor that uses this work area. The columns PARENT_HANDLEHASH_VALUE, andCHILD_NUMBER can be used to join with V$SQL to locate the child cursor using this area.
WORKAREA_ADDRESSRAW(4 | 8)Address of the work area handle. This is the primary key for the view.
OPERATION_TYPEVARCHAR2(20)Type of operation using the work area (SORTHASH JOINGROUP BYBUFFERINGBITMAP MERGE, orBITMAP CREATE)
OPERATION_IDNUMBERA unique number used to identify the operation in the execution plan. This identifier can be joined to V$SQL_PLAN to locate the operation that uses this work area.
POLICYVARCHAR2(10)Sizing policy for this work area (MANUAL or AUTO)
ESTIMATED_OPTIMAL_SIZENUMBEREstimated size (in bytes) required by this work area to execute the operation completely in memory (optimal execution). Derived from either optimizer statistics or previous executions.
ESTIMATED_ONEPASS_SIZENUMBEREstimated size (in bytes) required by this work area to execute the operation in a single pass. Derived from either optimizer statistics or previous executions.
LAST_MEMORY_USEDNUMBERMemory (in bytes) used by this work area during the last execution of the cursor
LAST_EXECUTIONVARCHAR2(10)Indicates whether this work area runs using OPTIMAL, ONE PASS, or ONE PASS memory requirement (or MULTI-PASS), during the last execution of the cursor
LAST_DEGREENUMBERDegree of parallelism used during the last execution of this operation
TOTAL_EXECUTIONSNUMBERNumber of times this work area was active
OPTIMAL_EXECUTIONSNUMBERNumber of times this work area ran in optimal mode
ONEPASS_EXECUTIONSNUMBERNumber of times this work area ran in one-pass mode
MULTIPASSES_EXECUTIONSNUMBERNumber of times this work area ran below the one-pass memory requirement
ACTIVE_TIMENUMBERAverage time this work area is active (in hundredths of a second)
MAX_TEMPSEG_SIZENUMBERMaximum temporary segment size (in bytes) created by an instantiation of this work area. This column is NULL if this work area has never spilled to disk.
LAST_TEMPSEG_SIZENUMBERTemporary segment size (in bytes) created in the last instantiation of this work area. This column is NULL if the last instantiation of this work area did not spill to disk.


7.5.1.2.6 V$SQL_WORKAREA

Oracle maintains cumulative work area statistics for each loaded cursor whose execution plan uses one or more work areas. Every time a work area is deallocated, theV$SQL_WORKAREA table is updated with execution statistics for that work area.

V$SQL_WORKAREA can be joined with V$SQL to relate a work area to a cursor. It can even be joined to V$SQL_PLAN to precisely determine which operator in the plan uses a work area.

Example 7-7 shows three typical queries on the V$SQL_WORKAREA dynamic view:

Example 7-7 Querying V$SQL_WORKAREA

The following query finds the top 10 work areas requiring most cache memory:

SELECT *
FROM   ( SELECT workarea_address, operation_type, policy, estimated_optimal_size
         FROM V$SQL_WORKAREA
        ORDER BY estimated_optimal_size )
 WHERE ROWNUM <= 10;

The following query finds the cursors with one or more work areas that have been executed in one or even multiple passes:

col sql_text format A80 wrap 
SELECT sql_text, sum(ONEPASS_EXECUTIONS) onepass_cnt,
       sum(MULTIPASSES_EXECUTIONS) mpass_cnt 
FROM V$SQL s, V$SQL_WORKAREA wa 
WHERE s.address = wa.address 
GROUP BY sql_text 
HAVING sum(ONEPASS_EXECUTIONS+MULTIPASSES_EXECUTIONS)>0;

Using the hash value and address of a particular cursor, the following query displays the cursor execution plan, including information about the associated work areas.

col "O/1/M" format a10
col name format a20
SELECT operation, options, object_name name, trunc(bytes/1024/1024) "input(MB)",
       trunc(last_memory_used/1024) last_mem,
       trunc(estimated_optimal_size/1024) optimal_mem, 
       trunc(estimated_onepass_size/1024) onepass_mem, 
       decode(optimal_executions, null, null, 
              optimal_executions||'/'||onepass_executions||'/'||
              multipasses_executions) "O/1/M"
  FROM V$SQL_PLAN p, V$SQL_WORKAREA w 
 WHERE p.address=w.address(+) 
   AND p.hash_value=w.hash_value(+) 
   AND p.id=w.operation_id(+) 
   AND p.address='88BB460C'
   AND p.hash_value=3738161960; 

OPERATION    OPTIONS  NAME     input(MB) LAST_MEM OPTIMAL_ME ONEPASS_ME O/1/M 
------------ -------- -------- --------- -------- ---------- ---------- ------
SELECT STATE                                                                  
HASH         GROUP BY               4582        8         16         16 16/0/0
HASH JOIN    SEMI                   4582     5976       5194       2187 16/0/0
TABLE ACCESS FULL     ORDERS          51                                      
TABLE ACCESS FUL      LINEITEM      1000                                      

You can get the address and hash value from the V$SQL view by specifying a pattern in the query. For example:

SELECT address, hash_value 
  FROM V$SQL 
WHERE sql_text LIKE '%my_pattern%';

댓글 없음:

댓글 쓰기