SQL Profile 总结(四)--使用示例

前提:sql profile工具的相关视图

dba_sql_profile

10g: sys.sqlprof$attr  &  sqlprof$

11g: sys.sqlobj$data  &  sys.sqlobj$

1、主要完成四个示例,如下

  • 使用dbms_sqltune.import_sql_profile过程手工指定提示的方式,这种方式要求非常高(查询块名等),一般不会使用
  • 使用create_sql_profile.sql脚本固定内存中已经有的SQL的执行计划,通过指定sql_id
  • 使用create_sql_profile_awr脚本来还原AWR里面保存的SQL语句的执行计划(暂时没环境测试)...
  • 将提示集手工移入到另外一条SQL语句的sql profile中(通过move_sql_profile.sql脚本实现);

示例:

一、使用dbms_sqltune.import_sql_profile过程手工指定提示的方式,这种方式要求非常高(查询块名等),一般不会使用

[[email protected] ~]$ sqlplus dbmon/dbmon_123

SQL*Plus: Release 11.2.0.1.0 Production on Wed Jun 11 16:37:06 2014

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, Oracle Label Security, OLAP, Data Mining,

Oracle Database Vault and Real Application Testing options

SQL> create table dh_sql as select rownum id,object_name name ,object_type type from dba_objects;

Table created.

SQL> create index ind_dh_sql on dh_sql(id);

Index created.

SQL> exec DBMS_STATS.GATHER_TABLE_STATS(OWNNAME=>‘dbmon‘,TABNAME=>‘dh_sql‘,ESTIMATE_PERCENT=>30,METHOD_OPT=>‘FOR ALL COLUMNS SIZE 1‘,NO_INVALIDATE=>FALSE,CASCADE=>TRUE,DEGREE => 1);

PL/SQL procedure successfully completed.

SQL> set linesize 200 pagesize 9999

SQL> select /* test1 */ id,name from dh_sql where id=771;

ID NAME

---------- --------------------------------------------------------------------------------------------------------------------------------

771 RULESET$

SQL> @sql_profiles.sql               --该脚本查看当前使用sql profile的语句

Enter value for sql_text:

old   3: where sql_text like nvl(‘&sql_text‘,‘%‘)

new   3: where sql_text like nvl(‘‘,‘%‘)

Enter value for name:

old   4: and name like nvl(‘&name‘,name)

new   4: and name like nvl(‘‘,name)

no rows selected

SQL> col name format a30

SQL> col type format a30

SQL> col sql_text format a40

SQL> select sql_text,sql_id,hash_value,child_number from v$sql a where sql_text like ‘%test1%‘ and sql_text not like ‘%v$sql%‘;

SQL_TEXT                                 SQL_ID        HASH_VALUE CHILD_NUMBER

---------------------------------------- ------------- ---------- ------------

select /* test1 */ id,name from dh_sql w 90nh2m7a3gsvf 3560432494            0

SQL> select * from table(dbms_xplan.display_cursor(‘90nh2m7a3gsvf‘,‘‘,‘‘));

PLAN_TABLE_OUTPUT

-----------------------------------------------------------------------------------------------------------------------------

SQL_ID  90nh2m7a3gsvf, child number 0

-------------------------------------

select /* test1 */ id,name from dh_sql where id=:"SYS_B_0"

Plan hash value: 1731829956

------------------------------------------------------------------------------------------

| Id  | Operation                   | Name       | Rows  | Bytes | Cost (%CPU)| Time     |

------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT            |            |       |       |     2 (100)|          |

|   1 |  TABLE ACCESS BY INDEX ROWID| DH_SQL     |     1 |    30 |     2   (0)| 00:00:09 |

|*  2 |   INDEX RANGE SCAN          | IND_DH_SQL |     1 |       |     1   (0)| 00:00:05 |

------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

2 - access("ID"=:SYS_B_0)

19 rows selected.

SQL> @create_1_hint_sql_profile.sql

Enter value for sql_id: 90nh2m7a3gsvf

