Database Reference
In-Depth Information
SQL Query
SCANNING
Components
scanned
PARSING
Syntax-checked
query
Data Dictionary
VALIDATING
Verified query
INTERNAL
REPRESENTATION
Query graph
Statistics
OPTIMIZING
Execution Plan
CODE
GENERATION
Generated Code
Database
RUNTIME
PROCESSING
Query Results
Figure 13-15
Query processing steps.
Internal representation. Create an internal representation or data structure for the
query in the form of a query tree or query graph. Usually this data structure con-
sists of translations of query components into relational algebra operations forming
a query tree or query graph.
Optimizing. Examine alternative execution strategies for the query, choose an
optimal strategy, and produce an execution plan.
Code generation. Generate code for executing the plan produced by the optimizer.
Runtime processing. Run the query code, compiled or interpreted, to produce the
query result.
The Query Optimizer
In a relational database system, the query optimizer plays a vital role by enhancing
performance a great deal. If every query is translated and executed in the haphaz-
ard manner in which it is written, database access tends to be slow and overall
performance suffers. User productivity diminishes in such an environment.
Figure 13-16 presents the overall function of the query optimizer.
First, the query optimizer must analyze the query and determine the various ways
in which the query may be executed. In the best of conditions, the query optimizer
must consider every possible way a query may be executed. Let us say that a query
consists of just three operations: SELECT, JOIN, and PROJECT. Even this simple
Search WWH ::




Custom Search