v$sql檢視和v$sqlarea檢視的構建
通過v$fixed_view_definition檢視,可以查詢得到v$sql檢視和v$sqlarea檢視的構建語句:
select view_definition from v$fixed_view_definition where view_name='GV$SQL';
select view_definition from v$fixed_view_definition where view_name='GV$SQLAREA';
GV$SQL的定義結構如下(Oracle 10gR2環境):
select inst_id,kglnaobj,kglfnobj,kglobt03,
kglobhs0+kglobhs1+kglobhs2+kglobhs3+kglobhs4+kglobhs5+kglobhs6+kglobt16,
kglobt08+kglob t11,kglobt10,kglobt01,decode(kglobhs6,0,0,1),
decode(kglhdlmd,0,0,1),kglhdlkc,kglobt04,kglobt05,kglobt48,kglobt35,
kglobpc6,kglhdldc,
substr(to_char(kglnatim,'YYYY-MM-DD/HH24:MI:SS'),1,19),kglhdivc,kglobt12,
kglobt13,kglobwdw,kglobt14,kglobwap,kglobwcc,kglobwcl,kglobwui,kglobt42,
kglobt43,kglobt15,kglobt02,
decode(kglobt32, 0, 'NONE', 1, 'ALL_ROWS', 2, 'FIRST_ROWS', 3, 'RULE',
4, 'CHOOSE', 'UNKNOWN'),
kglobtn0,kglobcce,kglobcceh,kglobt17,kglobt18,kglobts4,kglhdkmk,kglhdpar,
kglobtp0,kglnahsh,kglobt46,kglobt30,kglobt09,kglobts5,kglobt48,kglobts0,
kglobt19,kglobts1,kglobt20,kglobt21,kglobts2,kglobt06,kglobt07,
decode(kglobt28, 0, to_number(NULL), kglobt28),kglhdadr,kglobt29,
decode(bita nd(kglobt00,64),64, 'Y', 'N'),
decode(kglobsta, 1, 'VALID', 2, 'VALID_AUTH_ERROR', 3, 'VALID_COMPILE_ERROR',
4, 'VALID_UNAUTH', 5, 'INVALID_UNAUTH', 6, 'INVALID'),
kglobt31,
substr(to_char(kglobtt0,'YYYY-MM-DD/HH24:MI:SS'),1,19),
decode(kglobt33, 1, 'Y', 'N'),kglhdclt,kglobts3,kglobt44,kglobt45,kglobt47,
kglobt49,kglobcla,kglobcbca
from x$kglcursor_child
而GV$SQLAREA的檢視結構如下(Oracle 10gR2環境):
select inst_id,kglnaobj,kglfnobj,kglobt03,
kglobhs0+kglobhs1+kglobhs2+kglobhs3+kglobhs4+kglobhs5+kglobhs6,
kglobt08+kglobt11,k globt10,kglobt01,kglobccc,kglobclc,kglhdlmd,kglhdlkc,
kglobt04,kglobt05,kglobt48,kglobt35,kglobpc6,kglhdldc,
substr(to_c har(kglnatim,'YYYY-MM-DD/HH24:MI:SS'),1,19),
kglhdivc,kglobt12,kglobt13,kglobwdw,kglobt14,kglobwap,kglobwcc,kglobwcl,
kglobwui,kglobt42,kglobt43,kglobt15,kglobt02,
decode(kglobt32, 0, 'NONE', 1, 'ALL_ROWS', 2, 'FIRST_ROWS', 3, 'RULE',
4, 'CHOOSE', 'UNKNOWN'),
kglobtn0,kglobcce,kglobcceh,kglobt17,kglobt18,kglobts4,kglhdkmk,kglhdpar,
kglnahsh,kglobt46,kglobt30,kglobts0,kglobt19,kglobts1,kglobt20,kglobt21,
kglobts2,kglobt06,kglobt07,
decode(kglobt28, 0, NULL, kglobt28),kglhdadr,
decode(bitand(kglobt00,64),64, 'Y', 'N'),
decode(kglobsta, 1, 'VALID', 2, 'VALID_AUTH_ERROR', 3, 'VALID_COMPILE_ERROR',
4, 'VALID_UNAUTH', 5, 'INVALID_UNAUTH', 6 , 'INVALID'),
kglobt31,kglobtt0,decode(kglobt33, 1, 'Y', 'N'),kglhdclt,kglobts3,kglobt44,
kglobt45,kglobt47,kglobt49,kgl obcla,kglobcbca
from x$kglcursor_child_sqlid
where kglobt02 != 0
在Oracle 10g中,這兩個檢視來自兩個獨立的底層X$表,v$sqlarea檢視也不再包含Group by子句,這使得以前版本中查詢v$sqlarea的效能得以緩解。那麼version_count和v$sql的差異應該就來自底層x$表的變更,在v$sqlarea中增加了一個“!=0”的條件過濾(kglobt02對應檢視中的COMMAND_TYPE定義)。
能夠發現,所有的子指標在x$kglob([K]ernel [G]eneric [L]ibrary Cache Manager [OB]ject)表中全部存在,也就是說,觀察到的變化是由於底層表的變更導致不同過濾演算法導致的。在我的一個測試環境中,這樣的情況也可以看到:
sys@NEI> select a.sql_id,a.version_count,a.hash_value,count(*)
2 from v$sqlarea a ,v$sql b
3 where a.version_count >10 and a.hash_value=b.hash_value
4 group by a.sql_id,a.version_count,a.hash_value
5 order by 4;
SQL_ID VERSION_COUNT HASH_VALUE COUNT(*)
-------------------------- ------------- ---------- ----------
4gb7r5dm6hnzs 22 1718113272 1
以其中一個SQL為例進行進一步分析:
sys@NEI> select sql_id,hash_value,buffer_gets,executions,parsing_user_id
2 from v$sql
3 where hash_value = 1718113272
4 order by buffer_gets desc;SQL_ID HASH_VALUE BUFFER_GETS EXECUTIONS PARSING_USER_ID
-------------------------- ---------- ----------- ---------- ---------------
4gb7r5dm6hnzs 1718113272 22 956 0
注意到,所有的SQL都是執行過的。而從x$kglob中查詢得到的SQL或者Oracle 9i的v$sql檢視中查詢得到的SQL包含未執行或者buffer_gets為0的SQL指標,這部分在Oracle 10g中被從v$sqlarea中過濾了出去:
sys@NEI> select kglobt03,kglnahsh,kglobt14,kglhdexc,kglobt17
2 from x$kglob
3 where kglnahsh = 1718113272
4 order by kglobt14 desc,4;
KGLOBT03 KGLNAHSH KGLOBT14 KGLHDEXC KGLOBT17
-------------------------- ---------- ---------- ---------- ----------
4gb7r5dm6hnzs 1718113272 22 956 0
4gb7r5dm6hnzs 1718113272 0 0 2147483644
4gb7r5dm6hnzs 1718113272 0 10 0
4gb7r5dm6hnzs 1718113272 0 10 0
4gb7r5dm6hnzs 1718113272 0 10 0
4gb7r5dm6hnzs 1718113272 0 10 0
4gb7r5dm6hnzs 1718113272 0 10 0
4gb7r5dm6hnzs 1718113272 0 10 0
4gb7r5dm6hnzs 1718113272 0 10 0
4gb7r5dm6hnzs 1718113272 0 10 0
4gb7r5dm6hnzs 1718113272 0 10 0
4gb7r5dm6hnzs 1718113272 0 10 0
4gb7r5dm6hnzs 1718113272 0 12 0
4gb7r5dm6hnzs 1718113272 0 16 0
4gb7r5dm6hnzs 1718113272 0 16 0
4gb7r5dm6hnzs 1718113272 0 16 0
4gb7r5dm6hnzs 1718113272 0 16 0
4gb7r5dm6hnzs 1718113272 0 16 0
4gb7r5dm6hnzs 1718113272 0 16 0
4gb7r5dm6hnzs 1718113272 0 16 0
4gb7r5dm6hnzs 1718113272 0 16 0
4gb7r5dm6hnzs 1718113272 0 16 0
4gb7r5dm6hnzs 1718113272 0 16 0
23 rows selected.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8183550/viewspace-659588/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- V$SQLAREA 檢視TOP_SQLSQL
- v$sqlarea,v$sql,v$sqltext三個檢視的區別SQL
- 檢視 v$sql,v$sqlarea,$sqltext,v$sqltext_with_newlines 的差異SQL
- 授權某使用者,檢視動態效能檢視的許可權(如v$latch,v$lock,v$sqlarea,v$sql,v$sysstat)SQL
- Oracle動態效能檢視學習之v$sqltext & v$sqlareaOracleSQL
- [ZT]v$sqlarea,v$sql,v$sqltext這三個檢視提供的sql語句有什麼區別SQL
- 【Oracle九大效能檢視】之2.v$sqlarea_查效能SQLOracleSQL
- 使用V$SQL_PLAN檢視SQL
- v$sql_plan 檢視解析SQL
- v$session 檢視Session
- v$sql和v$sqlarea的區別SQL
- Oracle的V$檢視和DBA_檢視的參考提示Oracle
- V$SQL 和V$SQLAREA區別SQL
- v$sesstat,v$mystat,v$statname和v$sysstat檢視簡介
- Oracle常用的V$檢視Oracle
- v檢視的授權
- V$SQL、V$SQLSTATS、V$SQLAREASQL
- v$sql_plan這個檢視解析SQL
- 通過 v$sqlarea 查詢disk read嚴重(I/O)的SQL-- Oracle效能檢視SQLOracle
- 幾個檢視 v$mystat v$systata v$sessionSession
- v$sqlarea,v$sql,v$sqltext的區別和聯絡SQL
- 【會話】V$SESSION檢視會話Session
- oracle v$sysstat效能檢視Oracle
- Oracle 等待事件V$檢視Oracle事件
- v$resource_limit檢視MIT
- v$session_wait和v$session_event檢視SessionAI
- V$sql_text v$sqlarea v$sql 的區別SQL
- v$sesstat檢視和自開發工具
- v$sqlarea,v$sql,v$sqltext的區別和聯絡(zt)SQL
- v$sql,v$sqlarea,v$sqltext區別SQL
- 檢視v$sql_shared_cursor檢視獲取sql語句為什麼不能共享?SQL
- V$SQL_SHARED_CURSOR檢視硬解析的原因SQL
- Oracle的v$動態檢視 收藏Oracle
- V$session 檢視的小運用Session
- 自己總結的V$檢視(轉)
- 【Oracle九大效能檢視】之6.v$process檢視Oracle
- Oracle中效能檢視V$SYSSTATOracle
- v$active_session_history檢視Session