Enter value for profile_name (PROFILE_sqlid_MANUAL):

Enter value for category (DEFAULT):

Enter value for force_matching (false): true

old  16: sql_id = ‘&&sql_id‘;

new  16: sql_id = ‘90nh2m7a3gsvf‘;

old  18: select decode(‘&&profile_name‘,‘X0X0X0X0‘,‘PROFILE_‘||‘&&sql_id‘||‘_MANUAL‘,‘&&profile_name‘)

new  18: select decode(‘X0X0X0X0‘,‘X0X0X0X0‘,‘PROFILE_‘||‘90nh2m7a3gsvf‘||‘_MANUAL‘,‘X0X0X0X0‘)

Enter value for hint: FULL([email protected]$1)           --手工输入指定提示

old  24: profile => sqlprof_attr(‘&hint‘),

new  24: profile => sqlprof_attr(‘FULL([email protected]$1)‘),

old  25: category => ‘&&category‘,

new  25: category => ‘DEFAULT‘,

old  31: force_match => &&force_matching

new  31: force_match => true

PL/SQL procedure successfully completed.

SQL> select /* test1 */ id,name from dh_sql where id=771;

ID NAME

---------- ------------------------------

771 RULESET$

SQL> select * from table(dbms_xplan.display_cursor(‘90nh2m7a3gsvf‘,‘‘,‘‘));

PLAN_TABLE_OUTPUT

-----------------------------------------------------------------------------------------------------------------------------

SQL_ID  90nh2m7a3gsvf, child number 0

-------------------------------------

select /* test1 */ id,name from dh_sql where id=:"SYS_B_0"

Plan hash value: 1575588977

----------------------------------------------------------------------------

| Id  | Operation         | Name   | Rows  | Bytes | Cost (%CPU)| Time     |

----------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |        |       |       |   112 (100)|          |

|*  1 |  TABLE ACCESS FULL| DH_SQL |     1 |    30 |   112   (0)| 00:07:50 |

----------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

1 - filter("ID"=:SYS_B_0)

Note

-----

- SQL profile PROFILE_90nh2m7a3gsvf_MANUAL used for this statement

22 rows selected.

SQL> @sql_profiles.sql   --可以看到确实已经使用!

Enter value for sql_text:

old   3: where sql_text like nvl(‘&sql_text‘,‘%‘)

new   3: where sql_text like nvl(‘‘,‘%‘)

Enter value for name:

old   4: and name like nvl(‘&name‘,name)

new   4: and name like nvl(‘‘,name)

NAME                           CATEGORY        STATUS   SQL_TEXT                                                               FOR

------------------------------ --------------- -------- ---------------------------------------------------------------------

PROFILE_90nh2m7a3gsvf_MANUAL   DEFAULT         ENABLED  select /* test1 */ id,name from dh_sql where id=:"SYS_B_0"             YES

SQL> conn /as sysdba

Connected.

SQL> set serveroutput on size 9999

SQL> @profile_hint.sql

Enter value for profile_name: PROFILE_90nh2m7a3gsvf_MANUAL

old  19:    ‘and name like (‘‘&&profile_name‘‘) ‘||

new  19:    ‘and name like (‘‘PROFILE_90nh2m7a3gsvf_MANUAL‘‘) ‘||

old  38:    ‘and p.name like (‘‘&&profile_name‘‘)) ‘||

new  38:    ‘and p.name like (‘‘PROFILE_90nh2m7a3gsvf_MANUAL‘‘)) ‘||

HINT

-----------------------------------------------------------------------------------------------------------------------------

FULL([email protected]$1)               --可以看到sql profile的基表里面保存了我们指定的提示

二、使用create_sql_profile.sql脚本固定内存中已经有的SQL的执行计划,通过指定sql_id

SQL> conn dbmon/dbmon_123

Connected.

SQL> select * from dh_sql where name=‘DBA_TABLES‘;

ID NAME                           TYPE

---------- ------------------------------ ------------------------------

3167 DBA_TABLES                     VIEW

3168 DBA_TABLES                     SYNONYM

2 rows selected.

SQL> select /* test2 */ * from dh_sql where name=‘DBA_TABLES‘;

ID NAME                           TYPE

---------- ------------------------------ ------------------------------

3167 DBA_TABLES                     VIEW

3168 DBA_TABLES                     SYNONYM

2 rows selected.

SQL> select sql_text,sql_id,hash_value,child_number from v$sql a where sql_text like ‘%test2%‘ and sql_text not like ‘%v$sql%‘;

SQL_TEXT                                                               SQL_ID        HASH_VALUE CHILD_NUMBER

---------------------------------------------------------------------- ------------- ---------- ------------

select /* test2 */ * from dh_sql where name=:"SYS_B_0"                 0xy0uj562r893 1277927715            0

1 row selected.

SQL> select * from table(dbms_xplan.display_cursor(‘0xy0uj562r893‘,‘‘,‘‘));

PLAN_TABLE_OUTPUT

-----------------------------------------------------------------------------------------------------------------------------

SQL_ID  0xy0uj562r893, child number 0

-------------------------------------

select /* test2 */ * from dh_sql where name=:"SYS_B_0"

Plan hash value: 1575588977

----------------------------------------------------------------------------

| Id  | Operation         | Name   | Rows  | Bytes | Cost (%CPU)| Time     |

----------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |        |       |       |   112 (100)|          |

|*  1 |  TABLE ACCESS FULL| DH_SQL |     2 |    76 |   112   (0)| 00:07:50 |

----------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

1 - filter("NAME"=:SYS_B_0)

18 rows selected.

SQL> @create_sql_profile.sql    --使用这个脚本固定内存中指定SQL_ID的执行计划

Enter value for sql_id: 0xy0uj562r893

Enter value for child_no (0):

Enter value for profile_name (PROF_sqlid_planhash):

Enter value for category (DEFAULT):

Enter value for force_matching (FALSE): TRUE

old  19: sql_id = ‘&&sql_id‘

new  19: sql_id = ‘0xy0uj562r893‘

old  20: and child_number = &&child_no

new  20: and child_number = 0

old  27: decode(‘&&profile_name‘,‘X0X0X0X0‘,‘PROF_&&sql_id‘||‘_‘||plan_hash_value,‘&&profile_name‘)

new  27: decode(‘X0X0X0X0‘,‘X0X0X0X0‘,‘PROF_0xy0uj562r893‘||‘_‘||plan_hash_value,‘X0X0X0X0‘)

old  33: sql_id = ‘&&sql_id‘

new  33: sql_id = ‘0xy0uj562r893‘

old  34: and child_number = &&child_no;

new  34: and child_number = 0;

old  39: category => ‘&&category‘,

new  39: category => ‘DEFAULT‘,

old  41: force_match => &&force_matching

new  41: force_match => TRUE

old  52:   dbms_output.put_line(‘ERROR: sql_id: ‘||‘&&sql_id‘||‘ Child: ‘||‘&&child_no‘||‘ not found in v$sql.‘);

new  52:   dbms_output.put_line(‘ERROR: sql_id: ‘||‘0xy0uj562r893‘||‘ Child: ‘||‘0‘||‘ not found in v$sql.‘);

SQL>

SQL> select /* test2 */ * from dh_sql where name=‘DBA_TABLES‘;

ID NAME                           TYPE

---------- ------------------------------ ------------------------------

3167 DBA_TABLES                     VIEW

3168 DBA_TABLES                     SYNONYM

2 rows selected.

SQL> select * from table(dbms_xplan.display_cursor(‘0xy0uj562r893‘,‘‘,‘‘));

PLAN_TABLE_OUTPUT

-----------------------------------------------------------------------------------------------------------------------------

SQL_ID  0xy0uj562r893, child number 0

-------------------------------------

select /* test2 */ * from dh_sql where name=:"SYS_B_0"

Plan hash value: 1575588977

----------------------------------------------------------------------------

| Id  | Operation         | Name   | Rows  | Bytes | Cost (%CPU)| Time     |

