Finding an optimal query plan
Review:
the SQL parser
first reads in
an SQL query and
converts it to
an initial query plan:
Finding an optimal query plan
Then the
initial query plan must be
transformed into
an optimal (= best) query plan:
The optimal query plan
must be
an equivalent query plan
(= produce the same output set)
but with
"better" performance characteristics
Tools to find an optimal query plan:
algebraic laws
Example of an
algebraic law:
Example applying Algebraic Law
Initial query plan:
Example applying Algebraic Law
Algebraic law:
σstarName=name
( MovieStar × StarsIn )
≡
MovieStar ⋈starName=name StarsIn
Example applying Algebraic Law
Algebraic law:
σbirthdate LIKE '%1960'
( MovieStar ⋈ StarsIn )
≡
MovieStar ⋈
σbirthdate LIKE '%1960'(StarsIn)
Example applying Algebraic Law
We want the smaller input relation
as the left input relation
in a join (⋈) operator:
Comment on Algebraic Law
❮
❯