β

固定执行计划-使用coe_xfr_sql_profile(BASELINE)固定执行计划

Lunar的oracle实验室 145 阅读

联系: QQ(5163721)

标题: 固定执行计划-使用coe_xfr_sql_profile(BASELINE)固定执行计划

作者: Lunar ©版权所有[文章允许转载,但必须以链接方式注明源地址,否则追究法律责任.]

测试目的: 使用coe_xfr_sql_profile的方式固定执行计划和hint中指定no index,谁的优先级高?
在SQLT工具中包含了几个轻巧方便的coe脚本,用来固定执行计划,其中coe_xfr_sql_profile是我常用的。
.
固定执行计划-使用SQL Tuning Advisor
固定执行计划-手工指定PLAN OUTLINE
固定执行计划-手工指定索引名称的方式
固定执行计划-使用coe_xfr_sql_profile固定执行计划
固定执行计划-使用SPM(Sql Plan Management)固定执行计划
.
查看当前的SQL Profile:


LUNAR@lunardb>select * from dba_sql_profiles;

NAME                           CATEGORY                              SIGNATURE SQL_TEXT
------------------------------ ------------------------------ ---------------- --------------------------------------------------------------------------------
CREATED                                                                     LAST_MODIFIED
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
DESCRIPTION
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TYPE    STATUS   FOR          TASK_ID TASK_EXEC_NAME                      TASK_OBJ_ID      TASK_FND_ID      TASK_REC_ID
------- -------- --- ---------------- ------------------------------ ---------------- ---------------- ----------------
Lunar_bjgduva68mbqm_profile    DEFAULT                        9.9008162990E+18 select /*+ no_index(lunartest1 idx_lunartest1_n) */ * from lunartest1 where n=1
-JAN-16 10.53.46.000000 AM                                                12-JAN-16 10.53.46.000000 AM

MANUAL  ENABLED  YES


Elapsed: 00:00:00.00
LUNAR@lunardb>
LUNAR@lunardb>exec dbms_sqltune.drop_sql_profile('Lunar_bjgduva68mbqm_profile');  

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.14
LUNAR@lunardb>select * from dba_sql_profiles;

no rows selected

Elapsed: 00:00:00.01
LUNAR@lunardb>

使用coe_xfr_sql_profile脚本自动识别和指定执行计划:


LUNAR@lunardb>@coe_xfr_sql_profile.sql bjgduva68mbqm

Parameter 1:
SQL_ID (required)



 PLAN_HASH_VALUE      AVG_ET_SECS
---------------- ----------------
089107             .003

Parameter 2:
PLAN_HASH_VALUE (required)

Enter value for 2: 1172089107

Values passed to coe_xfr_sql_profile:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL_ID         : "bjgduva68mbqm"
PLAN_HASH_VALUE: "1172089107"

SQL>BEGIN
    IF :sql_text IS NULL THEN
      RAISE_APPLICATION_ERROR(-20100, 'SQL_TEXT for SQL_ID &&sql_id. was not found in memory (gv$sqltext_with_newlines) or AWR (dba_hist_sqltext).');
    END IF;
  END;
  /
SQL>SET TERM OFF;
SQL>BEGIN
    IF  ther_xml IS NULL THEN
      RAISE_APPLICATION_ERROR(-20101, 'PLAN for SQL_ID &&sql_id. and PHV &&plan_hash_value. was not found in memory (gv$sql_plan) or AWR (dba_hist_sql_plan).');
    END IF;
  END;
  /
SQL>SET TERM OFF;

Execute coe_xfr_sql_profile_bjgduva68mbqm_1172089107.sql
on TARGET system in order to create a custom SQL Profile
with plan 1172089107 linked to adjusted sql_text.


COE_XFR_SQL_PROFILE completed.
SQL>
SQL>@coe_xfr_sql_profile_bjgduva68mbqm_1172089107.sql
SQL>REM
SQL>REM $Header: 215187.1 coe_xfr_sql_profile_bjgduva68mbqm_1172089107.sql 11.4.4.4 2016/01/12 carlos.sierra $
SQL>REM
SQL>REM Copyright (c) 2000-2012, Oracle Corporation. All rights reserved.
SQL>REM
SQL>REM AUTHOR
SQL>REM   carlos.sierra@oracle.com
SQL>REM
SQL>REM SCRIPT
SQL>REM   coe_xfr_sql_profile_bjgduva68mbqm_1172089107.sql
SQL>REM
SQL>REM DESCRIPTION
SQL>REM   This script is generated by coe_xfr_sql_profile.sql
SQL>REM   It contains the SQL*Plus commands to create a custom
SQL>REM   SQL Profile for SQL_ID bjgduva68mbqm based on plan hash
SQL>REM   value 1172089107.
SQL>REM   The custom SQL Profile to be created by this script
SQL>REM   will affect plans for SQL commands with signature
SQL>REM   matching the one for SQL Text below.
SQL>REM   Review SQL Text and adjust accordingly.
SQL>REM
SQL>REM PARAMETERS
SQL>REM   None.
SQL>REM
SQL>REM EXAMPLE
SQL>REM   SQL> START coe_xfr_sql_profile_bjgduva68mbqm_1172089107.sql;
SQL>REM
SQL>REM NOTES
SQL>REM   1. Should be run as SYSTEM or SYSDBA.
SQL>REM   2. User must have CREATE ANY SQL PROFILE privilege.
SQL>REM   3. SOURCE and TARGET systems can be the same or similar.
SQL>REM   4. To drop this custom SQL Profile after it has been created:
SQL>REM  EXEC DBMS_SQLTUNE.DROP_SQL_PROFILE('coe_bjgduva68mbqm_1172089107');
SQL>REM   5. Be aware that using DBMS_SQLTUNE requires a license
SQL>REM  for the Oracle Tuning Pack.
SQL>REM   6. If you modified a SQL putting Hints in order to produce a desired
SQL>REM  Plan, you can remove the artifical Hints from SQL Text pieces below.
SQL>REM  By doing so you can create a custom SQL Profile for the original
SQL>REM  SQL but with the Plan captured from the modified SQL (with Hints).
SQL>REM
SQL>WHENEVER SQLERROR EXIT SQL.SQLCODE;
SQL>REM
SQL>VAR signature NUMBER;
SQL>VAR signaturef NUMBER;
SQL>REM
SQL>DECLARE
  sql_txt CLOB;
  h       SYS.SQLPROF_ATTR;
  PROCEDURE wa (p_line IN VARCHAR2) IS
  BEGIN
  DBMS_LOB.WRITEAPPEND(sql_txt, LENGTH(p_line), p_line);
  END wa;
  BEGIN
  DBMS_LOB.CREATETEMPORARY(sql_txt, TRUE);
  DBMS_LOB.OPEN(sql_txt, DBMS_LOB.LOB_READWRITE);
  -- SQL Text pieces below do not have to be of same length.
  -- So if you edit SQL Text (i.e. removing temporary Hints),
  -- there is no need to edit or re-align unmodified pieces.
  wa(q'[select /*+ no_index(lunartest1 idx_lunartest1_n) */ * from lunar]');
  wa(q'[test1 where n=1]');
  DBMS_LOB.CLOSE(sql_txt);
  h := SYS.SQLPROF_ATTR(
  q'[BEGIN_OUTLINE_DATA]',
  q'[IGNORE_OPTIM_EMBEDDED_HINTS]',
  q'[OPTIMIZER_FEATURES_ENABLE('11.2.0.4')]',
  q'[DB_VERSION('11.2.0.4')]',
  q'[ALL_ROWS]',
  q'[OUTLINE_LEAF(@"SEL$1")]',
  q'[FULL(@"SEL$1" "LUNARTEST1"@"SEL$1")]',
  q'[END_OUTLINE_DATA]');
  :signature := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt);
  :signaturef := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt, TRUE);
  DBMS_SQLTUNE.IMPORT_SQL_PROFILE (
  sql_text    => sql_txt,
  profile     => h,
  name        => 'coe_bjgduva68mbqm_1172089107',
  description => 'coe bjgduva68mbqm 1172089107 '||:signature||' '||:signaturef||'',
  category    => 'DEFAULT',
  validate    => TRUE,
  replace     => TRUE,
  force_match => FALSE /* TRUE:FORCE (match even when different literals in SQL). FALSE:EXACT (similar to CURSOR_SHARING) */ );
  DBMS_LOB.FREETEMPORARY(sql_txt);
  END;
  /

PL/SQL procedure successfully completed.

SQL>WHENEVER SQLERROR CONTINUE
SQL>SET ECHO OFF;

            SIGNATURE
---------------------
15202199990108


           SIGNATUREF
---------------------
816299026594015


... manual custom SQL Profile has been created


COE_XFR_SQL_PROFILE_bjgduva68mbqm_1172089107 completed
SQL>

因为删除了SQL Profile,对应的执行计划也会被删除,因此当前只有一个全表扫描的执行计划(上次测试留下的),以前的执行计划都不在了。
上面的执行过程中已经告诉我们,这个执行计划会使用全表扫描(q’[FULL(@"SEL$1" "LUNARTEST1"@"SEL$1")]‘):

  DBMS_LOB.CLOSE(sql_txt);
  h := SYS.SQLPROF_ATTR(
  q'[BEGIN_OUTLINE_DATA]',
  q'[IGNORE_OPTIM_EMBEDDED_HINTS]',
  q'[OPTIMIZER_FEATURES_ENABLE('11.2.0.4')]',
  q'[DB_VERSION('11.2.0.4')]',
  q'[ALL_ROWS]',
  q'[OUTLINE_LEAF(@"SEL$1")]',
  q'[FULL(@"SEL$1" "LUNARTEST1"@"SEL$1")]',
  q'[END_OUTLINE_DATA]');

我们查看一下这个SQL Profile的主要内容:


SYS@lunardb>conn lunar/lunar
Connected.
LUNAR@lunardb>select * from dba_sql_profiles;

NAME                           CATEGORY                              SIGNATURE SQL_TEXT
------------------------------ ------------------------------ ---------------- --------------------------------------------------------------------------------
CREATED                                                                     LAST_MODIFIED
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
DESCRIPTION
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TYPE    STATUS   FOR          TASK_ID TASK_EXEC_NAME                      TASK_OBJ_ID      TASK_FND_ID      TASK_REC_ID
------- -------- --- ---------------- ------------------------------ ---------------- ---------------- ----------------
coe_bjgduva68mbqm_1172089107   DEFAULT                        6.5941520220E+17 select /*+ no_index(lunartest1 idx_lunartest1_n) */ * from lunartest1 where n=1
-JAN-16 11.24.18.000000 AM                                                12-JAN-16 11.24.18.000000 AM
coe bjgduva68mbqm 1172089107 659415202199990108 9900816299026594015
MANUAL  ENABLED  NO

Elapsed: 00:00:00.01
LUNAR@lunardb>
LUNAR@lunardb>SELECT extractValue(value(h),'.') AS hint
  FROM sys.sqlobj$data od, sys.sqlobj$ so,
  table(xmlsequence(extract(xmltype(od.comp_data),'/outline_data/hint'))) h
  WHERE so.name = 'coe_bjgduva68mbqm_1172089107'
  AND so.signature = od.signature
  AND so.category = od.category
  AND so.obj_type = od.obj_type
  AND so.plan_id = od.plan_id;

HINT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.4')
DB_VERSION('11.2.0.4')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$1" "LUNARTEST1"@"SEL$1")
END_OUTLINE_DATA
 rows selected.

Elapsed: 00:00:00.02
LUNAR@lunardb>

现在我们产生一个正确的执行计划,让该sql执行时使用到索引:


LUNAR@lunardb>select * from lunartest1 where n=1;

Elapsed: 00:00:00.00

Execution Plan
----------------------------------------------------------
Plan hash value: 3241900148

-------------------------------------------------------------------------------------
| Id  | Operation        | Name             | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT |                  |     1 |     4 |     1   (0)| 00:00:01 |
|*  1 |  INDEX RANGE SCAN| IDX_LUNARTEST1_N |     1 |     4 |     1   (0)| 00:00:01 |
-------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
 - access("N"=1)


