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

相关推荐
heartbeat..15 小时前
Spring AOP 全面详解(通俗易懂 + 核心知识点 + 完整案例)
java·数据库·spring·aop
麦聪聊数据17 小时前
MySQL并发与锁:从“防止超卖”到排查“死锁”
数据库·sql·mysql
AC赳赳老秦18 小时前
DeepSeek 私有化部署避坑指南:敏感数据本地化处理与合规性检测详解
大数据·开发语言·数据库·人工智能·自动化·php·deepseek
YMatrix 官方技术社区19 小时前
YMatrix 存储引擎解密:MARS3 存储引擎如何超越传统行存、列存实现“时序+分析“场景性能大幅提升?
开发语言·数据库·时序数据库·数据库架构·智慧工厂·存储引擎·ymatrix
辞砚技术录19 小时前
MySQL面试题——索引2nd
数据库·mysql·面试
linweidong20 小时前
C++thread pool(线程池)设计应关注哪些扩展性问题?
java·数据库·c++
欧亚学术20 小时前
突发!刚刚新增17本期刊被剔除!
数据库·论文·sci·期刊·博士·scopus·发表
oMcLin21 小时前
如何在Oracle Linux 8.4上搭建并优化Kafka集群,确保高吞吐量的实时数据流处理与消息传递?
linux·oracle·kafka
黑白极客21 小时前
怎么给字符串字段加索引?日志系统 一条更新语句是怎么执行的
java·数据库·sql·mysql·引擎
大厂技术总监下海21 小时前
数据湖加速、实时数仓、统一查询层:Apache Doris 如何成为现代数据架构的“高性能中枢”?
大数据·数据库·算法·apache