当前位置:网站首页>使用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
边栏推荐
- smt贴片加工行业常见术语及知识汇总
- Detailed explanation of redis
- Notes on the method of passing items from the spider file to the pipeline in the case of a scratch crawler
- Alipay payment interface sandbox environment test and integration into an SSM e-commerce project
- 详解synchronize关键字
- 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
- Prototype chain test questions in JS --foo and getname
- Redis之哨兵
- Bit compressor [Blue Bridge Cup training]
猜你喜欢

10.4.1、数据中台

Literature research (II): quantitative evaluation of building energy efficiency performance based on short-term energy prediction

STEP7主站与远程I/O组网_过路老熊_新浪博客
![Find the minimum value of flipped array [Abstract bisection]](/img/b9/1e0c6196e6dc51ae2c48f6c5e83289.png)
Find the minimum value of flipped array [Abstract bisection]

The role of iomanip header file in actual combat

Summary of c++ references and pointers

文献调研(四):基于case-based reasoning、ANN、PCA的建筑小时用电量预测

Redis memory elimination mechanism

STEP7 master station and remote i/o networking_ Old bear passing by_ Sina blog

Redis之跳跃表
随机推荐
Alipay payment interface sandbox environment test and integration into an SSM e-commerce project
huibian
正则表达式介绍及一些语法
关于scrapy爬虫时,由spider文件将item传递到管道的方法注意事项
MongoDB的一些基础用法
【微信公众号H5】 生成带参数进入公众号关注页的二维码 监听用户关注公众号事件 自定义菜单栏 (服务端)
11.1.2、flink概述_Wordcount案例
电路板去板边—V-Cut分板机注意事项
SSM integrated learning notes (mainly ideas)
Joint simulation of STEP7 and WinCC_ Old bear passing by_ Sina blog
Let's talk about string today
Final and static
网络协议之:redis protocol详解
SMT行业AOI,X-RAY,ICT分别是什么?作用是?
手工制作 pl-2303hx 的USB转TTL电平串口的电路_过路老熊_新浪博客
Transformation of communication protocol between Siemens S7-200PLC and Danfoss inverter_ Old bear passing by_ Sina blog
Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or
迅为RK3568开发板使用RKNN-Toolkit-lite2运行测试程序
Number array de duplication in JS
Sentinel of redis