SQL> set linesize 200 pagesize 2000; SQL> select * from global_name; GLOBAL_NAME -------------------------------------------------------------------------------- oracledatabase12g.com SQL> select /* extract_me */ count(*) from maclean; COUNT(*) ---------- 9564 SQL> select sql_id from v$sql where sql_text like '%extract_me%' and sql_text not like '%like%'; SQL_ID ------------- 8vff23q8qp9fj SQL> exec dbms_workload_repository.create_snapshot; PL/SQL procedure successfully completed. QL> select * from table(dbms_xplan.display_cursor('8vff23q8qp9fj',0)); PLAN_TABLE_OUTPUT ------------------------------------- SQL_ID 8vff23q8qp9fj, child number 0 ------------------------------------- select /* extract_me */ count(*) from maclean Plan hash value: 1679547536 ---------------------------------------------------------------------- | Id | Operation | Name | Rows | Cost (%CPU)| Time | ---------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | 34 (100)| | | 1 | SORT AGGREGATE | | 1 | | | | 2 | TABLE ACCESS FULL| MACLEAN | 10438 | 34 (0)| 00:00:01 | ---------------------------------------------------------------------- Note ----- - dynamic sampling used for this statement 18 rows selected. /* 冲刷共享池后v$SQL/V$SQL_PLAN等动态视图内的记录会消失, 需要注意的是如果在AWR快照自动生成之前冲刷了共享池,那么可能丢失SQL的执行统计信息 */ SQL> alter system flush shared_pool; System altered. SQL> select * from table(dbms_xplan.display_cursor('8vff23q8qp9fj',0)); PLAN_TABLE_OUTPUT --------------------------------------------------------------------- SQL_ID: 8vff23q8qp9fj, child number: 0 cannot be found /* 此时就可以利用dbms_xplan.display_awr存储过程来抓取该SQL_ID对应的执行计划 */ SQL> select * from table(dbms_xplan.display_awr('8vff23q8qp9fj')); PLAN_TABLE_OUTPUT -------------------------------------------------- SQL_ID 8vff23q8qp9fj -------------------- select /* extract_me */ count(*) from maclean Plan hash value: 1679547536 ---------------------------------------------------------------------- | Id | Operation | Name | Rows | Cost (%CPU)| Time | ---------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | 34 (100)| | | 1 | SORT AGGREGATE | | 1 | | | | 2 | TABLE ACCESS FULL| MACLEAN | 10438 | 34 (0)| 00:00:01 | ---------------------------------------------------------------------- Note ----- - dynamic sampling used for this statement 18 rows selected. /* 这里可以代入'all'选项获取更细致的计划信息 */ SQL> select * from table(dbms_xplan.display_awr('8vff23q8qp9fj',null,null,'all')); PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------- SQL_ID 8vff23q8qp9fj -------------------- select /* extract_me */ count(*) from maclean Plan hash value: 1679547536 ---------------------------------------------------------------------- | Id | Operation | Name | Rows | Cost (%CPU)| Time | ---------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | 34 (100)| | | 1 | SORT AGGREGATE | | 1 | | | | 2 | TABLE ACCESS FULL| MACLEAN | 10438 | 34 (0)| 00:00:01 | ---------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$1 2 - SEL$1 / MACLEAN@SEL$1 Note ----- - dynamic sampling used for this statement 24 rows selected. /* 也可以从 dba_hist_sql_plan/dba_hist_sqltext等awr历史视图中直接观察该SQL ID对应的语句 */ SQL> select OPERATION,OPTIONS,OBJECT_NAME from dba_hist_sql_plan where sql_id='8vff23q8qp9fj'; OPERATION OPTIONS OBJECT_NAME ------------------------------ ------------------------------ ------------------------------- SELECT STATEMENT SORT AGGREGATE TABLE ACCESS FULL MACLEAN
Extract SQL Plan from AWR
原创maclean_007 ©著作权
文章标签 Oracle 数据库 tuning AWR DBMS_XPLAN.DISPLAY_A 文章分类 Oracle 数据库
-
使用Azure Automation自动调整App Services Plan大小
说到App Services Plan大家可能比较陌生,但是如果提到Azure App Services大家肯定都很熟悉,相信很多朋友都在其上托管了一些Web应用。其实我们所使用的App Services始终是在App Services Plan中运行的。App Services Plan的定价层确定了所提供的App Services功能和计划费用。这也就意味着,如果想要控制App Services所产生的费用,就需要从App Services Plan入手。
Azure 成本优化 App Services Plan Web应用