19.3.3.3 Reporting on Hint Usage: Tutorial
You can use the DBMS_XPLAN display functions to report on hint usage.
19.3.3.3 提示符使用报告:操作教程
可以使用DBMS_XPLAN显示函数来生成提示符使用报告。
Hint usage reporting is enabled by default. The steps for displaying a plan with hint information are the same as for displaying a plan normally.
提示符使用报告功能默认处于启用状态。显示包含提示符信息的执行计划步骤与常规执行计划显示步骤完全一致。
Assumptions
This tutorial assumes the following:
前提条件
本操作教程基于以下假设:
• An index named emp_emp_id_pk exists on the employees.employee_id column.
• You want to query a specific employee.
• You want to use the INDEX hint to force the optimizer to use emp_emp_id_pk.
•在employees.employee_id列上存在名为emp_emp_id_pk的索引
•需要查询特定员工信息
•计划使用INDEX提示符强制优化器使用emp_emp_id_pk索引
To report on hint usage:
-
Start SQL*Plus or SQL Developer, and log in to the database as user hr.
-
Explain the plan for the query of employees. For example, enter the following statement:
生成提示符使用报告的步骤:
-
启动SQL*Plus或SQL Developer,以hr用户身份登录数据库
-
解析employees表查询的执行计划
例如,输入以下语句:

- Query the plan table using a display function.
You can specify any of the following values in the format parameter:
- 使用显示函数查询计划表
可以在format参数中指定以下任意值:
• ALL
• TYPICAL
The following query displays all sections of the plan, including the hint usage information (sample output included):
以下查询将显示执行计划的所有部分,包括提示符使用信息(包含示例输出):


The Hint Report section shows that the query block for the INDEX(e emp_emp_id_pk) hint is SEL1. The table identifier is E@SEL1. The line number of the plan line is 2, which corresponds to the first line where the table E@SEL$1 appears in the plan table.
提示符报告部分显示,INDEX(e emp_emp_id_pk)提示符对应的查询块为SEL1。表标识符为E@SEL1。计划行号显示为2,对应计划表中E@SEL$1表首次出现的行位置。
See Also:
Oracle Database SQL Language Reference to learn more about EXPLAIN PLAN
另请参阅 :
Oracle Database SQL Language Reference 了解有关EXPLAIN PLAN的更多信息
19.3.3.4 Hint Usage Reports: Examples
These examples show various types of hint usage reports.
The following examples all show queries of tables in the hr schema.
19.3.3.4 提示符使用报告:示例
以下示例展示各类提示符使用报告的具体形式。
所有示例均展示对hr模式中表的查询操作。
Example 19-2 Statement-Level Unused Hint
The following example specifies an index range hint for the emp_manager_ix index:
示例19-2 语句级未使用提示符
以下示例为emp_manager_ix索引指定了索引范围提示符:

The following query of the plan table specifies the format value of TYPICAL, which shows only unused hints:
以下对计划表的查询指定了TYPICAL格式值,该设置仅显示未使用的提示符:

The U in the preceding hint usage report indicates that the INDEX_RS hint was not used. The report shows the total number of unused hints: U -- Unused (1).
前述提示符使用报告中的"U"标记表明INDEX_RS提示符未被使用。报告同时显示未使用提示符的总数统计:U - 未使用(1个)。
Example 19-3 Conflicting Hints
The following example specifies two hints, one for a skip scan and one for a fast full scan:
示例19-3 冲突的提示符
以下示例指定了两个相互冲突的提示符:一个要求跳跃扫描,另一个要求快速全扫描:

The following query of the plan table specifies the format value of TYPICAL, which shows only unused hints:
以下对计划表的查询指定了TYPICAL格式值,该设置仅显示未使用的提示符:


The preceding report shows that the INDEX_FFS(e) and INDEX_SS(e emp_manager_ix) hints conflict with one other. Index skip scans and index fast full scans are mutually exclusive. The optimizer ignored both hints, as indicated by the text U --- Unused (2). Even though the optimizer ignored the hint specifying the emp_manager_ix index, the optimizer used this index anyway based on its cost-based analysis.
前述报告显示INDEX_FFS(e)和INDEX_SS(e emp_manager_ix)两个提示符相互冲突。索引跳跃扫描与索引快速全扫描是互斥操作。优化器同时忽略了这两个提示符,如报告中的"U --- 未使用(2个)"所示。尽管优化器忽略了指定emp_manager_ix索引的提示符,但基于成本分析优化器最终仍选择了该索引。
Example 19-4
Multitable Hints The following example specifies four hints, one of which specifies two tables:
示例19-4 多表提示符
以下示例指定了四个提示符,其中一个提示符涉及对两个表的操作:


The preceding report shows that two hints were not used: USE_NL(t1, t2) and NLJ_PREFETCH(t2). Step 3 of the plan is an index full scan of the jobs table, which uses the alias t1. The report shows that the optimizer did not apply the USE_NL(t1, t2) hint for the access of jobs. Step 4 is an index unique scan of the employees table, which uses the alias t2. No U prefix exists for USE_NL(t1, t2), which means that the optimizer did use the hint for employees.
前述报告显示有两个提示符未被使用:USE_NL(t1, t2)和NLJ_PREFETCH(t2)。执行计划第3步是对jobs表(使用别名t1)的索引全扫描。报告表明优化器在处理jobs表时未应用USE_NL(t1, t2)提示符。第4步是对employees表(使用别名t2)的索引唯一扫描。USE_NL(t1, t2)提示符前没有U标记,说明优化器在处理employees表时实际采用了该提示符。