----------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |        |       |       |   112 (100)|          |

|*  1 |  TABLE ACCESS FULL| DH_SQL |     2 |    76 |   112   (0)| 00:07:50 |

----------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

1 - filter("NAME"=:SYS_B_0)

Note

-----

- SQL profile PROF_0xy0uj562r893_1575588977 used for this statement   --可以看到sql profile确实已经生效

22 rows selected.

--新建一个索引,确认已经固定执行计划的语句不会因为访问路径而改变执行计划

SQL> create index ind_dh_sql2 on dh_sql(name) compute statistics;

Index created.

SQL> select /* test2 */ * from dh_sql a where name=‘DBA_TABLES‘;

ID NAME                           TYPE

---------- ------------------------------ ------------------------------

3167 DBA_TABLES                     VIEW

3168 DBA_TABLES                     SYNONYM

2 rows selected.

SQL> select sql_text,sql_id,hash_value,child_number from v$sql a where sql_text like ‘%test2%‘ and sql_text not like ‘%v$sql%‘;

SQL_TEXT                                                               SQL_ID        HASH_VALUE CHILD_NUMBER

---------------------------------------------------------------------- ------------- ---------- ------------

select /* test2 */ * from dh_sql a where name=:"SYS_B_0"               bp7gpwq6w88nv 2378441371            0

select /* test2 */ * from dh_sql where name=:"SYS_B_0"                 0xy0uj562r893 1277927715            0

2 rows selected.

SQL> select * from table(dbms_xplan.display_cursor(‘bp7gpwq6w88nv‘,‘‘,‘‘));

PLAN_TABLE_OUTPUT

-----------------------------------------------------------------------------------------------------------------------------

SQL_ID  bp7gpwq6w88nv, child number 0

-------------------------------------

select /* test2 */ * from dh_sql a where name=:"SYS_B_0"

Plan hash value: 3828038811

-------------------------------------------------------------------------------------------

| Id  | Operation                   | Name        | Rows  | Bytes | Cost (%CPU)| Time     |

-------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT            |             |       |       |     4 (100)|          |

|   1 |  TABLE ACCESS BY INDEX ROWID| DH_SQL      |     2 |    76 |     4   (0)| 00:00:17 |

|*  2 |   INDEX RANGE SCAN          | IND_DH_SQL2 |     2 |       |     3   (0)| 00:00:13 |  --没有固定的语句使用索引计划

-------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

2 - access("NAME"=:SYS_B_0)

19 rows selected.

SQL> select /* test2 */ * from dh_sql where name=‘DBA_TABLES‘;

ID NAME                           TYPE

---------- ------------------------------ ------------------------------

3167 DBA_TABLES                     VIEW

3168 DBA_TABLES                     SYNONYM

2 rows selected.

SQL> select * from table(dbms_xplan.display_cursor(‘0xy0uj562r893‘,‘‘,‘‘));

PLAN_TABLE_OUTPUT

-----------------------------------------------------------------------------------------------------------------------------

SQL_ID  0xy0uj562r893, child number 0

-------------------------------------

select /* test2 */ * from dh_sql where name=:"SYS_B_0"

Plan hash value: 1575588977

----------------------------------------------------------------------------

| Id  | Operation         | Name   | Rows  | Bytes | Cost (%CPU)| Time     |

----------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |        |       |       |   112 (100)|          |

|*  1 |  TABLE ACCESS FULL| DH_SQL |     2 |    76 |   112   (0)| 00:07:50 |   --已经固定的执行计划还是使用全表扫描

----------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

1 - filter("NAME"=:SYS_B_0)

Note

-----

- SQL profile PROF_0xy0uj562r893_1575588977 used for this statement

22 rows selected.

SQL> conn /as sysdba

Connected.

SQL> set serveroutput on size 99999

SQL> @sql_profile_hints.sql

Enter value for profile_name: PROF_0xy0uj562r893_1575588977

old  19:    ‘and name like (‘‘&&profile_name‘‘) ‘||

