Worst ¡Case ¡Op,mal ¡Joins ¡
CompSci ¡590.04 ¡ Instructor: ¡Ashwin ¡Machanavajjhala ¡ ¡
1 ¡ Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡
Mul,-way Joins J(a,b,c) :- R(a,b) S(b,c) T(a,c) - - PowerPoint PPT Presentation
Worst Case Op,mal Joins CompSci 590.04 Instructor: Ashwin Machanavajjhala Lecture 19 : 590.04 Fall 15 1 Mul,-way Joins
CompSci ¡590.04 ¡ Instructor: ¡Ashwin ¡Machanavajjhala ¡ ¡
1 ¡ Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡
¡ ¡ ¡J(a,b,c) ¡:-‑ ¡R(a,b) ¡S(b,c) ¡T(a,c) ¡ ¡
handle ¡mul,-‑way ¡joins ¡is ¡to ¡do ¡them ¡one ¡pair ¡at ¡a ¡,me. ¡ ¡
– For ¡efficiency ¡reasons. ¡ ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 2 ¡
R1 R2 R4 R3 R1 R4 R2 Left-deep plan Bushy plan
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 3 ¡
R “ {a0} ˆ {b0, . . . , bm} Y {a0, . . . , am} ˆ {b0} S “ {b0} ˆ {c0, . . . , cm} Y {b0, . . . , bm} ˆ {c0} T “ {a0} ˆ {c0, . . . , cm} Y {a0, . . . , am} ˆ {c0}
C A B
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 4 ¡
R “ {a0} ˆ {b0, . . . , bm} Y {a0, . . . , am} ˆ {b0} S “ {b0} ˆ {c0, . . . , cm} Y {b0, . . . , bm} ˆ {c0} T “ {a0} ˆ {c0, . . . , cm} Y {a0, . . . , am} ˆ {c0}
– Ignoring ¡log ¡terms ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 5 ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 6 ¡
– Ignoring ¡log ¡terms ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 7 ¡
¡
have ¡been ¡doing ¡mulB-‑way ¡joins ¡subopBmally ¡for ¡40 ¡years!!! ¡
the ¡form ¡R(a,b) ¡S(b,c) ¡T(a,c). ¡ ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 8 ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 9 ¡
R “ {a0} ˆ {b0, . . . , bm} Y {a0, . . . , am} ˆ {b0} S “ {b0} ˆ {c0, . . . , cm} Y {b0, . . . , bm} ˆ {c0} T “ {a0} ˆ {c0, . . . , cm} Y {a0, . . . , am} ˆ {c0}
and ¡one ¡tuple ¡in ¡T ¡(ai, ¡c0) ¡
– Joining ¡tables ¡R ¡and ¡T ¡on ¡a0 ¡results ¡in ¡an ¡intermediate ¡of ¡N2. ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 10 ¡
(i) Compute σA“aipRq σA“aipTq and filter the re- sults by probing against S or
and ¡one ¡tuple ¡in ¡T ¡(ai, ¡c0) ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 11 ¡
(i) Compute σA“aipRq σA“aipTq and filter the re- sults by probing against S or
(ii) Consider each tuple in pb, cq P S and check if pai, bq P R and pai, cq P T.
There ¡are ¡O(N) ¡values ¡ai, ¡each ¡resul,ng ¡in ¡a ¡ single ¡join ¡record ¡(ai, ¡b0, ¡c0). ¡Checking ¡whether ¡ (b0, ¡c0) ¡is ¡in ¡S ¡is ¡O(1) ¡… ¡assuming ¡an ¡index ¡ There ¡are ¡N ¡rows ¡in ¡S. ¡Again, ¡checking ¡(ai, ¡b) ¡is ¡in ¡ R ¡and ¡(ai, ¡c) ¡is ¡in ¡T ¡takes ¡O(1) ¡… ¡ ¡ assuming ¡an ¡index ¡
and ¡one ¡tuple ¡in ¡T ¡(ai, ¡c0) ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 12 ¡
(i) Compute σA“aipRq σA“aipTq and filter the re- sults by probing against S or
(ii) Consider each tuple in pb, cq P S and check if pai, bq P R and pai, cq P T.
Such ¡ai’s ¡are ¡called ¡light ¡ ¡nodes. ¡Tradi,onal ¡join ¡ processing ¡works ¡here. ¡ ¡ ¡ Such ¡ai’s ¡are ¡called ¡heavy ¡nodes. ¡Need ¡to ¡ compute ¡the ¡join ¡jointly. ¡ ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 13 ¡
Algorithm 1 Computing Q with power of two choices. Input: RpA, Bq, S pB,Cq, TpA,Cq in sorted order
1: Q H 2: L πApRq X πApTq 3: For each a P L do 4:
If |σA“aR| ¨ |σA“aT| |S | then
5:
For each pb, cq P S do
6:
If pa, bq P R and pa, cq P T then
7:
Add pa, b, cq to Q
8:
else
9:
For each b P πBpσA“aRq ^ c P πCpσA“aTq do
10:
If pb, cq P S then
11:
Add pa, b, cq to Q
12: Return Q
Heavy ¡value ¡ Light ¡value ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 14 ¡
min |σA“aR| ¨ |σA“aT|, |S | ,
AGM ¡bound) ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 15 ¡
with ¡each ¡rela,on ¡(hyperedge) ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 16 ¡
A B C
T R S
xT “ 1
2
xR “ 1
2
xS “ 0 xS “ 1
2
xS ` xT “ 1 xS ` xT “ 1 xT “ 1 xR “ 1
Q
E
xF 1, @v P V, x 0
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 17 ¡
0 ¡to ¡rela,on ¡S ¡and ¡1 ¡each ¡to ¡R ¡and ¡T ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 18 ¡
A B C
T R S
xT “ 1
2
xR “ 1
2
xS “ 0 xS “ 1
2
xS ` xT “ 1 xS ` xT “ 1 xT “ 1 xR “ 1
Q
Join ¡size ¡is ¡at ¡most ¡Nn/2 ¡ ¡ ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 19 ¡
A1 A2 A3 A4
R1,2 R2,4 R3,4 R2,3 R1,3 R1,4
1
¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 20 ¡
min
plog2 |RF|q ¨ xF s.t.
xF 1, v P V x 0
ρ˚pQ, Dq linear program.
¡ ¡ ¡J(a,b,c) ¡:-‑ ¡R(a,b) ¡S(b,c) ¡T(a,c) ¡ ¡
handle ¡mul,-‑way ¡joins ¡is ¡to ¡do ¡them ¡one ¡pair ¡at ¡a ¡,me. ¡ ¡
– For ¡efficiency ¡reasons. ¡ ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 21 ¡
R1 R2 R4 R3 R1 R4 R2 Left-deep plan Bushy plan
data ¡and ¡using ¡different ¡algorithms ¡depending ¡on ¡the ¡skew ¡of ¡the ¡
Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 22 ¡