欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Oracle使用STORED OUTLINE固化执行计划--CURSOR_SHARING

程序员文章站 2022-04-29 20:48:05
...

Oracle执行计划存储纲要和SQL语句之间是一一对应的关系,因此如果我们改变了sql语句中的谓词条件,存储纲要就会失去作用或者说我

Oracle执行计划存储纲要和SQL语句之间是一一对应的关系,,因此如果我们改变了sql语句中的谓词条件,存储纲要就会失去作用或者说我们需要创建新的存储纲要来巩固执行计划,为了避免这种情况,我们可以使用变量来替代文本信息。

在没有使用绑定变量的情况下:

SQL> show user
USER 为 "EASY1"
SQL> select * from tab;

TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
T1 TABLE

SQL> select ol_name,creator from outln.ol$;

未选定行

SQL> create outline outline1 on select count(*) from t1 where object_id

大纲已创建。

SQL> set autotrace on explain
SQL> alter session set use_stored_outlines=true;

会话已更改。

SQL> select count(*) from t1 where object_id

COUNT(*)
----------
98


执行计划
----------------------------------------------------------
Plan hash value: 3900446664

--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 13 | | |
|* 2 | INDEX RANGE SCAN| I1 | 4411 | 57343 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------

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

2 - access("OBJECT_ID"

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

SQL> select count(*) from t1 where object_id

COUNT(*)
----------
192


执行计划
----------------------------------------------------------
Plan hash value: 3900446664

--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 2 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 13 | | |
|* 2 | INDEX RANGE SCAN| I1 | 192 | 2496 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------

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

2 - access("OBJECT_ID"

Note
-----
- dynamic sampling used for this statement (level=2)

Oracle使用STORED OUTLINE固化执行计划--CURSOR_SHARING