baseline学习1
来源:互联网 发布:淘宝优惠券生成淘口令 编辑:程序博客网 时间:2024/05/17 02:59
1.有关的两个参数
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_capture_sql_plan_baselines boolean TRUE
optimizer_use_sql_plan_baselines boolean TRUE
SQL> create table t1 nologging as select object_id,created from dba_objects;
Table created.
SQL> alter session set nls_data_format='yyyy/mm/dd hh24:mi:ss';
alter session set nls_data_format='yyyy/mm/dd hh24:mi:ss'
*
ERROR at line 1:
ORA-00922: missing or invalid option
SQL> alter session set nls_date_format='yyyy/mm/dd hh24:mi:ss';
Session altered.
SQL> exec :object_id :=72443
PL/SQL procedure successfully completed.
SQL> exec :created :='2010/09/05 06:16:41'
PL/SQL procedure successfully completed.
SQL>
SQL> set autot traceonly exp stat
SQL> select * from t1 where object_id=:object_id and created=:created;
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 8 | 176 | 46 (3)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 8 | 176 | 46 (3)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID"=TO_NUMBER(:OBJECT_ID) AND "CREATED"=:CREATED)
Note
-----
- dynamic sampling used for this statement (level=2)
- SQL plan baseline "SQL_PLAN_975htc2jdg7m8dbd90e8e" used for this statement
Statistics
----------------------------------------------------------
40 recursive calls
52 db block gets
289 consistent gets
181 physical reads
5848 redo size
406 bytes sent via SQL*Net to client
513 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> /
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 8 | 176 | 46 (3)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 8 | 176 | 46 (3)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID"=TO_NUMBER(:OBJECT_ID) AND "CREATED"=:CREATED)
Note
-----
- dynamic sampling used for this statement (level=2)
- SQL plan baseline "SQL_PLAN_975htc2jdg7m8dbd90e8e" used for this statement
Statistics
----------------------------------------------------------
5 recursive calls
0 db block gets
257 consistent gets
41 physical reads
0 redo size
406 bytes sent via SQL*Net to client
513 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> exec dbms_stats.gather_table_stats(user,'t1');
PL/SQL procedure successfully completed.
SQL> l
1* select * from t1 where object_id=:object_id and created=:created
SQL> /
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 46 (3)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 1 | 13 | 46 (3)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID"=TO_NUMBER(:OBJECT_ID) AND "CREATED"=:CREATED)
Note
-----
- SQL plan baseline "SQL_PLAN_975htc2jdg7m8dbd90e8e" used for this statement
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
184 consistent gets
0 physical reads
0 redo size
406 bytes sent via SQL*Net to client
513 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> create index idx_object_id on t1(object_id);
Index created.
SQL> create index idx_created on t1(created);
Index created.
SQL> l
1* create index idx_created on t1(created)
SQL> select * from t1 where object_id=:object_id and created=:created;
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 46 (3)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 1 | 13 | 46 (3)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID"=TO_NUMBER(:OBJECT_ID) AND "CREATED"=:CREATED)
Note
-----
- SQL plan baseline "SQL_PLAN_975htc2jdg7m8dbd90e8e" used for this statement
Statistics
----------------------------------------------------------
26 recursive calls
35 db block gets
219 consistent gets
2 physical reads
4056 redo size
406 bytes sent via SQL*Net to client
513 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> /
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 46 (3)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 1 | 13 | 46 (3)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID"=TO_NUMBER(:OBJECT_ID) AND "CREATED"=:CREATED)
Note
-----
- SQL plan baseline "SQL_PLAN_975htc2jdg7m8dbd90e8e" used for this statement
Statistics
----------------------------------------------------------
6 recursive calls
5 db block gets
185 consistent gets
0 physical reads
96 redo size
406 bytes sent via SQL*Net to client
513 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> exec dbms_stats.gather_table_stats(user,'t1',cascade=>true);
PL/SQL procedure successfully completed.
SQL> l
1* select * from t1 where object_id=:object_id and created=:created
SQL> /
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 46 (3)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 1 | 13 | 46 (3)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID"=TO_NUMBER(:OBJECT_ID) AND "CREATED"=:CREATED)
Note
-----
- SQL plan baseline "SQL_PLAN_975htc2jdg7m8dbd90e8e" used for this statement
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
183 consistent gets
0 physical reads
0 redo size
406 bytes sent via SQL*Net to client
513 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
--将全表扫描的PLAN_NAME=‘SQL_PLAN_975htc2jdg7m8dbd90e8e’ DISABLE
SQL> DECLARE
2 l_plans_altered PLS_INTEGER;
3 BEGIN
4 l_plans_altered := DBMS_SPM.alter_sql_plan_baseline(
5 sql_handle => 'SQL_93961960a2d79e68',
6 plan_name => 'SQL_PLAN_975htc2jdg7m8dbd90e8e',
7 attribute_name => 'ENABLED',
8 attribute_value => 'NO');
9 DBMS_OUTPUT.put_line('Plans Altered: ' || l_plans_altered);
10 END;
11 /
Plans Altered: 1
PL/SQL procedure successfully completed.
可以看到已经走回正常的执行计划
1* select * from t1 where object_id=:object_id and created=:created
SQL> /
Execution Plan
----------------------------------------------------------
Plan hash value: 2724989281
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 2 (0)| 00:00:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID| T1 | 1 | 13 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_OBJECT_ID | 1 | | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("CREATED"=:CREATED)
2 - access("OBJECT_ID"=TO_NUMBER(:OBJECT_ID))
删除baseline
SQL> declare
2 n PLS_INTEGER;
3 begin
4 n :=DBMS_SPM.DROP_SQL_PLAN_BASELINE (
5 sql_handle=>'SQL_93961960a2d79e68',
6 plan_name=> NULL)
7 ;
8 dbms_output.put_line(n);
9 end;
10 /
PL/SQL procedure successfully completed.
相对应的文档语法
DROP_SQL_PLAN_BASELINE Function
This function drops a single plan, or all plans associated with a SQL statement.
Syntax
DBMS_SPM.DROP_SQL_PLAN_BASELINE (
sql_handle IN VARCHAR2 := NULL,
plan_name IN VARCHAR2
这里有个问题,删除完baseline后,在同一个会话中,再次执行同样的主句,并不会被系统重新自动捕获;
1* select * from t1 where object_id=:object_id and created=:created
SQL> /
Execution Plan
----------------------------------------------------------
Plan hash value: 2724989281
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 2 (0)| 00:00:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID| T1 | 1 | 13 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_OBJECT_ID | 1 | | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("CREATED"=:CREATED)
2 - access("OBJECT_ID"=TO_NUMBER(:OBJECT_ID))
而需要重新新开一个会话执行
1* select * from t1 where object_id=:object_id and created=:created
SQL> /
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 2724989281
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 2 (0)| 00:00:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID| T1 | 1 | 13 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_OBJECT_ID | 1 | | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("CREATED"=:CREATED)
2 - access("OBJECT_ID"=TO_NUMBER(:OBJECT_ID))
Note
-----
- SQL plan baseline "SQL_PLAN_975htc2jdg7m890704d19" used for this statement
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
406 bytes sent via SQL*Net to client
513 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
- baseline学习1
- BaseLine
- 新炬网络Using Baseline学习笔记
- Oracle 11g 学习笔记 Using Baseline
- JPEG(baseline)压缩综述(3-1)
- 安卓开发学习之003 LinearLayout之baseLine详解
- Microsoft Baseline Security Analyzer 1.2.1安全性检查
- oracle 11g sql plan baseline(1)基本使用
- 迁移baseline
- Android 布局学习之——LinearLayout属性baselineAligned的作用及baseline
- Android 布局学习之——LinearLayout属性baselineAligned的作用及baseline
- 机器学习实践指南(二)—— 作为 baseline 的 SVM(scikit-learn)
- [Paper 学习笔记]PCANet: A Simple Deep Learning Baseline for Image Classification?
- Android ApiDemos示例解析(139):Views->Layouts->Baseline->Nested Example 1
- 什么是基线(Baseline)?
- DB2 Architect Baseline
- android:baseLine介绍
- 创建AWR 基线(baseline
- Java中遍历文件夹的2种方法
- retain cycle
- android HAL层驱动对接实例
- 给列表设颜色选择器
- 函数strstr()
- baseline学习1
- 23岁生日,写给自己
- Zend Debugger的安装
- ADB不能使用
- 英语词汇
- Spring整合Hibernate的步骤
- Database design basics
- 求不规则图形外接圆的算法 (附:三角形外接圆计算公式)
- 高效的sql-如何做