Anda di halaman 1dari 12

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.

Anda mungkin juga menyukai