Problem description
(Click in figure to
pull out
the relation statistics)
Initailization step:
find the
best join ordering
for all join combinations of
1 relation
Iteration step 1:
find the
best join ordering
for all join combinations of
2 relations
Considering all combination of
R and S:
(R ⋈ S and S ⋈ R)
Updated table:
Relations | size of | Cost of | Best join
joined | join result | join | ordering (plan)
------------+-------------+---------+-----------------
R | 1000 | 0 | R
S | 1000 | 0 | S
T | 1000 | 0 | T
U | 1000 | 0 | U
------------+-------------+---------+-----------------
R, S | 5000 | 0 | R ⋈ S (T(R) = T(S), we picked
an arbitrary ordering
------------+-------------+---------+-----------------
|
Iteration step 1:
find the
best join ordering
for all join combinations of
2 relations
Considering all combination of
R and T:
(R ⋈ T and T ⋈ R)
Updated table:
Relations | size of | Cost of | Best join
joined | join result | join | ordering (plan)
------------+-------------+---------+-----------------
R | 1000 | 0 | R
S | 1000 | 0 | S
T | 1000 | 0 | T
U | 1000 | 0 | U
------------+-------------+---------+-----------------
R, S | 5000 | 0 | R ⋈ S (T(R) = T(S), we picked
R, T | 1000000 | 0 | R ⋈ T an arbitrary ordering)
------------+-------------+---------+-----------------
|
Iteration step 1:
find the
best join ordering
for all join combinations of
2 relations
Considering all combination of
R and U:
(R ⋈ U and U ⋈ R)
Updated table:
Relations | size of | Cost of | Best join
joined | join result | join | ordering (plan)
------------+-------------+---------+-----------------
R | 1000 | 0 | R
S | 1000 | 0 | S
T | 1000 | 0 | T
U | 1000 | 0 | U
------------+-------------+---------+-----------------
R, S | 5000 | 0 | R ⋈ S (T(R) = T(S), we picked
R, T | 1000000 | 0 | R ⋈ T an arbitrary ordering)
R, U | 10000 | 0 | R ⋈ U
------------+-------------+---------+-----------------
|
Iteration step 1:
find the
best join ordering
for all join combinations of
2 relations
Considering all combination of
S and T:
(S ⋈ T and T ⋈ S)
Updated table:
Relations | size of | Cost of | Best join
joined | join result | join | ordering (plan)
------------+-------------+---------+-----------------
R | 1000 | 0 | R
S | 1000 | 0 | S
T | 1000 | 0 | T
U | 1000 | 0 | U
------------+-------------+---------+-----------------
R, S | 5000 | 0 | R ⋈ S (T(R) = T(S), we picked
R, T | 1000000 | 0 | R ⋈ T an arbitrary ordering)
R, U | 10000 | 0 | R ⋈ U
S, T | 2000 | 0 | S ⋈ T
------------+-------------+---------+-----------------
|
Iteration step 1:
find the
best join ordering
for all join combinations of
2 relations
Considering all combination of
S and U:
(S ⋈ U and U ⋈ S)
Updated table:
Relations | size of | Cost of | Best join
joined | join result | join | ordering (plan)
------------+-------------+---------+-----------------
R | 1000 | 0 | R
S | 1000 | 0 | S
T | 1000 | 0 | T
U | 1000 | 0 | U
------------+-------------+---------+-----------------
R, S | 5000 | 0 | R ⋈ S (T(R) = T(S), we picked
R, T | 1000000 | 0 | R ⋈ T an arbitrary ordering)
R, U | 10000 | 0 | R ⋈ U
S, T | 2000 | 0 | S ⋈ T
S, U | 1000000 | 0 | S ⋈ U
------------+-------------+---------+-----------------
|
Iteration step 1:
find the
best join ordering
for all join combinations of
2 relations
Considering all combination of
T and U:
(T ⋈ U and U ⋈ T)
Updated table:
(click to
pull out before continueing)
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Now
we compute the
optimal solution
for all combinations
of size 3:
Relations | size of | Cost of | Best join
joined | join result | join | ordering (plan)
------------+-------------+---------+-----------------
R,S,T | ??? | ??? | ???
R,S,U | ??? | ??? | ???
R,T,U | ??? | ??? | ???
S,T,U | ??? | ??? | ???
------------+-------------+---------+-----------------
|
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
R, S, T:
Which 3 way join ordering
has ther least cost
(= # tuples in the
intermediate result(s)) ???
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
R, S, T:
Best solution order and
its cost for
2 relations join are
given in the pull out !!!
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
R, S, T:
Best solution order and
its cost for
2 relations join are
given in the pull out !!!
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
R, S, T:
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
We have found our first
optimal solution
of size 3:
Relations | size of | Cost of | Best join
joined | join result | join | ordering (plan)
------------+-------------+---------+-----------------
R,S,T | 10000 | 2000 | (S ⋈ T) ⋈ R
R,S,U | ??? | ??? | ???
R,T,U | ??? | ??? | ???
S,T,U | ??? | ??? | ???
------------+-------------+---------+-----------------
|
Next:
combination of
R, S, U
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
R, S, U:
Which 3 way join ordering
has ther least cost
(= # tuples in the
intermediate result(s)) ???
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
R, S, U:
Best solution order and
its cost for
2 relations join are
given in the pull out !!!
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
R, S, U:
Best solution order and
its cost for
2 relations join are
given in the pull out !!!
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
R, S, U:
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
We have found our second
optimal solution
of size 3:
Relations | size of | Cost of | Best join
joined | join result | join | ordering (plan)
------------+-------------+---------+-----------------
R,S,T | 10000 | 2000 | (S ⋈ T) ⋈ R
R,S,U | 50000 | 5000 | (R ⋈ S) ⋈ U
R,T,U | ??? | ??? | ???
S,T,U | ??? | ??? | ???
------------+-------------+---------+-----------------
|
Next:
combination of
R, T, U
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
R, T, U:
Which 3 way join ordering
has ther least cost
(= # tuples in the
intermediate result(s)) ???
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
R, T, U:
Best solution order and
its cost for
2 relations join are
given in the pull out !!!
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
R, T, U:
Best solution order and
its cost for
2 relations join are
given in the pull out !!!
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
R, T, U:
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
We have found our third
optimal solution
of size 3:
Relations | size of | Cost of | Best join
joined | join result | join | ordering (plan)
------------+-------------+---------+-----------------
R,S,T | 10000 | 2000 | (S ⋈ T) ⋈ R
R,S,U | 50000 | 5000 | (R ⋈ S) ⋈ U
R,T,U | 10000 | 1000 | (T ⋈ U) ⋈ R
S,T,U | ??? | ??? | ???
------------+-------------+---------+-----------------
|
Next:
combination of
S, T, U
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
S, T, U:
Which 3 way join ordering
has ther least cost
(= # tuples in the
intermediate result(s)) ???
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
S, T, U:
Best solution order and
its cost for
2 relations join are
given in the pull out !!!
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
S, T, U:
Best solution order and
its cost for
2 relations join are
given in the pull out !!!
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Finding the best join ordering for
S, T, U:
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
Iteration step 2:
find the
best join ordering
for all join combinations of
3 relations
We have found all
optimal solution
of size 3:
Relations | size of | Cost of | Best join
joined | join result | join | ordering (plan)
------------+-------------+---------+-----------------
R,S,T | 10000 | 2000 | (S ⋈ T) ⋈ R
R,S,U | 50000 | 5000 | (R ⋈ S) ⋈ U
R,T,U | 10000 | 1000 | (T ⋈ U) ⋈ R
S,T,U | 2000 | 1000 | (T ⋈ U) ⋈ S
------------+-------------+---------+-----------------
|
Updated table:
(click to
pull out before continueing)
Iteration step 3:
find the
best join ordering
for all join combinations of
4 relations
Now
we compute the
optimal solution
for all combinations
of size 4:
Relations | size of | Cost of | Best join
joined | join result | join | ordering (plan)
------------+-------------+---------+-----------------
R,S,T,U | ??? | ??? | ???
------------+-------------+---------+-----------------
|
This row will give us the
optimal solution !!!
Iteration step 3:
find the
best join ordering
for all join combinations of
4 relations
Finding the best join ordering for
R, S, T, U:
Which 4 way join ordering
has ther least cost
(= # tuples in the
intermediate result(s)) ???
Iteration step 3:
find the
best join ordering
for all join combinations of
4 relations
Finding the best join ordering for
R, S, T, U:
Best solution order and
its cost for
3 relations join are
given in the pull out !!!
Iteration step 2:
find the
best join ordering
for all join combinations of
4 relations
Finding the best join ordering for
R, S, T, U:
Best solution order and
its cost for
2 relations join are
given in the pull out !!!
Iteration step 2:
find the
best join ordering
for all join combinations of
4 relations
Finding the best join ordering for
R, S, T, U:
With cost = 3000
DONE !!!
❮
❯