Optimizer Hints!

doc上的这段话对Optimizer Hints介绍的非常清楚,记录一下!

当然更重要的是能够熟练的使用各种hint来改变sql的执行计划从而优化sql

这里对下面一段做一点解释:

You can use hints to specify the following:

  • The optimization approach for a SQL statement
  • --The optimization approach 指的是cbo和rbo
  • The goal of the cost-based optimizer for a SQL statement
  • --The goal of the cost-based optimizer 指的是语句追求的是最大吞吐量( all_rows)还是最快响应时间(first_rows(n))
  • The access path for a table accessed by the statement
  • --The access path for a table accessed是指full table scan or index scan
  • The join order for a join statement
  • --是指表的连接顺序
  • A join operation in a join statement
  • --A join operation 指的应该是表与表之间的连接方法:nl,merge or hash

[@more@]

Optimizer Hints

Optimizer hints can be used with SQL statements to alter execution plans. This chapter explains how to use hints to force various approaches.

The chapter contains the following sections:

Understanding Optimizer Hints

Hints let you make decisions usually made by the optimizer. As an application designer, you might know information about your data that the optimizer does not know.

For example, you might know that a certain index is more selective for certain queries. Based on this information, you might be able to choose a more efficient execution plan than the optimizer. In such a case, use hints to force the optimizer to use the optimal execution plan.

You can use hints to specify the following:

  • The optimization approach for a SQL statement
  • The goal of the cost-based optimizer for a SQL statement
  • The access path for a table accessed by the statement
  • The join order for a join statement
  • A join operation in a join statement


    Note:

    The use of hints involves extra code that must be managed, checked, and controlled.


Hints provide a mechanism to direct the optimizer to choose a certain query execution plan based on the following criteria:

  • Join order
  • Join method
  • Access path
  • Parallelization

Hints (except for the RULE hint) invoke the cost-based optimizer (CBO). If you have not gathered statistics, then defaults are used.

See Also:

Chapter 3, "Gathering Optimizer Statistics" for more information on default values

Specifying Hints

Hints apply only to the optimization of the statement block in which they appear. A statement block is any one of the following statements or parts of statements:

  • A simple SELECT, UPDATE, or DELETE statement.
  • A parent statement or subquery of a complex statement.
  • A part of a compound query.

For example, a compound query consisting of two component queries combined by the UNION operator has two statement blocks, one for each component query. For this reason, hints in the first component query apply only to its optimization, not to the optimization of the second component query.

You can send hints for a SQL statement to the optimizer by enclosing them in a comment within the statement.

See Also:

Oracle9i SQL Reference for more information on comments

A statement block can have only one comment containing hints. This comment can only follow the SELECT, UPDATE, or DELETE keyword.


Exception:

The APPEND hint always follows the INSERT keyword, and the PARALLEL hint can follow the INSERT keyword.


The following syntax shows hints contained in both styles of comments that Oracle supports within a statement block.

{DELETE|INSERT|SELECT|UPDATE} /*+ hint [text] [hint[text]]... */

or

{DELETE|INSERT|SELECT|UPDATE} --+ hint [text] [hint[text]]...

where:

  • DELETE, INSERT, SELECT, and UPDATE are keywords that begin a statement block. Comments containing hints can appear only after these keywords.
  • + causes Oracle to interpret the comment as a list of hints. The plus sign must immediately follow the comment delimiter; no space is permitted.
  • hint is one of the hints discussed in this section. If the comment contains multiple hints, then each hint must be separated from the others by at least one space.
  • text is other commenting text that can be interspersed with the hints.

If you specify hints incorrectly, then Oracle ignores them but does not return an error:

  • Oracle ignores hints if the comment containing them does not follow a DELETE, SELECT, or UPDATE keyword.
  • Oracle ignores hints containing syntax errors, but considers other correctly specified hints within the same comment.
  • Oracle ignores combinations of conflicting hints, but considers other hints within the same comment.
  • Oracle ignores hints in all SQL statements in those environments that use PL/SQL version 1, such as Forms version 3 triggers, Oracle Forms 4.5, and Oracle Reports 2.5. These hints can be passed to the server, but the server ignores them.

The optimizer recognizes hints only when using the cost-based approach. If you include a hint (except the RULE hint) in a statement block, then the optimizer automatically uses the cost-based approach.

See Also:

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/19602/viewspace-1003107/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/19602/viewspace-1003107/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OceanBase 数据库在优化器方面与 MySQL 数据库的区别,主要表现在以下几个方面: 1. 查看执行计划的命令 1)输出的列信息仅包含 ID、OPERATOR、NAME、EST. ROWS 和 COST 以及算子的详细信息。 2)不支持使用 SHOW WARNINGS 显示额外的信息。 2. 查看统计信息 1)支持执行 ANALYZE TABLE 语句查询数据字典表存储有关列值的直方图统计信息。 2)支持通过内部表 __all_meta_table 查看表统计信息和列统计信息。 3. 查询改写优化 1)支持外联接优化 2)支持外联接简化 3)支持块嵌套循环和批量 Key 访问联接 4)支持条件过滤 5)支持常量叠算优化 6)支持 IS NULL 优化 (索引不存储 NULL 值) 7)支持 ORDER BY 优化 8)支持 GROUP BY 优化 9)支持 DISTINCT 消除 10)支持 LIMIT 下压 11)支持 Window 函数优化 12)支持避免全表扫描 13)支持谓词下压 4. Optimizer Hint 机制 1)支持联接顺序 Optimizer Hints 2)支持表级别的 Optimizer Hints 3)支持索引级别的 Optimizer Hints 4)语法支持 INDEX Hint、FULL Hint、ORDERED Hint 和 LEADING Hint 等,不支持 USE INDEX 和 FORCE INDEX。 5. 兼容 MySQL 数据库的并行执行能力包括并行查询、并行复制和并行写入等,且 OceanBase 数据库已经支持并行算子,包括并行聚集、并行联接、并行分组以及并行排序等。 6. OceanBase 数据库还支持计划缓存和预编译,MySQL 数据库并不支持。 以上是OceanBase与mysql的优化器区别,仿造该格式列出postgresql与mysql的优化器区别
07-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值