SQL profile纵览(10g)

第一篇:介绍    
    10g开始,查询优化器(Query optimizer)扩展成自动调整优化器(Automatic Tuning Optimizer).也就是扩展了功能。此时,我们就可以让它花更多时间来返回更优秀的执行计划。正常情况下,查询优化器要以最快的速度返回执行计划。与此不同的是,自动调整优化器可以花费较长的时间来产生一个高效的执行计划。它会用假设分析(what-if)来核实哪个才是最好的执行计划。sql概要其实也就是一系列的hint。


自动调整优化器是通过SQL调优建议器(SQL Tuning Advisor)来暴露给外界使用的。这个SQL调优建议器能创建一些建议,让Automatic Tuning Optimizer验证一下性能。比如建议收集遗漏或过时的对象统计,创建新索引,改变SQL语句或等。



  使用sql profile架构全图



第二篇:创建调优任务

--利用sql_id创建调优任务
set serveroutput on
declare
l_tuning_task varchar2(40);
begin
  l_tuning_task := dbms_sqltune.create_tuning_task(sql_id=>'b648tmaz9jshp');
  dbms_output.put_line(l_tuning_task);
end;
/
--利用sql文本
--利用AWR中的sql_id
--利用sql tuning set的名称--存储了一系列的SQL语句以及执行化境等信息的集合

第三篇:执行调优任务
-- 执行tuning task
begin
dbms_sqltune.execute_tuning_task('TASK_21822');
end;
/

第四篇:查看建议
select dbms_sqltune.report_tuning_task('TASK_262187') from dual;

第五篇:接受SQL概要
--有些sql概要接受不了,比如建议你加个索引,那这个建议你要接受就自己去建索引就是了,没必要在这里接受sql profile。
begin
sys.dbms_sqltune.accept_sql_profile(
task_name => 'TASK_262187',
task_owner => 'DBMGR',
name  => 'fir',
description =>'the first sql profile',
category =>'test',
replace =>true,
force_match=>true
);
end;
/
name与description是自己指定的sql概要名字与描述
category是处于管理的目的将一些SQL概要集中起来组成的一个类,默认值是default。
replace指定是否需要替换已有的sql概要,默认为false。
force_match指明文本标准化的方式,默认false。设置为true后,文本的大小写空格就不影响判断了。
无论哪个用户执行,格式化后文本一致就会自动重用已经接受的sql概要,也就是一系列的hint.

第五篇:更改SQL概要

--更改sql概要,name为sql概要名称,attribute_name可接受的值是name,descriptino,category,status
--下面的句子是disable一个sql profile,那么query optimizer就不会再用它了。
begin
dbms_sqltune.alter_sql_profile(
name => 'first_rows',
attribute_name => 'status',
value => 'disabled'
);



第七篇:激活SQL概要
要使用sql概要, sqltune_category参数要设置,true时类别default的概要被激活,false时没有sql概要能用,或指定某类别名称。意味着一次只能用一个类别的sql概要
alter session set sqltune_category=true;
alter system set sqltune_category=true;


第七篇:移动SQL概要
从10gR2开始
创建舞台表
begin
dbms_sqltune.create_stgtab_sqlprof(
table_name =>'MYSTGTAB',
schema_name=>user,
tablespace_name=>'USERS');end;

从数据字典复制名为first_rows的SQL概要到舞台表:
dbms_sqltune.pack_stgtab_sqlprof(
profile_name =>'first_rows',
profile_category =>'TEST',
staging_table_name =>'MYSTGTAB',
staging_schema_owner=>user
);

再将sql概要复制回数据字典前必须改变它的名称,同时也对类别做改变。
dbms_sqltune.remap_stgtab_sqlprof(
old_profile_name => 'first_rows',
new_profile_name =>'first_rows_clone',
new_profile_category =>'CLONE',
staging_table_name =>'MYSTGTAB',
stging_schema_owner=>user
);

第六篇:删除SQL概要
--无论是否接受,不再需要tuning task后,最好drop掉。
dbms_sqltune.drop_tuning_task('TASK_262185');

第七篇:视图与解释

--查看sql profile。sql profile不属于某个特定的用户.
select * from dba_sql_profiles;

实验文档.txt


posted on 2013-12-13 16:36  我的小人生  阅读(247)  评论(0编辑  收藏  举报