Maison >base de données >tutoriel mysql >Oracle使用STORED OUTLINE固化执行计划--CURSOR_SHARING
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)