70 likes | 231 Views
Yannakakis’ Algorithm. Semijoin . Let R, S, T and U be relations: R(A,B,C) S(C,D) T(D,E) U(E,F) Are the following always equivalent? Contained?. R (S (T U)) and R ((S T) U). (R S) (T U) and R (S (T U)). Contains.
E N D
Semijoin Let R, S, T and U be relations: R(A,B,C) S(C,D) T(D,E) U(E,F) Are the following always equivalent? Contained? R (S (T U)) and R ((S T) U) (R S) (T U) and R (S (T U)) Contains Consider {R(a,b,c), S(c,d1), T(d2,e), U(e,f)} Contains Consider {R(a,b,c), S(c,d), T(d,e1), U(e,f)}
Yannakakis’ Algorithm Problem: Compute a projection on Y of (R1 … Rn) where R1,…,Rn are acyclic, that is there is an attribute connected tree. Solution: Reduce the data using , then “carry upwards” attributes in Y. Example: R1=AB, R2=BC, R3=CD, R4=AM, R5=MN, R6=NK, R7=MT Y=TDB AB Stage 1: Reduction: UP and DOWN AM BC CD MN MT NK
Yannakakis’ Algorithm Problem: Compute a projection on Y of (R1 … Rn) where R1,…,Rn are acyclic, that is there is an attribute connected tree. Solution: Reduce the data using , then “carry upwards” attributes in Y. Example: R1=AB, R2=BC, R3=CD, R4=AM, R5=MN, R6=NK, R7=MT Y=TDB • Stage 2: Upwards • Proceed from the leaves towards the root. • Consider a node after all its subtree was handled. • Perform the join of a child and a parent, and project on the parent’s attributes Y. • The result is available by projecting Y from the root. • Can optimize, for example when joining the “last child” of the root.
Yannakakis’ Algorithm Problem: Compute a projection on Y of (R1 … Rn) where R1,…,Rn are acyclic, that is there is an attribute connected tree. Solution: Reduce the data using , then “carry upwards” attributes in Y. Y=TDB Example: R1=AB, R2=BC, R3=CDU, R4=AM, R5=MN, R6=NK, R7=MT TDB ABT AB Stage 2: Upwards (BCDABT) (AMTAB) AM T BC D Time Polynomial in (input + output) MN (CDUBC) MT Not needed CDU NK
Yannakakis’ Algorithm RA 3 0 4 0 AS 0 1 0 2 AP 00 NA 5 0 6 0 AM 0 7 0 8 How many tuples are there in (NA AM RA AS AP AM)[R S N M]?