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

相关推荐
山峰哥8 分钟前
数据库工程与SQL调优——从索引策略到查询优化的深度实践
数据库·sql·性能优化·编辑器
较劲男子汉19 分钟前
CANN Runtime零拷贝传输技术源码实战 彻底打通Host与Device的数据传输壁垒
运维·服务器·数据库·cann
java搬砖工-苤-初心不变24 分钟前
MySQL 主从复制配置完全指南:从原理到实践
数据库·mysql
山岚的运维笔记2 小时前
SQL Server笔记 -- 第18章:Views
数据库·笔记·sql·microsoft·sqlserver
roman_日积跬步-终至千里3 小时前
【LangGraph4j】LangGraph4j 核心概念与图编排原理
java·服务器·数据库
汇智信科3 小时前
打破信息孤岛,重构企业效率:汇智信科企业信息系统一体化运营平台
数据库·重构
野犬寒鸦3 小时前
从零起步学习并发编程 || 第六章:ReentrantLock与synchronized 的辨析及运用
java·服务器·数据库·后端·学习·算法
WHD3064 小时前
苏州数据库(SQL Oracle)文件损坏修复
hadoop·sql·sqlite·flume·memcached
晚霞的不甘5 小时前
揭秘 CANN 内存管理:如何让大模型在小设备上“轻装上阵”?
前端·数据库·经验分享·flutter·3d
市场部需要一个软件开发岗位5 小时前
JAVA开发常见安全问题:纵向越权
java·数据库·安全