| How to get list of top 15 sql order by by buffer gets [message #630491] |
Mon, 29 December 2014 05:10  |
kytemanaic
Messages: 55 Registered: February 2009
|
Member |
|
|
Hi all,
I'm trying to get a list of sql ordered by buffer gets
SELECT * FROM(
SELECT ROW_NUMBER () OVER (ORDER BY sql_ordered_by_gets.BUFFER_GETS_TOTAL DESC) rn, sql_ordered_by_gets.* FROM(
SELECT DISTINCT sql.SQL_ID
,BUFFER_GETS_TOTAL
, EXECUTIONS_TOTAL
--, BUFFER_GETS_TOTAL/EXECUTIONS_TOTAL "Gets Per Exec"
,total_buffer_gets.total_buffer_gets
, round(dhs.BUFFER_GETS_TOTAL/total_buffer_gets.total_buffer_gets*100,1) per_cent_buffer_total
,ELAPSED_TIME_TOTAL/1000000 elapsed_time
,round(CPU_TIME_TOTAL/ELAPSED_TIME_TOTAL*100,0) "%CPU"
, round(IOWAIT_TOTAL/ELAPSED_TIME_TOTAL*100,1) "%IO"
,dhs.MODULE
,sql.SQL_TEXT
FROM dba_hist_sqlstat dhs ,v$instance inst, v$sql sql
,(SELECT sum(BUFFER_GETS_TOTAL) total_buffer_gets FROM dba_hist_sqlstat dhs
JOIN v$instance inst
ON inst.INSTANCE_NUMBER = dhs.INSTANCE_NUMBER
JOIN v$sql sql
ON sql.sql_id = dhs.SQL_ID
AND dhs.INSTANCE_NUMBER=1
WHERE dhs.SNAP_ID=3482
AND dhs.EXECUTIONS_TOTAL>0
) total_buffer_gets
WHERE SNAP_ID=3482
AND dhs.INSTANCE_NUMBER=1
--AND dhs.sql_id='0a59tkkpx31vx'
AND inst.INSTANCE_NUMBER = dhs.INSTANCE_NUMBER
AND sql.sql_id= dhs.SQL_ID
--AND EXECUTIONS_TOTAL>0
) sql_ordered_by_gets
) WHERE rn>=1 and rn<=100;
when compare to AWR, it seems that my %total, i.e. %Total - Buffer Gets as a percentage of Total Buffer Gets, the figure seems to get wrong, could appreciate if someone could point out what's wrong with my sql.
thanks a lot!
|
|
|
|
|
|
|
|
|
|