首页 > 数据库 > Oracle > Optimizer Hints!
doc上的这段话对Optimizer Hints介绍的非常清楚,记录一下!
当然更重要的是能够熟练的使用各种hint来改变sql的执行计划从而优化sql
这里对下面一段做一点解释:
You can use hints to specify the following:
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:
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:
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:
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 |
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:
SELECT, UPDATE, or DELETE statement. 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 |
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:
DELETE, SELECT, or UPDATE keyword. 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博客 ” ,链接:https://blog.itpub.net/19602/viewspace-1003107/ ,如需转载,请注明出处,否则将追究法律责任。