首頁  >  文章  >  資料庫  >  Oracle使用STORED OUTLINE固化执行计划--CURSOR_SHARING

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

WBOY
WBOY原創
2016-06-07 17:34:411501瀏覽

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)

linux

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn