Query Optimization and Using Heuristics in query optimization.
A query has many possible execution strategies and the process of choosing a suitable one for processing a query is known as query optimization.The query optimizer module has the task of producing a good execution plan.
There are two main techniques that are employed during query optimization.
The first technique is based on heuristic rules for ordering the operation in a query execution strategy.a heuristic rules for ordering the operations in a query execution strategy.A heuristic is a rule that works well in most cases but is not guaranteed to work well in every case.
The second technique involves systematically estimating the cost of different execution strategies and choosing the execution plan with the lowest cost estimate.
Using Heuristics in query optimization
Optimization techniques that apply heuristic rules to modify the internal representation of a query which is usually in the form of a query tree.The scanner and parser of an SQL query first generate a data structure that corresponds to an initial query representation which is then optimized according to heuristic rules.
The heuristic query optimizer will transform this query tree into an equivalent final query tree that is efficient to execute.The optimizer must include rules for equivalence among relational algebra expressions that can be applied to transform the initial tree into the final optimized query tree.
Steps in converting a query tree during heuristic optimization.
- Initial query tree for SQL tree for SQL query Q.
- Moving select operation down the query tree.
- Applying the more restrictive select operation first.
- Replacing cartesian product and select with join operations.
- Moving project operations down the query tree.
0 Comments