mul way joins
play

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


  1. Worst ¡Case ¡Op,mal ¡Joins ¡ CompSci ¡590.04 ¡ Instructor: ¡Ashwin ¡Machanavajjhala ¡ ¡ Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 1 ¡

  2. � � � � � Mul,-­‑way ¡Joins ¡ ¡ ¡ ¡J(a,b,c) ¡:-­‑ ¡R(a,b) ¡S(b,c) ¡T(a,c) ¡ ¡ • Historically ¡databases ¡designers ¡decided ¡that ¡the ¡best ¡way ¡to ¡ handle ¡mul,-­‑way ¡joins ¡is ¡to ¡do ¡them ¡one ¡pair ¡at ¡a ¡,me. ¡ ¡ – For ¡efficiency ¡reasons. ¡ ¡ R2 R4 R3 R1 R3 R1 R2 R4 Left-deep plan Bushy plan � � � � � � Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 2 ¡

  3. How ¡fast ¡is ¡this ¡approach? ¡ R “ { a 0 } ˆ { b 0 , . . . , b m } Y { a 0 , . . . , a m } ˆ { b 0 } S “ { b 0 } ˆ { c 0 , . . . , c m } Y { b 0 , . . . , b m } ˆ { c 0 } T “ { a 0 } ˆ { c 0 , . . . , c m } Y { a 0 , . . . , a m } ˆ { c 0 } A B C Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 3 ¡

  4. How ¡fast ¡is ¡this ¡approach? ¡ R “ { a 0 } ˆ { b 0 , . . . , b m } Y { a 0 , . . . , a m } ˆ { b 0 } S “ { b 0 } ˆ { c 0 , . . . , c m } Y { b 0 , . . . , b m } ˆ { c 0 } T “ { a 0 } ˆ { c 0 , . . . , c m } Y { a 0 , . . . , a m } ˆ { c 0 } • Each ¡instance ¡has ¡2m+1 ¡rows. ¡ ¡ • J(a, ¡b, ¡c) ¡has ¡3m+1 ¡rows ¡ • Any ¡pairwise ¡join ¡(e.g., ¡J1(a,b,c) ¡= ¡R(a,b), ¡S(b,c)) ¡has ¡size ¡m 2 ¡+ ¡m ¡ Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 4 ¡

  5. What ¡does ¡this ¡mean ¡for ¡triangle ¡ coun,ng? ¡ • Every ¡database ¡system ¡necessarily ¡takes ¡O(N 2 ) ¡ – Ignoring ¡log ¡terms ¡ • Find ¡all ¡pairs ¡(b,c) ¡are ¡connected ¡with ¡a ¡ • Check ¡if ¡(b,c) ¡is ¡an ¡edge. ¡ ¡ • Is ¡this ¡the ¡best ¡we ¡can ¡do? ¡ ¡ Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 5 ¡

  6. Detour: ¡Can ¡Sampling ¡Help ¡Joins? ¡ • Sample(Join(R,S)) ¡≠ ¡Join(Sample(R), ¡Sample(S)) ¡ • In ¡R ¡x ¡S: ¡Half ¡the ¡records ¡have ¡‘a’ ¡and ¡half ¡the ¡records ¡have ¡‘b’ ¡ • In ¡Sample(R): ¡probability ¡‘a’ ¡appears ¡is ¡very ¡small. ¡ ¡ Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 6 ¡

  7. Back ¡to ¡triangle ¡coun,ng? ¡ • Every ¡database ¡system ¡necessarily ¡takes ¡O(N 2 ) ¡ – Ignoring ¡log ¡terms ¡ • Find ¡all ¡pairs ¡(b,c) ¡are ¡connected ¡with ¡a ¡ • Check ¡if ¡(b,c) ¡is ¡an ¡edge. ¡ ¡ • Is ¡this ¡the ¡best ¡we ¡can ¡do? ¡ ¡ Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 7 ¡

  8. We ¡can ¡do ¡becer! ¡ ¡ • … ¡not ¡only ¡for ¡triangle ¡counBng, ¡but ¡it ¡seems ¡database ¡systems ¡ have ¡been ¡doing ¡mulB-­‑way ¡joins ¡subopBmally ¡for ¡40 ¡years!!! ¡ • Triangle ¡coun,ng ¡can ¡be ¡solved ¡in ¡O(N 1.5 ), ¡and ¡so ¡can ¡any ¡join ¡of ¡ the ¡form ¡R(a,b) ¡S(b,c) ¡T(a,c). ¡ ¡ Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 8 ¡

  9. How? ¡ ¡ • Is ¡there ¡an ¡O(N) ¡algorithm ¡for ¡the ¡following ¡join ¡problem: ¡ ¡ ¡ R “ { a 0 } ˆ { b 0 , . . . , b m } Y { a 0 , . . . , a m } ˆ { b 0 } S “ { b 0 } ˆ { c 0 , . . . , c m } Y { b 0 , . . . , b m } ˆ { c 0 } T “ { a 0 } ˆ { c 0 , . . . , c m } Y { a 0 , . . . , a m } ˆ { c 0 } Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 9 ¡

  10. Power ¡of ¡Two ¡Choices: ¡Heavy ¡vs ¡Light ¡ • Consider ¡acribute ¡A ¡ • For ¡all ¡ai ¡not ¡equal ¡to ¡a0, ¡there ¡is ¡exactly ¡one ¡tuple ¡in ¡R ¡(ai, ¡b0) ¡ and ¡one ¡tuple ¡in ¡T ¡(ai, ¡c0) ¡ (i) Compute σ A “ a i p R q � σ A “ a i p T q and filter the re- sults by probing against S or • The ¡above ¡strategy ¡is ¡bad ¡for ¡a0 ¡ – Joining ¡tables ¡R ¡and ¡T ¡on ¡a0 ¡results ¡in ¡an ¡intermediate ¡of ¡N 2 . ¡ Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 10 ¡

  11. Power ¡of ¡Two ¡Choices: ¡Heavy ¡vs ¡Light ¡ • Consider ¡acribute ¡A ¡ There ¡are ¡O(N) ¡values ¡ai, ¡each ¡resul,ng ¡in ¡a ¡ single ¡join ¡record ¡(ai, ¡b0, ¡c0). ¡Checking ¡whether ¡ • For ¡all ¡ai ¡not ¡equal ¡to ¡a0, ¡there ¡is ¡exactly ¡one ¡tuple ¡in ¡R ¡(ai, ¡b0) ¡ (b0, ¡c0) ¡is ¡in ¡S ¡is ¡O(1) ¡… ¡ assuming ¡an ¡index ¡ and ¡one ¡tuple ¡in ¡T ¡(ai, ¡c0) ¡ (i) Compute σ A “ a i p R q � σ A “ a i p T q and filter the re- sults by probing against S or • For ¡ai ¡= ¡a0: ¡ ¡ (ii) Consider each tuple in p b , c q P S and check if p a i , b q P R and p a i , c q P T . 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 ¡ Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 11 ¡

  12. Power ¡of ¡Two ¡Choices: ¡Heavy ¡vs ¡Light ¡ • Consider ¡acribute ¡A ¡ Such ¡ai’s ¡are ¡called ¡ light ¡ ¡nodes. ¡Tradi,onal ¡join ¡ processing ¡works ¡here. ¡ ¡ • For ¡all ¡ai ¡not ¡equal ¡to ¡a0, ¡there ¡is ¡exactly ¡one ¡tuple ¡in ¡R ¡(ai, ¡b0) ¡ ¡ and ¡one ¡tuple ¡in ¡T ¡(ai, ¡c0) ¡ (i) Compute σ A “ a i p R q � σ A “ a i p T q and filter the re- sults by probing against S or • For ¡ai ¡= ¡a0: ¡ ¡ (ii) Consider each tuple in p b , c q P S and check if p a i , b q P R and p a i , c q P T . Such ¡ai’s ¡are ¡called ¡ heavy ¡ nodes. ¡Need ¡to ¡ compute ¡the ¡join ¡jointly. ¡ ¡ Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 12 ¡

  13. Power ¡of ¡Two ¡Choices ¡Algorithm ¡ Algorithm 1 Computing Q � with power of two choices. Input: R p A , B q , S p B , C q , T p A , C q in sorted order 1: Q � � H 2: L � π A p R q X π A p T q 3: For each a P L do Heavy ¡value ¡ If | σ A “ a R | ¨ | σ A “ a T | � | S | then 4: For each p b , c q P S do 5: If p a , b q P R and p a , c q P T then 6: Add p a , b , c q to Q � 7: else 8: Light ¡value ¡ For each b P π B p σ A “ a R q ^ c P π C p σ A “ a T q 9: do If p b , c q P S then 10: Add p a , b , c q to Q � 11: 12: Return Q Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 13 ¡

  14. Run,me ¡Analysis ¡ • Compu,ng ¡L ¡takes: ¡ ¡ min � | σ A “ a R | ¨ | σ A “ a T | , | S | � , • Rest ¡of ¡the ¡algorithm ¡takes: ¡ ¡ � � � � min � | σ A “ a R | ¨ | σ A “ a T | , | S | � . � � | S | ¨ | ¨ | R | ¨ | T | . � a P L Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 14 ¡

  15. Can ¡we ¡do ¡becer? ¡ ¡ • NO! ¡ ¡ • A ¡matching ¡lower ¡bound ¡by ¡Atserias ¡Grohe ¡and ¡Marx ¡(or ¡the ¡ AGM ¡bound) ¡ Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 15 ¡

  16. AGM ¡Bound ¡ • Let ¡V ¡denote ¡the ¡set ¡of ¡rela,ons ¡ • Every ¡rela,on ¡is ¡a ¡subset ¡of ¡acributes ¡F ¡(or ¡a ¡hyper ¡edge) ¡ • Let ¡x ¡be ¡a ¡vector ¡of ¡weights ¡associated ¡ with ¡each ¡rela,on ¡(hyperedge) ¡ x R “ 1 A 2 x T “ 1 x R “ 1 2 x T “ 1 • Frac%onal ¡Edge ¡Cover : ¡ ¡ T R E � � � � � � � � x | x F � 1 , @ v P V , x � 0 � � B C S � � � � � F : v P F x S ` x T “ 1 x S “ 1 x S ` x T “ 1 2 x S “ 0 Q � Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 16 ¡

  17. AGM ¡Bound ¡ � | R F | x F . | Q | “ | � F P E R F | � F P E Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 17 ¡

  18. Examples ¡ • Triples ¡query ¡ • Best ¡frac,onal ¡cover ¡assigns ¡weight ¡0.5 ¡to ¡each ¡rela,on ¡ • Join ¡size ¡is ¡at ¡most ¡(|R|. ¡|S|. ¡|T|) 0.5 ¡ x R “ 1 A 2 x T “ 1 x R “ 1 2 x T “ 1 • Another ¡frac,onal ¡cover ¡assings ¡ ¡ T R 0 ¡to ¡rela,on ¡S ¡and ¡1 ¡each ¡to ¡R ¡and ¡T ¡ B C S • Join ¡size ¡is ¡at ¡most ¡|R|.|T| ¡ x S ` x T “ 1 x S “ 1 x S ` x T “ 1 2 x S “ 0 Q � Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 18 ¡

  19. Examples ¡ • J(a,b,c,d) ¡:-­‑ ¡R(a,b,) ¡S(b,c) ¡T(c,d) ¡U(a,c) ¡X(a,d) ¡Y(b,d) ¡Z(c,d) ¡ • One ¡cover ¡is ¡assigning ¡weight ¡of ¡1/(n-­‑1) ¡to ¡all ¡rela,ons ¡ R 1 , 2 A 2 A 1 • If ¡all ¡rela,ons ¡have ¡size ¡N, ¡ ¡ Join ¡size ¡is ¡at ¡most ¡N n/2 ¡ ¡ ¡ R 1 , 3 R 2 , 3 R 2 , 4 A 3 A 4 R 3 , 4 R 1 , 4 1 Lecture ¡19 ¡: ¡590.04 ¡Fall ¡15 ¡ 19 ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend