某條sql的buffer gets 的歷史月度變化
----統計某條sql的buffer_gets 月度變化----適用於9i庫--
select n.hash_value,n.stime,n.executions_delta_sum,n.buffer_gets_delta_sum,n.avg_buffer_gets,
round ((n.avg_buffer_gets - lag(n.avg_buffer_gets) over (order by n.stime ))/n.avg_buffer_gets*100,2) buffer_get_perc
from
(
select m.hash_value,
to_char(m.snap_time, 'YYYY-MM') stime,
sum(m.executions_delta) executions_delta_sum,
sum(m.buffer_gets_delta) buffer_gets_delta_sum,
round (sum(m.buffer_gets_delta)/sum(m.executions_delta),2) avg_buffer_gets
from (select a.hash_value,
b.snap_time,
round(a.executions - lag(a.executions)
over(order by a.snap_id)) executions_delta,
round(a.buffer_gets - lag(a.buffer_gets)
over(order by a.snap_id)) buffer_gets_delta
from stats$sql_summary a, stats$snapshot b
where a.hash_value = '3197777015'
and a.snap_id = b.snap_id
and b.snap_time BETWEEN
TO_DATE('2012/04/01 00:00:05', 'yyyy/mm/dd hh24:mi:ss') AND
TO_DATE('2012/07/01 00:00:10', 'yyyy/mm/dd hh24:mi:ss')
order by a.snap_id) M
where m.executions_delta > 0
and m.buffer_gets_delta > 0
group by m.hash_value, to_char(m.snap_time, 'YYYY-MM')
)N
-- select sysdate,to_char(sysdate,'ww'),to_char(sysdate,'YYYY-MM') from dual;
round ((n.avg_buffer_gets - lag(n.avg_buffer_gets) over (order by n.stime ))/n.avg_buffer_gets*100,2) buffer_get_perc
from
(
select m.hash_value,
to_char(m.snap_time, 'YYYY-MM') stime,
sum(m.executions_delta) executions_delta_sum,
sum(m.buffer_gets_delta) buffer_gets_delta_sum,
round (sum(m.buffer_gets_delta)/sum(m.executions_delta),2) avg_buffer_gets
from (select a.hash_value,
b.snap_time,
round(a.executions - lag(a.executions)
over(order by a.snap_id)) executions_delta,
round(a.buffer_gets - lag(a.buffer_gets)
over(order by a.snap_id)) buffer_gets_delta
from stats$sql_summary a, stats$snapshot b
where a.hash_value = '3197777015'
and a.snap_id = b.snap_id
and b.snap_time BETWEEN
TO_DATE('2012/04/01 00:00:05', 'yyyy/mm/dd hh24:mi:ss') AND
TO_DATE('2012/07/01 00:00:10', 'yyyy/mm/dd hh24:mi:ss')
order by a.snap_id) M
where m.executions_delta > 0
and m.buffer_gets_delta > 0
group by m.hash_value, to_char(m.snap_time, 'YYYY-MM')
)N
-- select sysdate,to_char(sysdate,'ww'),to_char(sysdate,'YYYY-MM') from dual;
----統計某條sql的buffer_gets 周度變化----適用於9i庫--
select n.hash_value,n.stime,n.executions_delta_sum,n.buffer_gets_delta_sum,n.avg_buffer_gets,
round ((n.avg_buffer_gets - lag(n.avg_buffer_gets) over (order by n.stime ))/n.avg_buffer_gets*100,2) buffer_get_perc
from
(
select m.hash_value,
to_char(m.snap_time, 'WW') stime,
sum(m.executions_delta) executions_delta_sum,
sum(m.buffer_gets_delta) buffer_gets_delta_sum,
round (sum(m.buffer_gets_delta)/sum(m.executions_delta),2) avg_buffer_gets
from (select a.hash_value,
b.snap_time,
round(a.executions - lag(a.executions)
over(order by a.snap_id)) executions_delta,
round(a.buffer_gets - lag(a.buffer_gets)
over(order by a.snap_id)) buffer_gets_delta
from stats$sql_summary a, stats$snapshot b
where a.hash_value = '3197777015'
and a.snap_id = b.snap_id
and b.snap_time BETWEEN
TO_DATE('2012/04/01 00:00:05', 'yyyy/mm/dd hh24:mi:ss') AND
TO_DATE('2012/07/01 00:00:10', 'yyyy/mm/dd hh24:mi:ss')
order by a.snap_id) M
where m.executions_delta > 0
and m.buffer_gets_delta > 0
group by m.hash_value, to_char(m.snap_time, 'WW')
)N
-- select sysdate,to_char(sysdate,'ww'),to_char(sysdate,'YYYY-MM') from dual;
round ((n.avg_buffer_gets - lag(n.avg_buffer_gets) over (order by n.stime ))/n.avg_buffer_gets*100,2) buffer_get_perc
from
(
select m.hash_value,
to_char(m.snap_time, 'WW') stime,
sum(m.executions_delta) executions_delta_sum,
sum(m.buffer_gets_delta) buffer_gets_delta_sum,
round (sum(m.buffer_gets_delta)/sum(m.executions_delta),2) avg_buffer_gets
from (select a.hash_value,
b.snap_time,
round(a.executions - lag(a.executions)
over(order by a.snap_id)) executions_delta,
round(a.buffer_gets - lag(a.buffer_gets)
over(order by a.snap_id)) buffer_gets_delta
from stats$sql_summary a, stats$snapshot b
where a.hash_value = '3197777015'
and a.snap_id = b.snap_id
and b.snap_time BETWEEN
TO_DATE('2012/04/01 00:00:05', 'yyyy/mm/dd hh24:mi:ss') AND
TO_DATE('2012/07/01 00:00:10', 'yyyy/mm/dd hh24:mi:ss')
order by a.snap_id) M
where m.executions_delta > 0
and m.buffer_gets_delta > 0
group by m.hash_value, to_char(m.snap_time, 'WW')
)N
-- select sysdate,to_char(sysdate,'ww'),to_char(sysdate,'YYYY-MM') from dual;
----統計某條sql的buffer_gets 月度變化----適用於10g庫--
select m.*,
round((m.avg_buffer_gets - lag(m.avg_buffer_gets) over (order by m.stime))/m.avg_buffer_gets *100,2) buffer_gets_perc
from
(
select s.sql_id,
to_char(sn.begin_interval_time, 'YYYYMM') stime,
sum(s.buffer_gets_delta) buffer_gets_delta,
sum(s.executions_delta) executions_delta,
--round(s.buffer_gets_delta/s.rows_processed_delta,2) avg_rows_per_buffergets,
round(sum(s.buffer_gets_delta) /sum(s.executions_delta), 2) avg_buffer_gets
from dba_hist_snapshot sn, sys.WRH$_SQLSTAT s
where sn.snap_id = s.snap_id
and s.sql_id = '32gwz557f2fj3'
/*
('32gwz557f2fj3',
'1ydby3vmrrc2a',
'2c93jk7wgr4vu',
'8ufxhfhg5p2gv',
'3x30pc8mjrbdb',
'axnpu3jgp2a51'
)
*/
and s.executions_delta > 0
--and sn.begin_interval_time between to_date('2012-09-18 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-09-19 00:00:00','yyyy-mm-dd hh24:mi:ss')
group by sql_id,to_char(sn.begin_interval_time, 'YYYYMM')
order by 2
) M
order by a.sql_id,a.stime
round((m.avg_buffer_gets - lag(m.avg_buffer_gets) over (order by m.stime))/m.avg_buffer_gets *100,2) buffer_gets_perc
from
(
select s.sql_id,
to_char(sn.begin_interval_time, 'YYYYMM') stime,
sum(s.buffer_gets_delta) buffer_gets_delta,
sum(s.executions_delta) executions_delta,
--round(s.buffer_gets_delta/s.rows_processed_delta,2) avg_rows_per_buffergets,
round(sum(s.buffer_gets_delta) /sum(s.executions_delta), 2) avg_buffer_gets
from dba_hist_snapshot sn, sys.WRH$_SQLSTAT s
where sn.snap_id = s.snap_id
and s.sql_id = '32gwz557f2fj3'
/*
('32gwz557f2fj3',
'1ydby3vmrrc2a',
'2c93jk7wgr4vu',
'8ufxhfhg5p2gv',
'3x30pc8mjrbdb',
'axnpu3jgp2a51'
)
*/
and s.executions_delta > 0
--and sn.begin_interval_time between to_date('2012-09-18 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-09-19 00:00:00','yyyy-mm-dd hh24:mi:ss')
group by sql_id,to_char(sn.begin_interval_time, 'YYYYMM')
order by 2
) M
order by a.sql_id,a.stime
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22578826/viewspace-745208/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 某條SQL突然變慢的問題分析SQL
- oracle buffer gets=db block gets+consistent getsOracleBloC
- 檢視sql 執行計劃的歷史變更SQL
- 如何展示主資料的歷史變化(一)
- 如何展示主資料的歷史變化(二)
- 如何展示主資料的歷史變化(三)
- 如何展示主資料的歷史變化(四)
- 【Oracle】如何檢視sql 執行計劃的歷史變更OracleSQL
- git刪除歷史中的某個大檔案Git
- Git檢視某個歷史版本的最佳實踐Git
- 批次殺執行某條sql的sessionSQLSession
- SQL Server 查詢歷史執行的SQL語句SQLServer
- Java記憶體模型的歷史變遷Java記憶體模型
- 寫有效的歷史資料遷移sqlSQL
- Oracle中檢視sql命令歷史,檢視rman命令歷史OracleSQL
- 網路同步在遊戲歷史中的發展變化(五)—— 物理同步遊戲
- 展示主資料的歷史變化的幾種業務需求及其實現方法
- 一條SQL語句的執行計劃變化探究SQL
- TopSQL,計算某條sql的CPU time.SQL
- ZT 寫有效的歷史資料遷移sqlSQL
- 查詢SQL Server的歷史執行記錄SQLServer
- Oracle檢視歷史TOP SQLOracleSQL
- HTTP的歷史HTTP
- Laravel 的歷史Laravel
- Java的歷史Java
- Macromedia的歷史Mac
- DNF端游到手遊的演變歷史:從ACT遊戲到MMORPG化遊戲
- 一次優化log_buffer_space的經歷優化
- 自然語言處理歷史史詩:NLP的正規化演變與Python全實現自然語言處理Python
- HTTP 協議的歷史演變和設計思路HTTP協議
- 遊戲中“血條”設計的進化史遊戲
- C++的歷史C++
- IBM的歷史IBM
- 《程式設計時間簡史系列》JavaScript 模組化的歷史程式程式設計JavaScript
- MySQL系列之一條更新SQL的生命歷程MySql
- 清除shared pool中某條sql的執行計劃SQL
- sql server 中刪除內容重複的某條記錄SQLServer
- Oracle檢視sql_id 的歷史執行計劃OracleSQL