Fundamentals of Database Systems: (Query Optimization - I)
Fundamentals of Database Systems: (Query Optimization - I)
Malay Bhattacharyya
Assistant Professor
1 Basics
3 Problems
Outline Basics Statistics for Query Evaluation Problems
An example query
Find the basic pay and grade pay of ISI employees who are single.
Outline Basics Statistics for Query Evaluation Problems
An example query
Find the basic pay and grade pay of ISI employees who are single.
πBPay ,GPay
|
σstatus=”single”
|
./
HRA ./
BASIC GRADE
Find the basic pay and grade pay of ISI employees who are single.
πBPay ,GPay
|
./
σstatus=”single” ./
|
HRA BASIC GRADE
Catalog information
Histogram –
Outline Basics Statistics for Query Evaluation Problems
Final comments
The estimation of size does not work well in the following cases:
Values of the attribute on which the selection is applied are
not uniformly distributed.
The number of tuples is pretty low.
The number of distinct values for an attribute is pretty low.
The predicates connected together (by logical AND or OR)
under the selection are dependent on each other.
Outline Basics Statistics for Query Evaluation Problems
Table: TOY
ID COLOR COST
T1 Blue 10 NTOY = 6
T2 Blue 10 V (COLOR, TOY ) = 2
T3 Red 20 V (COST , TOY ) = 3
T4 Blue 20 min(COST , TOY ) = 10
T5 Red 30 max(COST , TOY ) = 30
T6 Red 30 HTOY = 3
NTOY
S(σCOLOR=Red (TOY )): V (COLOR,TOY ) = 3.
NTOY ∗(20−min(COST ,TOY ))
S(σCOST ≤20 (TOY )): max(COST ,TOY )−min(COST ,TOY ) = 3.
S(σ(COLOR=Red)∧(COST ≤20) (TOY )):
S(σCOLOR=Red (TOY ))∗S(σCOST ≤20 (TOY ))
NTOY = 1.5
Outline Basics Statistics for Query Evaluation Problems
Cartesian product:
S(R1 × R2 ) is equal to NR1 ∗ NR2 (each tuple occupies LR1 + LR2
bytes).
Natural join:
If A(R1 ) ∩ A(R2 ) = φ: S(R1 ./ R2 ) equals to NR1 ∗ NR2
If A(R1 ) ∩ A(R2 ) is a key for R1 : S(R1 ./ R2 ) is no greater
than NR2
If A(R1 ) ∩ A(R2 ) is a key for R2 : S(R1 ./ R2 ) is no greater
than NR1
If A(R1 ) ∩ A(R2 ) = X is neither a key for R1 nor for R2 :
N 1 ∗NR2 NR1 ∗NR2
S(R1 ./ R2 ) is the minimum of VR(X ,R1 ) and V (X ,R2 )
Outline Basics Statistics for Query Evaluation Problems
Problems