HelloDBA [English]
搜索Internet 搜索 HelloDBABA
  Oracle技术站。email: fuyuncat@gmail.com  MSN: fuyuncat@hotmail.com   acoug  acoug 

Oracle SQL提示含义与示例 --- 统计数据和优化器提示

[English]

作者: fuyuncat

来源: www.HelloDBA.com

日期: 2013-01-08 04:57:59

分享到  新浪微博 腾讯微博 人人网 i贴吧 开心网 豆瓣 淘宝 推特 Facebook GMail Blogger Orkut Google Bookmarks

 《Oracle 高性能SQL引擎剖析:Oracle SQL 优化与调优技术详解》一书的附录部分。作为对该书的补充,帮助读者理解和掌握“提示”这一项在SQL优化中使用的这一重要辅助手段。

统计数据提示

CARDINALITY        

语法:CARDINALITY([<@查询块>] [<>] <基数>)

描述:指定查询块或对象的基数大小

HELLODBA.COM>exec sql_explain('select /*+ FULL(T) CARDINALITY(@"SEL$1" 10) */* from T_TABLES T, T_USERS u where t.owner=u.username', 'TYPICAL');

 

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

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

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

|   0 | SELECT STATEMENT   |          |    10 |  3530 |    31   (4)| 00:00:01 |

|*  1 |  HASH JOIN         |          |  2696 |   929K|    31   (4)| 00:00:01 |

|   2 |   TABLE ACCESS FULL| T_USERS  |    31 |  3472 |     3   (0)| 00:00:01 |

|   3 |   TABLE ACCESS FULL| T_TABLES |  2696 |   634K|    28   (4)| 00:00:01 |

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

CPU_COSTING

语法:CPU_COSTING                 

描述:指示优化器在代价估算时考虑CPU代价

HELLODBA.COM>alter session set "_optimizer_cost_model"=io;

 

Session altered.

 

HELLODBA.COM>exec sql_explain('select /*+CPU_COSTING*/* from t_users, t_tables','TYPICAL OUTLINE');

 

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

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

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

|   0 | SELECT STATEMENT     |          | 83576 |    28M|   835   (3)| 00:00:09 |

|   1 |  MERGE JOIN CARTESIAN|          | 83576 |    28M|   835   (3)| 00:00:09 |

|   2 |   TABLE ACCESS FULL  | T_USERS  |    31 |  3472 |     3   (0)| 00:00:01 |

|   3 |   BUFFER SORT        |          |  2696 |   634K|   832   (4)| 00:00:09 |

|   4 |    TABLE ACCESS FULL | T_TABLES |  2696 |   634K|    27   (4)| 00:00:01 |

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

NO_CPU_COSTING

语法:NO_CPU_COSTING              

描述:禁止优化器在代价估算时考虑CPU代价

HELLODBA.COM>exec sql_explain('select /*+NO_CPU_COSTING*/* from t_users','TYPICAL OUTLINE');

… …

Note

-----

   - cpu costing is off (consider enabling it)

DBMS_STATS

语法:DBMS_STATS                  

描述:出现在DBMS_STATS包收集统计数据的递归调用语句上,告诉优化器该语句是收集统计数据用的,不做额外处理(如自动调优)

示例(以下是对DBMS_STATS收集表统计数据过程跟踪得到的语句):

select /*+ no_parallel(t) no_parallel_index(t) dbms_stats cursor_sharing_exact use_weak_name_resl dynamic_sampling(0) no_monitoring no_substrb_pad */ count(*)  from "DEMO"."T_OBJECTS" sample block (  9.1911764706,1) t

DYNAMIC_SAMPLING

语法:DYNAMIC_SAMPLING([<@查询块>] [<>] <采用级别>)

描述:指定查询块或者表的采样级别,从010

HELLODBA.COM>exec dbms_stats.delete_table_stats('DEMO', 'T_OBJECTS_DUMMY');

 

PL/SQL procedure successfully completed.

 

HELLODBA.COM>exec sql_explain('select /*+ DYNAMIC_SAMPLING(3) */* from t_objects_dummy o, t_users u where o.owner=u.username', 'TYPICAL');

... ...

Note

-----

   - dynamic sampling used for this statement (level=3)

DYNAMIC_SAMPLING_EST_CDN

语法:DYNAMIC_SAMPLING_EST_CDN([<@查询块>] <>)

描述:指示优化器对已经存在统计数据的表也进行动态采样;

HELLODBA.COM>exec dbms_stats.gather_table_stats('DEMO', 'T_OBJECTS_DUMMY');

 

PL/SQL procedure successfully completed.

 

HELLODBA.COM>exec sql_explain('select /*+ DYNAMIC_SAMPLING(3) DYNAMIC_SAMPLING_EST_CDN(O) */* from t_objects_dummy o, t_users u where o.owner=u.username', 'TYPICAL');

... ...

 

Note

-----

   - dynamic sampling used for this statement (level=3)

GATHER_PLAN_STATISTICS

语法:GATHER_PLAN_STATISTICS      

描述:指示SQL执行器在运行SQL时收集语句的统计数据;

示例:

HELLODBA.COM>exec sql_explain('select /*+qb_name(M) GATHER_PLAN_STATISTICS*/* from t_tables t, t_users u where t.owner=u.username', 'BASIC LAST ALLSTATS', FALSE);

 

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

| Id |Operation          |Name    |Starts |E-Rows |A-Rows |   A-Time  |Buffers |OMem |1Mem | Used-Mem |

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

|*  1| HASH JOIN         |        |     1 |  2069 |  2071 |00:00:00.01|   2082 | 767K| 767K| 1161K (0)|

|   2|  TABLE ACCESS FULL|T_USERS |     1 |    43 |    43 |00:00:00.01|      7 |      |    |         |

|   3|  TABLE ACCESS FULL|T_TABLES|     1 |  2071 |  2071 |00:00:00.01|   2075 |      |    |         |

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

NO_STATS_GSETS

语法:NO_STATS_GSETS              

描述:不将对集合分组查询过程中产生的内部递归语句的运行统计数据计算在原语句的统计数据内。

HELLODBA.COM>SELECT /*+gather_plan_statistics*/ owner, object_type, count(object_id) obj_cnt FROM t_objects o GROUP BY GROUPING SETS (owner, object_type);

... ...

67 rows selected.

 

HELLODBA.COM>SELECT /*+gather_plan_statistics NO_STATS_GSETS*/ owner, object_type, count(object_id) obj_cnt FROM t_objects o GROUP BY GROUPING SETS (owner, object_type);

... ...

67 rows selected.

 

HELLODBA.COM>select substr(sql_text,1, 50), sharable_mem, executions, buffer_gets from v$sql where sql_text like 'SELECT /*+gather_plan_statistics%';

 

SUBSTR(SQL_TEXT,1,50)                                              SHARABLE_MEM EXECUTIONS BUFFER_GETS

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

SELECT /*+gather_plan_statistics*/ owner, object_t                         38421          1    4034

SELECT /*+gather_plan_statistics NO_STATS_GSETS*/                          38428          1    1490

OPT_ESTIMATE

语法:OPT_ESTIMATE([<@查询块>] <对象类型> <对象> <调整数据>=<数字>)

描述:指示优化器采用调整的对象的统计数据。其中,对象类型可以为QUERY_BLOCK/TABLE/INDEX_FILTER/INDEX_SCAN/INDEX_SKIP_SCAN/JOIN;相应对象为<@查询块>/<>/<索引所在表 索引>/JOIN(<关联对象1> <关联对象2>);调整数据可以为ROWS/SCALE_ROWS/MIN/MAXOPT_ESTIMATE/COLUMN_STATS/INDEX_STATS/TABLE_STATS提示通常是用于的SQL优化配置的辅助数据。

HELLODBA.COM>exec sql_explain('SELECT /*+QB_NAME(M) OPT_ESTIMATE(INDEX_SCAN U T_USERS_PK ROWS=8)*/ * from t_users u where user_id<:A','TYPICAL');

 

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

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

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

|   0 | SELECT STATEMENT            |            |     2 |   224 |     2   (0)| 00:00:01 |

