当前位置:网站首页>使用coe_load_sql_profile.sql固定执行计划
使用coe_load_sql_profile.sql固定执行计划
2022-06-25 22:13:00 【文档搬运工】
参考文档:
Directing Plans with Baselines/Profiles Using coe_load_sql_baseline.sql / coe_load_sql_profile.sql (shipped with SQLT) (Doc ID 1400903.1)
-- 在emp上创建索引
[email protected]>create index i_emp_ename on emp(ename);
Index created.
[email protected]>
-- 收集统计信息
exec dbms_stats.gather_table_stats(ownname=>'BB',tabname=>'EMP')
[email protected]>exec dbms_stats.gather_table_stats(ownname=>'BB',tabname=>'EMP');
PL/SQL procedure successfully completed.
[email protected]>
-- 运行原始的SQL
select ename from emp where ename='name';
[email protected]>select ename from emp where ename='name';
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 4001599462
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 1 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| I_EMP_ENAME | 1 | 6 | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("ENAME"='name')
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
1 consistent gets
0 physical reads
0 redo size
548 bytes sent via SQL*Net to client
391 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
[email protected]>
-- 运行加了hint的sql
select /*+ FULL (EMP) */ ename from emp where ename='name';
[email protected]>select /*+ FULL (EMP) */ ename from emp where ename='name';
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 3956160932
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| EMP | 1 | 6 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("ENAME"='name')
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
2 consistent gets
0 physical reads
0 redo size
349 bytes sent via SQL*Net to client
409 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
[email protected]>
-- 查询两个SQL语句的SQL ID和plan hash value ,原始的SQL ID 66q0r9w4df2f5 ,plan hash 4001599462 , 修改后的SQLID 3w056txhg3vdu ,plan hash 3956160932
select sql_id ,plan_hash_value, sql_text from v$sql where sql_text like '%emp%';
select sql_id ,plan_hash_value, sql_text from v$sql where sql_text like '%ename=%'
[email protected]>/
SQL_ID PLAN_HASH_VALUE
------------- ---------------
SQL_TEXT
--------------------------------------------------------------------------------------------------------------------------------------------
bzb3b959pd6yp 4001599462
EXPLAIN PLAN SET STATEMENT_ID='PLUS401365' FOR select ename from emp where ename='name'
66q0r9w4df2f5 4001599462
select ename from emp where ename='name'
3w056txhg3vdu 3956160932
select /*+ FULL (EMP) */ ename from emp where ename='name'
SQL_ID PLAN_HASH_VALUE
------------- ---------------
SQL_TEXT
--------------------------------------------------------------------------------------------------------------------------------------------
3jykb0m137vfj 3956160932
EXPLAIN PLAN SET STATEMENT_ID='PLUS401365' FOR select /*+ FULL (EMP) */ ename from emp where ename='name'
7g6bm1swrzzmv 903671040
select sql_id ,plan_hash_value, sql_text from v$sql where sql_text like '%ename=%'
[email protected]>
-- 使用coe_load_sql_profile.sql
[email protected]>conn system/oracle
ERROR:
ORA-28002: the password will expire within 7 days
Connected.
[email protected]>@/tmp/coe_load_sql_profile.sql
Parameter 1:
ORIGINAL_SQL_ID (required)
Enter value for 1: 66q0r9w4df2f5
Parameter 2:
MODIFIED_SQL_ID (required)
Enter value for 2: 3w056txhg3vdu
PLAN_HASH_VALUE AVG_ET_SECS
-------------------- --------------------
3956160932 .001
Parameter 3:
PLAN_HASH_VALUE (required)
Enter value for 3: 3956160932
Values passed to coe_load_sql_profile:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ORIGINAL_SQL_ID: "66q0r9w4df2f5"
MODIFIED_SQL_ID: "3w056txhg3vdu"
PLAN_HASH_VALUE: "3956160932"
SQL>BEGIN
2 IF :sql_text IS NULL THEN
3 RAISE_APPLICATION_ERROR(-20100, 'SQL_TEXT for original SQL_ID &&original_sql_id. was not found in memory (gv$sqltext_with_newlines) or AWR (dba_hist_sqltext).');
4 END IF;
5 END;
6 /
SQL>SET TERM OFF;
SQL>BEGIN
2 IF :other_xml IS NULL THEN
3 RAISE_APPLICATION_ERROR(-20101, 'PLAN for modified SQL_ID &&modified_sql_id. and PHV &&plan_hash_value. was not found in memory (gv$sql_plan) or AWR (dba_hist_sql_plan).');
4 END IF;
5 END;
6 /
SQL>
SQL>SET ECHO OFF;
0001 BEGIN_OUTLINE_DATA
0002 IGNORE_OPTIM_EMBEDDED_HINTS
0003 OPTIMIZER_FEATURES_ENABLE('19.1.0')
0004 DB_VERSION('19.1.0')
0005 ALL_ROWS
0006 OUTLINE_LEAF(@"SEL$1")
0007 FULL(@"SEL$1" "EMP"@"SEL$1")
0008 END_OUTLINE_DATA
dropping staging table "STGTAB_SQLPROF_66Q0R9W4DF2F5"
staging table "STGTAB_SQLPROF_66Q0R9W4DF2F5" did not exist
creating staging table "STGTAB_SQLPROF_66Q0R9W4DF2F5"
packaging new sql profile into staging table "STGTAB_SQLPROF_66Q0R9W4DF2F5"
PROFILE_NAME
------------------------------
66Q0R9W4DF2F5_3956160932
SQL>REM
SQL>REM SQL Profile
SQL>REM ~~~~~~~~~~~
SQL>REM
SQL>SELECT signature, name, category, type, status
2 FROM dba_sql_profiles WHERE name = :name;
SIGNATURE NAME CATEGORY TYPE STATUS
-------------------- -------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------- ------- --------
10938475214343355302 66Q0R9W4DF2F5_3956160932 DEFAULT MANUAL ENABLED
SQL>SELECT description
2 FROM dba_sql_profiles WHERE name = :name;
DESCRIPTION
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ORIGINAL:66Q0R9W4DF2F5 MODIFIED:3W056TXHG3VDU PHV:3956160932 SIGNATURE:10938475214343355302 CREATED BY COE_LOAD_SQL_PROFILE.SQL
SQL>SET ECHO OFF;
****************************************************************************
* Enter SYSTEM password to export staging table STGTAB_SQLPROF_66q0r9w4df2f5
****************************************************************************
Export: Release 19.0.0.0.0 - Production on Thu Dec 2 01:49:23 2021
Version 19.5.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
Password:
EXP-00056: ORACLE error 28002 encountered
ORA-28002: the password will expire within 7 days
Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.5.0.0.0
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)
Note: grants on tables/views/sequences/roles will not be exported
Note: indexes on tables will not be exported
Note: constraints on tables will not be exported
About to export specified tables via Conventional Path ...
. . exporting table STGTAB_SQLPROF_66Q0R9W4DF2F5 1 rows exported
Export terminated successfully without warnings.
If you need to implement this Custom SQL Profile on a similar system,
import and unpack using these commands:
imp SYSTEM file=STGTAB_SQLPROF_66q0r9w4df2f5.dmp tables=STGTAB_SQLPROF_66q0r9w4df2f5 ignore=Y
BEGIN
DBMS_SQLTUNE.UNPACK_STGTAB_SQLPROF (
profile_name => '66Q0R9W4DF2F5_3956160932',
replace => TRUE,
staging_table_name => 'STGTAB_SQLPROF_66q0r9w4df2f5',
staging_schema_owner => 'SYSTEM' );
END;
/
adding: coe_load_sql_profile_66q0r9w4df2f5.log (deflated 76%)
adding: STGTAB_SQLPROF_66q0r9w4df2f5.dmp (deflated 86%)
adding: coe_load_sql_profile.log (deflated 62%)
deleting: coe_load_sql_profile.log
coe_load_sql_profile completed.
SQL>
-- 运行原始的SQL语句进行查询 ,可以看到使用了SQL PROFILE。 执行了全表扫描
select ename from emp where ename='name';
[email protected]>select ename from emp where ename='name';
no rows selected
Execution Plan
----------------------------------------------------------
Plan hash value: 3956160932
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| EMP | 1 | 6 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("ENAME"='name')
Note
-----
- SQL profile "66Q0R9W4DF2F5_3956160932" used for this statement
Statistics
----------------------------------------------------------
8 recursive calls
0 db block gets
5 consistent gets
1 physical reads
0 redo size
349 bytes sent via SQL*Net to client
391 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
[email protected]>
-- 官方文档中,使用SQL_base_line (略)
SQL> @coe_load_sql_baseline.sql
Parameter 1:
ORIGINAL_SQL_ID (required)
Enter value for 1: 329d885bxvrcr
Parameter 2:
MODIFIED_SQL_ID (required)
Enter value for 2: 4f74t4ab7rd5y
PLAN_HASH_VALUE AVG_ET_SECS
-------------------- --------------------
2872589290 .003
Parameter 3:
PLAN_HASH_VALUE (required)
Enter value for 3: 2872589290
Values passed to coe_load_sql_baseline:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ORIGINAL_SQL_ID: "329d885bxvrcr"
MODIFIED_SQL_ID: "4f74t4ab7rd5y"
PLAN_HASH_VALUE: " 2872589290"
.
.
.
****************************************************************************
* Enter <User_Name> password to export staging table STGTAB_BASELINE_329d885bxvrcr
****************************************************************************
Export: Release 11.2.0.3.0 - Production on Sun Mar 11 15:08:56 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Password:
.
.
.
deleting: coe_load_sql_baseline.log
coe_load_sql_baseline completed.
-- 查看结果
SQL> select ename from emp where ename='name';
Plan hash value: 2872589290
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| EMP | 1 | 6 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("ENAME"='name')
Note
-----
- SQL plan baseline "329D885BXVRCR_4F74T4AB7RD5Y" used for this statement
END
END
-- 2022-01-06 add
--查询sqlprofile
select * from dba_sql_profiles
-- 清理sqlprofile
DBMS_SQLTUNE.DROP_SQL_PROFILE(name => 'CFASMT43SSN4U_1445457117')
END
边栏推荐
- ValueError: color kwarg must have one color per data set. 9 data sets and 1 colors were provided解决
- 兆欧表电压档位选择_过路老熊_新浪博客
- Redis之哨兵
- 对象数组去重
- 11.1.2、flink概述_Wordcount案例
- 文獻調研(三):數據驅動的建築能耗預測模型綜述
- Bit compressor [Blue Bridge Cup training]
- Some common operation methods of array
- 在step7中实现模拟量数值与工程量数值之间的转换_过路老熊_新浪博客
- Lazy people teach you to use kiwi fruit to lose 16 kg in a month_ Old bear passing by_ Sina blog
猜你喜欢
Common problems encountered when creating and publishing packages using NPM
(Reprint) visual explanation of processes and threads
Some common operation methods of array
Search rotation array ii[Abstract dichotomy exercise]
DNS复习
Recommended system design
Alipay payment interface sandbox environment test and integration into an SSM e-commerce project
Recherche documentaire (3): examen des modèles de prévision de la consommation d'énergie des bâtiments fondés sur les données
ASA如何配置端口映射及PAT
Notes on the method of passing items from the spider file to the pipeline in the case of a scratch crawler
随机推荐
寻找翻转数组的最小值[抽象二分]
Rocket之消息存储
文獻調研(三):數據驅動的建築能耗預測模型綜述
10.4.1、數據中臺
Smt贴片加工出现元件立碑的解决方法
搜索旋转数组II[抽象二分练习]
The role of iomanip header file in actual combat
懒人教你用猕猴桃一月饱减16斤_过路老熊_新浪博客
如何绕过SSL验证
别再吃各种维生素C片了,这6种维生素C含量最高的水果
dhcp复习
SMT葡萄球现象解决办法
Implement const in Es5
Topic36——53. Maximum subarray and
Idea common shortcut keys
Talk about singleton mode!
Literature research (I): hourly energy consumption prediction of office buildings based on integrated learning and energy consumption pattern classification
Reading notes on how to connect the network - hubs, routers and routers (III)
Joint simulation of STEP7 and WinCC_ Old bear passing by_ Sina blog
MongoDB的一些基础用法