new  19:    ‘and name like (‘‘PROF_0xy0uj562r893_1575588977‘‘) ‘||

old  38:    ‘and p.name like (‘‘&&profile_name‘‘)) ‘||

new  38:    ‘and p.name like (‘‘PROF_0xy0uj562r893_1575588977‘‘)) ‘||

HINT

-----------------------------------------------------------------------------------------------------------------------------

IGNORE_OPTIM_EMBEDDED_HINTS

OPTIMIZER_FEATURES_ENABLE(‘11.2.0.1‘)

DB_VERSION(‘11.2.0.1‘)

OPT_PARAM(‘_optim_peek_user_binds‘ ‘false‘)

OPT_PARAM(‘_optimizer_null_aware_antijoin‘ ‘false‘)

OPT_PARAM(‘_bloom_filter_enabled‘ ‘false‘)

OPT_PARAM(‘_optimizer_extended_cursor_sharing‘ ‘none‘)

OPT_PARAM(‘_gby_hash_aggregation_enabled‘ ‘false‘)

OPT_PARAM(‘_bloom_pruning_enabled‘ ‘false‘)

OPT_PARAM(‘_optimizer_extended_cursor_sharing_rel‘ ‘none‘)

OPT_PARAM(‘_optimizer_adaptive_cursor_sharing‘ ‘false‘)

OPT_PARAM(‘_optimizer_use_feedback‘ ‘false‘)

ALL_ROWS

OUTLINE_LEAF(@"SEL$1")

FULL(@"SEL$1" "DH_SQL"@"SEL$1")

15 rows selected.

三、使用create_sql_profile_awr脚本来还原AWR里面保存的SQL语句的执行计划(暂时没环境测试)...

四、将提示集手工移入到另外一条SQL语句的sql profile中(通过move_sql_profile.sql脚本实现);方法如下:

1、执行一条与需要固定执行计划的SQL语句结构一致的语句

2、通过各种方法来实现将第一步运行的SQL语句,得到自己预期的执行计划(添加提示,修改参数等等)

3、通过这个语句运行产生的提示集合(v$sql_plan.other_xml列),来为需要固定的SQL语句创建sql profile从而固定执行计划

SQL> select * from table(dbms_xplan.display_cursor(‘bp7gpwq6w88nv‘,‘‘,‘‘));

PLAN_TABLE_OUTPUT

-----------------------------------------------------------------------------------------------------------------------------

SQL_ID  bp7gpwq6w88nv, child number 0

-------------------------------------

select /* test2 */ * from dh_sql a where name=:"SYS_B_0"

Plan hash value: 3828038811

-------------------------------------------------------------------------------------------

| Id  | Operation                   | Name        | Rows  | Bytes | Cost (%CPU)| Time     |

-------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT            |             |       |       |     4 (100)|          |

|   1 |  TABLE ACCESS BY INDEX ROWID| DH_SQL      |     2 |    76 |     4   (0)| 00:00:17 |

|*  2 |   INDEX RANGE SCAN          | IND_DH_SQL2 |     2 |       |     3   (0)| 00:00:13 |  --需要固定的SQL的执行计划

-------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

2 - access("NAME"=:SYS_B_0)

19 rows selected.

SQL> select /* test2 */ /*+ full(a) */ *from dh_sql a where name=‘DBA_TABLES‘;

ID NAME                           TYPE

---------- ------------------------------ ------------------------------

3167 DBA_TABLES                     VIEW

3168 DBA_TABLES                     SYNONYM

2 rows selected.

SQL> select sql_text,sql_id,hash_value,child_number from v$sql a where sql_text like ‘%test2%‘ and sql_text not like ‘%v$sql%‘;

SQL_TEXT                                                               SQL_ID        HASH_VALUE CHILD_NUMBER

---------------------------------------------------------------------- ------------- ---------- ------------

select /* test2 */ * from dh_sql a where name=:"SYS_B_0"               bp7gpwq6w88nv 2378441371            0

select /* test2 */ * from dh_sql where name=:"SYS_B_0"                 0xy0uj562r893 1277927715            0