|   1 |  TABLE ACCESS BY INDEX ROWID| T_USERS    |     2 |   224 |     2   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | T_USERS_PK |     8 |       |     1   (0)| 00:00:01 |

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

COLUMN_STATS

语法:COLUMN_STATS(<> <字段> <SCALE|NULL> [<调整统计数据1>=<数字1> ...])

描述:指示优化器使用调整的字段统计数据优化语句。其中,SCALE|NULL表示是否对统计数据进行放缩;可调整的统计数据包括:length(字段长度)、distinct(唯一值数)、nulls(空值数)、min(最小值)和max(最大值)。

HELLODBA.COM>exec sql_explain('select /*+qb_name(M) OPT_ESTIMATE(TABLE O scale_rows=721) COLUMN_STATS(t_objects, OBJECT_NAME, scale, length=666666) */object_name from t_objects o', 'TYPICAL OUTLINE');

 

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

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

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

|   0 | SELECT STATEMENT     |                |    51M|  4958M|   185   (2)| 00:00:02 |

|   1 |  INDEX FAST FULL SCAN| T_OBJECTS_IDX8 |    51M|  4958M|   185   (2)| 00:00:02 |

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

INDEX_STATS

语法:INDEX_STATS(<> <索引> <SCALE|NULL> [<调整统计数据1>=<数字1> ...])

描述:指示优化器使用调整的索引统计数据优化语句。其中,SCALE|NULL表示是否对统计数据进行放缩;可调整的统计数据包括:blocks(叶子数据块数)、index_rows(索引记录数)、keys(索引键值数)和clustering_factor(簇集因子)。

HELLODBA.COM>exec sql_explain('select /*+qb_name(M) index(o (object_id)) OPT_ESTIMATE(TABLE O scale_rows=721) INDEX_STATS(t_objects, t_objects_pk, scale, clustering_factor=66666) */object_name from t_objects o where object_id < 10000', 'TYPICAL OUTLINE');

 

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

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

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

|   0 | SELECT STATEMENT            |              |  7010K|   200M|  9023   (1)| 00:01:31 |

|   1 |  TABLE ACCESS BY INDEX ROWID| T_OBJECTS    |  7010K|   200M|  9023   (1)| 00:01:31 |

|*  2 |   INDEX RANGE SCAN          | T_OBJECTS_PK |  9723 |       |    20   (0)| 00:00:01 |

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

TABLE_STATS

语法:TABLE_STATS(<> <SCALE|NULL> [<调整统计数据1>=<数字1> ...])

描述:指示优化器使用调整的表统计数据优化语句。其中,SCALE|NULL表示是否对统计数据进行放缩;可调整的统计数据包括:blocks(数据块数)和rows(记录数)。

HELLODBA.COM>exec sql_explain('select /*+qb_name(M) OPT_ESTIMATE(TABLE t_objects scale_rows=0.1) TABLE_STATS(t_objects,scale, blocks=10 rows=1000) */* from t_objects', 'TYPICAL OUTLINE');

 

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

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

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

|   0 | SELECT STATEMENT  |           |  4765 |   567K|  1666   (1)| 00:00:07 |

|   1 |  TABLE ACCESS FULL| T_OBJECTS |  4765 |   567K|  1666   (1)| 00:00:07 |

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

优化器提示

NUM_INDEX_KEYS

语法:NUM_INDEX_KEYS([<@查询块>] <> <索引> <索引键数>)

描述:指示优化器在进行“INLIST ITERATOR”操作时,使用多少个索引键来访问索引

HELLODBA.COM>exec sql_explain('SELECT /*+ NUM_INDEX_KEYS(o T_OBJECTS_IDX8 2) */* FROM t_objects o WHERE owner = :A AND object_name IN (:B1, :B2, :B3)', 'BASIC OUTLINE PREDICATE');

… …

 

