V$SQLTEXT
This view contains the complete SQL text for the SQL statements in the shared pool.
Useful Columns for V$SQLTEXT
HASH_VALUE
: Hash value for the SQL statementADDRESS
: Address of the SQL statement cursor in SGASQL_TEXT
: Statement text in 64 character chunksPIECE
: Ordering information for the SQL statement pieces
Join Columns for V$SQLTEXT
Table 24-27 lists the join columns forV$SQLTEXT
.
Table 24-27 Join Columns for V$SQLTEXT
Column | View | Joined Column(s) |
---|---|---|
|
|
|
|
|
|
Example 24-30 Finding the SQL Statement for a Hash Value
SELECT sql_text FROM V$SQLTEXT WHERE hash_value = 228801498 ORDER BY piece; SQL_TEXT ---------------------------------------------------------------- select dbsu.primary_flag, i.site_use_code, i.rowid from ra_customers dbc, ra_addresses dbad, ra_site_uses dbsu, ra_customers_ interface i where (((((((i.orig_system_customer_ref=dbc.orig_system_reference and dbad.address_id=dbsu.address_id) and i.site_use_code=dbsu.site_use_code) and dbsu.status='A') and dbad.customer_id=dbc.customer_id) and i.request_id=:b0) and nvl(i.validated_flag,'N')<>'Y') and ((i.primary_site_use_flag='Y' and dbsu.primary_flag='Y') or dbsu.site_use_code in ('STMTS','DUN','LEGAL')))
V$SQLAREA
This view keeps track of all the shared cursors present in the shared pool. It has one row for every SQL statement present in the shared pool. It is an invaluable view for finding the resource usage of a SQL statement.
Information columns in V$SQLAREA
These two columns are used to identify the SQL statement. Sometimes, two different statements could hash to the same value. In such cases, it is necessary to use the address along with the hash_value.
PARSING_USER_ID
: User who parsed the first cursor for the statementVERSION_COUNT
: Number of cursors for the statementKEPT_VERSIONS
: Cursors of the statement pinned usingDBMS_SHARED_POOL
.KEEP
()SHARABLE_MEMORY
: Total shared memory used by the cursorPERSISTENT_MEMORY
: Total persistent memory used by the cursorRUNTIME_MEMORY
: Total runtime memory used by the cursorSQL_TEXT
: Up to first 1000 characters of SQL statementMODULE
,ACTION
: Information about the session parsing the first cursor if set usingDBMS_APPLICATION_INFO
Other Useful Columns in V$SQLAREA
These columns get incremented with each execution of the statement.
BUFFER_GETS
: Number of logical reads for this statementDISK_READS
: Number of physical reads for this statementSORTS
: Number of sorts for this statementCPU_TIME
: CPU time used for parsing and executing this statementELAPSED_TIME
: Elapsed time for parsing and executing this statementPARSE_CALLS
: Number of parse calls (hard and soft) for this statementEXECUTIONS
: Number of times this statement was executedINVALIDATIONS
: Number of times the cursors for this statement have been invalidatedLOADS
: Number of loads (and reloads) for this statementROWS_PROCESSED
: Total number of rows this statement returns
Join Columns in V$SQLAREA
Table 24-26 lists the join columns for V$SQLAREA
.
Table 24-26 Join Columns for V$SQLAREA
Column | View | Joined Column(s) |
---|---|---|
|
|
|
|
|
|
|
|
|
Example 24-28 Finding Resource-intensive SQL
There are several costs you can use:
- Total logical I/O (LIO), LIO for each execution
- Total physical I/O (PIO), PIO for each execution
- PIO/LIO (poor cache hit ratio)
- parse_calls, parse_calls for each executions
SELECT hash_value, executions, buffer_gets, disk_reads, parse_calls FROM V$SQLAREA WHERE buffer_gets > 10000000 OR disk_reads > 1000000 ORDER BY buffer_gets + 100*disk_reads DESC; HASH_VALUE EXECUTIONS BUFFER_GETS DISK_READS PARSE_CALLS ---------- ---------- ----------- ---------- ----------- 2676594883 126 7583140 6199113 126 4074144966 126 7264362 6195433 49 228801498 136 236116544 2371187 136 360282550 5467 21102603 4476317 2355 1559420740 201 8197831 4537591 39 3213702248 28039654 364516977 44 131 1547710012 865 7579025 3337735 865 3000880481 4481 3676546 2212658 2885 1398193708 4946 73018658 1515257 1418 1052917712 8342025 201246652 38240 327462 371697988 7 74380777 862611 7 1514306888 3922461 29073852 1223482 268 1848522009 1 1492281 1483635 1 1478599096 28042103 140210513 594 164 226079402 21473 22121577 1034787 4484 478652562 4468 21669366 1020370 4438 2054874295 73520 118272694 29987 73520
Example 24-29 Finding Resources Used by a SQL Statement
SELECT hash_value, buffer_gets, disk_reads, executions, parse_calls FROM V$SQLAREA WHERE hash_Value = 228801498 AND address = hextoraw('CBD8E4B0'); HASH_VALUE BUFFER_GETS DISK_READS EXECUTIONS PARSE_CALLS ---------- ----------- ---------- ---------- ----------- 228801498 236116544 2371187 136 136