oracle SQL的HASH_VALUE 理解

当执行SQL语句时,Oracle会在共享池中查找匹配的文本并尝试重执行现有子游标。如果所有现有子游标无法重用,Oracle会进行硬解析创建新的子游标。V$SQLTEXT显示SQL语句的文本,而V$SQL提供每个原始SQL文本子游标的统计信息。当父游标达到1024个子游标时,下次执行该SQL失败分享时,会标记父游标为过时并创建新父游标。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

To explain how this can happen: When a SQLstatement is executed, we find the matching text in the shared pool, if itexists. Then we try to reexecute an existing child cursor if possible. If allof the already existing children for that parent cursor cannot be reused (i.e.cannot be shared), Oracle needs to hard parse and thereby creates another childcursor. If we continue not-sharing existing child cursors, at the point when aparent has 1024 child cursors, the next time a user attempts to execute thatSQL text and there is a failure to share any of these cursors, the parent with1024 cursors is marked as obsolete, and a new parent is created.

 


sql_address

sql_hash_value

V$SQLTEXT

V$SQLTEXT displays the text of SQL statements belonging to shared SQL cursors in the SGA.

ColumnDatatypeDescription
ADDRESSRAW(4 | 8)Used with HASH_VALUE to uniquely identify a cached cursor
HASH_VALUENUMBERUsed with ADDRESS to uniquely identify a cached cursor
SQL_IDVARCHAR2(13)SQL identifier of a cached cursor
COMMAND_TYPENUMBERCode for the type of SQL statement (SELECTINSERT, and so on)
PIECENUMBERNumber used to order the pieces of SQL text
SQL_TEXTVARCHAR2(64)A column containing one piece of the SQL text



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_COUNT column 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 the DBMS_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. If CURSOR_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_MEMNUMBERTypecheck memory
IO_CELL_OFFLOAD_ELIGIBLE_BYTESNUMBERNumber 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_BYTESNUMBERNumber of I/O bytes exchanged between Oracle Database and the storage system
PHYSICAL_READ_REQUESTSNUMBERNumber of physical read I/O requests issued by the monitored SQL
PHYSICAL_READ_BYTESNUMBERNumber of bytes read from disks by the monitored SQL
PHYSICAL_WRITE_REQUESTSNUMBERNumber of physical write I/O requests issued by the monitored SQL
PHYSICAL_WRITE_BYTESNUMBERNumber of bytes written to disks by the monitored SQL
OPTIMIZED_PHY_READ_REQUESTSNUMBERNumber of physical read I/O requests from Database Smart Flash Cache issued by the monitored SQL
LOCKED_TOTALNUMBERTotal number of times the child cursor has been locked
PINNED_TOTALNUMBERTotal number of times the child cursor has been pinned
IO_CELL_UNCOMPRESSED_BYTESNUMBERNumber 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_BYTESNUMBERNumber 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




下面摘抄eygle深入解析ORACLE 中关于SQL执行过程的描述  

 1.首先获得librarycache latch,根据SQL的HASH_VALUE在library cache中查找是否存在此HASH_VALUE,如果找到这个HASH_VALUE,称之为软解析,

 Server获得改SQL执行计划转向第4步,如果找不到共享代码就进行硬解析。 

 2.释放librarypool cache,获得shared pool latch,查找并锁定自由空间(在bucket 中查找chunk)。如果找不到,报ORA-04031错误

 3.释放shared poollatch,重新获得library cache latch,将SQL执行计划放入library cache中。

 4.释放librarycache latch,保持null模式的library cache pin/lock.  

 5.开始执行。 Librarycache latch可以理解为硬/软解析的时候发生的,

 因为解析的时候会搜索librarycache,

 所以会产生librarycache latch Library cache pin 是在执行的阶段发生的


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值