Outline Data

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

 

  /*+

      BEGIN_OUTLINE_DATA

      NUM_INDEX_KEYS(@"SEL$1" "O"@"SEL$1" "T_OBJECTS_IDX8" 2)

      INDEX_RS_ASC(@"SEL$1" "O"@"SEL$1" ("T_OBJECTS"."OWNER"

              "T_OBJECTS"."OBJECT_NAME" "T_OBJECTS"."SUBOBJECT_NAME"

              "T_OBJECTS"."OBJECT_ID" "T_OBJECTS"."DATA_OBJECT_ID"

              "T_OBJECTS"."OBJECT_TYPE" "T_OBJECTS"."CREATED" "T_OBJECTS"."STATUS"))

      OUTLINE_LEAF(@"SEL$1")

      OPTIMIZER_FEATURES_ENABLE('10.2.0.4')

      IGNORE_OPTIM_EMBEDDED_HINTS

      END_OUTLINE_DATA

  */

 

Predicate Information (identified by operation id):

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

 

   3 - access("OWNER"=:A AND ("OBJECT_NAME"=:B1 OR "OBJECT_NAME"=:B2 OR

              "OBJECT_NAME"=:B3))

BIND_AWARE

语法:BIND_AWARE

描述:指示优化器对绑定变量值的变化敏感,使得优化器利用扩展游标共享特性对语句进行自动优化;

HELLODBA.COM>var owner varchar2(30)

HELLODBA.COM>exec :owner := 'DEMO';

 

PL/SQL procedure successfully completed.

 

HELLODBA.COM>select /*+bind_aware*/* from t_objects where owner = :owner;

... ...

 

HELLODBA.COM>select sql_id, sql_text, is_bind_aware from v$sql where sql_text like 'select /*+bind_aware*/%';

 

SQL_ID        SQL_TEXT                                                       IS_BIND_AWARE

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

6asc1cwrbw925 select /*+bind_aware*/* from t_objects where owner = :owner    Y

NO_BIND_AWARE

语法:NO_BIND_AWARE               

描述:禁止优化器对绑定变量值的变化敏感,使得优化器不会利用扩展游标共享特性对语句进行自动优化;

HELLODBA.COM>select /*+no_bind_aware*/* from t_objects where owner = :owner;

... ...

 

HELLODBA.COM>select sql_id, sql_text, is_bind_aware from v$sql where sql_text like 'select /*+no_bind_aware*/%';

 

SQL_ID        SQL_TEXT                                                       IS_BIND_AWARE

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

586x9p08ag5f3 select /*+no_bind_aware*/* from t_objects where owner = :owner N

CURSOR_SHARING_EXACT

语法:CURSOR_SHARING_EXACT         

描述:指示优化器在使用共享游标时,对语句进行精确匹配,不会将变量值转换为绑定变量;

HELLODBA.COM>show parameter cursor_sharing

 

NAME                                 TYPE                             VALUE

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

cursor_sharing                       string                           SIMILAR

HELLODBA.COM>select count(*) from t_objects o where owner = 'DEMO';

… …

 

HELLODBA.COM>select sql_text from v$sql where sql_text like 'select count(*) from t_objects%';

 

SQL_TEXT

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

select count(*) from t_objects o where owner = :"SYS_B_0"

 

 

HELLODBA.COM>select count(*) from t_objects o where owner = 'DEMO';

… …

 

HELLODBA.COM>select sql_text from v$sql where sql_text like 'select /*+CURSOR_SHARING_EXACT*/count(*) from t_objects%';

 

SQL_TEXT

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

select /*+CURSOR_SHARING_EXACT*/count(*) from t_objects o where owner = 'DEMO'

DML_UPDATE

语法:DML_UPDATE

描述:用于更新位图关联索引的递归调用语句(UPD_JOININDEX),指明是由DML语句导致的数据更新。

FBTSCAN

语法:FBTSCAN

描述:用于对表的闪回(Flashback)查询。指示优化器查询闪回表(FlashBack Table)而非数据表本身。通常用于闪回查询的内部递归调用语句。这一提示会导致逻辑结果的改变。

HELLODBA.COM>var scn number

HELLODBA.COM>begin

  2    select dbms_flashback.get_system_change_number into :scn from dual;

  3  end;

  4  /

 

PL/SQL procedure successfully completed.

 

