TA的每日心情 | 开心 2023-8-9 11:05 |
---|
|
- set lines 170 pages 1000
- select * from table(dbms_xplan.display('&sqlid'));--预估执行计划
- select * from table(dbms_xplan.display_cursor('&sqlid'));--内存执行计划
- select * from table(dbms_xplan.display_cursor('&sql_id',0,'ADVANCED'));--cursor advanced
- select * from table(dbms_xplan.display_awr('&sqlid'));--awr执行计划
- select plan_table_output from table (dbms_xplan.display_awr('&sql_id',null,null,'ADVANCED +PEEKED_BINDS'));--awr advanced
- select * from table(dbms_xplan.display_sqlset('&sqlid'));--sqlset执行计划
复制代码
可以通过下面的三个视图查询到sql执行计划的历史信息:
DBA_HIST_SQL_PLAN
DBA_HIST_SQLSTAT
DBA_HIST_SNAPSHOT
查看语句的历史执行信息,是否发生变化,何时发生了变化。如果发生了变化,找出以前的执行计划,与当前的执行计划进行对比,有什么不同。
- --v$sql_plan
- select distinct sql_id,plan_hash_value,to_char(timestamp,'yyyymmdd hh24:mi:ss') timestamp from v$sql_plan where sql_id='&sql_id' order by timestamp;
复制代码- --dba_hist_sql_plan
- select distinct sql_id,plan_hash_value,to_char(timestamp,'yyyymmdd hh24:mi:ss') timestamp from dba_hist_sql_plan where sql_id='&sql_id' order by timestamp;
复制代码
- --v$sql_plan
- col options
- FOR a15 col operation
- FOR a20 col object_name
- FOR a20
- SET lines 0
- SELECT plan_hash_value
- ,id
- ,operation
- ,options
- ,object_name
- ,depth
- ,cost
- ,to_char(TIMESTAMP, 'yyyymmdd hh24:mi:ss') TIMESTAMP
- FROM v$sql_plan
- WHERE sql_id = '&&sql_id'
- AND plan_hash_value IN (
- SELECT DISTINCT plan_hash_value
- FROM v$sql_plan
- WHERE sql_id = '&&sql_id'
- )
- ORDER BY id
- ,TIMESTAMP;
复制代码
- --dba_hist_sql_plan
- col options
- FOR a15 col operation
- FOR a20 col object_name
- FOR a20
- SET lines 0
- SELECT plan_hash_value
- ,id
- ,operation
- ,options
- ,object_name
- ,depth
- ,cost
- ,bytes
- ,cpu_cost
- ,io_cost
- ,TIME
- ,to_char(TIMESTAMP, 'yyyymmdd hh24:mi:ss') TIMESTAMP
- FROM dba_hist_sql_plan
- WHERE sql_id = '&&sql_id'
- AND plan_hash_value IN (
- SELECT DISTINCT plan_hash_value
- FROM dba_hist_sql_plan
- WHERE sql_id = '&&sql_id'
- )
- ORDER BY id
- ,TIMESTAMP;
复制代码
查看出来执行计划的变化之后 可以使用如下sql查看发生了那些变化!
- col options for a15 col operation for a20 col object_name for a20
- select
- plan_hash_value
- , id
- , operation
- , options
- , object_name
- , depth
- , cost
- , to_char(TIMESTAMP,'yyyymmdd hh24:mi:ss')
- from
- DBA_HIST_SQL_PLAN
- where
- sql_id ='&&sql_id'
- and plan_hash_value in (select distinct(plan_hash_value) from DBA_HIST_SQL_PLAN where sql_id='&&sql_id')
- order by ID , TIMESTAMP;
复制代码 |
|