How to Specify an INDEX Hint oracle官方文档
发表于:2024-12-12 作者:千家信息网编辑
千家信息网最后更新 2024年12月12日,How to Specify an INDEX Hint (Doc ID 50607.1)Applies to:Oracle Database - Enterprise Edition - Versi
千家信息网最后更新 2024年12月12日How to Specify an INDEX Hint oracle官方文档How to Specify an INDEX Hint (Doc ID 50607.1)
Applies to:
Oracle Database - Enterprise Edition - Version 9.2.0.1 to 11.2.0.2 [Release 9.2 to 11.2]
Information in this document applies to any platform.
Purpose
This article explains how to specify index hints successfully.
Troubleshooting Steps
The format for an index hint is:
select /*+ index(TABLE_NAME INDEX_NAME) */ col1...
There are a number of rules that need to be applied to this hint:
The TABLE_NAME is mandatory in the hint
The table alias MUST be used if the table is aliased in the query
If TABLE_NAME or alias is spelled incorrectly then the hint will not be used.
The INDEX_NAME is optional.
If an INDEX_NAME is entered without a TABLE_NAME then the hint will not be applied.
If a TABLE_NAME is supplied on its own then the optimizer will decide which index to use based on statistics.
If the INDEX_NAME is spelt incorrectly but the TABLE_NAME is spelled correctly then the hint will not be applied even though the TABLE_NAME is correct.
If there are multiple index hints to be applied, then the simplest way of addressing this is to repeat the index hint syntax for each index e.g.:
SELECT /*+ index(TABLE_NAME1 INDEX_NAME1) index(TABLE_NAME2 INDEX_NAME2) */ col1...
Remember that the parser/optimizer may have transformed/rewritten the query or may have chosen an access path which make the use of the index invalid and this may result in the index not being used.
Legacy Note: As long as the index() hint structure is correct this will force the use of the Cost Based Optimizer (CBO). This will happen even if the alias or table name is incorrect.
Examples
The examples below use a table CBOTAB with a unique single column index called CBOTAB1 on column COL1.
Correct hint to force use of the index:
explain plan for select /*+ index(cbotab) */ col1 from cbotab;
explain plan for select /*+ index(cbotab cbotab1) */ col1 from cbotab;
explain plan for select /*+ index(a cbotab1) */ col1 from cbotab a;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=151
INDEX FULL SCAN CBOTAB1 [ANALYZED] Cost=151 Card=10000 Bytes=100000
The TABLE_NAME is mandatory in the hint.
In the following example the TABLE_NAME was omitted so the index was not used.
SQL> explain plan for select /*+ index() */ col1 from cbotab;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=10
TABLE ACCESS FULL CBOTAB [ANALYZED] Cost=10 Card=10000 Bytes=100000
The INDEX_NAME is optional.
Both of the following examples use the index:
explain plan for select /*+ index(cbotab) */ col1 from cbotab;
explain plan for select /*+ index(cbotab cbotab1) */ col1 from cbotab;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=151
INDEX FULL SCAN CBOTAB1 [ANALYZED] Cost=151 Card=10000 Bytes=100000
The table alias MUST be used if the table is aliased in the query
SQL> explain plan for select /*+ index(cbotab) */ col1 from cbotab mytable;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=10
TABLE ACCESS FULL CBOTAB [ANALYZED] Cost=10 Card=10000 Bytes=100000
Correct use of alias in hint:
SQL> explain plan for select /*+ index(mytable) */ col1 from cbotab mytable;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=151
INDEX FULL SCAN CBOTAB1 [ANALYZED] Cost=151 Card=10000 Bytes=100000
If TABLE_NAME or alias is spelled incorrectly then the hint will not be used.
SQL> explain plan for select /*+ index(COBTAB) */ col1 from cbotab;
SQL> explain plan for select /*+ index(MITABLE) */ col1 from cbotab mytable;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=10
TABLE ACCESS FULL CBOTAB [ANALYZED] Cost=10 Card=10000 Bytes=100000
If an INDEX_NAME is entered without a TABLE_NAME then the hint will not be applied.
SQL> explain plan for select /*+ index(cbotab1) */ col1 from cbotab;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=10
TABLE ACCESS FULL CBOTAB [ANALYZED] Cost=10 Card=10000 Bytes=100000
If a TABLE_NAME is supplied on its own then the optimizer will decide which index to use based on statistics.
explain plan for select /*+ index(cbotab) */ col1 from cbotab;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=151
INDEX FULL SCAN CBOTAB1 [ANALYZED] Cost=151 Card=10000 Bytes=100000
If the INDEX_NAME is spelt incorrectly but the TABLE_NAME is spelt correctly then the hint will not be applied even though the TABLE_NAME is correct.
SQL> explain plan for select /*+ index(cbotab COBTAB1) */ col1 from cbotab;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=10
TABLE ACCESS FULL CBOTAB [ANALYZED] Cost=10 Card=10000 Bytes=100000
Applies to:
Oracle Database - Enterprise Edition - Version 9.2.0.1 to 11.2.0.2 [Release 9.2 to 11.2]
Information in this document applies to any platform.
Purpose
This article explains how to specify index hints successfully.
Troubleshooting Steps
The format for an index hint is:
select /*+ index(TABLE_NAME INDEX_NAME) */ col1...
There are a number of rules that need to be applied to this hint:
The TABLE_NAME is mandatory in the hint
The table alias MUST be used if the table is aliased in the query
If TABLE_NAME or alias is spelled incorrectly then the hint will not be used.
The INDEX_NAME is optional.
If an INDEX_NAME is entered without a TABLE_NAME then the hint will not be applied.
If a TABLE_NAME is supplied on its own then the optimizer will decide which index to use based on statistics.
If the INDEX_NAME is spelt incorrectly but the TABLE_NAME is spelled correctly then the hint will not be applied even though the TABLE_NAME is correct.
If there are multiple index hints to be applied, then the simplest way of addressing this is to repeat the index hint syntax for each index e.g.:
SELECT /*+ index(TABLE_NAME1 INDEX_NAME1) index(TABLE_NAME2 INDEX_NAME2) */ col1...
Remember that the parser/optimizer may have transformed/rewritten the query or may have chosen an access path which make the use of the index invalid and this may result in the index not being used.
Legacy Note: As long as the index() hint structure is correct this will force the use of the Cost Based Optimizer (CBO). This will happen even if the alias or table name is incorrect.
Examples
The examples below use a table CBOTAB with a unique single column index called CBOTAB1 on column COL1.
Correct hint to force use of the index:
explain plan for select /*+ index(cbotab) */ col1 from cbotab;
explain plan for select /*+ index(cbotab cbotab1) */ col1 from cbotab;
explain plan for select /*+ index(a cbotab1) */ col1 from cbotab a;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=151
INDEX FULL SCAN CBOTAB1 [ANALYZED] Cost=151 Card=10000 Bytes=100000
The TABLE_NAME is mandatory in the hint.
In the following example the TABLE_NAME was omitted so the index was not used.
SQL> explain plan for select /*+ index() */ col1 from cbotab;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=10
TABLE ACCESS FULL CBOTAB [ANALYZED] Cost=10 Card=10000 Bytes=100000
The INDEX_NAME is optional.
Both of the following examples use the index:
explain plan for select /*+ index(cbotab) */ col1 from cbotab;
explain plan for select /*+ index(cbotab cbotab1) */ col1 from cbotab;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=151
INDEX FULL SCAN CBOTAB1 [ANALYZED] Cost=151 Card=10000 Bytes=100000
The table alias MUST be used if the table is aliased in the query
SQL> explain plan for select /*+ index(cbotab) */ col1 from cbotab mytable;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=10
TABLE ACCESS FULL CBOTAB [ANALYZED] Cost=10 Card=10000 Bytes=100000
Correct use of alias in hint:
SQL> explain plan for select /*+ index(mytable) */ col1 from cbotab mytable;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=151
INDEX FULL SCAN CBOTAB1 [ANALYZED] Cost=151 Card=10000 Bytes=100000
If TABLE_NAME or alias is spelled incorrectly then the hint will not be used.
SQL> explain plan for select /*+ index(COBTAB) */ col1 from cbotab;
SQL> explain plan for select /*+ index(MITABLE) */ col1 from cbotab mytable;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=10
TABLE ACCESS FULL CBOTAB [ANALYZED] Cost=10 Card=10000 Bytes=100000
If an INDEX_NAME is entered without a TABLE_NAME then the hint will not be applied.
SQL> explain plan for select /*+ index(cbotab1) */ col1 from cbotab;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=10
TABLE ACCESS FULL CBOTAB [ANALYZED] Cost=10 Card=10000 Bytes=100000
If a TABLE_NAME is supplied on its own then the optimizer will decide which index to use based on statistics.
explain plan for select /*+ index(cbotab) */ col1 from cbotab;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=151
INDEX FULL SCAN CBOTAB1 [ANALYZED] Cost=151 Card=10000 Bytes=100000
If the INDEX_NAME is spelt incorrectly but the TABLE_NAME is spelt correctly then the hint will not be applied even though the TABLE_NAME is correct.
SQL> explain plan for select /*+ index(cbotab COBTAB1) */ col1 from cbotab;
Query Plan
--------------------------------------------------------------------------------
SELECT STATEMENT [CHOOSE] Cost=10
TABLE ACCESS FULL CBOTAB [ANALYZED] Cost=10 Card=10000 Bytes=100000
e.g.
官方
文档
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
博学宝服务器错误怎么办
软件开发项目公司电话
内蒙古手机app软件开发
理性消费谨防网络安全的宣传画
软件开发合同起诉流程
关系数据库原理考题
数据库传输大量数据
去哪买服务器
深圳回收服务器cpu
巴彦淖尔软件开发培训学校
信息网络安全英语介绍
广东常用软件开发价格大全
破产企业债权人网络技术服务
镇安租房软件开发
软件开发工程师需要什么配置电脑
学院网络安全工作要点2021
惠普服务器怎么设置数据保护
云主机挂机服务器
数据库软件未激活可以调用吗
火影忍者手游474服务器
sql数据库怎样追踪查询
天和兴是网络安全公司吗
网络安全事故导致的危害英语
数据库表和自由表
云顶手游无法接通服务器
c数据库连接
如何设置数据库中表的输入掩码
杭州启维网络技术有限公司
阴阳师以前登录过的服务器
上海惠普服务器维修多少钱