HELLODBA.COM>insert into t_tables(owner, table_name) values('NONE', 'NOTHING');

 

1 row created.

 

HELLODBA.COM>commit;

 

Commit complete.

 

HELLODBA.COM>SELECT /*+ QB_NAME(V) FBTSCAN FULL(S) */ count(SYS_FBT_INSDEL) FROM T_TABLES as of SCN :SCN S;

 

COUNT(SYS_FBT_INSDEL)

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

                   67

 

HELLODBA.COM>SELECT /*+ QB_NAME(V) FULL(S) */ count(SYS_FBT_INSDEL) FROM T_TABLES as of SCN :SCN S;

 

COUNT(SYS_FBT_INSDEL)

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

                    0

ALL_ROWS

语法:ALL_ROWS                    

描述:指示优化器在优化语句时,以消耗最少资源的最佳吞吐量为优化目标

HELLODBA.COM>exec sql_explain('select /*+ all_rows */* from t_objects o where rownum <= 10', 'TYPICAL OUTLINE');

 

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

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

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

|   0 | SELECT STATEMENT   |           |    10 |  1220 |  1670   (1)| 00:00:07 |

|*  1 |  COUNT STOPKEY     |           |       |       |            |          |

|   2 |   TABLE ACCESS FULL| T_OBJECTS | 47585 |  5669K|  1670   (1)| 00:00:07 |

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

FIRST_ROWS

语法:FIRST_ROWS([<记录数>])

描述:指示优化器在优化语句时,以最高效地返回前面指定数量的记录为目标。

HELLODBA.COM>exec sql_explain('select /*+ first_rows(10) */* from t_objects o', 'TYPICAL OUTLINE');

 

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

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

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

|   0 | SELECT STATEMENT  |           |    10 |  1220 |     5   (0)| 00:00:01 |

|   1 |  TABLE ACCESS FULL| T_OBJECTS |    10 |  1220 |     5   (0)| 00:00:01 |

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

RULE

语法:RULE                        

描述:指示优化器基于规则(RBO)选择执行计划;

HELLODBA.COM>exec sql_explain('select /*+ rule */* from t_objects o where object_id > 0', 'TYPICAL OUTLINE');

… …

 

Outline Data

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

 

  /*+

      BEGIN_OUTLINE_DATA

      … …

      RBO_OUTLINE

      … …

      END_OUTLINE_DATA

  */

CHOOSE

语法:CHOOSE                      

描述:指示优化器根据当前环境来选择优化模型;

HELLODBA.COM>exec dbms_stats.delete_table_stats('DEMO', 'T_OBJECTS_DUMMY');

 

PL/SQL procedure successfully completed.

 

HELLODBA.COM>exec sql_explain('select /*+ choose */* from t_objects_dummy o where rownum <= 10', 'BASIC NOTE');

… …

Note

-----

   - rule based optimizer used (consider using cbo)

ORDERED_PREDICATES

语法:ORDERED_PREDICATES           

描述:该提示指示优化器对除索引键值以外的谓词条件按照既定规则顺序评估代价,如果两个谓词符合相同规则,则按照其在WHERE子句中出现的顺序进行评估。这些顺序为:

    1. 不存在用户自定义函数、类型方法以及子查询的谓词条件;

    2. 存在用户自定义函数、类型方法的谓词条件,并且存在相关统计数据;

    3. 存在用户自定义函数、类型方法的谓词条件,不存在相关统计数据;

    4. 未在WHERE子句中出现的谓词条件,这种条件可能是由查询转换时产生的;

    5. 存在子查询的谓词条件;

(比较以下两个执行计划的代价)

HELLODBA.COM>exec sql_explain('select /*+ full(o) */* from t_objects o, t_tables t where o.owner = t.owner and o.object_name = t.table_name and exists (select 1 from t_tables t where o.object_name=t.table_name) and o.owner in (select username from t_users) and to_char(object_id)=:B and object_type = :A', 'TYPICAL');

 

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

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

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

|   0 | SELECT STATEMENT             |             |     1 |   372 |   297   (3)| 00:00:03 |