Statistics
----------------------------------------------------------
  recursive calls
  db block gets
  consistent gets
  physical reads
  redo size
  bytes sent via SQL*Net to client
  bytes received via SQL*Net from client
  SQL*Net roundtrips to/from client
  sorts (memory)
  sorts (disk)
  rows processed

LUNAR@lunardb>

找出sqlid


SYS@lunardb>select sql_id,sql_text from v$sql where sql_text like '%select * from lunartest1 where n=1%';

SQL_ID
-------------
SQL_TEXT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
b2bfyz3qnrxu
EXPLAIN PLAN SET STATEMENT_ID='PLUS80018' FOR select * from lunartest1 where n=1

fjmxgdhw858hz
select * from lunartest1 where n=1
ka8pzvvkqwwg
select sql_id,sql_text from v$sql where sql_text like '%select * from lunartest1 where n=1%'


Elapsed: 00:00:00.02
SYS@lunardb>

找出正确的outline:


SYS@lunardb>select * from table(dbms_xplan.display_cursor('fjmxgdhw858hz',null,'outline'));

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  fjmxgdhw858hz, child number 0
-------------------------------------
select * from lunartest1 where n=1

Plan hash value: 3241900148

-------------------------------------------------------------------------------------
| Id  | Operation        | Name             | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT |                  |       |       |     1 (100)|          |
|*  1 |  INDEX RANGE SCAN| IDX_LUNARTEST1_N |     1 |     4 |     1   (0)| 00:00:01 |
-------------------------------------------------------------------------------------

Outline Data
-------------

  /*+
      BEGIN_OUTLINE_DATA
      IGNORE_OPTIM_EMBEDDED_HINTS
      OPTIMIZER_FEATURES_ENABLE('11.2.0.4')
      DB_VERSION('11.2.0.4')
      ALL_ROWS
      OUTLINE_LEAF(@"SEL$1")
      INDEX(@"SEL$1" "LUNARTEST1"@"SEL$1" ("LUNARTEST1"."N"))
      END_OUTLINE_DATA
  */

Predicate Information (identified by operation id):
---------------------------------------------------
 - access("N"=1)
 rows selected.

Elapsed: 00:00:00.02
SYS@lunardb>

这里我们看到已经使用了索引。
使用coe_xfr_sql_profile固定执行计划:


LUNAR@lunardb>@coe_xfr_sql_profile.sql bjgduva68mbqm

Parameter 1:
SQL_ID (required)



 PLAN_HASH_VALUE      AVG_ET_SECS
---------------- ----------------
089107             .003

Parameter 2:
PLAN_HASH_VALUE (required)

Enter value for 2: 3241900148

Values passed to coe_xfr_sql_profile:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL_ID         : "bjgduva68mbqm"
PLAN_HASH_VALUE: "3241900148"

SQL>BEGIN
    IF :sql_text IS NULL THEN
      RAISE_APPLICATION_ERROR(-20100, 'SQL_TEXT for SQL_ID &&sql_id. was not found in memory (gv$sqltext_with_newlines) or AWR (dba_hist_sqltext).');
    END IF;
  END;
  /
SQL>SET TERM OFF;
SQL>BEGIN
    IF  ther_xml IS NULL THEN
      RAISE_APPLICATION_ERROR(-20101, 'PLAN for SQL_ID &&sql_id. and PHV &&plan_hash_value. was not found in memory (gv$sql_plan) or AWR (dba_hist_sql_plan).');
    END IF;
  END;
  /
SQL>SET TERM OFF;

Execute coe_xfr_sql_profile_bjgduva68mbqm_3241900148.sql
on TARGET system in order to create a custom SQL Profile
with plan 3241900148 linked to adjusted sql_text.


COE_XFR_SQL_PROFILE completed.
SQL>

现在,测试一下,使用SYS用户绑定是否会影响其他用户使用执行计划:


SYS@lunardb>@coe_xfr_sql_profile_bjgduva68mbqm_3241900148.sql
SYS@lunardb>REM
SYS@lunardb>REM $Header: 215187.1 coe_xfr_sql_profile_bjgduva68mbqm_3241900148.sql 11.4.4.4 2016/01/12 carlos.sierra $
SYS@lunardb>REM
SYS@lunardb>REM Copyright (c) 2000-2012, Oracle Corporation. All rights reserved.
SYS@lunardb>REM
SYS@lunardb>REM AUTHOR
SYS@lunardb>REM   carlos.sierra@oracle.com
SYS@lunardb>REM
SYS@lunardb>REM SCRIPT
SYS@lunardb>REM   coe_xfr_sql_profile_bjgduva68mbqm_3241900148.sql
SYS@lunardb>REM
SYS@lunardb>REM DESCRIPTION
SYS@lunardb>REM   This script is generated by coe_xfr_sql_profile.sql
SYS@lunardb>REM   It contains the SQL*Plus commands to create a custom
SYS@lunardb>REM   SQL Profile for SQL_ID bjgduva68mbqm based on plan hash
SYS@lunardb>REM   value 3241900148.
SYS@lunardb>REM   The custom SQL Profile to be created by this script
SYS@lunardb>REM   will affect plans for SQL commands with signature
SYS@lunardb>REM   matching the one for SQL Text below.
SYS@lunardb>REM   Review SQL Text and adjust accordingly.
SYS@lunardb>REM
SYS@lunardb>REM PARAMETERS
SYS@lunardb>REM   None.
SYS@lunardb>REM
SYS@lunardb>REM EXAMPLE
SYS@lunardb>REM   SQL> START coe_xfr_sql_profile_bjgduva68mbqm_3241900148.sql;
SYS@lunardb>REM
SYS@lunardb>REM NOTES
SYS@lunardb>REM   1. Should be run as SYSTEM or SYSDBA.
SYS@lunardb>REM   2. User must have CREATE ANY SQL PROFILE privilege.
SYS@lunardb>REM   3. SOURCE and TARGET systems can be the same or similar.
SYS@lunardb>REM   4. To drop this custom SQL Profile after it has been created:
SYS@lunardb>REM  EXEC DBMS_SQLTUNE.DROP_SQL_PROFILE('coe_bjgduva68mbqm_3241900148');
SYS@lunardb>REM   5. Be aware that using DBMS_SQLTUNE requires a license
SYS@lunardb>REM  for the Oracle Tuning Pack.
SYS@lunardb>REM   6. If you modified a SQL putting Hints in order to produce a desired
SYS@lunardb>REM  Plan, you can remove the artifical Hints from SQL Text pieces below.
SYS@lunardb>REM  By doing so you can create a custom SQL Profile for the original
SYS@lunardb>REM  SQL but with the Plan captured from the modified SQL (with Hints).
SYS@lunardb>REM
SYS@lunardb>WHENEVER SQLERROR EXIT SQL.SQLCODE;
SYS@lunardb>REM
SYS@lunardb>VAR signature NUMBER;
SYS@lunardb>VAR signaturef NUMBER;
SYS@lunardb>REM
SYS@lunardb>DECLARE
  sql_txt CLOB;
  h       SYS.SQLPROF_ATTR;
  PROCEDURE wa (p_line IN VARCHAR2) IS
  BEGIN
  DBMS_LOB.WRITEAPPEND(sql_txt, LENGTH(p_line), p_line);
  END wa;
  BEGIN
  DBMS_LOB.CREATETEMPORARY(sql_txt, TRUE);
  DBMS_LOB.OPEN(sql_txt, DBMS_LOB.LOB_READWRITE);
  -- SQL Text pieces below do not have to be of same length.
  -- So if you edit SQL Text (i.e. removing temporary Hints),
  -- there is no need to edit or re-align unmodified pieces.
  wa(q'[select /*+ no_index(lunartest1 idx_lunartest1_n) */ * from lunar]');
  wa(q'[test1 where n=1]');
  DBMS_LOB.CLOSE(sql_txt);
  h := SYS.SQLPROF_ATTR(
  q'[BEGIN_OUTLINE_DATA]',
  q'[IGNORE_OPTIM_EMBEDDED_HINTS]',
  q'[OPTIMIZER_FEATURES_ENABLE('11.2.0.4')]',
  q'[DB_VERSION('11.2.0.4')]',
  q'[ALL_ROWS]',
  q'[OUTLINE_LEAF(@"SEL$1")]',
  q'[INDEX(@"SEL$1" "LUNARTEST1"@"SEL$1" ("LUNARTEST1"."N"))]',
  q'[END_OUTLINE_DATA]');
  :signature := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt);
  :signaturef := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt, TRUE);
  DBMS_SQLTUNE.IMPORT_SQL_PROFILE (
  sql_text    => sql_txt,
  profile     => h,
  name        => 'coe_bjgduva68mbqm_3241900148',
  description => 'coe bjgduva68mbqm 3241900148 '||:signature||' '||:signaturef||'',
  category    => 'DEFAULT',
  validate    => TRUE,
  replace     => TRUE,
  force_match => FALSE /* TRUE:FORCE (match even when different literals in SQL). FALSE:EXACT (similar to CURSOR_SHARING) */ );
  DBMS_LOB.FREETEMPORARY(sql_txt);
  END;
  /

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.11
SYS@lunardb>WHENEVER SQLERROR CONTINUE
SYS@lunardb>SET ECHO OFF;

            SIGNATURE
