outline for 绑定变量
1.获取带绑定变量sql的 child_number,hash_value
select child_number,hash_value,address,sql_text from v$sql
where sql_text like 'select * from t where id%';
2.创建outline
begin
dbms_outln.create_outline (
hash_value =>3573770389,
child_number =>0,
category =>'CATE_OUTLINE');
end;
/
- SQL> var v_id number;
- SQL> exec :v_id :=5;
- PL/SQL 过程已成功完成。
- 提交完成。
- SQL> set autot traceonly
- SQL> select * from t where id=:v_id;
- 执行计划
- ----------------------------------------------------------
- Plan hash value: 1601196873
- --------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
- --------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 100 | 1300 | 7 (15)| 00:00:01 |
- |* 1 | TABLE ACCESS FULL| T | 100 | 1300 | 7 (15)| 00:00:01 |
- --------------------------------------------------------------------------
- Predicate Information (identified by operation id):
- ---------------------------------------------------
- 1 - filter("ID"=TO_NUMBER(:V_ID))
- Note
- -----
- - dynamic sampling used for this statement
- 统计信息
- ----------------------------------------------------------
- 0 recursive calls
- 0 db block gets
- 0 consistent gets
- 0 physical reads
- 0 redo size
- 0 bytes sent via SQL*Net to client
- 0 bytes received via SQL*Net from client
- 0 SQL*Net roundtrips to/from client
- 0 sorts (memory)
- 0 sorts (disk)
- 1 rows processed
- SQL> col child_number for 999999999999
- SQL> col hash_values for 999999999999
- SQL> col hash_value for 999999999999
- SQL> col address for a20
- SQL> col sql_text for a50
- SQL> set linesize 200
- SQL> select child_number,hash_value,address,sql_text from v$sql
- 2 where sql_text like 'select * from t where id%';
- CHILD_NUMBER HASH_VALUE ADDRESS SQL_TEXT
- ------------- ------------- -------------------- --------------------------------------------------
- 0 3573770389 22E58344 select * from t where id=:v_id
- SQL> begin
- 2 dbms_outln.create_outline (
- 3 hash_value =>3573770389,
- 4 child_number =>0,
- 5 category =>'CATE_OUTLINE');
- 6 end;
- 7 /
- PL/SQL 过程已成功完成。
- 提交完成。
- SQL> select name, sql_text ,used,category
- 2 from user_outlines
- 3 where category=upper('cate_outline');
- NAME SQL_TEXT USED CATEGORY
- -------------------- -------------------------------------------------- ---------- ------------------------------
- SYS_OUTLINE_12071817 select * from t where id=:v_id UNUSED CATE_OUTLINE
- 153216201
- SQL> alter system set USE_STORED_OUTLINES =cate_outline;
- 系统已更改。
- SQL> set autot traceonly
- SQL> exec :v_id :=1;
- PL/SQL 过程已成功完成。
- 提交完成。
- SQL> select * from t where id=:v_id;
- 执行计划
- ----------------------------------------------------------
- Plan hash value: 1601196873
- --------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
- --------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 16 | 208 | 6 (0)| 00:00:01 |
- |* 1 | TABLE ACCESS FULL| T | 16 | 208 | 6 (0)| 00:00:01 |
- --------------------------------------------------------------------------
- Predicate Information (identified by operation id):
- ---------------------------------------------------
- 1 - filter("ID"=TO_NUMBER(:V_ID))
- Note
- -----
- - outline "SYS_OUTLINE_12071817153216201" used for this statement
- 统计信息
- ----------------------------------------------------------
- 35 recursive calls
- 123 db block gets
- 44 consistent gets
- 0 physical reads
- 632 redo size
- 402 bytes sent via SQL*Net to client
- 385 bytes received via SQL*Net from client
- 2 SQL*Net roundtrips to/from client
- 2 sorts (memory)
- 0 sorts (disk)
- 1 rows processed
- SQL> exec :v_id :=10;
- PL/SQL 过程已成功完成。
- 提交完成。
- SQL> select * from t where id=:v_id;
- 执行计划
- ----------------------------------------------------------
- Plan hash value: 1601196873
- --------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
- --------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 16 | 208 | 6 (0)| 00:00:01 |
- |* 1 | TABLE ACCESS FULL| T | 16 | 208 | 6 (0)| 00:00:01 |
- --------------------------------------------------------------------------
- Predicate Information (identified by operation id):
- ---------------------------------------------------
- 1 - filter("ID"=TO_NUMBER(:V_ID))
- Note
- -----
- - outline "SYS_OUTLINE_12071817153216201" used for this statement
- 统计信息
- ----------------------------------------------------------
- 0 recursive calls
- 0 db block gets
- 24 consistent gets
- 0 physical reads
- 0 redo size
- 402 bytes sent via SQL*Net to client
- 385 bytes received via SQL*Net from client
- 2 SQL*Net roundtrips to/from client
- 0 sorts (memory)
- 0 sorts (disk)
- 1 rows processed
- SQL> create index ind_t_id on t(id);
- 索引已创建。
- SQL> comment on column t.id is 'dddd';
- 注释已创建。
- SQL> select * from t where id=:v_id;
- 执行计划
- ----------------------------------------------------------
- Plan hash value: 1601196873
- --------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
- --------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 16 | 208 | 6 (0)| 00:00:01 |
- |* 1 | TABLE ACCESS FULL| T | 16 | 208 | 6 (0)| 00:00:01 |
- --------------------------------------------------------------------------
- Predicate Information (identified by operation id):
- ---------------------------------------------------
- 1 - filter("ID"=TO_NUMBER(:V_ID))
- Note
- -----
- - outline "SYS_OUTLINE_12071817153216201" used for this statement
- 统计信息
- ----------------------------------------------------------
- 1 recursive calls
- 0 db block gets
- 24 consistent gets
- 0 physical reads
- 0 redo size
- 402 bytes sent via SQL*Net to client
- 385 bytes received via SQL*Net from client
- 2 SQL*Net roundtrips to/from client
- 0 sorts (memory)
- 0 sorts (disk)
- 1 rows processed
- SQL> alter system set use_stored_outlines=false;
- 系统已更改。
- SQL> select * from t where id=:v_id;
- 执行计划
- ----------------------------------------------------------
- Plan hash value: 3343177607
- -----------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
- -----------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | 100 | 1300 | 1 (0)| 00:00:01 |
- |* 1 | INDEX RANGE SCAN| IND_T_ID | 100 | 1300 | 1 (0)| 00:00:01 |
- -----------------------------------------------------------------------------
- Predicate Information (identified by operation id):
- ---------------------------------------------------
- 1 - access("ID"=TO_NUMBER(:V_ID))
- Note
- -----
- - dynamic sampling used for this statement
- 统计信息
- ----------------------------------------------------------
- 13 recursive calls
- 0 db block gets
- 30 consistent gets
- 4 physical reads
- 0 redo size
- 402 bytes sent via SQL*Net to client
- 385 bytes received via SQL*Net from client
- 2 SQL*Net roundtrips to/from client
- 0 sorts (memory)
- 0 sorts (disk)
- 1 rows processed
