0% found this document useful (0 votes)
15 views11 pages

Query Optimization

Uploaded by

tadesefufa8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views11 pages

Query Optimization

Uploaded by

tadesefufa8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Query Processing

and Optimization
Kuribachew Gizaw(PhD)

Dec2023
Outline
 Introduction
 Algorithm for query Processing and Optimization
 Dynamic versus Static Optimization
 Query Decomposition
 Stages of Query Decomposition
 Heuristical Processing Stages
Introduction
 Query Processing is the activities involved in parsing, validating,
optimizing, and executing a query.
 Query Optimization is the activity of choosing an efficient execution
strategy for processing a query.
 An important aspect of query processing is query optimization. As there
are many equivalent transformations of the same high-level query,
 The aim of query optimization is to choose the one that minimizes
resource usage. Generally, we try to reduce the total execution time of
the query, which is the sum of the execution times of all individual
operations that make up the query
Algorithms for Query Processing and Optimization
Dynamic versus static optimization
 Dynamic Optimization: Carrying out a query dynamically every time the query runs.
 The advantage of dynamic query optimization arises from the fact that all information required to
select an optimum strategy is up to date.
 The disadvantages are that the performance of the query is affected because the query has to be
parsed, validated, and optimized before it can be executed. Further, it may be necessary to reduce the
number of execution strategies to be analyzed to achieve an acceptable overhead, which may have the
effect of selecting a less than optimum strategy.
 Static Optimization: Carrying out a query after the query is parsed, validated, and
optimized once. This approach is similar to the approach taken by a compiler for a
programming language.
 The advantages of static optimization are that the runtime overhead is removed, and there may be
more time available to evaluate a larger number of execution strategies, thereby increasing the
chances of finding a more optimum strategy.
Dynamic versus static optimization
 The disadvantages arise from the fact that the execution strategy that is chosen as being
optimal when the query is compiled may no longer be optimal when the query is run.
 However, a hybrid approach could be used to overcome this disadvantage, where the
query is re-optimized if the system detects that the database statistics have changed
significantly since the query was last compiled. Alternatively, the system could compile
the query for the first execution in each session, and then cache the optimum plan for
the remainder of the session, so the cost is spread across the entire DBMS session.
Query Decomposition
 Query decomposition is the first phase of query processing. The aims of query decomposition
are to transform a high-level query into a relational algebra query, and to check that the
query is syntactically and semantically correct.
 The typical stages of query decomposition are:
 Analysis
 Normalization
 Semantic analysis
 Simplification
 Query restructuring.
Stages of Query Decomposition
 1-Analysis: the query is lexically and syntactically analyzed using the techniques of
programming language compilers.
 In addition, this stage verifies that the relations and attributes specified in the query
are defined in the system catalog. It also verifies that any operations applied to
database objects are appropriate for the object type.
 2-Normalization: The normalization stage of query processing converts the query into
a normalized form that can be more easily manipulated. The predicate (in SQL, the
WHERE condition), which may be arbitrarily complex, can be converted into one of two
forms by applying a few transformation rules
 Conjunctive normal form: A sequence of conjuncts that are connected with the ∧ (AND)
operator.
 Disjunctive normal form: A sequence of disjuncts that are connected with the ∨ (OR)
operator.
Stages of Query Decomposition
 3-Semantic analysis: The objective of semantic analysis is to reject normalized queries
that are incorrectly formulated or contradictory. A query is incorrectly formulated if
components do not contribute to the generation of the result, which may happen if some
join specifications are missing. A query is contradictory if its predicate cannot be satisfied
by any tuple.
 4- Simplification: The objectives of the simplification stage are to detect redundant
qualifications, eliminate common subexpressions, and transform the query to a
semantically equivalent but more easily and efficiently computed form.
 Typically, access restrictions, view definitions, and integrity constraints are considered at this
stage, some of which may also introduce redundancy. If the user does not have the appropriate
access to all the components of the query, the query must be rejected.
 5-Query restructuring : In the final stage of query decomposition, the query is
restructured to provide a more efficient implementation.
Heuristical Processing Strategies
 (1) Perform Selection operations as early as possible.
 (2) Combine the Cartesian product with a subsequent Selection operation whose
predicate represents a join condition into a Join operation.
 (3) Use associativity of binary operations to rearrange leaf nodes so that the leaf nodes
with the most restrictive Selection operations are executed first.
 (4) Perform Projection operations as early as possible.
 (5) Compute common expressions once.
Thank You!

You might also like