---------------------
15202199990108


           SIGNATUREF
---------------------
816299026594015


... manual custom SQL Profile has been created


COE_XFR_SQL_PROFILE_bjgduva68mbqm_3241900148 completed
SYS@lunardb>
SYS@lunardb>select * from dba_sql_profiles;

NAME                           CATEGORY                              SIGNATURE SQL_TEXT
------------------------------ ------------------------------ ---------------- --------------------------------------------------------------------------------
CREATED                                                                     LAST_MODIFIED
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
DESCRIPTION
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TYPE    STATUS   FOR          TASK_ID TASK_EXEC_NAME                      TASK_OBJ_ID      TASK_FND_ID      TASK_REC_ID
------- -------- --- ---------------- ------------------------------ ---------------- ---------------- ----------------
coe_bjgduva68mbqm_3241900148   DEFAULT                        6.5941520220E+17 select /*+ no_index(lunartest1 idx_lunartest1_n) */ * from lunartest1 where n=1
-JAN-16 11.24.18.000000 AM                                                12-JAN-16 11.40.52.000000 AM
coe bjgduva68mbqm 3241900148 659415202199990108 9900816299026594015
MANUAL  ENABLED  NO


Elapsed: 00:00:00.00
SYS@lunardb>

再次执行查询:


LUNAR@lunardb>select /*+ no_index(lunartest1 idx_lunartest1_n) */ * from lunartest1 where n=1;

Elapsed: 00:00:00.01

Execution Plan
----------------------------------------------------------
Plan hash value: 3241900148

-------------------------------------------------------------------------------------
| Id  | Operation        | Name             | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT |                  |     1 |     4 |     1   (0)| 00:00:01 |
|*  1 |  INDEX RANGE SCAN| IDX_LUNARTEST1_N |     1 |     4 |     1   (0)| 00:00:01 |
-------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
 - access("N"=1)

Note
-----
   - SQL profile "coe_bjgduva68mbqm_3241900148" used for this statement


Statistics
----------------------------------------------------------
  recursive calls
  db block gets
  consistent gets
  physical reads
  redo size
  bytes sent via SQL*Net to client
  bytes received via SQL*Net from client
  SQL*Net roundtrips to/from client
  sorts (memory)
  sorts (disk)
  rows processed

LUNAR@lunardb>

这里我们看到该SQL还是忽略了hint而使用了索引。
结论:
1,使用SYS用户绑定执行计划不会影响其他用户使用该SQL Profile及执行效果
2,这里已经使用了我们的SQL PROFILE(coe_bjgduva68mbqm_3241900148),sql使用了索引,说明coe_xfr_sql_profile绑定执行计划的方式比hint的优先级高

作者:Lunar的oracle实验室
世间所有相遇都是久别重逢

发表评论