1.背景

前段时间,利用v$sql分析过一个项目的数据流程。发现对v$sql的一些字段理解的一知半解。
实质是对Oracel的sql执行机制理解不深。
把相关的总结一下。

2.v$sql的定义

Column Datatype Description

SQL_TEXT

VARCHAR2(1000)

First thousand characters of the SQL text for the current cursor

SQL_FULLTEXT

CLOB

All characters of the SQL text for the current cursor

SQL_ID

VARCHAR2(13)

SQL identifier of the parent cursor in the library cache

SHARABLE_MEM

NUMBER

Amount of shared memory used by a cursor. If multiple child cursors exist, then the sum of all shared memory used by all child cursors.

PERSISTENT_MEM

NUMBER

Fixed amount of memory used for the lifetime of an open cursor. If multiple child cursors exist, then the fixed sum of memory used for the lifetime of all the child cursors.

RUNTIME_MEM

NUMBER

Fixed amount of memory required during execution of a cursor. If multiple child cursors exist, then the fixed sum of all memory required during execution of all the child cursors.

SORTS

NUMBER

Sum of the number of sorts that were done for all the child cursors

VERSION_COUNT

NUMBER

Number of child cursors that are present in the cache under this parent

LOADED_VERSIONS

NUMBER

Number of child cursors that are present in the cache and have their context heap loaded

OPEN_VERSIONS

NUMBER

Number of child cursors that are currently open under this current parent

USERS_OPENING

NUMBER

Number of users that have any of the child cursors open

FETCHES

NUMBER

Number of fetches associated with the SQL statement

EXECUTIONS

NUMBER

Total number of executions, totalled over all the child cursors

PX_SERVERS_EXECUTIONS

NUMBER

Total number of executions performed by parallel execution servers (0 when the statement has never been executed in parallel)

END_OF_FETCH_COUNT

NUMBER

Number 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_COUNT column should be less or equal to the value of the EXECUTIONS column.

USERS_EXECUTING

NUMBER

Total number of users executing the statement over all child cursors

LOADS

NUMBER

Number of times the object was loaded or reloaded

FIRST_LOAD_TIME

VARCHAR2(19)

Timestamp of the parent creation time

INVALIDATIONS

NUMBER

Total number of invalidations over all the child cursors

PARSE_CALLS

NUMBER

Sum of all parse calls to all the child cursors under this parent

DISK_READS

NUMBER

Sum of the number of disk reads over all child cursors

DIRECT_WRITES

NUMBER

Sum of the number of direct writes over all child cursors

BUFFER_GETS

NUMBER

Sum of buffer gets over all child cursors

APPLICATION_WAIT_TIME

NUMBER

Application wait time (in microseconds)

CONCURRENCY_WAIT_TIME

NUMBER

Concurrency wait time (in microseconds)

CLUSTER_WAIT_TIME

NUMBER

Cluster wait time (in microseconds)

USER_IO_WAIT_TIME

NUMBER

User I/O Wait Time (in microseconds)

PLSQL_EXEC_TIME

NUMBER

PL/SQL execution time (in microseconds)

JAVA_EXEC_TIME

NUMBER

Java execution time (in microseconds)

ROWS_PROCESSED

NUMBER

Total number of rows processed on behalf of this SQL statement

COMMAND_TYPE

NUMBER

Oracle command type definition

OPTIMIZER_MODE

VARCHAR2(10)

Mode under which the SQL statement was executed

OPTIMIZER_COST

NUMBER

Cost of this query given by the optimizer

OPTIMIZER_ENV

RAW(2000)

Optimizer environment

OPTIMIZER_ENV_HASH_VALUE

NUMBER

Hash value for the optimizer environment

PARSING_USER_ID

NUMBER

User ID of the user that has parsed the very first cursor under this parent

PARSING_SCHEMA_ID

NUMBER

Schema ID that was used to parse this child cursor

PARSING_SCHEMA_NAME

VARCHAR2(30)

Schema name that was used to parse this child cursor

KEPT_VERSIONS

NUMBER

Number of child cursors that have been marked to be kept using the DBMS_SHARED_POOL package

ADDRESS

RAW(4 | 8)

Address of the handle to the parent for this cursor

HASH_VALUE

NUMBER

Hash value of the parent statement in the library cache

OLD_HASH_VALUE

NUMBER

Old SQL hash value

PLAN_HASH_VALUE

NUMBER

