0% found this document useful (0 votes)
100 views12 pages

Heuristic Query Optimization Techniques

The document discusses heuristic query optimization. It begins by explaining that a query optimizer's goal is to choose an efficient execution strategy by minimizing resource usage. It then provides details on heuristic rules that reorder operations in a query tree and semantic optimization using schema constraints. Examples are given showing how a sample query is optimized by applying operations like selection before joins. The optimization process and algorithm aims to reduce processing by applying selections early and replacing Cartesian products and selections with join operations.

Uploaded by

Parul Puri
Copyright
© Attribution Non-Commercial (BY-NC)
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)
100 views12 pages

Heuristic Query Optimization Techniques

The document discusses heuristic query optimization. It begins by explaining that a query optimizer's goal is to choose an efficient execution strategy by minimizing resource usage. It then provides details on heuristic rules that reorder operations in a query tree and semantic optimization using schema constraints. Examples are given showing how a sample query is optimized by applying operations like selection before joins. The optimization process and algorithm aims to reduce processing by applying selections early and replacing Cartesian products and selections with join operations.

Uploaded by

Parul Puri
Copyright
© Attribution Non-Commercial (BY-NC)
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

HEURISTIC QUERY

OPTIMISATION
INTRODUCTION

Primal goal of optimiser is choosing an efficient execution strategy.

Query optimiser tend to minimise the use of certain resources.

1. Heuristic query optimization


2. Systematic estimation model.

Heuristic search is based on heuristic rules. This rules typically


reorders the operation in a query tree.
Heuristic rules modify the internal representation of a query.

One of the main rules is to apply SELECT operation before


applying the JOIN or other binary operation.

Semantic query optimization is also used with the heuristic query


rules.

It uses constraints specified on the database schema such as


unique attribute and other more complex constraints in order to
modify one query into other.
ISSUES

There are three basic issues in query optimization.

1. How to use the available indexes.

2. How to use memory to accumulate information and perform


intermediate steps such as sorting.

3. How to determine the order in which joins should be performed.


INPUT USED IN QUERY
OPTIMIZATION

Relational algebra query tree generated by the query simplifier module


of query decomposition.

Estimation formula used to determine the cardinality of the


intermediate result tables.

A cost model

Statistical data from the database catalogue


EXAMPLE
EMPLOYEE
(EMP-NAME,EMP-ID,BIRTH-DATE,EMP-ADDRESS,EMP-
SALARY,EMP-DEPT-NO)
DEPARTMENT
(DEPT-NAME,DEPT-NO,DEPT-MGR-ID,DEPT-MGR-START-
DATE)
DEPT_LOCATION
(DEPT-NO,DEPT –LOCATION)
PROJECT
(PROJ-NAME,PROJ-LOCATION,PROJ-DEPT-NO)
WORKS ON
(E-ID,P-NO,HOURS)
DEPENDENT
(E-ID,DEPENDENT-NAME,SEX,BIRTH-DATE,RELATION)
TO FIND THE NAMES OF
EMPLOYEES BORN AFTER 1970
WHO WORK ON A PROJECT
NAMED GROWTH
SQL QUERY:
SELECT EMP-NAME FROM EMPLOYEE,
WORKS_ON,PROJECT WHERE PROJ-NAME = “GROWTH”
AND PROJ-NO=P NO AND E-ID=EMP-ID AND BIRTH
DATE=“31-12-1970”
INITIAL QUERY TREE
ΠEMP-NAME

σPROJ-NAME= “ growth "AND PROJ NO=P-NO AND E-ID=EMP-ID AND BIRTH


–DATE> “31-12-1970”

PROJECT

EMPLOYEE WORKS_ON
IMPROVED QUERY TREE BY APPLYING SELECT OPERATION

Π EMP-NAME

σ PROJ-NO=P-NO

σE-ID=E-ID σ PROJ NAME=“GROWTH”

PROJECT

σBIRTH-DATE>”31-12-1970” WORKS_ON

EMPLOYEEE
IMPROVED QUERY TREE BY APPLYING RESTRICTIVE SELECT
OPERATION

Π EMP-NAME

σ E-ID=EMP-ID

σPROJ-NO = P-NO σBIRTH-DATE> “31-12-1970”

EMPLOYEE

WORKS_ON
σPROJ-NAME=“GROWTH”