select /* test2 */ /*+ full(a) */ *from dh_sql a where name=:"SYS_B_0" 6vq4tjw38m8hk  109683218            0

3 rows selected.

SQL> select * from table(dbms_xplan.display_cursor(‘6vq4tjw38m8hk‘,‘‘,‘‘));

PLAN_TABLE_OUTPUT

-----------------------------------------------------------------------------------------------------------------------------

SQL_ID  6vq4tjw38m8hk, child number 0

-------------------------------------

select /* test2 */ /*+ full(a) */ *from dh_sql a where name=:"SYS_B_0"

Plan hash value: 1575588977

----------------------------------------------------------------------------

| Id  | Operation         | Name   | Rows  | Bytes | Cost (%CPU)| Time     |

----------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |        |       |       |   112 (100)|          |

|*  1 |  TABLE ACCESS FULL| DH_SQL |     2 |    76 |   112   (0)| 00:07:50 |   --我们指定的预期执行计划

----------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

1 - filter("NAME"=:SYS_B_0)

18 rows selected.

SQL> @create_sql_profile.sql     ---为这个预期的SQL执行计划创建sql profile

Enter value for sql_id: 6vq4tjw38m8hk

Enter value for child_no (0):

Enter value for profile_name (PROF_sqlid_planhash):

Enter value for category (DEFAULT):

Enter value for force_matching (FALSE): TRUE

old  19: sql_id = ‘&&sql_id‘

new  19: sql_id = ‘6vq4tjw38m8hk‘

old  20: and child_number = &&child_no

new  20: and child_number = 0

old  27: decode(‘&&profile_name‘,‘X0X0X0X0‘,‘PROF_&&sql_id‘||‘_‘||plan_hash_value,‘&&profile_name‘)

new  27: decode(‘X0X0X0X0‘,‘X0X0X0X0‘,‘PROF_6vq4tjw38m8hk‘||‘_‘||plan_hash_value,‘X0X0X0X0‘)

old  33: sql_id = ‘&&sql_id‘

new  33: sql_id = ‘6vq4tjw38m8hk‘

old  34: and child_number = &&child_no;

new  34: and child_number = 0;

old  39: category => ‘&&category‘,

new  39: category => ‘DEFAULT‘,

old  41: force_match => &&force_matching

new  41: force_match => TRUE

old  52:   dbms_output.put_line(‘ERROR: sql_id: ‘||‘&&sql_id‘||‘ Child: ‘||‘&&child_no‘||‘ not found in v$sql.‘);

new  52:   dbms_output.put_line(‘ERROR: sql_id: ‘||‘6vq4tjw38m8hk‘||‘ Child: ‘||‘0‘||‘ not found in v$sql.‘);

SQL> select /* test2 */ /*+ full(a) */ *from dh_sql a where name=‘DBA_TABLES‘;

ID NAME                           TYPE

---------- ------------------------------ ------------------------------

3167 DBA_TABLES                     VIEW

3168 DBA_TABLES                     SYNONYM

2 rows selected.

SQL> select * from table(dbms_xplan.display_cursor(‘6vq4tjw38m8hk‘,‘‘,‘‘));

PLAN_TABLE_OUTPUT

-----------------------------------------------------------------------------------------------------------------------------

SQL_ID  6vq4tjw38m8hk, child number 0

-------------------------------------

select /* test2 */ /*+ full(a) */ *from dh_sql a where name=:"SYS_B_0"

Plan hash value: 1575588977

----------------------------------------------------------------------------

| Id  | Operation         | Name   | Rows  | Bytes | Cost (%CPU)| Time     |

----------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |        |       |       |   112 (100)|          |

|*  1 |  TABLE ACCESS FULL| DH_SQL |     2 |    76 |   112   (0)| 00:07:50 |

----------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

1 - filter("NAME"=:SYS_B_0)

Note

-----

- SQL profile PROF_6vq4tjw38m8hk_1575588977 used for this statement

22 rows selected.

SQL> @move_sql_profile.sql           --需要一些权限,建议用SYS用户执行