Numeric representation of the current 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).

FULL_PLAN_HASH_VALUE

NUMBER

Numeric representation of the complete SQL plan for this cursor. Comparing one FULL_PLAN_HASH_VALUE to another easily identifies whether or not two plans are the same (rather than comparing the two plans line by line). Note that the FULL_PLAN_HASH_VALUE cannot be compared across databases releases. It is not backward compatible.

MODULE

VARCHAR2(64)

Contains the name of the module that was executing when the SQL statement was first parsed as set by calling DBMS_APPLICATION_INFO.SET_MODULE

MODULE_HASH

NUMBER

Hash value of the module that is named in the MODULE column

ACTION

VARCHAR2(64)

Contains the name of the action that was executing when the SQL statement was first parsed as set by calling DBMS_APPLICATION_INFO.SET_ACTION

ACTION_HASH

NUMBER

Hash value of the action that is named in the ACTION column

SERIALIZABLE_ABORTS

NUMBER

Number of times the transaction failed to serialize, producing ORA-08177 errors, totalled over all the child cursors

OUTLINE_CATEGORY

VARCHAR2(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_TIME

NUMBER

CPU time (in microseconds) used by this cursor for parsing, executing, and fetching

ELAPSED_TIME

NUMBER

Elapsed time (in microseconds) used by this cursor for parsing, executing, and fetching. If the cursor uses parallel execution, then ELAPSED_TIME is the cumulative time for the query coordinator, plus all parallel query slave processes.

OUTLINE_SID

VARCHAR2(40)

Outline session identifier

LAST_ACTIVE_CHILD_ADDRESS

RAW(4 | 8)

Address (identifier) of the child cursor that was the last to be active in the group (that is, the child cursor on behalf of which statistics in V$SQL were updated)

REMOTE

VARCHAR2(1)

Indicates whether the cursor is remote mapped (Y) or not (N)

OBJECT_STATUS

VARCHAR2(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_VALUE

NUMBER

Hash 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. If CURSOR_SHARING is not used, then the value is 0.

LAST_LOAD_TIME

DATE

Time at which the query plan was loaded into the library cache

IS_OBSOLETE

VARCHAR2(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_SENSITIVE

VARCHAR2(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_AWARE

VARCHAR2(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.

CHILD_LATCH

NUMBER

Child latch number that is protecting the cursor. This column is obsolete and maintained for backward compatibility.

SQL_PROFILE

VARCHAR2(64)

SQL profile used for this statement, if any

SQL_PATCH

VARCHAR2(30)

SQL patch used for this statement, if any

SQL_PLAN_BASELINE

VARCHAR2(30)

SQL plan baseline used for this statement, if any

PROGRAM_ID

NUMBER

Program identifier

PROGRAM_LINE#

NUMBER

Program line number

EXACT_MATCHING_SIGNATURE

NUMBER

Signature used when the CURSOR_SHARING parameter is set to EXACT

FORCE_MATCHING_SIGNATURE

NUMBER

Signature used when the CURSOR_SHARING parameter is set to FORCE

LAST_ACTIVE_TIME

DATE

Time at which the query plan was last active

BIND_DATA

RAW(2000)

Bind data

TYPECHECK_MEM

NUMBER

Typecheck memory

IO_CELL_OFFLOAD_ELIGIBLE_BYTES

NUMBER

Number of I/O bytes which can be filtered by the Exadata storage system

See Also: Oracle Exadata Storage Server Software documentation for more information

IO_INTERCONNECT_BYTES

NUMBER

Number of I/O bytes exchanged between Oracle Database and the storage system

PHYSICAL_READ_REQUESTS

NUMBER

Number of physical read I/O requests issued by the monitored SQL

PHYSICAL_READ_BYTES

NUMBER

Number of bytes read from disks by the monitored SQL

PHYSICAL_WRITE_REQUESTS

NUMBER

Number of physical write I/O requests issued by the monitored SQL

PHYSICAL_WRITE_BYTES

NUMBER

Number of bytes written to disks by the monitored SQL

OPTIMIZED_PHY_READ_REQUESTS

NUMBER

Number of physical read I/O requests from Database Smart Flash Cache issued by the monitored SQL

LOCKED_TOTAL

NUMBER

Total number of times the child cursor has been locked

PINNED_TOTAL

NUMBER

Total number of times the child cursor has been pinned

IO_CELL_UNCOMPRESSED_BYTES

NUMBER

Number of uncompressed bytes (that is, size after decompression) that are offloaded to the Exadata cells

See Also: Oracle Exadata Storage Server Software documentation for more information

IO_CELL_OFFLOAD_RETURNED_BYTES

NUMBER

Number of bytes that are returned by Exadata cell through the regular I/O path

See Also: Oracle Exadata Storage Server Software documentation for more information

CON_ID

NUMBER

The ID of the container to which the data pertains. Possible values include:

  • 0: This value is used for rows containing data that pertain to the entire CDB. This value is also used for rows in non-CDBs.

  • 1: This value is used for rows containing data that pertain to only the root

  • n: Where n is the applicable container ID for the rows containing data

IS_REOPTIMIZABLE

VARCHAR2(1)

This columns shows whether the next execution matching this child cursor will trigger a reoptimization. The values are:

  • Y: If the next execution will trigger a reoptimization

  • R: If the child cursor contains reoptimization information, but will not trigger reoptimization because the cursor was compiled in reporting mode

  • N: If the child cursor has no reoptimization information

IS_RESOLVED_ADAPTIVE_PLAN

VARCHAR2(1)

This column shows whether all of the adaptive parts of a plan have been resolved to the final plan. Once the plan is resolved, the plan hash value and the plan displayed by DBMS_XPLAN will not change through the end of execution. The values for this column are:

  • NULL: If the plan is not adaptive

  • Y: If the plan is fully resolved

  • N: If the plan is not yet fully resolved

See Also: Oracle Database PL/SQL Packages and Types Reference for more information about the DBMS_XPLAN package

2.1 sql包含的要素

sql在Oracle看来,不是简单的sql语句,还应该包含

  1. sql语句
  2. 内存(成本)
  3. 执行次数(效果,被缓存的sql应该要被多次执行,否则被消耗的内存没有发挥价值)
  4. cost:物理读、缓存读;
  5. 环境:优化器配置、schema、客户端等。

3.疑问和解释

3.1 cursor、parent cursor、child cursor?

cursor:是library cache中的内存区域。sql要执行,先分配内存。
parent cursor:保存sql文本。每一个相同的sql文本对应1个parent cursor。即如果sql文本一致,会划入到1个parent cursor中。
child cursor:保存除sql文本外的其他内容。涉及sql运行原理,相同的sql文本,在schema、优化器参数、绑定变量大改时,其实本质是不一样的。child cursor就保存了这些信息。

This is by Oracle database design that you have two kinds of cursors: Parent and Child. For each SQL statement that you execute, Oracle engine will generate two cursors: parent and child cursor. Two cursors are generated because for the same SQL statement, there could be other differences like there can be different bind values or two different schema or different literals values, etc. The parent Cursor will hold the SQL statement and the child cursor will hold the information related to the differences. This essentially makes child cursor as deciding factor as to SQL statement will go for hard or soft parse.
参考:http://expertoracle.com/2017/11/17/db-tuning-basics-3-parent-and-child-cursors/

3.2 v$sql与v$sqlarea的区别

v$sql:V$SQL lists statistics on shared SQL area without the GROUP BY clause and contains one row for each child of the original SQL text entered.
是针对每个child的统计信息,顾
v$sqlarea:V$SQLAREA displays statistics on shared SQL areas and contains one row per SQL string. It provides statistics on SQL statements that are in memory, parsed, and ready for execution.
是针对每个sql文本,即parent的统计信息。

4.应用场景

4.1 应用操作对应的SQL分析

一些系统是黑盒的,没有源码,想知道数据流程,可以通过监控v$sql里缓存的sql分析。

4.2 优化类:sql统计信息的使用

1)top耗资源的进程对应的sql内容

select t.SQL_ID,t.SERIAL#,t.USERNAME,t.SQL_ID,a.SQL_TEXT,a.SQL_FULLTEXT
from v$session t, v$process s, v$sqlarea a
where t.PADDR = s.ADDRand s.SPID in (’18348‘)and a.SQL_ID = t.SQL_ID;

2)查看最耗时的sql、最消耗磁盘读取的sql等。

Oracle动态视图v$sql的说明和使用相关推荐

  1. Oracle 动态游标 PL/SQL 动态SQL语句 open for [using] 语句

    PL/SQL:open for [using] 语句 2017年07月19日 09:52:55 学孩儿无牙哭做粥 阅读数:681 标签: oracleSQLPLSQL 更多 个人分类: ORACLES ...

  2. oracle查视图的sql,oracle通过v$sql视图查询sql的平均执行时间(代码实例)

    oracle通过v$sql视图查询sql的平均执行时间(代码实例) select sql_text,executions 总执行次数,elapsed_time/1000 总耗时(秒), elapsed ...

  3. oracle hcmc,oracle11g中SQL优化(SQL TUNING)新特性之Adaptive Cursor Sharing (ACS)

    1.   ACS简介 Oracle Database 11g提供了Adaptive Cursor Sharing (ACS)功能,以克服以往不该共享的游标被共享的可能性.ACS使用两个新指标:sens ...

  4. ORACLE动态sql在存储过程中出现表或视图不存在的解决方法

    ORACLE动态sql在存储过程中出现表或视图不存在的解决方法 CREATE OR REPLACE PROCEDURE P_test is strsql varchar2(2000); BEGIN   ...

  5. oracle 关系 表 视图_oracle动态视图v$,v_$,gv$,gv_$与x$之间的关系

    前言:在oracle运维的过程中,经常会使用到一些以V$开头的动态视图,比如V$session, 有一次偶然看到有人用V_$session, 初以为别人写错了,没想到desc v_$session以后 ...

  6. oracle 动态sql列转行_Oracle 行转列 动态出转换的列

    10月的第二天,前天写了个Oracle中行转列的pivot的基本使用方法,然后,因为pivot的用法中,正常情况下,我们需要转出多少个列,都得在我们的sql中完完整整地写出,而不能直接在里面写个查询来 ...

  7. oracle v$context,30.Oracle杂记——Oracle常用动态视图v$session

    30.Oracle杂记--Oracle常用动态视图v$session 视图v$session:有关会话的信息 这个视图包含了超级多的列,说明其包含巨大的信息,小伙伴千万要记得使用,不然浪费掉了ORAC ...

  8. Oracle 动态性能视图 (x$, v$, gv$, v_$, gv_$)

    sys :  x$(内存对象))--->v$(内存对象)---->v_$(view)----->v$(public sysnonym) 一. 动态性能视图 1.1 动态性能图 动态性 ...

  9. Oracle 存储过程,Hibernate 调用存储过程,JDBC调用存储过程,Oracle 动态SQL

    Oracle 存储过程学习 目录 Oracle 存储过程........................................................................ ...

最新文章

  1. JavaScriptSerializer序列化和反序列化JSON:使用自定义JavaScriptConverter
  2. python快速入门答案-Python快速入门(一)
  3. 用户空间和内核空间通讯之【proc文件系统】
  4. 20220202--CTF刷题MISC方向--第5题--反编译
  5. #if, #ifdef, #ifndef, #else, #elif, #endif的用法
  6. 基于Python+Django的图书馆管理系统
  7. python爬虫基础教程1_Python爬虫系列(一)入门教学
  8. Android Stduio 发生 Process ‘command ‘somePath:java.exe‘‘ finished with non-zero exit value 2 异常的解决办法
  9. 使用GHOST打包制作gho镜像文件
  10. html 防网页假死,JavaScript-如何防止由于脚本引起的浏览器假死
  11. 剑指offer--46.47.发散思维能力
  12. STM32 TIM高级定时器死区时间的计算
  13. Kaspersky Anti-Virus NDIS Filter导致的网络故障一例
  14. Whitelabel Error Page问题解决方案
  15. 2019机器学习框架之争:与Tensorflow竞争白热化,进击的PyTorch赢在哪里?
  16. webots车轮下陷问题 车轮在地下
  17. RobotSim机器人快速成型-离线编程仿真软件
  18. Miller-Rabin素数检测算法笔记
  19. 指标体系:指标的设计方法
  20. 我对软件分层设计的思考

热门文章

  1. 【面试】求最大最小的数
  2. Duplicate class com.amap.api.fence.DistrictItem found in modules jetified-3dmap-9.3.1.jar (com.amap.
  3. python菜鸟教程python机器学习工具库
  4. 1-思维与系统-习题
  5. 个人python练习
  6. mt4服务器修改,修改mt4服务器地址
  7. java连接数据库用户 'sa' 登录失败。 ClientConnectionId:解决方法
  8. 2345浏览器写CSDN博客错误
  9. ncnn param文件及bin模型可视化解析
  10. mybatisplus 自增主键失效,自增主键超大