PROJECT
IMPROVED QUERY TREE BY MOVING PROJECT OPERATION, REPLACING
CARTESIAN PRODUCT AND SELECT OPERATION WITH JOIN OP

Π EMP-NAME

E-ID=EMP-ID

Π EMP-NAME,E-ID
Π E-ID

σ BIRTH-DATE> “31-12-1970”
PROJ-NO=PNO

Π PROJ N0 ΠE-ID,PNO EMPLOYEE

WORKS_ON

σ PROJ-NAME=“GROWTH”

PROJECT
ALGORITHM

Perform selection operation earliest to reduce the subsequent


processing of relation.

Perform commutatively of select operation with other operation at the


earliest to move each select operation down the query.

Combine the Cartesian product with subsequent select operation


whose predicates represent a join condition into a join operation.

Use commutaitivity and associatively of binary operation


Perform projection operation
Compute common expression.

Common questions

Powered by AI

The primary goal of a query optimiser is to choose an efficient execution strategy for queries by minimising the use of resources such as time and computational power. Heuristic query optimisation achieves this by applying heuristic rules to reorder operations in a query tree, enhancing the internal representation of a query. For instance, one key heuristic rule is to apply SELECT operations before JOIN or other binary operations, thereby reducing the amount of data processed in subsequent operations. Furthermore, semantic query optimisation may be used to transform a query using database schema constraints to increase efficiency .

Commutativity and associativity properties of binary operations can be leveraged to rearrange operations within a query for optimal performance. By reordering operations without affecting the query result, these properties allow for reordering joins and other operations to reduce intermediate results and leverage indices more effectively. As a result, it enables more efficient execution strategies by structuring operations in a way that minimises computational load and resource usage .

Heuristic query optimisation techniques adapt to changes in database constraints over time by continuously leveraging the latest schema constraints and statistical data during query transformations. This ensures that query optimisers remain responsive to changes such as additions of new constraints or alterations in data distribution. Optimization rules can be dynamically adjusted based on these changes, maintaining query execution efficiency even as the database evolves .

The three main issues in query optimisation are: (1) How to effectively use available indexes to quickly access information; (2) How to utilise memory efficiently to accumulate information and perform intermediate steps like sorting; (3) How to sequence joins optimally, which can significantly impact query performance. Addressing these issues is crucial for enhancing the overall efficiency of query execution strategies .

Effective query optimisation relies on several inputs: a relational algebra query tree, estimation formulas, a cost model, and statistical data from the database catalog. The query tree represents the structure of the query for the optimiser. Estimation formulas predict the cardinality of intermediate results, guiding decision-making on operation ordering. The cost model provides a basis for assessing different execution strategies, while statistical data aids in understanding data distribution and accessing patterns, which helps in selecting optimal strategies .

Heuristic query optimisation utilises statistical data from the database catalogue to guide the execution strategy by providing insights into data distribution and access patterns. This information can inform decisions such as which indices to use, which join paths to prioritise, or how to order operations to minimise intermediate result sizes. By understanding frequent access patterns and data cardinality, the optimiser can tailor query execution plans for efficiency .

Applying SELECT operations before JOIN operations reduces the amount of data processed in the join, as SELECT operations filter data earlier in the execution plan. This leads to smaller intermediate tables, thereby decreasing the computational workload for JOIN operations, which are often more resource-intensive. As a result, query performance is improved through reduced processing time and resource usage .

Combining the Cartesian product with subsequent select operations transforms these operations into a join, which is far more efficient. The Cartesian product tends to be computationally expensive due to the creation of large intermediate relations. By combining it with a select operation whose predicate reflects a join condition, the operation becomes a join, which effectively limits the result set to only relevant data, improving query execution performance .

Semantic query optimisation integrates with heuristic rules by employing schema constraints and data properties to transform queries into more efficient forms. For example, constraints such as unique attributes can be used to eliminate redundant operations or to simplify query conditions. By leveraging these constraints, semantic optimisation can modify queries to be more efficient while retaining their original intent, working in conjunction with heuristic rules to enhance query execution .

In the database schema provided, performing selection operations early in the query plan is beneficial because it significantly reduces the size of data sets that need to be processed in subsequent operations. Early filtering through selection eliminates unnecessary data, leading to smaller intermediate tables, which means less computational overhead when performing more complex operations such as joins. This results in a more efficient execution plan, reducing both time and resources needed .

You might also like