Enter value for profile_name: PROF_6vq4tjw38m8hk_1575588977

Enter value for sql_id: bp7gpwq6w88nv

Enter value for category (DEFAULT):

Enter value for force_matching (false): TRUE

old  18:    ‘and name like (‘‘&&profile_name‘‘) ‘||

new  18:    ‘and name like (‘‘PROF_6vq4tjw38m8hk_1575588977‘‘) ‘||

old  36:    ‘and p.name like (‘‘&&profile_name‘‘)) ‘||

new  36:    ‘and p.name like (‘‘PROF_6vq4tjw38m8hk_1575588977‘‘)) ‘||

old  55: and name like (‘&&profile_name‘)

new  55: and name like (‘PROF_6vq4tjw38m8hk_1575588977‘)

old  66: sql_id = ‘&&sql_id‘;

new  66: sql_id = ‘bp7gpwq6w88nv‘;

old  71: , category => ‘&&category‘

new  71: , category => ‘DEFAULT‘

old  72: , name => ‘PROFILE_‘||‘&&sql_id‘||‘_moved‘

new  72: , name => ‘PROFILE_‘||‘bp7gpwq6w88nv‘||‘_moved‘

old  77: , force_match => &&force_matching

new  77: , force_match => TRUE

declare

*

ERROR at line 1:

ORA-00942: table or view does not exist

ORA-06512: at line 26

SQL> conn /as sysdba

Connected.

SQL> set verify off

SQL> @move_sql_profile.sql

Enter value for profile_name: PROF_6vq4tjw38m8hk_1575588977

Enter value for sql_id: bp7gpwq6w88nv

Enter value for category (DEFAULT):

Enter value for force_matching (false):

PL/SQL procedure successfully completed.

SQL> conn dbmon/dbmon_123

Connected.

SQL> select /* test2 */ * from dh_sql a where name=‘DBA_TABLES‘;

ID NAME                           TYPE

---------- ------------------------------ ------------------------------

3167 DBA_TABLES                     VIEW

3168 DBA_TABLES                     SYNONYM

2 rows selected.

SQL> select * from table(dbms_xplan.display_cursor(‘bp7gpwq6w88nv‘,‘‘,‘‘));

PLAN_TABLE_OUTPUT

-----------------------------------------------------------------------------------------------------------------------------

SQL_ID  bp7gpwq6w88nv, child number 0

-------------------------------------

select /* test2 */ * from dh_sql a where name=:"SYS_B_0"

Plan hash value: 1575588977

----------------------------------------------------------------------------

| Id  | Operation         | Name   | Rows  | Bytes | Cost (%CPU)| Time     |

----------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |        |       |       |   112 (100)|          |

|*  1 |  TABLE ACCESS FULL| DH_SQL |     2 |    76 |   112   (0)| 00:07:50 |

----------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

1 - filter("NAME"=:SYS_B_0)

Note

-----

- SQL profile PROFILE_bp7gpwq6w88nv_moved used for this statement   --目的达成!

22 rows selected.

时间: 2024-11-10 07:24:24

SQL Profile 总结(四)--使用示例的相关文章

SQL Profile 总结(一)

一.前提概述 在介绍SQL Profile之前,不得不说的一个工具就是SQL Tuning Advisor:这个工具是从Oracle 10g開始引入,它的任务就是分析一个指定的SQL语句,并建议怎样使用一些方法来提高指定语句的性能,比如:收集缺失的对象统计信息.或者收集过时的对象统计信息.创建新的索引.调整SQL语句结构.採用SQL Profile等等方式. 二.为什么SQL Tuning Advisor可以找出提高语句性能的方法? 这须要从SQL Tuning Advisor的工作原理開始说明

通过案例学调优之--SQL Profile

