当前位置:网站首页>使用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
边栏推荐
- (Reprint) visual explanation of processes and threads
- 安装PSU的时候/usr/bin/ld:warning: -z lazyload ignore
- Lazy people teach you to use kiwi fruit to lose 16 kg in a month_ Old bear passing by_ Sina blog
- 手工制作 pl-2303hx 的USB轉TTL電平串口的電路_過路老熊_新浪博客
- 贴片加工厂家讲解__ICT是什么?主要测试什么?ICT测试的优缺点?
- Using swiper to realize the rotation chart
- 11.1.1、flink概述_flink概述
- 正则表达式介绍及一些语法
- SMT操作员是做什么的?工作职责?
- 详解synchronize关键字
猜你喜欢

手工制作 pl-2303hx 的USB轉TTL電平串口的電路_過路老熊_新浪博客

POSTMAN测试出现SSL无响应

手工制作 pl-2303hx 的USB转TTL电平串口的电路_过路老熊_新浪博客

Recherche documentaire (3): examen des modèles de prévision de la consommation d'énergie des bâtiments fondés sur les données

Simulation connection between WinCC and STEP7_ Old bear passing by_ Sina blog

Notes on the method of passing items from the spider file to the pipeline in the case of a scratch crawler

用frp搭建云电脑

STEP7主站与远程I/O组网_过路老熊_新浪博客

博图软件中多重背景块的建立_过路老熊_新浪博客

【微信公众号H5】 生成带参数进入公众号关注页的二维码 监听用户关注公众号事件 自定义菜单栏 (服务端)
随机推荐
给定参数n,从1到n会有n个整数1,2,3,...,n,这n个数组共有n!种排列,按照大小顺序升序排列出所有列的情况,并一一标记,给定n和k,返回第k个值
【微信公众号H5】 生成带参数进入公众号关注页的二维码 监听用户关注公众号事件 自定义菜单栏 (服务端)
Unsigned and signed vernacular
利用VBScript连接mysql数据库_过路老熊_新浪博客
10.4.1 data console
Shredding Company poj 1416
Record a simple question with ideas at the moment of brushing leetcode - Sword finger offer 09 Implementing queues with two stacks
Realize the conversion between analog quantity value and engineering quantity value in STEP7_ Old bear passing by_ Sina blog
解决线程并发安全问题
Shredding Company poj 1416
Literature research (IV): Hourly building power consumption prediction based on case-based reasoning, Ann and PCA
文献调研(四):基于case-based reasoning、ANN、PCA的建筑小时用电量预测
14.1.1 promethues monitoring, four data types metrics, pushgateway
搜索旋转数组II[抽象二分练习]
Connecting MySQL database with VBScript_ Old bear passing by_ Sina blog
About Simple Data Visualization
文献调研(一):基于集成学习和能耗模式分类的办公楼小时能耗预测
keil编译运行错误,缺少error:#5:#includecore_cm3.h_过路老熊_新浪博客
Number array de duplication in JS
My blog is 2 years old and 167 days old today. I received the pioneer blogger Badge_ Old bear passing by_ Sina blog