[20120806]11G SPM的学习3.txt

简介: [20120806]11G SPM的学习3.txt继续上面的学习:SQL> select * from v$version ;BANNER---------------------------------------------...
[20120806]11G SPM的学习3.txt

继续上面的学习:

SQL> select * from v$version ;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

create table t as select rownum id , cast(dbms_random.string('a',6 ) as varchar2(10)) name from dual connect by level
--分析表
BEGIN
  SYS.DBMS_STATS.GATHER_TABLE_STATS (
      OwnName        => user
     ,TabName        => 'T'
    ,Estimate_Percent  => NULL
    ,Method_Opt        => 'FOR ALL COLUMNS SIZE 1 '
    ,Degree            => 4
    ,Cascade           => TRUE
    ,No_Invalidate     => TRUE);
END;
/

--建立sql plan baseline,忽略...

create index i_t_id on t(id);

select sql_handle, plan_name, enabled, accepted,fixed,origin,signature from dba_sql_plan_baselines ;

--为了后面能操作比较快,我定义如下变量:

variable v_sql_handle      varchar2(30);
variable v_plan_name_full  varchar2(30);
variable v_plan_name_index varchar2(30);
exec :v_sql_handle      := 'SYS_SQL_a45a9e109f85e5a4'
exec :v_plan_name_full  := 'SQL_PLAN_a8qny22gsbtd494ecae5c'
exec :v_plan_name_index := 'SQL_PLAN_a8qny22gsbtd40893a4b2'

1.理解FIXED=yes|NO

 如果FIXED=NO,如果存在多个执行计划(当然enabled=yes,aceepted=yes),oracle应该选择cosing最小的那个.
如果存在多个计划并且仅仅1个FIXED=yes,oracle将使用这个计划.
如果存在多个计划并且仅仅多个FIXED=yes,oracle将使用costing最小的执行计划.

SQL> select sql_handle, plan_name, enabled, accepted,fixed,origin,signature from dba_sql_plan_baselines ;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN                       SIGNATURE
------------------------------ ------------------------------ --- --- --- -------------- -----------------------
SYS_SQL_a45a9e109f85e5a4       SQL_PLAN_a8qny22gsbtd40893a4b2 YES NO  NO  AUTO-CAPTURE      11842951964357158308
SYS_SQL_a45a9e109f85e5a4       SQL_PLAN_a8qny22gsbtd494ecae5c YES YES NO  MANUAL-LOAD       11842951964357158308

