690 shaares
3 liens privés
3 liens privés
showing current expensive queries plus most expensive object from execution plan:
select sa.sql_id,
sp.child_number,
sp.plan_hash_value,
sa.parsing_schema_name SQL_PARSED_BY,
sa.module,
sa.action,
sa.buffer_gets,
sa.BG_PER_EXEC,
sp.object_owner,
--sp.object_name, -- this is the group factor
sa.optimizer_cost,
sp.cost COST_PER_EXP_OBJECT,
round((sp.cost/sa.optimizer_cost)*100,0) OBJECT_COST_RELATION,
listagg(OBJECT_NAME,', ') within group (order by object_name) MOST_EXPENSIVE_OBJECTS,
sa.sql_text
from
(select sql_id,
child_number,
parsing_schema_name,
module,action,
buffer_gets,
round(buffer_gets/nullif(executions,0),0) BG_PER_EXEC,
optimizer_cost,
sql_text
from v$sql
where parsing_schema_name <>'SYS'
) sa,
(select sql_id, child_number, plan_hash_value, object_owner, object_name,cost,
rank() over (partition by sql_id,child_number order by cost desc nulls last) costrank
-- result set partitioned by sql and child to avoid duplicates
-- when same sql is executed by multiple users
from v$sql_plan
where (operation like '%INDEX%' or operation like '%TABLE%' or operation like '%MAT%')
--and options='FULL' -- would limit to full table scans / full object scans
and object_owner <>'SYS'
) sp
where sa.sql_id=sp.sql_id
and sa.child_number=sp.child_number
and costrank=1 -- only use top costly object of each partition
group by sa.sql_id,
sp.child_number,
sp.plan_hash_value,
sa.parsing_schema_name,
sa.module,
sa.action,
sa.buffer_gets,
sa.BG_PER_EXEC,
sp.object_owner,
--sp.object_name, -- this is the group factor
sa.optimizer_cost,
sp.cost,
round((sp.cost/sa.optimizer_cost)*100,0),
sa.sql_text
order by BG_PER_EXEC desc nulls last
;