Oracle sql tuning guide 翻译 Part 6-5 --- Hint使用报告的操作方法和例子

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:

  1. Start SQL*Plus or SQL Developer, and log in to the database as user hr.

  2. Explain the plan for the query of employees. For example, enter the following statement:

生成提示符使用报告的步骤:

  1. 启动SQL*Plus或SQL Developer,以hr用户身份登录数据库

  2. 解析employees表查询的执行计划

例如,输入以下语句:

  1. Query the plan table using a display function.

You can specify any of the following values in the format parameter:

  1. 使用显示函数查询计划表

可以在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表时实际采用了该提示符。

相关推荐
倔强的石头_11 小时前
kingbase备份与恢复实战(二)—— sys_dump库级逻辑备份与恢复(Windows详细步骤)
数据库
jiayou642 天前
KingbaseES 实战:深度解析数据库对象访问权限管理
数据库
李广坤3 天前
MySQL 大表字段变更实践(改名 + 改类型 + 改长度)
数据库
爱可生开源社区4 天前
2026 年,优秀的 DBA 需要具备哪些素质?
数据库·人工智能·dba
随逸1774 天前
《从零搭建NestJS项目》
数据库·typescript
加号34 天前
windows系统下mysql多源数据库同步部署
数据库·windows·mysql
シ風箏4 天前
MySQL【部署 04】Docker部署 MySQL8.0.32 版本(网盘镜像及启动命令分享)
数据库·mysql·docker
李慕婉学姐4 天前
Springboot智慧社区系统设计与开发6n99s526(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
数据库·spring boot·后端
百锦再4 天前
Django实现接口token检测的实现方案
数据库·python·django·sqlite·flask·fastapi·pip
tryCbest4 天前
数据库SQL学习
数据库·sql