exec :v_report := DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE(sql_handle => :v_sql_handle);
exec :v_basenum := DBMS_SPM.ALTER_SQL_PLAN_BASELINE (sql_handle =>:v_sql_handle',plan_name=> :v_plan_name_full,attribute_name=>'FIXED',attribute_value=>'YES');

SQL> select sql_handle, plan_name, enabled, accepted,fixed,origin,signature from dba_sql_plan_baselines ;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN                       SIGNATURE
------------------------------ ------------------------------ --- --- --- -------------- -----------------------
SYS_SQL_a45a9e109f85e5a4       SQL_PLAN_a8qny22gsbtd40893a4b2 YES YES NO  AUTO-CAPTURE      11842951964357158308
SYS_SQL_a45a9e109f85e5a4       SQL_PLAN_a8qny22gsbtd494ecae5c YES YES YES MANUAL-LOAD       11842951964357158308

select * from t where id=:x;
SQL> @dpc
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID  3yxwagyspybax, child number 1
-------------------------------------
select * from t where id=:x

Plan hash value: 1601196873

--------------------------------------------------------
| Id  | Operation         | Name | E-Rows | Cost (%CPU)|
--------------------------------------------------------
|   0 | SELECT STATEMENT  |      |        |    69 (100)|
|*  1 |  TABLE ACCESS FULL| T    |      1 |    69   (2)|
--------------------------------------------------------

Peeked Binds (identified by position):
--------------------------------------

   1 - (NUMBER): 100

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("ID"=:X)

Note
-----
   - SQL plan baseline SQL_PLAN_a8qny22gsbtd494ecae5c used for this statement

--执行计划并没有选择索引扫描。把走index的基线也设置fixed=yes

exec :v_basenum := DBMS_SPM.ALTER_SQL_PLAN_BASELINE (sql_handle =>:v_sql_handle,plan_name=> :v_plan_name_index,attribute_name=>'FIXED',attribute_value=>'YES')
SQL> select sql_handle, plan_name, enabled, accepted,fixed,origin,signature from dba_sql_plan_baselines ;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN                       SIGNATURE
------------------------------ ------------------------------ --- --- --- -------------- -----------------------
SYS_SQL_a45a9e109f85e5a4       SQL_PLAN_a8qny22gsbtd40893a4b2 YES YES YES AUTO-CAPTURE      11842951964357158308
SYS_SQL_a45a9e109f85e5a4       SQL_PLAN_a8qny22gsbtd494ecae5c YES YES YES MANUAL-LOAD       11842951964357158308

select * from t where id=:x;
SQL> @dpc
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
SQL_ID  3yxwagyspybax, child number 1
-------------------------------------
select * from t where id=:x

Plan hash value: 4153437776

--------------------------------------------------------------------
| Id  | Operation                   | Name   | E-Rows | Cost (%CPU)|
--------------------------------------------------------------------
|   0 | SELECT STATEMENT            |        |        |     2 (100)|
|   1 |  TABLE ACCESS BY INDEX ROWID| T      |      1 |     2   (0)|
|*  2 |   INDEX RANGE SCAN          | I_T_ID |      1 |     1   (0)|
--------------------------------------------------------------------

Peeked Binds (identified by position):
--------------------------------------

   1 - (NUMBER): 100

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("ID"=:X)

Note
-----
   - SQL plan baseline SQL_PLAN_a8qny22gsbtd40893a4b2 used for this statement

2.如果任何一个计划fixed=yes,oracle将停止捕获和evolv新的计划.把使用索引的执行计划fixed=NO,accepted=NO
--    Also, if any of the plan is marked as fixed, oracle will stop capturing and evolving new plans.To simulate the test, lets
--again mark the plan(using index) as fixed=no and accepted=no.

exec :v_basenum := DBMS_SPM.drop_sql_plan_baseline (sql_handle =>:v_sql_handle,plan_name=> :v_plan_name_index);

SQL> select sql_handle, plan_name, enabled, accepted,fixed,origin,signature from dba_sql_plan_baselines ;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN                       SIGNATURE
------------------------------ ------------------------------ --- --- --- -------------- -----------------------
SYS_SQL_a45a9e109f85e5a4       SQL_PLAN_a8qny22gsbtd494ecae5c YES YES YES MANUAL-LOAD       11842951964357158308

select * from t where id=:x
SQL> @dpc
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID  3yxwagyspybax, child number 1
-------------------------------------
select * from t where id=:x
Plan hash value: 1601196873
--------------------------------------------------------
| Id  | Operation         | Name | E-Rows | Cost (%CPU)|
--------------------------------------------------------
|   0 | SELECT STATEMENT  |      |        |    69 (100)|
|*  1 |  TABLE ACCESS FULL| T    |      1 |    69   (2)|
--------------------------------------------------------
Peeked Binds (identified by position):
-------------------------------------
   1 - (NUMBER): 100
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter("ID"=:X)
Note
-----
   - SQL plan baseline SQL_PLAN_a8qny22gsbtd494ecae5c used for this statement

SQL> select sql_handle, plan_name, enabled, accepted,fixed,origin,signature from dba_sql_plan_baselines ;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN                       SIGNATURE
------------------------------ ------------------------------ --- --- --- -------------- -----------------------
SYS_SQL_a45a9e109f85e5a4       SQL_PLAN_a8qny22gsbtd494ecae5c YES YES YES MANUAL-LOAD       11842951964357158308
--视图dba_sql_plan_baselines里面仅仅一条记录。

exec :v_basenum := DBMS_SPM.ALTER_SQL_PLAN_BASELINE (sql_handle =>:v_sql_handle,plan_name=> :v_plan_name_full,attribute_name=>'FIXED',attribute_value=>'NO');
select * from t where id=:x;
exec :v_basenum := DBMS_SPM.ALTER_SQL_PLAN_BASELINE (sql_handle =>:v_sql_handle,plan_name=> :v_plan_name_full,attribute_name=>'FIXED',attribute_value=>'YES');

SQL> select sql_handle, plan_name, enabled, accepted,fixed,origin,signature from dba_sql_plan_baselines ;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN                       SIGNATURE
------------------------------ ------------------------------ --- --- --- -------------- -----------------------
SYS_SQL_a45a9e109f85e5a4       SQL_PLAN_a8qny22gsbtd40893a4b2 YES NO  NO  AUTO-CAPTURE      11842951964357158308
SYS_SQL_a45a9e109f85e5a4       SQL_PLAN_a8qny22gsbtd494ecae5c YES YES YES MANUAL-LOAD       11842951964357158308

variable v_report clob;
exec :v_report := DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE(sql_handle => :v_sql_handle);
SQL> print :v_report
V_REPORT
-----------------------------------------------------------------------------------------

-------------------------------------------------------------------------------
                        Evolve SQL Plan Baseline Report
-------------------------------------------------------------------------------

Inputs:
-------
  SQL_HANDLE = SYS_SQL_a45a9e109f85e5a4
  PLAN_NAME  =
  TIME_LIMIT = DBMS_SPM.AUTO_LIMIT
  VERIFY     = YES
  COMMIT     = YES

-------------------------------------------------------------------------------
                                 Report Summary
-------------------------------------------------------------------------------
There were no SQL plan baselines that required processing.

SQL> select sql_handle, plan_name, enabled, accepted,fixed,origin,signature from dba_sql_plan_baselines ;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN                       SIGNATURE
------------------------------ ------------------------------ --- --- --- -------------- -----------------------
SYS_SQL_a45a9e109f85e5a4       SQL_PLAN_a8qny22gsbtd40893a4b2 YES NO  NO  AUTO-CAPTURE      11842951964357158308
SYS_SQL_a45a9e109f85e5a4       SQL_PLAN_a8qny22gsbtd494ecae5c YES YES YES MANUAL-LOAD       11842951964357158308
--走索引的基线accepted依旧是NO。

exec :v_basenum := DBMS_SPM.ALTER_SQL_PLAN_BASELINE (sql_handle =>:v_sql_handle,plan_name=> :v_plan_name_full,attribute_name=>'FIXED',attribute_value=>'NO');
exec :v_report := DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE(sql_handle => :v_sql_handle);
exec :v_basenum := DBMS_SPM.ALTER_SQL_PLAN_BASELINE (sql_handle =>:v_sql_handle,plan_name=> :v_plan_name_full,attribute_name=>'FIXED',attribute_value=>'YES');
SQL> select sql_handle, plan_name, enabled, accepted,fixed,origin,signature from dba_sql_plan_baselines ;
SQL_HANDLE                     PLAN_NAME                      ENA ACC FIX ORIGIN                       SIGNATURE
------------------------------ ------------------------------ --- --- --- -------------- -----------------------
SYS_SQL_a45a9e109f85e5a4       SQL_PLAN_a8qny22gsbtd40893a4b2 YES YES NO  AUTO-CAPTURE      11842951964357158308
SYS_SQL_a45a9e109f85e5a4       SQL_PLAN_a8qny22gsbtd494ecae5c YES YES YES MANUAL-LOAD       11842951964357158308

select * from t where id=:x;
SQL> @dpc
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID  3yxwagyspybax, child number 1
-------------------------------------
select * from t where id=:x
Plan hash value: 1601196873
--------------------------------------------------------
| Id  | Operation         | Name | E-Rows | Cost (%CPU)|
--------------------------------------------------------
|   0 | SELECT STATEMENT  |      |        |    69 (100)|
|*  1 |  TABLE ACCESS FULL| T    |      1 |    69   (2)|
--------------------------------------------------------
Peeked Binds (identified by position):
--------------------------------------
   1 - (NUMBER): 100
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter("ID"=:X)
Note
-----
   - SQL plan baseline SQL_PLAN_a8qny22gsbtd494ecae5c used for this statement
--可以发现执行计划选择的全表扫描。并没有选择index range scan。

Here's the quick summary,
1.  ENABLED=YES (For any of the plan) :- Oracle will start capturing new plans for those queries.
2. Enabled=NO :-  Than plan won't we used.
3.  Accepted=Yes (Any one Plan) :- That plan will be used for execution
4.  Accepted=YES (For Multiple plans):- Any one plan can be used if fixed=no for all plans.
5. Accepted=No: Plan won't be used.
6.  FIXED=YES (for only one plan) Only that plan will be used and oracle will stop capturing/evolving new plans.
7.  FIXED=YES (for many plans) Oracle will chose execution plan only from that pool.



目录
相关文章
|
机器学习/深度学习 人工智能 算法
人工智能的伦理困境与未来挑战
【8月更文挑战第13天】 本文旨在探讨人工智能技术发展过程中所面临的伦理问题和未来的挑战。随着AI技术的不断进步,其在社会中的作用日益重要,但同时也引发了一系列伦理问题,如隐私保护、自动化失业、算法偏见等。文章将分析这些伦理问题的具体表现,并讨论如何在技术创新的同时,确保AI的发展能够符合社会伦理标准,促进人类社会的和谐发展。
266 0
|
11月前
|
数据挖掘 BI 数据安全/隐私保护
【今日小贴士】自定义水印~
【今日小贴士】自定义水印~
|
机器学习/深度学习 数据采集 DataWorks
DataWorks产品评测:数据处理与分析的最佳实践
DataWorks是阿里巴巴推出的大数据开发治理平台,支持从数据采集、预处理、存储到分析的全流程操作。本文评测了其在用户画像分析中的应用,包括数据收集、清洗、特征工程、模型训练、结果评估及应用部署等步骤,展示了其在提高数据资产管理效率、支持多种编程语言和技术栈、集成丰富可视化工具等方面的优势。同时,文章也指出了DataWorks在使用过程中的一些不便与问题,并提出了改进建议。
391 17
|
人工智能 供应链 数据挖掘
跨境电商目前现状
2024年,跨境电商市场持续增长,全球市场规模预计达2.1万亿美元,中国跨境电商进出口额达1.22万亿元。行业竞争加剧,技术创新和政策支持成为重要推动力。市场多元化趋势明显,新兴市场增长迅速,销售渠道多样化,但海外政策调整带来一定挑战。
如何用宜搭1分钟搞定消息通知
消息通知是在流程表单发起编辑等阶段操作后或者设置定时规则定时通知指定人员的功能
3409 0
如何用宜搭1分钟搞定消息通知
|
存储 编解码 Serverless
C语言实现DFT计算
本文主要介绍了利用C语言实现DFT计算的思路并给出了程序设计
799 0
|
存储 数据处理 对象存储
R语言-稀疏矩阵对象格式介绍&重构方法
在单细胞领域,基于稀疏矩阵对于处理 scRNA-seq 表达谱数据这类大型数据是非常必要的,因为构建分析对象的时候稀疏矩阵相比稠密矩阵拥有更高的数据处理效率和速度。本文重点介绍 在R语言平台关于 Matrix包中Sparse Matrix对象的格式, 与Dense Matrix的转换以及重构方法。
1167 0
R语言-稀疏矩阵对象格式介绍&重构方法
|
存储
蓝桥杯第十二讲--图论【习题】(二)
蓝桥杯第十二讲--图论【习题】
192 0
蓝桥杯第十二讲--图论【习题】(二)
|
网络协议 前端开发 应用服务中间件
Docker 容器网络配置
Docker 容器网络配置
794 0