通过案例学调优之--SQL Profile 一.什么是SQL Profile(概要) SQL Profile在性能优化中占有一个重要的位置. MOS里这么描述SQL Profile: SQL Profile是10g中的新特性,作为自动SQL调整过程的一部分,由Oracle企业管理器来管理.除了OEM,SQL Profile可以通过DBMS_SQLTUNE包来进行管理. 查询优化器有时候会因为缺乏足够的信息,而对一条SQL语句做出错误的估计,生成糟糕的执行计划.而自动SQL调整通过SQL概要分析来

SQL中的四种语言DDL,DML,DCL,TCL

1.DDL(Data Definition Language)数据库定义语言statements are used to define the database structure or schema. DDL是SQL语言的四大功能之一.用于定义数据库的三级结构,包括外模式.概念模式.内模式及其相互之间的映像,定义数据的完整性.安全控制等约束DDL不需要commit.CREATEALTERDROPTRUNCATECOMMENTRENAME 2.DML(Data Manipulation Lang

SQL总结(四)编辑类

SQL总结(四)编辑类 应有尽有 1.数据库 创建数据库语法: CREATE DATABASE database_name 1)创建测试库 CREATE DATABASE TestDB 2)使用库 USE TestDB 3)删除库 DROP DATABASE TestDB 2.表 1)创建用户信息表,包括ID.姓名.年龄.专业ID.所在城市 CREATE TABLE Students( ID int, Name nvarchar(20), Age int, MajorID int, City n

SQL Profile 如何使用

这些文章是我从<基于Oracle的SQL优化> 书中找到的 可以参考一下我的实验过程 SQL Profile Oracle10G中的SQL Profile可以说是Oracle 9i中的Stored Outline的进化. Stored Outline能够实现的功能SQL Profile也完全能够实现. 与Stored Outline相比,SQL Profile具备如下优点: 更容易生成.更改和控制. 在对SQL语句的支持上做得更好,也就是说适用范围更广. 使用SQL Profile可以容易实现

Oracle 通过sql profile为sql语句加hint

sql profile最大的优点是在不修改sql语句和会话执行环境的情况下去优化sql的执行效率,适合无法在应用程序中修改sql时.sql profile最常用方法大概是:--创建产生sql tuning advisor任务DECLARE  tuning_task varchar2(100);  l_sql_id    v$session.prev_sql_id%TYPE;BEGIN  l_sql_id    := '6w02d3ggsj4xb';  tuning_task := dbms_sq

c#在sql中存取图片image示例

这篇文章主要介绍了c#在sql中存取图片image示例,需要的朋友可以参考下 (1)控制台应用程序下演示插入图片 复制代码 代码如下: public void InsertIMG() { //将需要存储的图片读取为数据流 FileStream fs = new FileStream(@"E:\c.jpg", FileMode.Open,FileAccess.Read); Byte[] btye2 = new byte[fs.Length]; fs.Read(btye2 , 0, Con

Oracle固定SQL的执行计划(一)---SQL Profile

我们都希望对于所有在Oracle数据库中执行的SQL,CBO都能产生出正确的执行计划,但实际情况却并非如此,由于各种各样的原因(比如目标SQL所涉及的对象的统计信息的不准确,或者CBO内部一些成本计算公式的先天缺陷等),导致有时CBO产生效率不高.甚至是错误的执行计划.特别是CBO对目标SQL所产生的初始执行计划是正确的,后来由于某种原因(比如统计信息的变更等)而导致CBO重新对其产生了错误的执行计划,这种执行计划的改变往往会导致目标SQL执行时间呈数量级的递增,而且常常会让我们很困惑:这个SQ

SQL Server之 (四) ADO增删查改 登录demo 带参数的sql语句 插入自动返回行号

SQL Server之 (四) ADO增删查改  登录demo  带参数的sql语句  插入自动返回行号 自己学习笔记,转载请注明出处,谢谢!---酸菜 1.什么是ADO.NET ADO.NET是一组类库,这组类库可以让我们通过程序的方式访问数据库,并以各种方式操作存储在其中的数据; ADO.NET是基于.NET FrameWork,与.NET FrameWork类库的其余部分是高度集成的 2.连接数据库的步骤 ①创建连接字符串 Data Source=XXX-PC; Initial Catal