oracle SQL的HASH_VALUE 理解

来源:互联网 发布:淘宝衣服的宣传海报 编辑:程序博客网 时间:2024/05/22 05:56

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.

ColumnDatatypeDescriptionADDRESSRAW(4 | 8)Used with HASH_VALUE to uniquely identify a cached cursorHASH_VALUENUMBERUsed with ADDRESS to uniquely identify a cached cursorSQL_IDVARCHAR2(13)SQL identifier of a cached cursorCOMMAND_TYPENUMBERCode for the type of SQL statement (SELECTINSERT, and so on)PIECENUMBERNumber used to order the pieces of SQL textSQL_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.

ColumnDatatypeDescriptionSQL_TEXTVARCHAR2(1000)First thousand characters of the SQL text for the current cursorSQL_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 cacheSHARABLE_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 cursorSORTSNUMBERNumber of sorts that were done for the child cursorLOADED_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 statementFETCHESNUMBERNumber of fetches associated with the SQL statementEXECUTIONSNUMBERNumber of executions that took place on this object since it was brought into the library cachePX_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 statementLOADSNUMBERNumber of times the object was either loaded or reloadedFIRST_LOAD_TIMEVARCHAR2(19)Timestamp of the parent creation timeINVALIDATIONSNUMBERNumber of times this child cursor has been invalidatedPARSE_CALLSNUMBERNumber of parse calls for this child cursorDISK_READSNUMBERNumber of disk reads for this child cursorDIRECT_WRITESNUMBERNumber of direct writes for this child cursorBUFFER_GETSNUMBERNumber of buffer gets for this child cursorAPPLICATION_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 returnsCOMMAND_TYPENUMBEROracle command type definitionOPTIMIZER_MODEVARCHAR2(10)Mode under which the SQL statement was executedOPTIMIZER_COSTNUMBERCost of this query given by the optimizerOPTIMIZER_ENVRAW(2000)Optimizer environmentOPTIMIZER_ENV_HASH_VALUENUMBERHash value for the optimizer environmentPARSING_USER_IDNUMBERUser ID of the user who originally built this child cursorPARSING_SCHEMA_IDNUMBERSchema ID that was used to originally build this child cursorPARSING_SCHEMA_NAMEVARCHAR2(30)Schema name that was used to originally build this child cursorKEPT_VERSIONSNUMBERIndicates whether this child cursor has been marked to be kept pinned in the cache using the DBMS_SHARED_POOL packageADDRESSRAW(4 | 8)Address of the handle to the parent for this cursorTYPE_CHK_HEAPRAW(4)Descriptor of the type check heap for this child cursorHASH_VALUENUMBERHash value of the parent statement in the library cacheOLD_HASH_VALUENUMBEROld SQL hash valuePLAN_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 cursorSERVICEVARCHAR2(64)Service nameSERVICE_HASHNUMBERHash value for the name listed in the SERVICEcolumnMODULEVARCHAR2(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_MODULEMODULE_HASHNUMBERHash value of the module listed in the MODULE columnACTIONVARCHAR2(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_ACTIONACTION_HASHNUMBERHash value of the action listed in the ACTION columnSERIALIZABLE_ABORTSNUMBERNumber of times the transaction failed to serialize, producing ORA-08177 errors, per cursorOUTLINE_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 fetchingELAPSED_TIMENUMBERElapsed time (in microseconds) used by this cursor for parsing, executing, and fetchingOUTLINE_SIDNUMBEROutline session identifierCHILD_ADDRESSRAW(4 | 8)Address of the child cursorSQLTYPENUMBERDenotes the version of the SQL language used for this statementREMOTEVARCHAR2(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 cacheIS_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 anySQL_PATCHVARCHAR2(30)SQL patch used for this statement, if anySQL_PLAN_BASELINEVARCHAR2(30)SQL plan baseline used for this statement, if anyPROGRAM_IDNUMBERProgram identifierPROGRAM_LINE#NUMBERProgram line numberEXACT_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 FORCELAST_ACTIVE_TIMEDATETIme at which the query plan was last activeBIND_DATARAW(2000)Bind dataTYPECHECK_MEMNUMBERTypecheck memoryIO_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 systemPHYSICAL_READ_REQUESTSNUMBERNumber of physical read I/O requests issued by the monitored SQLPHYSICAL_READ_BYTESNUMBERNumber of bytes read from disks by the monitored SQLPHYSICAL_WRITE_REQUESTSNUMBERNumber of physical write I/O requests issued by the monitored SQLPHYSICAL_WRITE_BYTESNUMBERNumber of bytes written to disks by the monitored SQLOPTIMIZED_PHY_READ_REQUESTSNUMBERNumber of physical read I/O requests from Database Smart Flash Cache issued by the monitored SQLLOCKED_TOTALNUMBERTotal number of times the child cursor has been lockedPINNED_TOTALNUMBERTotal number of times the child cursor has been pinnedIO_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 是在执行的阶段发生的