|   1 |  NESTED LOOPS                |             |       |       |            |          |

|   2 |   NESTED LOOPS               |             |     1 |   372 |   297   (3)| 00:00:03 |

|   3 |    NESTED LOOPS SEMI         |             |     1 |   131 |   296   (3)| 00:00:03 |

|   4 |     NESTED LOOPS             |             |     1 |   110 |   295   (3)| 00:00:03 |

|*  5 |      TABLE ACCESS FULL       | T_OBJECTS   |     1 |   100 |   295   (3)| 00:00:03 |

|*  6 |      INDEX UNIQUE SCAN       | T_USERS_UK  |     1 |    10 |     0   (0)| 00:00:01 |

|*  7 |     INDEX RANGE SCAN         | T_TABLES_PK |  1097 | 23037 |     1   (0)| 00:00:01 |

|*  8 |    INDEX UNIQUE SCAN         | T_TABLES_PK |     1 |       |     0   (0)| 00:00:01 |

|   9 |   TABLE ACCESS BY INDEX ROWID| T_TABLES    |     1 |   241 |     1   (0)| 00:00:01 |

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

 

HELLODBA.COM>exec sql_explain('select /*+ full(o) ORDERED_PREDICATES */* from t_objects o, t_tables t where o.owner = t.owner and o.object_name = t.table_name and exists (select 1 from t_tables t where o.object_name=t.table_name) and o.owner in (select username from t_users) and to_char(object_id)=:B and object_type = :A', 'TYPICAL');

 

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

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

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

|   0 | SELECT STATEMENT             |             |     1 |   372 |   298   (3)| 00:00:03 |

|   1 |  NESTED LOOPS                |             |       |       |            |          |

|   2 |   NESTED LOOPS               |             |     1 |   372 |   298   (3)| 00:00:03 |

|   3 |    NESTED LOOPS SEMI         |             |     1 |   131 |   297   (3)| 00:00:03 |

|   4 |     NESTED LOOPS             |             |     1 |   110 |   296   (3)| 00:00:03 |

|*  5 |      TABLE ACCESS FULL       | T_OBJECTS   |     1 |   100 |   296   (3)| 00:00:03 |

|*  6 |      INDEX UNIQUE SCAN       | T_USERS_UK  |     1 |    10 |     0   (0)| 00:00:01 |

|*  7 |     INDEX RANGE SCAN         | T_TABLES_PK |  1097 | 23037 |     1   (0)| 00:00:01 |

|*  8 |    INDEX UNIQUE SCAN         | T_TABLES_PK |     1 |       |     0   (0)| 00:00:01 |

|   9 |   TABLE ACCESS BY INDEX ROWID| T_TABLES    |     1 |   241 |     1   (0)| 00:00:01 |

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

SKIP_EXT_OPTIMIZER

语法:SKIP_EXT_OPTIMIZER          

描述:指示优化器跳过扩展优化器。Oracle允许用户可以自定义统计数据、选择率和代价计算函数来对用户自定义函数或者域索引进行优化,以扩展优化器(CBO)。

SKIP_UNQ_UNUSABLE_IDX

语法:SKIP_UNQ_UNUSABLE_IDX([<@查询块>] <> [<索引1> ...]) 或者 SKIP_UNQ_UNUSABLE_IDX([<@查询块>] <> [(<索引字段列表1>) ...])

描述:指示优化器忽略表上状态为UNUSABLE的索引

HELLODBA.COM>alter index t_tables_pk unusable;

 

Index altered.

 

HELLODBA.COM>select /*+ index(t t_tables_pk) */count(1) from t_tables t;

select /*+ index(t t_tables_pk) */count(1) from t_tables t

*

ERROR at line 1:

ORA-01502: index 'DEMO.T_TABLES_PK' or partition of such index is in unusable state

 

HELLODBA.COM>select /*+ SKIP_UNQ_UNUSABLE_IDX(t) index(t t_tables_pk) */count(1) from t_tables t;

 

  COUNT(1)

----------

      2696

Top

Copyright ©2005,HelloDBA.Com 保留一切权利

申明
by fuyuncat