- what is Oracle Optimizer .
- How it works
- How we can manipulate optimizer for session or Individual Query
A SQL statement can be executed in many
different ways, such as
- full table scans,
- index scans,
- nested loops, and
- hash joins.
What is Query optimizer - The query optimizer determines the most
efficient way to execute a SQL statement after considering many factors related to
the objects referenced and the conditions specified in the query.
Note:The
optimizer might not make the same decisions from one version of Oracle to the
next. In recent versions, the optimizer might make different decisions, because
better information is available.
The output from the optimizer is a plan that
describes an optimum method of execution. The Oracle server provides query optimization.
For any
SQL statement processed by Oracle, the optimizer performs the operations listed
in below table
Operation
|
Description
|
Evaluation of
expressions and conditions
|
The optimizer first
evaluates expressions and conditions containing constants as fully as
possible.
|
Statement
transformation
|
For complex
statements involving, for example, correlated subqueries or views, the
optimizer might transform the original statement into an equivalent join
statement
|
Choice of optimizer
goals
|
The optimizer determines
the goal of optimization.
|
Choice of access
paths
|
For each table
accessed by the statement, the optimizer chooses one or more of the available
access paths to obtain table data
|
Choice of join
orders
|
For a join statement
that joins more than two tables, the optimizer chooses which pair of tables
is joined first, and then which table is joined to the result, and so on.
|
You can influence the optimizer's choices by
setting the optimizer goal, and
gathering representative statistics for the query optimizer.
The
application designer can use hints in SQL statements to instruct the optimizer
about how a statement should be executed.
Throughput - This goal chooses the least amount of
resources necessary to process all rows by statement.
Response Time - This Goal uses
the least amount of resources necessary
to process the first row accessed by a SQL statement.
We can choose the optimizer Goal based on our need -
For applications performed in batch, such as Oracle Reports applications throughput is best option
For interactive applications, such as Oracle Forms applications or SQL*Plus
queries, response time is best option.
How to Set the Goal of Optimizer
OPTIMIZER_MODE
initialization
parameter establishes the default behavior for choosing an
optimization approach for the instance
Command to Set the MODE for Session
ALTER SESSION SET OPTIMIZER_MODE = FIRST_ROWS_1;
ALTER SESSION SET OPTIMIZER_MODE =ALL_ROWS;
To
specify the goal of the query optimizer for an individual SQL
statement, we can use hints Any of
these hints in an individual SQL statement can override the
OPTIMIZER_MODE
initialization
parameter for that SQL statement
Hints let you make decisions usually made by the
optimizer
No comments:
Post a Comment