- 爱易网页
-
数据库教程
- oracle储存提纲(stored outline)
日期:2014-05-16 浏览次数:20456 次
oracle存储提纲(stored outline)
oracle存储提纲(stored outline)用来提供稳定的执行计划。从oracle 11g开始,逐渐被sql计划继续取代。下面是存储提纲的具体过程,结果在oracle 11g r2版本测试
--创建测试表和索引
create table oln_test as select * from dba_tables;
set autotrace on;
SQL> create index idex_oln on oln_test (TABLE_NAME);
SQL> select OWNER from oln_test where table_name = 'OLN_TEST';
----------------------
Plan hash value: 3038230087
----------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 34 | 1 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| OLN_TEST | 1 | 34 | 1 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDEX_OLN | 1 | | 1 (0)| 00:00:01 |
----------------------------------------------------
SQL> select /*+FULL(oln_test)*/ OWNER from oln_test where table_name = 'OLN_TEST';
----------------------
Plan hash value: 1307524366
------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 34 | 13 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| OLN_TEST | 1 | 34 | 13 (0)| 00:00:01 |
------------------------------------------
-- 生成outline
-- Create the OUTLINE for ORIGINALSQL
CREATE OR REPLACE OUTLINE oln_to ON
select OWNER from oln_test where table_name = 'OLN_TEST';
-- Create the OUTLINE for HINTSQL
CREATE OR REPLACE OUTLINE oln_hint ON
select /*+FULL(oln_test)*/ OWNER from oln_test where table_name = 'OLN_TEST';
-- 交换outline
方法1:直接更新DBA_OUTLINES表(oracle官方不推荐)
SQL> conn / as sysdba
UPDATE DBA_OUTLINES
SET NAME=DECODE(NAME,'OLN_HINT','OLN_TO','OLN_TO','OLN_HINT')
WHERE NAME IN ('OLN_TO','OLN_HINT');
commit;
--验证结果,已使用outline
SQL> select OWNER from oln_test where table_name = 'OLN_TEST';
----------------------------------------------
Plan hash value: 1307524366
------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------
| 0 | SELECT STATEMENT | | 33 | 1122 | 13 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| OLN_TEST | 33 | 1122 | 13 (0)| 00:00:01 |
------------------------------------------
Note
-----
- outline "OLN_HINT" used for this statement