SELECT DISTINCT p.Sql_Id AS Sql_Id, CASE WHEN p.Id = 0 THEN Sq.Module ELSE NULL END AS Module, p.Id, Lpad(' ', 4 * Depth) || p.Operation AS Operation, p.Options AS "Access", p.Object_Name AS "Object", p.Cost AS "Cost", Trunc(p.Cpu_Cost / 1000000, 2) AS "Cpu_Seconds", p.Cardinality, p.Io_Cost AS "IO Cost", p.TIME, p.Filter_Predicates, p.Access_Predicates, CASE WHEN p.Id = 0 THEN Sq.Sql_Text ELSE NULL END AS Sql_Text, CASE WHEN p.Id = 0 THEN Sq.Last_Active_Time ELSE NULL END AS Last_Active_Time, Filtro.Costosum FROM V$sql_Plan p INNER JOIN V$sql Sq ON Sq.Sql_Id = p.Sql_Id INNER JOIN (SELECT Filtro_Rownum.Sql_Id, Filtro_Rownum.Costosum FROM (SELECT Tmp.Sql_Id, SUM(Tmp.Cost) AS Costosum FROM (SELECT s.Sql_Text, p.Sql_Id, p.Plan_Hash_Value, p.Cost FROM V$sql s INNER JOIN V$sql_Plan p ON s.Sql_Id = p.Sql_Id WHERE 1 = 1 AND Upper(s.Sql_Text) NOT LIKE '%EXPLAIN PLAN%' AND s.Last_Active_Time > SYSDATE - 0.3 AND upper(s.Module) <> Upper('PL/SQL Developer') AND p.Cost IS NOT NULL AND p.ID = 0 ORDER BY p.Cost DESC, p.Cpu_Cost DESC, p.Io_Cost DESC) Tmp GROUP BY Tmp.Sql_Id order by sum(tmp.cost) desc) Filtro_Rownum WHERE Rownum < 200) Filtro ON Filtro.Sql_Id = p.Sql_Id ORDER BY Filtro.Costosum DESC, p.Sql_Id, p.Id
this blog is intended to be a place to store code snippets, examples, notes... in order to have them handy and to quickly find during the everyday work
Search This Blog
Tuesday, 31 January 2012
Oracle, resource-consuming queries
Etichette:
Oracle DBA
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment