利用outline固定执行计划

来源:互联网 发布:sap 物料主数据 编辑:程序博客网 时间:2024/06/05 04:33
登录scott创建实验用表TEST1:create table test1 (name varchar2(10));
插入数据:insert into test1 values('luyang'); 
 insert into test1(name) values('zhengda');
          insert into test1(name) values('sunyi');
 insert into test1(name) values('lixuefei');
 




1、管理员用户授权
grant create any outline to scott;




2、登录scott用户创建outline
create or replace outline TEST1_OUTLINE
for category demo on
select * from test1 where name='luyang';




3、查看概要是否生成
COL NAME FOR A30
COL CATEGORY FOR A10
COL SQL_TEXT FOR A30
select name, category, used, sql_text
from user_outlines
where category = 'DEMO';


NAME                           CATEGORY   USED   SQL_TEXT
------------------------------ ---------- ------ ------------------------------
TEST1_OUTLINE                  DEMO       UNUSED select * from test1 where name
                                                 ='luyang'


4、修改OUTLN用户密码、解锁
alter user outln account unlock identified by outln;




5、使用outln用户,exp导出outline的数据
exp outln/outln tables=OL\$,OL\$HINTS file=ol.dmp log=ol.log






以上是在我的10G库上的操作
*********************************************************************************************************
以下是在我的11G库上的操作




6、使用outln用户,导入outline数据
imp outln/outln file=c:\ol.dmp ignore=y log=c:\ol.log;






7、使用sys用户更新outline的signature
exec dbms_outln.update_signatures;
启用stored outline
alter system set use_stored_outlines=demo; 




8、检查outlines是否被使用
conn scott/tiger
create index ind_test1 on test1(name);
set autotrace trace explain;
select * from test1 where name='luyang';


Execution Plan
----------------------------------------------------------
Plan hash value: 4122059633


---------------------------------------------------------------------------
| Id  | Operation         | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |       |     1 |     7 |     3   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| TEST1 |     1 |     7 |     3   (0)| 00:00:01 |
---------------------------------------------------------------------------


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


   1 - filter("NAME"='luyang')


Note
-----
   - outline "TEST1_OUTLINE" used for this statement


注意执行计划指出online已经使用
说明outline已经启用。


























停止db使用outline功能: 
alter system set use_stored_outlines=false; 




注意:outline固定执行计划只能针对固定的sql语句,如果上面试验你用select * from scott.test1 where name='luyang';也不会走outline的!















原创粉丝点击