1.6 PPT - Query Optimization
1.6 PPT - Query Optimization
ENGINEERING
SEMESTER : 5th
Introduction
Catalog Information for Cost Estimation
Estimation of Statistics
Dynamic Programming for Choosing
Evaluation Plans
Introduction
Alternative ways of evaluating a given query
Equivalent expressions
Different algorithms for each operation (Chapter 13)
Cost difference between a good and a bad way of evaluating a
query can be enormous
Example: performing a r X s followed by a selection r.A =
s.B is much slower than performing a join on the same
condition
Need to estimate the cost of operations
Depends critically on statistical information about relations which the
database must maintain
E.g. number of tuples, number of distinct values for join
attributes, etc.
Need to estimate statistics for intermediate results to compute cost
of complex expressions
Introduction (Cont.)
Relations generated by two equivalent expressions have the
same set of attributes and contain the same set of tuples,
although their attributes may be ordered differently.
Introduction (Cont.)
ARMIET/IT/SEM-5/SSA/ADMT
Transformation of Relational Expressions
ARMIET/IT/SEM-5/SSA/ADMT
Equivalence Rules
ARMIET/IT/SEM-5/SSA/ADMT
Pictorial Depiction of Equivalence Rules
ARMIET/IT/SEM-5/SSA/ADMT
Equivalence Rules (Cont.)
(E1
1 E2) 2 3 E3 = E1 2 3 (E2 2 E3)
ARMIET/IT/SEM-5/SSA/ADMT
Equivalence Rules (Cont.)
7. The selection operation distributes over the theta join operation
under the following two conditions:
(a) When all the attributes in 0 involve only the attributes of
one
ARMIET/IT/SEM-5/SSA/ADMT
Equivalence Rules (Cont.)
ARMIET/IT/SEM-5/SSA/ADMT
Equivalence Rules (Cont.)
insimilarly
and place offor in place of
ARMIET/IT/SEM-5/SSA/ADMT
YouTube Link: Cartesian Product
https://www.youtube.com/watch?v=_IUP114x2gM
ARMIET/IT/SEM-5/SSA/ADMT
Example with Multiple Transformations
ARMIET/IT/SEM-5/SSA/ADMT
Projection Operation Example
account) depositor)
customer-name((branch-city = “Brooklyn” (branch)
When we compute
(branch-city = “Brooklyn” (branch) account )
we obtain a relation whose schema is:
(branch-name, branch-city, assets, account-number, balance)
Push projections using equivalence rules 8a and 8b; eliminate
unneeded attributes from intermediate results to get:
customer-name ((
account-number ( (branch-city = “Brooklyn” (branch) account ))
depositor)
ARMIET/IT/SEM-5/SSA/ADMT
Join Ordering Example
(r1 r2) r3
so that we compute and store a smaller temporary relation.
Join Ordering Example (Cont.)
depositor)
Could compute account depositor first, and
join result with
branch-city = “Brooklyn” (branch)
but account depositor is likely to be a large
relation.
Since it is more likely that only a small fraction of the
account
branch-city = “Brooklyn”
bank’s customers have (branch)
accounts in branches located
first.
in Brooklyn, it is better to compute
ARMIET/IT/SEM-5/SSA/ADMT
1.7 Assignment
ARMIET/IT/SEM-5/SSA/ADMT
Evaluation Plan
Objective :
An evaluation plan is a written document that describes how you will
monitor and evaluate your program.
Logical Question :