v$sql系列试图

V$SQL(具体):
包含不同user执行的sql(有可能相同),可以用来定位session and user
PLAN_HASH_VALUE 用来区别相同的sql是否具有相同的执行计划
V$SQL_PLAN(具体):
包含执行过的并且仍然在shared pool中的sql执行计划
EXPLAIN PLAN 显示的是理论上的执行计划,而V$SQL_PLAN记录的是实际的执行计划,其差别来源于系统或sessIon参数的影响,比如hash_area_size。
作用:
查看SQL实际的执行计划
查找某种特定执行路径和方法的的sql,比如full table scan or index range scan 或者nest loop join
查找没有被使用到的INDEX
进行执行计划的对比,比如先将原来的数据存储到表中
通过ADDRESS,HASH_VALUE,CHILD_NUMBER(如果>0,即一个SQL有多个CURSOR)字段可以与V$SQL连接

常用字段:
OBJECT#: Object number of the table or the index
OBJECT_OWNER: Name of the user who owns the schema containing the table or index
OBJECT_NAME: Name of the table or index
V$SQLAREA(统计):
仍然在shared pool中的SQL的资源使用统计信息
比如可以得到某个sql的buffer_gets, disk_reads等信息
可以看作v$sql按照SQL_TEXT GROUP BY 的聚合信息。
通过ADDRESS,HASH_VALUE 字段与V$SQLTEXT 连接得到完整的SQL
因为有时不同的SQL使用了相同的HASH_VALUE,这时就要用ADDRESS来区别。
常用到的列:
PARSING_USER_ID: User who parsed the first cursor for the statement
VERSION_COUNT: Number of cursors for the statement
KEPT_VERSIONS: Cursors of the statement pinned using DBMS_SHARED_POOL.KEEP()
SHARABLE_MEMORY: Total shared memory used by the cursor
PERSISTENT_MEMORY: Total persistent memory used by the cursor
RUNTIME_MEMORY: Total runtime memory used by the cursor
SQL_TEXT: Up to first 1000 characters of SQL statement
MODULE, ACTION: Information about the session parsing the first cursor if set using DBMS_APPLICATION_INFO
BUFFER_GETS: Number of logical reads for this statement
DISK_READS: Number of physical reads for this statement
SORTS: Number of sorts for this statement
CPU_TIME: CPU time used for parsing and executing this statement
ELAPSED_TIME: Elapsed time for parsing and executing this statement
PARSE_CALLS: Number of parse calls (hard and soft) for this statement
EXECUTIONS: Number of times this statement was executed
INVALIDATIONS: Number of times the cursors for this statement have been invalidated
LOADS: Number of loads (and reloads) for this statement
ROWS_PROCESSED: Total number of rows this statement returns
查看消耗资源最多的SQL:
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;
V$SQLTEXT:
记录shared pool中完整的SQL语句,按照PIECE排序
V$SQLTEXT.HASH_VALUE=V$SESSION.SQL_HASH_VALUE
V$SQLTEXT.ADDRESS=V$SESSION.SQL_ADDRESS

你可能感兴趣的:(数据库,职场,休闲,sql系列)