使用sql baseline替换执行计划
发表于:2024-10-31 作者:千家信息网编辑
千家信息网最后更新 2024年10月31日,1.分别执行下列SQL点击(此处)折叠或打开SQL1:select /*www1*/ /*+ full(LOGIN_LOG) */IP_ADDRESS from LOGIN_LOG where ses
千家信息网最后更新 2024年10月31日使用sql baseline替换执行计划
1.分别执行下列SQL
点击(此处)折叠或打开
- SQL1:select /*www1*/ /*+ full(LOGIN_LOG) */IP_ADDRESS from LOGIN_LOG where session_id=1273523;
- SQL2:select /*www2*/ /*+ index(LOGIN_LOG LOGIN_LOG_PK) */IP_ADDRESS from LOGIN_LOG where session_id=1273523;
2.查看SQL_ID和PLAN_HASH_VALUE
点击(此处)折叠或打开
- select * from v$sql where sql_text like '%www1%'
- select * from v$sql where sql_text like '%www2%'
- SQL1: 2pqkr80bqn6wb 3779830307
- SQL2: 7510s3wam524g 3865870674
3.查看执行计划
点击(此处)折叠或打开
- SQL1
- SQL> select * from table(dbms_xplan.display_cursor('2pqkr80bqn6wb','',''));
- PLAN_TABLE_OUTPUT
- --------------------------------------------------------------------------------
- SQL_ID 2pqkr80bqn6wb, child number 0
- -------------------------------------
- select /*www1*/ /*+ full(LOGIN_LOG) */IP_ADDRESS from LOGIN_LOG where
- session_id=1273523
- Plan hash value: 3779830307
- -------------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
- -------------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | | | 95461 (100)| |
- PLAN_TABLE_OUTPUT
- --------------------------------------------------------------------------------
- |* 1 | TABLE ACCESS FULL| LOGIN_LOG | 286K| 10M| 95461 (1)| 00:19:06 |
- -------------------------------------------------------------------------------
- Predicate Information (identified by operation id):
- ---------------------------------------------------
- 1 - filter("SESSION_ID"=1273523)
- 19 rows selected.
- SQL2
- SQL> select * from table(dbms_xplan.display_cursor('7510s3wam524g','',''));
- PLAN_TABLE_OUTPUT
- --------------------------------------------------------------------------------
- SQL_ID 7510s3wam524g, child number 0
- -------------------------------------
- select /*www2*/ /*+ index(LOGIN_LOG LOGIN_LOG_PK) */IP_ADDRESS from
- LOGIN_LOG where session_id=1273523
- Plan hash value: 3865870674
- --------------------------------------------------------------------------------
- ------------
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)
- PLAN_TABLE_OUTPUT
- --------------------------------------------------------------------------------
- | Time |
- --------------------------------------------------------------------------------
- ------------
- | 0 | SELECT STATEMENT | | | | 3433 (100)
- | |
- | 1 | TABLE ACCESS BY INDEX ROWID| LOGIN_LOG | 286K| 10M| 3433 (1)
- | 00:00:42 |
- PLAN_TABLE_OUTPUT
- --------------------------------------------------------------------------------
- |* 2 | INDEX RANGE SCAN | LOGIN_LOG_PK | 114K| | 3 (0)
- | 00:00:01 |
- --------------------------------------------------------------------------------
- ------------
- Predicate Information (identified by operation id):
- ---------------------------------------------------
- 2 - access("SESSION_ID"=1273523)
- PLAN_TABLE_OUTPUT
- --------------------------------------------------------------------------------
- 20 rows selected.
4.从库缓存中为SQL1创建baseline
点击(此处)折叠或打开
- DECLARE
- l_plans_loaded PLS_INTEGER;
- BEGIN
- l_plans_loaded := DBMS_SPM.load_plans_from_cursor_cache(sql_id => '2pqkr80bqn6wb',plan_hash_value=>'3779830307');
- END;
- /
- select sql_handle,plan_name,dbms_lob.substr(sql_text,60,1) sql_text,ACCEPTED from dba_sql_plan_baselines;
- SQL_d3e16c6839796f24 SQL_PLAN_d7sbcd0wrkvt433a13db8 select /*www1*/ /*+ full(LOGIN_LOG) */IP_ADDRESS from LOGIN_ YES
5.将符合我们预期的SQL2的执行计划的载入到第一次生成的sql baseline中
点击(此处)折叠或打开
- DECLARE
- k1 pls_integer;
- begin
- k1 := DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE (
- sql_id=>'7510s3wam524g',
- plan_hash_value=>3865870674,sql_handle=>'SQL_d3e16c6839796f24'
- );
- end;
- /
- 基线SQL_d3e16c6839796f24出现2个执行计划
- select sql_handle,plan_name,dbms_lob.substr(sql_text,60,1) sql_text,ACCEPTED from dba_sql_plan_baselines;
- SQL_d3e16c6839796f24 SQL_PLAN_d7sbcd0wrkvt433a13db8 select /*www1*/ /*+ full(LOGIN_LOG) */IP_ADDRESS from LOGIN_ YES
- SQL_d3e16c6839796f24 SQL_PLAN_d7sbcd0wrkvt47b166b46 select /*www1*/ /*+ full(LOGIN_LOG) */IP_ADDRESS from LOGIN_ YES
6.修改原先SQL2执行计划的状态为fixed
点击(此处)折叠或打开
- SET SERVEROUTPUT ON
- DECLARE
- v_text PLS_INTEGER;
- BEGIN
- v_text := DBMS_SPM.alter_sql_plan_baseline(sql_handle => 'SQL_d3e16c6839796f24',plan_name => 'SQL_PLAN_d7sbcd0wrkvt47b166b46',
- attribute_name => 'fixed',attribute_value => 'YES');
- DBMS_OUTPUT.put_line('Plans Altered: ' || v_text );
- END;
- /
- select sql_handle,plan_name,dbms_lob.substr(sql_text,60,1) sql_text,ACCEPTED,FIXED from dba_sql_plan_baselines;
- SQL_d3e16c6839796f24 SQL_PLAN_d7sbcd0wrkvt433a13db8 select /*www1*/ /*+ full(LOGIN_LOG) */IP_ADDRESS from LOGIN_ YES NO
- SQL_d3e16c6839796f24 SQL_PLAN_d7sbcd0wrkvt47b166b46 select /*www1*/ /*+ full(LOGIN_LOG) */IP_ADDRESS from LOGIN_ YES YES
7.原SQL1执行计划被改变
点击(此处)折叠或打开
- SQL> select /*www1*/ /*+ full(LOGIN_LOG) */IP_ADDRESS from LOGIN_LOG where session_id=1273523;
- Execution Plan
- ----------------------------------------------------------
- --------------------------------------------------------------------------------
- -
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)
- |
- --------------------------------------------------------------------------------
- -
- | 0 | SELECT STATEMENT | | 286K| 10M| 3433 (1)
- |
- | 1 | TABLE ACCESS BY INDEX ROWID| LOGIN_LOG | 286K| 10M| 3433 (1)
- |
- | 2 | INDEX RANGE SCAN | LOGIN_LOG_PK | 114K| | 3 (0)
- |
- --------------------------------------------------------------------------------
- -
- Note
- -----
- - 'PLAN_TABLE' is old version
- Statistics
- ----------------------------------------------------------
- 18 recursive calls
- 16 db block gets
- 19 consistent gets
- 4 physical reads
- 11856 redo size
- 541 bytes sent via SQL*Net to client
- 524 bytes received via SQL*Net from client
- 2 SQL*Net roundtrips to/from client
- 0 sorts (memory)
- 0 sorts (disk)
- 1 rows processed
- SQL> select * from table(dbms_xplan.display_cursor('2pqkr80bqn6wb','',''));
- PLAN_TABLE_OUTPUT
- --------------------------------------------------------------------------------
- SQL_ID 2pqkr80bqn6wb, child number 0
- -------------------------------------
- select /*www1*/ /*+ full(LOGIN_LOG) */IP_ADDRESS from LOGIN_LOG where
- session_id=1273523
- Plan hash value: 3779830307
- -------------------------------------------------------------------------------
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
- -------------------------------------------------------------------------------
- | 0 | SELECT STATEMENT | | | | 95461 (100)| |
- PLAN_TABLE_OUTPUT
- --------------------------------------------------------------------------------
- |* 1 | TABLE ACCESS FULL| LOGIN_LOG | 286K| 10M| 95461 (1)| 00:19:06 |
- -------------------------------------------------------------------------------
- Predicate Information (identified by operation id):
- ---------------------------------------------------
- 1 - filter("SESSION_ID"=1273523)
- SQL_ID 2pqkr80bqn6wb, child number 2
- -------------------------------------
- select /*www1*/ /*+ full(LOGIN_LOG) */IP_ADDRESS from LOGIN_LOG where
- PLAN_TABLE_OUTPUT
- --------------------------------------------------------------------------------
- session_id=1273523
- Plan hash value: 3865870674
- --------------------------------------------------------------------------------
- ------------
- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)
- | Time |
- --------------------------------------------------------------------------------
- PLAN_TABLE_OUTPUT
- --------------------------------------------------------------------------------
- ------------
- | 0 | SELECT STATEMENT | | | | 3433 (100)
- | |
- | 1 | TABLE ACCESS BY INDEX ROWID| LOGIN_LOG | 286K| 10M| 3433 (1)
- | 00:00:42 |
- |* 2 | INDEX RANGE SCAN | LOGIN_LOG_PK | 114K| | 3 (0)
- | 00:00:01 |
- PLAN_TABLE_OUTPUT
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- ------------
- Predicate Information (identified by operation id):
- ---------------------------------------------------
- 2 - access("SESSION_ID"=1273523)
- Note
- -----
- PLAN_TABLE_OUTPUT
- --------------------------------------------------------------------------------
- - SQL plan baseline SQL_PLAN_d7sbcd0wrkvt47b166b46 used for this statement
- 43 rows selected.
基线
状态
第一次
缓存
生成
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
陌陌软件开发多少钱
深圳惠敏软件开发怎么样
大者网络技术有限公司
怎么加入新建服务器
盘古网络技术服务有限公司
安全教育日网络安全活动
未来网络安全的发展重点
零基础做软件开发的书籍
数据库管理技术 试题
为知笔记自建服务器如何收藏
辽宁电力应急软件开发检测中心
cepii世界贸易数据库
热点连接找不到服务器是什么意思
万德数据库导出不到exclel
军用服务器 安全
河北ntp网络时间服务器
独立部署数据库
网络安全问题英语面试问题
网信办县级网络安全主要工作
赛扬服务器
小学生网络安全防护宣传语
首部网络安全法
索尼区域链数据库
数据库表的degree
免费文献查询数据库
网络安全保护管理办法
辽宁电力应急软件开发检测中心
当前流行的软件开发工具
周口网络安全工程师认证
关于网络安全的手抄报漂亮的