Vous êtes sur la page 1sur 2

How to use hints in Oracle sql for performance

With hints one can influence the optimizer. The usage of hints (with exception of the RULE-
hint) causes Oracle to use the Cost Based optimizer.

The following syntax is used for hints:

select /*+ HINT */ name


from emp
where id =1;

Where HINT is replaced by the hint text.


When the syntax of the hint text is incorrect, the hint text is ignored and will not be used.
here you can find undocumented hints.

Hints for Optimization Approaches and Goals


The ALL_ROWS hint explicitly chooses the cost-based
ALL_ROWS approach to optimize a statement block with a goal of best
throughput (that is, minimum total resource consumption).
The FIRST_ROWS hint explicitly chooses the cost-based
approach to optimize a statement block with a goal of best
response time (minimum resource usage to return first
FIRST_ROWS row). In newer Oracle version you should give a parameter
with this hint: FIRST_ROWS(n) means that the optimizer
will determine an executionplan to give a fast response for
returning the first n rows.
The CHOOSE hint causes the optimizer to choose
between the rule-based approach and the cost-based
CHOOSE
approach for a SQL statement based on the presence of
statistics for the tables accessed by the statement
The RULE hint explicitly chooses rule-based optimization
for a statement block. This hint also causes the optimizer
RULE
to ignore any other hints specified for the statement block.
The RULE hint does not work any more in Oracle 10g.
Hints for Access Paths
The FULL hint explicitly chooses a full table scan for the
specified table. The syntax of the FULL hint is FULL(table)
FULL where table specifies the alias of the table (or table name
if alias does not exist) on which the full table scan is to be
performed.
The ROWID hint explicitly chooses a table scan by
ROWID for the specified table. The syntax of the ROWID
ROWID hint is ROWID(table) where table specifies the name or
alias of the table on which the table access by ROWID is
to be performed. (This hint depricated in Oracle 10g)
The CLUSTER hint explicitly chooses a cluster scan to
access the specified table. The syntax of the CLUSTER
CLUSTER
hint is CLUSTER(table) where table specifies the name or
alias of the table to be accessed by a cluster scan.
The HASH hint explicitly chooses a hash scan to access
the specified table. The syntax of the HASH hint is
HASH
HASH(table) where table specifies the name or alias of the
table to be accessed by a hash scan.
The HASH_AJ hint transforms a NOT IN subquery into a
hash anti-join to access the specified table. The syntax of
HASH_AJ the HASH_AJ hint is HASH_AJ(table) where table
specifies the name or alias of the table to be accessed.
(depricated in Oracle 10g)
The INDEX hint explicitly chooses an index scan for the
specified table. The syntax of the INDEX hint is
INDEX(table index) where:table specifies the name or
Cost Based Optimizer (CBO) and Database Statistics
Whenever a valid SQL statement is processed Oracle has to decide how to retrieve the
necessary data. This decision can be made using one of two methods:

• Rule Based Optimizer (RBO) - This method is used if the server has no internal statistics
relating to the objects referenced by the statement. This method is no longer favoured by
Oracle and will be desupported in future releases.
• Cost Based Optimizer (CBO) - This method is used if internal statistics are present. The
CBO checks several possible execution plans and selects the one with the lowest cost,
where cost relates to system resources.

Vous aimerez peut-être aussi