Slideshow:
|
|
|
|
N = # relations in the join problem (R1,R2,...,RN)
/* ===================================================
k = # relations in the join expression
(We build the size k up one by one)
=================================================== */
for ( k = 3, 4, ...., N ) do
{
/* ========================================================
Visualize help:
if k = 4 then
Φ = { {R1,R2,R3,R4}, {R1,R2,R3,R5}, ....
======================================================== */
for ( each subset Φ of size k ) do
{
/* ======================================
Initilaize (assume some minimum cost)
====================================== */
minCost = ∞; // minCost to join the setset relations in Φ
optSol = ∅; // Best join ordering (left-deep join tree)
/* --------------------------------------------
Try each possible relation Ri as
the last relation in left-deep join tree
⋈
/ \
opt Si Ri <-- Try each relation Ri here
(opt Si can be found in data structure !)
-------------------------------------------- */
for ( each elem Ri ∈ Φ ) do
{
Si = Φ − Ri
// Notice that:
// the optimal join order on S has already been computed !!!
Cost(Ri) = cost of this (left-deep) join tree
⋈
/ \
opt Si Ri <-- Try each relation Ri here
if ( Cost(Ri) < minCost )
{
minCost = Cost(Ri);
optSol = ⋈
/ \
opt Si Ri
}
}
/* ===============================================
Now we found the lowest cost for the join order
for the list of relations Φ
=============================================== */
Enter minCost in the Least cost column
Enter optSol in the order column
Compute the estimate join size and enter
}
}
|
We will see a worked-out example in the next webpage.