FAQ: Questions Asked Frequently Mahmoud Abo Khamis Hung Q. Ngo . Atri Rudra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Table of Contents The FAQ problem Summary of Results and Approach The OutsideIn algorithm The InsideOut algorithm Choosing a variable ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Table of Contents The FAQ problem Summary of Results and Approach The OutsideIn algorithm The InsideOut algorithm Choosing a variable ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Notations ▶ Xi denote variables, i ∈ [n] = {1, . . . , n}, . . . .... .... .... . . . . . Notations ▶ Xi denote variables, i ∈ [n] = {1, . . . , n}, ▶ xi are values in discrete domain Dom(Xi ) . . . .... .... .... . . . . . Notations ▶ Xi denote variables, i ∈ [n] = {1, . . . , n}, ▶ xi are values in discrete domain Dom(Xi ) ▶ x = (x1 , . . . , xn ) ∈ Dom(X1 ) × · · · × Dom(Xn ) . . . .... .... .... . . . . . Notations ▶ Xi denote variables, i ∈ [n] = {1, . . . , n}, ▶ xi are values in discrete domain Dom(Xi ) ▶ x = (x1 , . . . , xn ) ∈ Dom(X1 ) × · · · × Dom(Xn ) ▶ For any S ⊆ [n], xS = (xi )i∈S ∈ ∏ Dom(Xi ) i∈S e.g. x{2,5,8} = (x2 , x5 , x8 ) ∈ Dom(X2 ) × Dom(X5 ) × Dom(X8 ) . . . .... .... .... . . . . . Function Aggregate Query: the Problem ψ14 (X1 , X4 ) FAQ-expression ψ13 (X1 , X3 ) ψ23 (X2 , X3 ) φ(x3 ) = ∑∏ x1 x2 φ(X3 ) max ψ1,2,4 ψ2,3 ψ1,3 ψ1,4 x4 ψ124 (X1 , X2 , X4 ) All functions have the same range D . . . .... .... .... . . . . . Function Aggregate Query: the Input ψ14 (X1 , X4 ) FAQ-expression ψ13 (X1 , X3 ) ψ23 (X2 , X3 ) φ(x3 ) = ∑∏ x1 x2 max ψ1,2,4 ψ2,3 ψ1,3 ψ1,4 x4 ψ124 (X1 , X2 , X4 ) ▶ All functions have the same range D φ(X3 ) n=4 n variables X1 , . . . , Xn . . . .... .... .... . . . . . Function Aggregate Query: the Input ψ14 (X1 , X4 ) ψ23 (X2 , X3 ) φ(x3 ) = ∑∏ x1 ψ124 (X1 , X2 , X4 ) All functions have the same range D FAQ-expression ψ13 (X1 , X3 ) x2 φ(X3 ) max ψ1,2,4 ψ2,3 ψ1,3 ψ1,4 x4 V = {1, 2, 3, 4} E = {{1, 4}, {1, 3}, {2, 3}, {1, 2, 4}} ▶ ▶ n variables X1 , . . . , Xn a multi-hypergraph H = (V, E) . . . .... .... .... . . . . . Function Aggregate Query: the Input ψ14 (X1 , X4 ) All functions have the same range D FAQ-expression ψ13 (X1 , X3 ) ψ23 (X2 , X3 ) φ(x3 ) = ∑∏ x1 ψ124 (X1 , X2 , X4 ) x2 φ(X3 ) max ψ1,2,4 ψ2,3 ψ1,3 ψ1,4 x4 V = {1, 2, 3, 4} E = {{1, 4}, {1, 3}, {2, 3}, {1, 2, 4}} ▶ ▶ n variables X1 , . . . , Xn a multi-hypergraph H = (V, E) ▶ Each vertex is a variable (notation overload: V = [n]) . . . .... .... .... . . . . . Function Aggregate Query: the Input ψ14 (X1 , X4 ) All functions have the same range D FAQ-expression ψ13 (X1 , X3 ) ψ23 (X2 , X3 ) φ(x3 ) = ∑∏ x1 x2 φ(X3 ) max ψ1,2,4 ψ2,3 ψ1,3 ψ1,4 x4 V = {1, 2, 3, 4} ψ124 (X1 , X2 , X4 ) E = {{1, 4}, {1, 3}, {2, 3}, {1, 2, 4}} ▶ ▶ n variables X1 , . . . , Xn a multi-hypergraph H = (V, E) ▶ ▶ Each vertex is a variable (notation overload: V = [n]) To each hyperedge S ∈ E there corresponds a factor ψS ∏ ψS : Dom(Xi ) → D i∈S . . . .... .... .... . . . . . Function Aggregate Query: the Input ψ14 (X1 , X4 ) All functions have the same range D FAQ-expression ψ13 (X1 , X3 ) ψ23 (X2 , X3 ) φ(x3 ) = ∑∏ x1 x2 φ(X3 ) max ψ1,2,4 ψ2,3 ψ1,3 ψ1,4 x4 V = {1, 2, 3, 4} ψ124 (X1 , X2 , X4 ) E = {{1, 4}, {1, 3}, {2, 3}, {1, 2, 4}} ▶ ▶ n variables X1 , . . . , Xn a multi-hypergraph H = (V, E) ▶ ▶ Each vertex is a variable (notation overload: V = [n]) To each hyperedge S ∈ E there corresponds a factor ψS ∏ ψS : Dom(Xi ) → D i∈S R+ , {true, false}, {0, 1}, 2U , etc. . . . .... .... .... . . . . . Function Aggregate Query: the Input ψ14 (X1 , X4 ) All functions have the same range D FAQ-expression ψ13 (X1 , X3 ) ψ23 (X2 , X3 ) φ(x3 ) = ∑∏ x1 x2 φ(X3 ) max ψ1,2,4 ψ2,3 ψ1,3 ψ1,4 x4 F = {3} ψ124 (X1 , X2 , X4 ) ▶ ▶ n variables X1 , . . . , Xn a multi-hypergraph H = (V, E) ▶ ▶ Each vertex is a variable (notation overload: V = [n]) To each hyperedge S ∈ E there corresponds a factor ψS ∏ ψS : Dom(Xi ) → D i∈S R+ , {true, false}, {0, 1}, 2U , etc. ▶ a set F ⊆ V of free variables (wlog, F = [f ] = {1, . . . , f }) . . . .... .... .... . . . . . Function Aggregate Query: the Output ψ14 (X1 , X4 ) ψ23 (X2 , X3 ) All functions have the same range D FAQ-expression ψ13 (X1 , X3 ) φ(x3 ) = ∑∏ x1 x2 φ(X3 ) max ψ1,2,4 ψ2,3 ψ1,3 ψ1,4 x4 ψ124 (X1 , X2 , X4 ) ▶ Compute the function φ : ∏ Dom(Xi ) → D. i∈F . . . .... .... .... . . . . . Function Aggregate Query: the Output ψ14 (X1 , X4 ) ψ23 (X2 , X3 ) All functions have the same range D FAQ-expression ψ13 (X1 , X3 ) φ(x3 ) = ∑∏ x1 x2 φ(X3 ) max ψ1,2,4 ψ2,3 ψ1,3 ψ1,4 x4 ψ124 (X1 , X2 , X4 ) ▶ Compute the function φ : ∏ Dom(Xi ) → D. i∈F ▶ φ defined by the FAQ-expression ⊕(f +1) ⊕(n−1) φ(x[f ] ) = ··· xf +1 ∈Dom(Xf +1 ) ⊕(n) ⊗ xn−1 ∈Dom(Xn−1 ) xn ∈Dom(Xn ) S∈E ψS (xS ) . . . .... .... .... . . . . . Function Aggregate Query: the Output ψ14 (X1 , X4 ) ψ23 (X2 , X3 ) All functions have the same range D FAQ-expression ψ13 (X1 , X3 ) φ(x3 ) = ∑∏ x1 x2 φ(X3 ) max ψ1,2,4 ψ2,3 ψ1,3 ψ1,4 x4 ψ124 (X1 , X2 , X4 ) ▶ Compute the function φ : ∏ Dom(Xi ) → D. i∈F ▶ φ defined by the FAQ-expression ⊕(f +1) ⊕(n−1) φ(x[f ] ) = ··· xf +1 ∈Dom(Xf +1 ) ▶ For each ⊕(n) ⊗ xn−1 ∈Dom(Xn−1 ) xn ∈Dom(Xn ) S∈E ψS (xS ) ⊕(i) . . . .... .... .... . . . . . Function Aggregate Query: the Output ψ14 (X1 , X4 ) ψ23 (X2 , X3 ) All functions have the same range D FAQ-expression ψ13 (X1 , X3 ) φ(x3 ) = ∑∏ x1 x2 φ(X3 ) max ψ1,2,4 ψ2,3 ψ1,3 ψ1,4 x4 ψ124 (X1 , X2 , X4 ) ▶ Compute the function φ : ∏ Dom(Xi ) → D. i∈F ▶ φ defined by the FAQ-expression ⊕(f +1) ⊕(n−1) φ(x[f ] ) = ··· xf +1 ∈Dom(Xf +1 ) ▶ ⊕ For each ((i) ⊕(i) ⊗) ▶ Either D, , ⊕(n) ⊗ xn−1 ∈Dom(Xn−1 ) xn ∈Dom(Xn ) S∈E ψS (xS ) is a commutative semiring . . . .... .... .... . . . . . Function Aggregate Query: the Output ψ14 (X1 , X4 ) ψ23 (X2 , X3 ) All functions have the same range D FAQ-expression ψ13 (X1 , X3 ) φ(x3 ) = ∑∏ x1 x2 φ(X3 ) max ψ1,2,4 ψ2,3 ψ1,3 ψ1,4 x4 ψ124 (X1 , X2 , X4 ) ▶ Compute the function φ : ∏ Dom(Xi ) → D. i∈F ▶ φ defined by the FAQ-expression ⊕(f +1) ⊕(n−1) φ(x[f ] ) = ··· xf +1 ∈Dom(Xf +1 ) ▶ ⊕ For each ((i) ⊕(i) ⊗) ▶ ▶ Either D, ⊕(i) ⊗ Or = , ⊕(n) ⊗ xn−1 ∈Dom(Xn−1 ) xn ∈Dom(Xn ) S∈E ψS (xS ) is a commutative semiring . . . .... .... .... . . . . . SumProd = FAQ-SS without free variables ▶ SumProd: compute the constant ⊕⊕ ⊕⊗ ⊕⊗ φ= ··· ψS (xS ) = ψS (xS ) x1 x2 xn S∈E x S∈E . . . .... .... .... . . . . . SumProd = FAQ-SS without free variables ▶ SumProd: compute the constant ⊕⊕ ⊕⊗ ⊕⊗ φ= ··· ψS (xS ) = ψS (xS ) x1 ▶ x2 xn S∈E x S∈E Where (D, ⊕, ⊗) is a commutative semiring Additive identity 0 ∈ D : 0 ⊕ e = e ⊕ 0 = e Multiplicative identity 1 ∈ D : 1 ⊗ e = e ⊗ 1 = e Annihilation by 0 0 ⊗ e = e ⊗ 0 = 0 Distributive law a ⊗ b ⊕ a ⊗ c = a ⊗ (b ⊕ c) . . . .... .... .... . . . . . SumProd = FAQ-SS without free variables ▶ SumProd: compute the constant ⊕⊕ ⊕⊗ ⊕⊗ φ= ··· ψS (xS ) = ψS (xS ) x1 x2 xn S∈E x S∈E ▶ Where (D, ⊕, ⊗) is a commutative semiring Additive identity 0 ∈ D : 0 ⊕ e = e ⊕ 0 = e Multiplicative identity 1 ∈ D : 1 ⊗ e = e ⊗ 1 = e Annihilation by 0 0 ⊗ e = e ⊗ 0 = 0 Distributive law a ⊗ b ⊕ a ⊗ c = a ⊗ (b ⊕ c) ▶ Common examples (there are many more!) Boolean ({true, false}, ∨, ∧) sum-product (R, +, ×) max-product (R+ , max, ×) set (2U , ∪, ∩) . . . .... .... .... . . . . . Problem (CSP = Boolean Join Query) is there a “truth assignment” x satisfying all constraints? . . . .... .... .... . . . . . Problem (CSP = Boolean Join Query) is there a “truth assignment” x satisfying all constraints? ▶ Boolean semiring ({true, false}, ∨, ∧) ⊕⊗ x S∈E ψS (xS ) = ∨ ∧ x ψS (xS ) S∈E . . . .... .... .... . . . . . Problem (CSP = Boolean Join Query) is there a “truth assignment” x satisfying all constraints? ▶ Boolean semiring ({true, false}, ∨, ∧) ⊕⊗ ψS (xS ) = x S∈E ▶ constraint ψS : ∏ ∨ ∧ x ψS (xS ) S∈E Dom(Xi ) → {true, false} with support S i∈S . . . .... .... .... . . . . . Problem (CSP = Boolean Join Query) is there a “truth assignment” x satisfying all constraints? ▶ Boolean semiring ({true, false}, ∨, ∧) ⊕⊗ ψS (xS ) = x S∈E ▶ constraint ψS : ∏ ∨ ∧ x ψS (xS ) S∈E Dom(Xi ) → {true, false} with support S i∈S ▶ truth assignment satisfying all constraints . . . .... .... .... . . . . . Problem (CSP = Boolean Join Query) is there a “truth assignment” x satisfying all constraints? ▶ Boolean semiring ({true, false}, ∨, ∧) ⊕⊗ ψS (xS ) = x S∈E ▶ constraint ψS : ∏ ∨ ∧ x ψS (xS ) S∈E Dom(Xi ) → {true, false} with support S i∈S ▶ truth assignment satisfying all constraints ▶ over all possible truth assignments . . . .... .... .... . . . . . Problem (#CSP = Join cardinality query) count number of satisfying assignments x . . . .... .... .... . . . . . Problem (#CSP = Join cardinality query) count number of satisfying assignments x ▶ Sum-product semiring ({0, 1}, +, ×) ⊕⊗ x S∈E ψS (xS ) = ∑ ∏ x ψS (xS ) S∈E . . . .... .... .... . . . . . Problem (#CSP = Join cardinality query) count number of satisfying assignments x ▶ Sum-product semiring ({0, 1}, +, ×) ⊕⊗ ψS (xS ) = x S∈E ▶ constraint ψS : ∏ ∑ ∏ x ψS (xS ) S∈E Dom(Xi ) → {0, 1}, where i∈S { ψS (x) = 1 0 xS satisfies constraint otherwise . . . .... .... .... . . . . . Problem (#CSP = Join cardinality query) count number of satisfying assignments x ▶ Sum-product semiring ({0, 1}, +, ×) ⊕⊗ ψS (xS ) = x S∈E ▶ constraint ψS : ∏ ∑ ∏ x ψS (xS ) S∈E Dom(Xi ) → {0, 1}, where i∈S { ψS (x) = ▶ 1 0 xS satisfies constraint otherwise count 1 only if x satisfies all constraints . . . .... .... .... . . . . . Problem (#CSP = Join cardinality query) count number of satisfying assignments x ▶ Sum-product semiring ({0, 1}, +, ×) ⊕⊗ ψS (xS ) = x S∈E ▶ constraint ψS : ∏ ∑ ∏ x ψS (xS ) S∈E Dom(Xi ) → {0, 1}, where i∈S { ψS (x) = 1 0 xS satisfies constraint otherwise ▶ count 1 only if x satisfies all constraints ▶ sum over all possible truth assignments . . . .... .... .... . . . . . Many examples for FAQ-SS w/o free variables ▶ Boolean conjunctive query evaluation (Boolean semiring) ▶ SAT (Boolean semiring) ▶ Quantifier-free conjunctive query evaluation (set semiring) ▶ k-colorability (Boolean) ▶ Permanent (Sum-Product semiring) ▶ Partition function (Sum-Product semiring) ▶ etc. ▶ Sum-Prod = Marginalize a Product Function problem ▶ ▶ Dechter (Artificial Intelligence 1999) Aji and McEliece (IEEE Trans. Inform. Theory 2000) . . . .... .... .... . . . . . Adding free variables Problem (FAQ-SS with free variables) Compute the function ⊕⊗ ⊕ ⊗ ⊕ φ(x[f ] ) = ··· ψS (xS ) = ψS (xS ) xf +1 xn S∈E x[n]−[f ] S∈E . . . .... .... .... . . . . . Adding free variables Problem (FAQ-SS with free variables) Compute the function ⊕⊗ ⊕ ⊗ ⊕ φ(x[f ] ) = ··· ψS (xS ) = ψS (xS ) xf +1 ▶ xn S∈E x[n]−[f ] S∈E In DB jargons: we have Group By! . . . .... .... .... . . . . . Problem (Conjunctive Query Evaluation – CQE) ∧ Φ(x[f ] ) = ∃xf +1 · · · ∃xn R(vars(R)) R∈atoms(Φ) ▶ Boolean Semiring ({true, false}), ∨, ∧) ▶ FAQ-SS instance: φ(x[f ] ) = ∨ xf +1 ··· ∨∧ φS (xS ). xn S∈E . . . .... .... .... . . . . . Problem (Matrix Chain Multiplication – MCM) Let Ai = (a(i) x,y ), compute A = A1 × A2 × · · · Ak . |{z} |{z} |{z} |{z} p0 ×pk p0 ×p1 p1 ×p2 pk−1 ×pk . . . .... .... .... . . . . . Problem (Matrix Chain Multiplication – MCM) Let Ai = (a(i) x,y ), compute A = A1 × A2 × · · · Ak . |{z} |{z} |{z} |{z} p0 ×pk ▶ p0 ×p1 p1 ×p2 pk−1 ×pk Sum-product semiring (R, +, ×), (C, +, ×), (Z, +, ×) . . . .... .... .... . . . . . Problem (Matrix Chain Multiplication – MCM) Let Ai = (a(i) x,y ), compute A = A1 × A2 × · · · Ak . |{z} |{z} |{z} |{z} p0 ×pk ▶ ▶ p0 ×p1 p1 ×p2 pk−1 ×pk Sum-product semiring (R, +, ×), (C, +, ×), (Z, +, ×) FAQ-SS instance: . . . .... .... .... . . . . . Problem (Matrix Chain Multiplication – MCM) Let Ai = (a(i) x,y ), compute A = A1 × A2 × · · · Ak . |{z} |{z} |{z} |{z} p0 ×pk ▶ ▶ p0 ×p1 p1 ×p2 pk−1 ×pk Sum-product semiring (R, +, ×), (C, +, ×), (Z, +, ×) FAQ-SS instance: ▶ Variables: Dom(Xi ) = [pi ], i ∈ {0, . . . , k} . . . .... .... .... . . . . . Problem (Matrix Chain Multiplication – MCM) Let Ai = (a(i) x,y ), compute A = A1 × A2 × · · · Ak . |{z} |{z} |{z} |{z} p0 ×pk ▶ ▶ p0 ×p1 p1 ×p2 pk−1 ×pk Sum-product semiring (R, +, ×), (C, +, ×), (Z, +, ×) FAQ-SS instance: ▶ ▶ Variables: Dom(Xi ) = [pi ], i ∈ {0, . . . , k} Factors: ψi,i+1 (xi , xi+1 ) = a(i) xi ,xi+1 . . . .... .... .... . . . . . Problem (Matrix Chain Multiplication – MCM) Let Ai = (a(i) x,y ), compute A = A1 × A2 × · · · Ak . |{z} |{z} |{z} |{z} p0 ×pk ▶ ▶ p0 ×p1 p1 ×p2 pk−1 ×pk Sum-product semiring (R, +, ×), (C, +, ×), (Z, +, ×) FAQ-SS instance: ▶ ▶ ▶ Variables: Dom(Xi ) = [pi ], i ∈ {0, . . . , k} Factors: ψi,i+1 (xi , xi+1 ) = a(i) xi ,xi+1 Compute new function φ : [p0 ] × [pk ] → D φ(x0 , xk ) = ∑ x1 ··· ∑ k−1 ∏ ψi,i+1 (xi , xi+1 ). xk−1 i=0 . . . .... .... .... . . . . . Probabilistic Graphical Models ▶ In PGMs, factors are also called potential functions . . . .... .... .... . . . . . Probabilistic Graphical Models ▶ ▶ In PGMs, factors are also called potential functions Three typical inference/learning tasks on PGMs ▶ ▶ ▶ Compute some marginal distribution Compute p(xA | xB ) Compute argmaxxA p(xA | xB ) (e.g. MAP queries) . . . .... .... .... . . . . . Probabilistic Graphical Models ▶ ▶ In PGMs, factors are also called potential functions Three typical inference/learning tasks on PGMs ▶ ▶ ▶ ▶ Compute some marginal distribution Compute p(xA | xB ) Compute argmaxxA p(xA | xB ) (e.g. MAP queries) These problems are precisely FAQ-SS (i.e. SumProd) on ▶ ▶ (R+ , +, ×) (R+ , max, ×) . . . .... .... .... . . . . . Many more examples ▶ Discrete Fourier Transform ▶ Hollant Problem (as in Holographic algorithms) ▶ Graph Homomorphism Problem ▶ Weighted CSP ▶ List recoverable codes ▶ LDPC codes With a squint: also called Aggregate over Factorized DB ▶ ▶ ▶ Bakibayev et al. (VLDB 2014), Olteanu-Zavodny (TODS 2015) etc. . . . .... .... .... . . . . . Why the generality of FAQ again? ψ14 (X1 , X4 ) ψ23 (X2 , X3 ) All functions have the same range D FAQ-expression ψ13 (X1 , X3 ) φ(x3 ) = ∑∏ x1 x2 φ(X3 ) max ψ1,2,4 ψ2,3 ψ1,3 ψ1,4 x4 ψ124 (X1 , X2 , X4 ) ▶ Compute the function φ : ∏ Dom(Xi ) → D. i∈F ▶ φ defined by the FAQ-expression ⊕(f +1) ⊕(n−1) φ(x[f ] ) = ··· xf +1 ∈Dom(Xf +1 ) ▶ ⊕ For each ((i) ⊕(i) ⊗) ▶ ▶ Either D, ⊕(i) ⊗ Or = , ⊕(n) ⊗ xn−1 ∈Dom(Xn−1 ) xn ∈Dom(Xn ) S∈E ψS (xS ) is a commutative semiring . . . .... .... .... . . . . . Quantified Conjunctive Queries Problem (QCQ with free variables) Given Qi ∈ {∃, ∀}, for i > f . Φ(X1 , . . . , Xf ) = Qf +1 Xf +1 · · · Qn Xn ∧ R , R∈atoms(Φ) . . . .... .... .... . . . . . Quantified Conjunctive Queries Problem (QCQ with free variables) Given Qi ∈ {∃, ∀}, for i > f . ∧ Φ(X1 , . . . , Xf ) = Qf +1 Xf +1 · · · Qn Xn R , R∈atoms(Φ) ▶ FAQ instance: ▶ ▶ ({0, 1}, {max, ×}, ×) Compute the function φ(x1 , · · · , xf ) = where ⊕(i) ⊕(f +1) xf +1 ∈{0,1} { = max × ··· ⊕(n) ∏ xn ∈{0,1} S∈E ψS (xS ) if Qi = ∃ if Qi = ∀ . . . .... .... .... . . . . . # Quantified Conjunctive Queries Problem (#QCQ) Given Qi ∈ {∃, ∀}, for i > f , and expression ∧ Φ(X1 , . . . , Xf ) = Qf +1 Xf +1 · · · Qn Xn R , R∈atoms(Φ) Count the number of x[f ] for which Φ(x[f ] ) = true . . . .... .... .... . . . . . # Quantified Conjunctive Queries Problem (#QCQ) Given Qi ∈ {∃, ∀}, for i > f , and expression ∧ Φ(X1 , . . . , Xf ) = Qf +1 Xf +1 · · · Qn Xn R , R∈atoms(Φ) Count the number of x[f ] for which Φ(x[f ] ) = true ▶ FAQ instance: ▶ ▶ ({0, 1} ∪ R+ , {max, ×, +}, ×) Compute the constant ∑ ∑ ⊕(f +1) ⊕(n) ∏ φ= ··· ··· ψS (xS ) x1 xf xf +1 ∈{0,1} { where ⊕ (i) = max × xn ∈{0,1} S∈E if Qi = ∃ if Qi = ∀ . . . .... .... .... . . . . . Table of Contents The FAQ problem Summary of Results and Approach The OutsideIn algorithm The InsideOut algorithm Choosing a variable ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Algorithm InsideOut FAQ-expression σ OutsideIn1 to compute φ OutsideIn2 φ .. . OutsideInn . . . .... .... .... . . . . . The Algorithm InsideOut FAQ-expression σ OutsideIn1 to compute φ OutsideIn2 φ .. . OutsideInn ▶ InsideOut represents dynamic programming . . . .... .... .... . . . . . The Algorithm InsideOut FAQ-expression σ OutsideIn1 to compute φ OutsideIn2 φ .. . OutsideInn ▶ InsideOut represents dynamic programming ▶ is variable elimination with new twists ▶ ▶ Variable Elimination (Zhang-Poole, JAIR 1996) Bucket Elimination (Dechter, Artif. Intell. 1999) . . . .... .... .... . . . . . The Algorithm InsideOut FAQ-expression σ OutsideIn1 to compute φ OutsideIn2 φ .. . OutsideInn ▶ InsideOut represents dynamic programming ▶ is variable elimination with new twists ▶ ▶ ▶ Variable Elimination (Zhang-Poole, JAIR 1996) Bucket Elimination (Dechter, Artif. Intell. 1999) OutsideIn represents backtracking search . . . .... .... .... . . . . . The Algorithm InsideOut FAQ-expression σ OutsideIn1 to compute φ OutsideIn2 φ .. . OutsideInn ▶ InsideOut represents dynamic programming ▶ is variable elimination with new twists ▶ ▶ ▶ Variable Elimination (Zhang-Poole, JAIR 1996) Bucket Elimination (Dechter, Artif. Intell. 1999) OutsideIn represents backtracking search ▶ any worst-case optimal join algorithm, such as ▶ ▶ NPRR (Ngo et al., PODS 2012) Leapfrog-Triejoin (Veldhuizen, ICDT’2014) . . . .... .... .... . . . . . The Algorithm InsideOut FAQ-expression σ OutsideIn1 to compute φ OutsideIn2 Runtime = Õ(N faqw(σ) + |φ|) φ .. . OutsideInn ▶ InsideOut represents dynamic programming ▶ is variable elimination with new twists ▶ ▶ ▶ Variable Elimination (Zhang-Poole, JAIR 1996) Bucket Elimination (Dechter, Artif. Intell. 1999) OutsideIn represents backtracking search ▶ any worst-case optimal join algorithm, such as ▶ ▶ NPRR (Ngo et al., PODS 2012) Leapfrog-Triejoin (Veldhuizen, ICDT’2014) . . . .... .... .... . . . . . The Algorithm InsideOut FAQ-expression σ OutsideIn1 to compute φ OutsideIn2 .. . OutsideInn ▶ faqw(σ) is the “width” of σ φ FAQ-analog of fractional hypertree width InsideOut represents dynamic programming ▶ is variable elimination with new twists ▶ ▶ ▶ Runtime = Õ(N faqw(σ) + |φ|) Variable Elimination (Zhang-Poole, JAIR 1996) Bucket Elimination (Dechter, Artif. Intell. 1999) OutsideIn represents backtracking search ▶ any worst-case optimal join algorithm, such as ▶ ▶ NPRR (Ngo et al., PODS 2012) Leapfrog-Triejoin (Veldhuizen, ICDT’2014) . . . .... .... .... . . . . . Technical Contributions FAQ-expr. σ for φ, hypergraph H . . . .... .... .... . . . . . Technical Contributions EVO(φ) = set of expressions “semantically equivalent” to φ FAQ-expr. σ for φ, hypergraph H EVO(φ) . . . .... .... .... . . . . . Technical Contributions EVO(φ) = set of expressions “semantically equivalent” to φ FAQ-expr. σ for φ, hypergraph H EVO(φ) φ(x3 ) = φ(x3 ) = ∑∑∑ x2 x1 ∑ ∑ x1 x2 max ψ1,2,4 ψ2,3 ψ1,3 ψ1,4 ψ2,5 x5 max x4 x4 ∑ ψ1,2,4 ψ2,3 ψ1,3 ψ1,4 ψ2,5 x5 . . . .... .... .... . . . . . Technical Contributions σ ∗ = arg min faqw(τ ) τ ∈EVO(φ) FAQ-expr. σ for φ, hypergraph H EVO(φ) FAQ-expr. σ ∗ for φ . . . .... .... .... . . . . . Technical Contributions σ ∗ = arg min faqw(τ ) τ ∈EVO(φ) FAQ-expr. σ for φ, hypergraph H EVO(φ) FAQ-expr. σ for φ ∗ ∗ Runtime = Õ(N faqw(σ ) + |φ|) = Õ(N opt + |φ|) InsideOut φ . . . .... .... .... . . . . . Technical Contributions ∗ Runtime = Õ(N faqw(σ ) + |φ|) FAQ-expr. σ for φ, hypergraph H EVO(φ) FAQ-expr. σ for φ ∗ = Õ(N opt + |φ|) InsideOut φ poly(|H|) ∑ x1 ,x4 ∏ max x3 x2 ,x7 ∑ x5 max x6 Expression Tree Precedence Poset P . . . .... .... .... . . . . . Technical Contributions ∗ Runtime = Õ(N faqw(σ ) + |φ|) FAQ-expr. σ for φ, hypergraph H EVO(φ) FAQ-expr. σ for φ ∗ = Õ(N opt + |φ|) InsideOut φ EVO(φ) = CWE(LinEx(P )) poly(|H|) LinEx(P ) ⊆ EVO(φ) ∑ x1 ,x4 ∏ max x3 x2 ,x7 ∑ x5 max x6 Expression Tree Precedence Poset P . . . .... .... .... . . . . . Technical Contributions ∗ Runtime = Õ(N faqw(σ ) + |φ|) FAQ-expr. σ for φ, hypergraph H EVO(φ) FAQ-expr. σ for φ ∗ = Õ(N opt + |φ|) InsideOut φ EVO(φ) = CWE(LinEx(P )) poly(|H|) LinEx(P ) ⊆ EVO(φ) min faqw(τ ) = min τ ∈LinEx(P ) τ ∈EVO(φ) faqw(τ ) ∑ x1 ,x4 ∏ max x3 x2 ,x7 ∑ x5 max x6 Expression Tree Precedence Poset P . . . .... .... .... . . . . . Technical Contributions FAQ-expr. σ for φ, hypergraph H EVO(φ) FAQ-expr. σ ∗ for φ InsideOut φ EVO(φ) = CWE(LinEx(P )) poly(|H|) LinEx(P ) ⊆ EVO(φ) min faqw(τ ) = min τ ∈LinEx(P ) τ ∈EVO(φ) faqw(τ ) ∑ x1 ,x4 poly(|H|) ∏ max x3 x2 ,x7 ∑ x5 Expression Tree Precedence Poset P max x6 Tree Decomposition of H . . . .... .... .... . . . . . Technical Contributions FAQ-expr. σ for φ, hypergraph H EVO(φ) FAQ-expr. σ ∗ for φ InsideOut φ EVO(φ) = CWE(LinEx(P )) poly(|H|) LinEx(P ) ⊆ EVO(φ) min faqw(τ ) = min τ ∈LinEx(P ) τ ∈EVO(φ) faqw(τ ) ∑ x1 ,x4 poly(|H|) ∏ max x3 x2 ,x7 ∑ x5 Expression Tree Precedence Poset P poly(|H|) max x6 Tree Decomposition of H FAQ-expr. σ̄ for φ faqw(σ̄) ≤ opt + g(opt) g = approx. factor for fractional hypertree width of H . . . .... .... .... . . . . . Technical Contributions Runtime = Õ(N opt+g(opt) + |φ|) FAQ-expr. σ for φ, hypergraph H EVO(φ) FAQ-expr. σ ∗ for φ InsideOut φ EVO(φ) = CWE(LinEx(P )) poly(|H|) LinEx(P ) ⊆ EVO(φ) min faqw(τ ) = min τ ∈LinEx(P ) τ ∈EVO(φ) faqw(τ ) ∑ x1 ,x4 poly(|H|) ∏ max x3 x2 ,x7 ∑ x5 Expression Tree Precedence Poset P poly(|H|) max x6 Tree Decomposition of H FAQ-expr. σ̄ for φ faqw(σ̄) ≤ opt + g(opt) g = approx. factor for fractional hypertree width of H . . . .... .... .... . . . . . Some Corollaries Problem Previous Algo. #QCQ No non-trivial algo QCQ Õ(N PW(H) + |φ|) InsideOut Õ(N Õ(N faqw(φ) + |φ|) faqw(φ) + |φ|) faqw(φ) + |φ|) Chen-Dalmau (LICS 2012) DM(H) + |φ|) #CQ Õ(N Joins Durand-Mengel (ICDT 2013) ( ) fhtw(H) Õ N + |φ| Marginal Distrib. Õ(N MAP query Õ(N Õ(N ( ) fhtw(H) Õ N + |φ| Grohe-Marx (SODA’06) htw(φ) + |φ|) Õ(N htw(φ) + |φ|) Õ(N faqw(φ) + |φ|) faqw(φ) + |φ|) Kask et al. (Artif. Intel. 2005) Matrix Chain Mult. DP bound DFT O(N logp N ) DP Bound O(N logp N ) Aji-McEliece (IEEE Trans. IT 2000) Dechter (Artif. Intell. 1999) Textbook . . . .... .... .... . . . . . Table of Contents The FAQ problem Summary of Results and Approach The OutsideIn algorithm The InsideOut algorithm Choosing a variable ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . How are factors accessed? ▶ A factor oracle for each input factor ψS . . . .... .... .... . . . . . How are factors accessed? ▶ A factor oracle for each input factor ψS ▶ Oracle = (complexity people’s) fancy name for an API . . . .... .... .... . . . . . How are factors accessed? ▶ A factor oracle for each input factor ψS ▶ ▶ Oracle = (complexity people’s) fancy name for an API Output factor: a table of tuples ⟨xF , φ[xF ]⟩ but only store tuples for which φ[xF ] ̸= 0 . . . .... .... .... . . . . . How are factors accessed? ▶ A factor oracle for each input factor ψS ▶ ▶ Oracle = (complexity people’s) fancy name for an API Output factor: a table of tuples ⟨xF , φ[xF ]⟩ but only store tuples for which φ[xF ] ̸= 0 ▶ Called the listing representation . . . .... .... .... . . . . . How are factors accessed? ▶ A factor oracle for each input factor ψS ▶ ▶ Oracle = (complexity people’s) fancy name for an API Output factor: a table of tuples ⟨xF , φ[xF ]⟩ but only store tuples for which φ[xF ] ̸= 0 ▶ Called the listing representation Example (Salary : {ID, Name} → R+ ) . . . .... .... .... . . . . . How are factors accessed? ▶ A factor oracle for each input factor ψS ▶ ▶ Oracle = (complexity people’s) fancy name for an API Output factor: a table of tuples ⟨xF , φ[xF ]⟩ but only store tuples for which φ[xF ] ̸= 0 ▶ Called the listing representation Example (Salary : {ID, Name} → R+ ) ID 1234 5678 9999 Name AnHai Doan Current Hung Ngo Future Hung Ngo Salary $400,000 $100,000 $1,000,000 . . . .... .... .... . . . . . Notation: conditional factor ▶ Let ψS be a factor ▶ Let K ⊆ [n], yK ∈ ∏ Dom(Xi ) i∈K ▶ Conditional factor ψS (· | yK ) : ∏ Dom(Xi ) → D i∈S where ψS (xS | yK ) = { 0 ψS (xS ) if S ∩ K ̸= ∅ and xS∩K ̸= yS∩K otherwise. . . . .... .... .... . . . . . Notation: conditional factor ▶ Let ψS be a factor ▶ Let K ⊆ [n], yK ∈ ∏ Dom(Xi ) i∈K ▶ Conditional factor ψS (· | yK ) : ∏ Dom(Xi ) → D i∈S where ψS (xS | yK ) = ▶ { 0 ψS (xS ) if S ∩ K ̸= ∅ and xS∩K ̸= yS∩K otherwise. Salary(ID=9999 | Name = “Future Hung Ngo”) = $1, 000, 000. . . . .... .... .... . . . . . Notation: conditional factor ▶ Let ψS be a factor ▶ Let K ⊆ [n], yK ∈ ∏ Dom(Xi ) i∈K ▶ Conditional factor ψS (· | yK ) : ∏ Dom(Xi ) → D i∈S where ψS (xS | yK ) = { 0 ψS (xS ) if S ∩ K ̸= ∅ and xS∩K ̸= yS∩K otherwise. ▶ Salary(ID=9999 | Name = “Future Hung Ngo”) = $1, 000, 000. ▶ Salary(ID=9999 | Name = “Paris Koutris”) = $0. . . . .... .... .... . . . . . OutsideIn for FAQ-SS without free variables φ = ⊕ x1 ··· ⊕⊗ ψS (xS ) xn S∈E . . . .... .... .... . . . . . OutsideIn for FAQ-SS without free variables φ = ⊕ x1 = ··· ⊕⊗ ψS (xS ) xn S∈E ⊕ x1 ∈ Dom(X1 ) ⊕ ⊗ ψS (xS | x1 ) x[n]−{1} S∈E . . . .... .... .... . . . . . OutsideIn for FAQ-SS without free variables φ = ⊕ x1 = ··· ⊕⊗ Subproblem on H − {1} ψS (xS ) xn S∈E ⊕ x1 ∈ Dom(X1 ) ⊕ ⊗ ψS (xS | x1 ) x[n]−{1} S∈E . . . .... .... .... . . . . . OutsideIn for FAQ-SS without free variables φ = ⊕ x1 = Runtime O(Dn ) ··· ⊕⊗ Subproblem on H − {1} ψS (xS ) xn S∈E ⊕ x1 ∈ Dom(X1 ) ⊕ ⊗ ψS (xS | x1 ) x[n]−{1} S∈E . . . .... .... .... . . . . . OutsideIn for FAQ-SS without free variables φ = ⊕ ··· x1 xn S∈E ⊕ = Runtime O(Dn ) = ⊕⊗ Subproblem on H − {1} ψS (xS ) ⊕ ⊗ ψS (xS | x1 ) x[n]−{1} S∈E x1 ∈ Dom(X1 ) ⊕ ⊕ ⊗ ψS (xS | x1 ) . x1 ∈ I 1 x[n]−{1} S∈E . . . .... .... .... . . . . . OutsideIn for FAQ-SS without free variables φ = ⊕ ··· x1 xn S∈E ⊕ = Runtime O(Dn ) = ⊕⊗ Subproblem on H − {1} ψS (xS ) ⊕ ⊗ ψS (xS | x1 ) x[n]−{1} S∈E x1 ∈ Dom(X1 ) ⊕ ⊕ ⊗ ψS (xS | x1 ) . x1 ∈ I 1 x[n]−{1} S∈E { } I1 = x1 | ψS (· | x1 ) ̸≡ 0, ∀S ∈ E . . . .... .... .... . . . . . OutsideIn = Backtracking Search . . . .... .... .... . . . . . OutsideIn = Backtracking Search ▶ Question: How good is OutsideIn? . . . .... .... .... . . . . . OutsideIn = Backtracking Search ▶ ▶ Question: How good is OutsideIn? Answer: Worst-case optimal for joins! . . . .... .... .... . . . . . OutsideIn = Backtracking Search ▶ ▶ Question: How good is OutsideIn? Answer: Worst-case optimal for joins! ▶ ▶ Grohe, Marx (SODA’06) Atserias, Grohe, Marx (FOCS’08) AGM-bound . . . .... .... .... . . . . . OutsideIn = Backtracking Search ▶ ▶ Question: How good is OutsideIn? Answer: Worst-case optimal for joins! ▶ ▶ ▶ Grohe, Marx (SODA’06) Atserias, Grohe, Marx (FOCS’08) Ngo, Ré, Porat, Rudra (PODS’12) AGM-bound NPRR algorithm . . . .... .... .... . . . . . OutsideIn = Backtracking Search ▶ ▶ Question: How good is OutsideIn? Answer: Worst-case optimal for joins! ▶ ▶ ▶ ▶ Grohe, Marx (SODA’06) Atserias, Grohe, Marx (FOCS’08) AGM-bound Ngo, Ré, Porat, Rudra (PODS’12) NPRR algorithm Veldhuizen (ICDT’14) Leapfrog-Triejoin algorithm . . . .... .... .... . . . . . OutsideIn = Backtracking Search ▶ ▶ Question: How good is OutsideIn? Answer: Worst-case optimal for joins! ▶ ▶ ▶ ▶ ▶ Grohe, Marx (SODA’06) Atserias, Grohe, Marx (FOCS’08) AGM-bound Ngo, Ré, Porat, Rudra (PODS’12) NPRR algorithm Veldhuizen (ICDT’14) Leapfrog-Triejoin algorithm Ngo, Ré, Rudra (SIGMOD Records’13) Generic-Join . . . .... .... .... . . . . . Background: fractional edge cover of H X1 X2 X3 . . . .... .... .... . . . . . Background: fractional edge cover of H X1 λ=1 λ=1 X2 X3 λ=0 . . . .... .... .... . . . . . Background: fractional edge cover of H X1 λ= 1 2 λ= X2 1 2 X3 λ= 1 2 . . . .... .... .... . . . . . Background: fractional edge cover of B = {1, 2, 3} X4 X1 X5 X8 X7 X6 X2 X3 . . . .... .... .... . . . . . Background: fractional edge cover of B = {1, 2, 3} X4 X1 X5 X8 λ=1 X7 λ=1 X6 X2 X3 λ=0 . . . .... .... .... . . . . . Background: fractional edge cover of B = {1, 2, 3} λ=1 X4 X1 X5 X8 X7 X6 X2 X3 λ=1 . . . .... .... .... . . . . . Background: fractional edge cover of B = {1, 2, 3} λ= X4 X1 X5 λ= X6 1 3 X8 X7 2 3 λ= X2 2 3 X3 λ= 1 3 . . . .... .... .... . . . . . Background: fractional edge cover ▶ H = (V, E) a multi hypergraph ▶ B⊆V ▶ a fractional edge cover of B is a vector (λS )S∈E , s.t. ∑ λS ≥ 1, ∀v ∈ B S:v∈S λS ▶ ≥ 0, ∀S ∈ E. called fractional edge cover of H when B = V . . . .... .... .... . . . . . Pros of OutsideIn Theorem (Runtime of OutsideIn) Let (λS )S∈E be any fractional edge cover of H, then OutsideIn runs in time ( ) ∏ λS |ψS | Õ mn S∈E . . . .... .... .... . . . . . Pros of OutsideIn Theorem (Runtime of OutsideIn) Let (λS )S∈E be any fractional edge cover of H, then OutsideIn runs in time ( ) ∏ λS |ψS | Õ mn AGM-bound S∈E . . . .... .... .... . . . . . Pros of OutsideIn Theorem (Runtime of OutsideIn) Let (λS )S∈E be any fractional edge cover of H, then OutsideIn runs in time ( ) ∏ λS |ψS | Õ mn AGM-bound S∈E ▶ OutsideIn is worst-case optimal for joins ▶ Very simple to implement . . . .... .... .... . . . . . Pros of OutsideIn Theorem (Runtime of OutsideIn) Let (λS )S∈E be any fractional edge cover of H, then OutsideIn runs in time ( ) ∏ λS |ψS | Õ mn AGM-bound S∈E ▶ OutsideIn is worst-case optimal for joins ▶ Very simple to implement ▶ Works for FAQ-SS (i.e. Sum-Prod) with free variables! . . . .... .... .... . . . . . Pros of OutsideIn Theorem (Runtime of OutsideIn) Let (λS )S∈E be any fractional edge cover of H, then OutsideIn runs in time ( ) ∏ λS |ψS | Õ mn AGM-bound S∈E ▶ OutsideIn is worst-case optimal for joins ▶ Very simple to implement ▶ Works for FAQ-SS (i.e. Sum-Prod) with free variables! ▶ Works well for dense queries (such as cliques) . . . .... .... .... . . . . . Pros of OutsideIn Theorem (Runtime of OutsideIn) Let (λS )S∈E be any fractional edge cover of H, then OutsideIn runs in time ( ) ∏ λS |ψS | Õ mn AGM-bound S∈E ▶ OutsideIn is worst-case optimal for joins ▶ Very simple to implement ▶ Works for FAQ-SS (i.e. Sum-Prod) with free variables! ▶ Works well for dense queries (such as cliques) ▶ Works with any variable ordering . . . .... .... .... . . . . . Pros of OutsideIn Theorem (Runtime of OutsideIn) Let (λS )S∈E be any fractional edge cover of H, then OutsideIn runs in time ( ) ∏ λS |ψS | Õ mn AGM-bound S∈E ▶ OutsideIn is worst-case optimal for joins ▶ Very simple to implement ▶ Works for FAQ-SS (i.e. Sum-Prod) with free variables! ▶ Works well for dense queries (such as cliques) ▶ Works with any variable ordering ▶ Virtually zero memory footprint (backtracking search!). . . . .... .... .... . . . . . Examples of AGM-bound ▶ Q = R(A, B) 1 S(B, C) 1 T (A, C), |R| = |S| = |T | = N – . . . .... .... .... . . . . . Examples of AGM-bound ▶ Q = R(A, B) 1 S(B, C) 1 T (A, C), |R| = |S| = |T | = N ▶ OutsideIn runs in time Õ(N 3/2 ) for any input – . . . .... .... .... . . . . . Examples of AGM-bound ▶ Q = R(A, B) 1 S(B, C) 1 T (A, C), |R| = |S| = |T | = N ▶ OutsideIn runs in time Õ(N 3/2 ) for any input ▶ N 3/2 is the AGM-bound AGM(H) – . . . .... .... .... . . . . . Examples of AGM-bound ▶ Q = R(A, B) 1 S(B, C) 1 T (A, C), |R| = |S| = |T | = N ▶ OutsideIn runs in time Õ(N 3/2 ) for any input ▶ N 3/2 is the AGM-bound AGM(H) ▶ 3/2 is the fractional edge cover number ρ∗H – . . . .... .... .... . . . . . Examples of AGM-bound ▶ Q = R(A, B) 1 S(B, C) 1 T (A, C), |R| = |S| = |T | = N ▶ OutsideIn runs in time Õ(N 3/2 ) for any input ▶ ▶ N 3/2 is the AGM-bound AGM(H) ▶ 3/2 is the fractional edge cover number ρ∗H Any join-project plan requires Ω(N 2 ) for some input – . . . .... .... .... . . . . . Examples of AGM-bound ▶ Q = R(A, B) 1 S(B, C) 1 T (A, C), |R| = |S| = |T | = N ▶ OutsideIn runs in time Õ(N 3/2 ) for any input ▶ N 3/2 is the AGM-bound AGM(H) ▶ 3/2 is the fractional edge cover number ρ∗H ▶ Any join-project plan requires Ω(N 2 ) for some input ▶ Q = R(A, B, C) 1 S(A, B, D) 1 T (A, C, D) 1 W (B, C, D) – . . . .... .... .... . . . . . Examples of AGM-bound ▶ Q = R(A, B) 1 S(B, C) 1 T (A, C), |R| = |S| = |T | = N ▶ OutsideIn runs in time Õ(N 3/2 ) for any input ▶ N 3/2 is the AGM-bound AGM(H) ▶ 3/2 is the fractional edge cover number ρ∗H ▶ Any join-project plan requires Ω(N 2 ) for some input ▶ Q = R(A, B, C) 1 S(A, B, D) 1 T (A, C, D) 1 W (B, C, D) ▶ OutsideIn runs in time Õ(N 4/3 ) for any input – . . . .... .... .... . . . . . Examples of AGM-bound ▶ Q = R(A, B) 1 S(B, C) 1 T (A, C), |R| = |S| = |T | = N ▶ OutsideIn runs in time Õ(N 3/2 ) for any input ▶ N 3/2 is the AGM-bound AGM(H) ▶ 3/2 is the fractional edge cover number ρ∗H ▶ Any join-project plan requires Ω(N 2 ) for some input ▶ Q = R(A, B, C) 1 S(A, B, D) 1 T (A, C, D) 1 W (B, C, D) ▶ OutsideIn runs in time Õ(N 4/3 ) for any input – ▶ N 4/3 is the AGM-bound AGM(H) . . . .... .... .... . . . . . Examples of AGM-bound ▶ Q = R(A, B) 1 S(B, C) 1 T (A, C), |R| = |S| = |T | = N ▶ OutsideIn runs in time Õ(N 3/2 ) for any input ▶ N 3/2 is the AGM-bound AGM(H) ▶ 3/2 is the fractional edge cover number ρ∗H ▶ Any join-project plan requires Ω(N 2 ) for some input ▶ Q = R(A, B, C) 1 S(A, B, D) 1 T (A, C, D) 1 W (B, C, D) ▶ OutsideIn runs in time Õ(N 4/3 ) for any input – ▶ N 4/3 is the AGM-bound AGM(H) ▶ 4/3 is the fractional edge cover number ρ∗H . . . .... .... .... . . . . . Examples of AGM-bound ▶ Q = R(A, B) 1 S(B, C) 1 T (A, C), |R| = |S| = |T | = N ▶ OutsideIn runs in time Õ(N 3/2 ) for any input ▶ N 3/2 is the AGM-bound AGM(H) ▶ 3/2 is the fractional edge cover number ρ∗H ▶ Any join-project plan requires Ω(N 2 ) for some input ▶ Q = R(A, B, C) 1 S(A, B, D) 1 T (A, C, D) 1 W (B, C, D) ▶ OutsideIn runs in time Õ(N 4/3 ) for any input – ▶ ▶ N 4/3 is the AGM-bound AGM(H) ▶ 4/3 is the fractional edge cover number ρ∗H Any join-project plan requires Ω(N 2 ) for some input . . . .... .... .... . . . . . Cons of OutsideIn ▶ Horrible for large acyclic queries . . . .... .... .... . . . . . Cons of OutsideIn ▶ Horrible for large acyclic queries ▶ Yannakakis algorithm runs in time Õ(N + |output|) on any (α-)acyclic query . . . .... .... .... . . . . . Cons of OutsideIn ▶ Horrible for large acyclic queries ▶ Yannakakis algorithm runs in time Õ(N + |output|) on any (α-)acyclic query ▶ On a 2k-path query, AGM-bound is O(N k ). X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 . . . .... .... .... . . . . . Cons of OutsideIn ▶ Horrible for large acyclic queries ▶ Yannakakis algorithm runs in time Õ(N + |output|) on any (α-)acyclic query ▶ On a 2k-path query, AGM-bound is O(N k ). λ=1 X1 λ=1 X2 X3 λ=1 X4 X5 λ=1 X6 X7 λ=1 X8 X9 X10 . . . .... .... .... . . . . . Cons of OutsideIn ▶ Horrible for large acyclic queries ▶ Yannakakis algorithm runs in time Õ(N + |output|) on any (α-)acyclic query ▶ On a 2k-path query, AGM-bound is O(N k ). λ=1 X1 ▶ λ=1 X2 X3 λ=1 X4 X5 λ=1 X6 X7 λ=1 X8 X9 X10 More generally, horrible whenever fhtw < AGM-bound. . . . .... .... .... . . . . . Table of Contents The FAQ problem Summary of Results and Approach The OutsideIn algorithm The InsideOut algorithm Choosing a variable ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ-SS without free variables φ = ⊕ x1 ··· ⊕⊗ ψS (xS ) xn S∈E . . . .... .... .... . . . . . FAQ-SS without free variables φ = ⊕ ··· x1 = ⊕ x1 ⊕⊗ ψS (xS ) xn S∈E ··· ⊕ ( ⊕⊗ xn−1 xn S∈E ) ψS (xS ) . . . .... .... .... . . . . . FAQ-SS without free variables φ = ⊕ ··· x1 = ⊕ x1 ⊕⊗ ψS (xS ) xn S∈E ··· ⊕ ( ⊕⊗ xn−1 xn S∈E ) ψS (xS ) . . . .... .... .... . . . . . FAQ-SS without free variables φ = ⊕ ··· x1 = ⊕ = x1 ψS (xS ) xn S∈E ··· x1 ⊕ ⊕⊗ ··· ⊕ ( ⊕⊗ xn−1 xn S∈E ⊕ ⊗ xn−1 n∈S / ) ψS (xS ) ψS (xS ) ( ⊕⊗ ) ψS (xS ) xn n∈S . . . .... .... .... . . . . . FAQ-SS without free variables φ = ⊕ ··· x1 = ⊕ = x1 ψS (xS ) xn S∈E ··· x1 ⊕ ⊕⊗ ··· ⊕ ( ⊕⊗ xn−1 xn S∈E ⊕ ⊗ xn−1 n∈S / ) ψS (xS ) ψS (xS ) ( ⊕⊗ ) ψS (xS ) xn n∈S ⊗ distributes over ⊕ . . . .... .... .... . . . . . FAQ-SS without free variables φ = ⊕ ··· x1 = ⊕ = x1 ψS (xS ) xn S∈E ··· x1 ⊕ ⊕⊗ ··· ⊕ ( ⊕⊗ xn−1 xn S∈E ⊕ ⊗ xn−1 n∈S / ) ψS (xS ) ψS (xS ) ( ⊕⊗ ) ψS (xS ) xn n∈S . . . .... .... .... . . . . . FAQ-SS without free variables φ = ⊕ ··· x1 = ⊕ = x1 ψS (xS ) xn S∈E ··· x1 ⊕ ⊕⊗ ··· ⊕ ( ⊕⊗ xn−1 xn S∈E ⊕ ⊗ xn−1 n∈S / ) ψS (xS ) ψS (xS ) ( ⊕⊗ ∪ Un = S ) S:n∈S ψS (xS ) xn n∈S . . . .... .... .... . . . . . FAQ-SS without free variables φ = ⊕ ··· x1 = ⊕ = x1 ψS (xS ) xn S∈E ··· x1 ⊕ ⊕⊗ ··· ⊕ ( ⊕⊗ xn−1 xn S∈E ⊕ ⊗ xn−1 n∈S / ) ψS (xS ) ψS (xS ) ( ⊕⊗ ∪ Un = S ) S:n∈S ψS (xS ) xn n∈S ψUn −{n} (xUn −{n} ) . . . .... .... .... . . . . . FAQ-SS without free variables φ = ⊕ ··· ⊕⊗ x1 = ⊕ ··· x1 = ⊕ ··· x1 = ⊕ x1 ψS (xS ) xn S∈E ⊕ ( ⊕⊗ xn−1 xn S∈E ⊕ ⊗ xn−1 n∈S / ··· ⊕⊗ ) ψS (xS ) ψS (xS ) ( ⊕⊗ ∪ Un = S ) S:n∈S ψS (xS ) xn n∈S ψS (xS ) ⊗ ψUn −{n} (xUn −{n} ) xn−1 n∈S / ψUn −{n} (xUn −{n} ) . . . .... .... .... . . . . . FAQ-SS without free variables φ = ⊕ ··· ⊕⊗ x1 = ⊕ ··· x1 = ⊕ ··· x1 = ⊕ x1 ψS (xS ) xn S∈E ⊕ ( ⊕⊗ xn−1 xn S∈E ⊕ ⊗ xn−1 n∈S / ··· ⊕⊗ ) ψS (xS ) ψS (xS ) ( ⊕⊗ ∪ Un = S ) S:n∈S ψS (xS ) xn n∈S ψS (xS ) ⊗ ψUn −{n} (xUn −{n} ) xn−1 n∈S / . . . .... .... .... . . . . . FAQ-SS without free variables φ = ⊕ ··· ⊕⊗ x1 = ⊕ ··· x1 = ⊕ ··· x1 = ⊕ x1 ψS (xS ) xn S∈E ⊕ ( ⊕⊗ xn−1 xn S∈E ⊕ ⊗ xn−1 n∈S / ··· ⊕⊗ ) ψS (xS ) ψS (xS ) ( ⊕⊗ ∪ Un = S ) S:n∈S ψS (xS ) xn n∈S ψS (xS ) ⊗ ψUn −{n} (xUn −{n} ) xn−1 n∈S / . . . .... .... .... . . . . . FAQ-SS without free variables φ = ⊕ ··· ⊕⊗ x1 = ⊕ ··· x1 = ⊕ ··· x1 = ⊕ x1 ψS (xS ) xn S∈E ⊕ ( ⊕⊗ xn−1 xn S∈E ⊕ ⊗ ) ψS (xS ) ψS (xS ) ( ⊕⊗ xn−1 n∈S / ··· ⊕⊗ ∪ Un = S ) S:n∈S ψS (xS ) xn n∈S ψS (xS ) ⊗ ψUn −{n} (xUn −{n} ) xn−1 n∈S / New instance of FAQ-SS Hn−1 = ([n − 1], En−1 ) En−1 = E + (Un − {n}) − {S | n ∈ S} . . . .... .... .... . . . . . Naïve InsideOut = Variable Elimination φ = ⊕ x1 ··· ⊕⊗ xn−1 n∈S / ⊕ ⊗ ψS (xS ) ψS (xS ) xn S∈∂(n) . . . .... .... .... . . . . . Naïve InsideOut = Variable Elimination φ = ⊕ x1 ··· ⊕⊗ xn−1 n∈S / ⊕ ⊗ ψS (xS ) ψS (xS ) xn S∈∂(n) . . . .... .... .... . . . . . Naïve InsideOut = Variable Elimination φ = ⊕ x1 ··· ⊕⊗ xn−1 n∈S / ⊕ ⊗ ψS (xS ) ψS (xS ) xn S∈∂(n) ψUn −{n} (xUn −{n} ) . . . .... .... .... . . . . . Naïve InsideOut = Variable Elimination φ = ⊕ x1 ··· ⊕⊗ ⊕ ⊗ ψS (xS ) ψS (xS ) xn−1 n∈S / But how do we compute this? xn S∈∂(n) ψUn −{n} (xUn −{n} ) . . . .... .... .... . . . . . Naïve InsideOut = Variable Elimination φ = ⊕ x1 ··· ⊕⊗ ⊕ ⊗ ψS (xS ) ψS (xS ) xn−1 n∈S / Run the OutsideIn algorithm! xn S∈∂(n) ψUn −{n} (xUn −{n} ) . . . .... .... .... . . . . . Naïve InsideOut = Variable Elimination φ = ⊕ x1 ··· ⊕⊗ ⊕ ⊗ ψS (xS ) ψS (xS ) xn−1 n∈S / xn S∈∂(n) ψUn −{n} (xUn −{n} ) Run the OutsideIn algorithm! ∏ (n) Runtime ≈ |Un | · |∂(n)| · |ψS |λS S∈∂(n) . . . .... .... .... . . . . . Naïve InsideOut = Variable Elimination φ = ⊕ x1 ··· ⊕⊗ ⊕ ⊗ ψS (xS ) ψS (xS ) xn−1 n∈S / xn S∈∂(n) Theorem (Runtime of Naïve InsideOut) For a given variable ordering v1 , . . . , vn , the runtime of Naïve InsideOut makes is Õ of n ∑ k=1 |Uk | · |∂(vk )| · ∏ S∈∂(vk ) (k) |ψS |λS ≤ mn n ∑ ∏ (k) |ψS |λS k=1 S∈∂(vk ) . . . .... .... .... . . . . . Naïve InsideOut = Variable Elimination φ = ⊕ x1 ··· ⊕⊗ ⊕ ⊗ ψS (xS ) ψS (xS ) xn−1 n∈S / xn S∈∂(n) Theorem (Runtime of Naïve InsideOut) For a given variable ordering v1 , . . . , vn , the runtime of Naïve InsideOut makes is Õ of n ∑ k=1 |Uk | · |∂(vk )| · ∏ S∈∂(vk ) (k) |ψS |λS ≤ mn n ∑ ∏ (k) |ψS |λS k=1 S∈∂(vk ) Corollary (Textbook result – Zhang-Poole’95, Dechter’96) For a “good” variable ordering, PGM inference can be done in time O(mn2 Dw+1 ) where w = tree-width(H) = tw(H). . . . .... .... .... . . . . . Pros and Cons of Naïve InsideOut ▶ The good: O(kN )-time for k-path query! . . . .... .... .... . . . . . Pros and Cons of Naïve InsideOut ▶ The good: O(kN )-time for k-path query! ▶ The bad: consider the following (part of a) graph 1 2 3 4 5 6 7 8 9 . . . .... .... .... . . . . . Pros and Cons of Naïve InsideOut ▶ The good: O(kN )-time for k-path query! ▶ The bad: consider the following (part of a) graph 1 2 3 4 5 6 7 8 9 . . . .... .... .... . . . . . Pros and Cons of Naïve InsideOut ▶ The good: O(kN )-time for k-path query! ▶ The bad: consider the following (part of a) graph 1 2 3 4 5 6 7 8 9 . . . .... .... .... . . . . . Pros and Cons of Naïve InsideOut ▶ The good: O(kN )-time for k-path query! ▶ The bad: consider the following (part of a) graph λ{i,9} = 1, ∀i ∈ {5, 6, 7, 8} 1 2 3 4 5 6 7 8 9 . . . .... .... .... . . . . . Pros and Cons of Naïve InsideOut ▶ The good: O(kN )-time for k-path query! ▶ The bad: consider the following (part of a) graph λ{i,9} = 1, ∀i ∈ {5, 6, 7, 8} 1 ▶ 2 3 4 5 6 7 8 9 Say |ψS | = N , then runtime O(N 4 ). . . . .... .... .... . . . . . Pros and Cons of Naïve InsideOut ▶ The good: O(kN )-time for k-path query! ▶ The bad: consider the following (part of a) graph 1 ▶ 2 3 4 5 6 7 8 9 Say |ψS | = N , then runtime O(N 4 ). . . . .... .... .... . . . . . Pros and Cons of Naïve InsideOut ▶ The good: O(kN )-time for k-path query! ▶ The bad: consider the following (part of a) graph 1 ▶ 2 3 4 5 6 7 8 9 Say |ψS | = N , then runtime O(N 4 ). . . . .... .... .... . . . . . Pros and Cons of Naïve InsideOut ▶ The good: O(kN )-time for k-path query! ▶ The bad: consider the following (part of a) graph Runtime O(N 2 )? 1 ▶ 2 3 4 5 6 7 8 9 Say |ψS | = N , then runtime O(N 4 ). . . . .... .... .... . . . . . Pros and Cons of Naïve InsideOut ▶ The good: O(kN )-time for k-path query! ▶ The bad: consider the following (part of a) graph Runtime O(N 2 )? 1 ▶ ▶ 2 3 4 5 6 7 8 9 Say |ψS | = N , then runtime O(N 4 ). Good idea, but naïve application increases U9 . . . .... .... .... . . . . . 01-projection ▶ Projection onto U9 : 1 2 3 4 5 6 7 8 9 . . . .... .... .... . . . . . 01-projection ▶ Projection onto U9 : 1 2 3 4 5 6 7 8 9 . . . .... .... .... . . . . . 01-projection ▶ Projection onto U9 : 1 ▶ 2 3 4 5 6 7 8 9 Formally, S ∈ E, U ⊆ V s.t. S ∩ U ̸= ∅, ∏ ψS|U : Dom(Xi ) → {0, 1}, i∈S∩U where { 1 ψS|U (xS∩U ) = 0 if ∃yS s.t. ψS (yS ) ̸= 0 and yS∩U = xS∩U otherwise . . . .... .... .... . . . . . InsideOut = VE + 01-projections φ= ⊕ x1 ··· ⊕⊗ xn−1 n∈S / ⊕ ⊗ ψS (xS ) ψS (xS ) xn S∈∂(n) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . InsideOut = VE + 01-projections φ= ⊕ x1 ··· ⊕⊗ xn−1 n∈S / ⊕ ⊗ ψS (xS ) ψS (xS ) xn S∈∂(n) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . InsideOut = VE + 01-projections φ= ⊕ x1 ··· ⊕⊗ xn−1 n∈S / ψS (xS ) ⊕ ⊗ ⊗ ψS (xS ) ⊗ ψS|Un (xS∩Un ) S ∈∂(n) / S∩Un ̸=∅ xn S∈∂(n) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . InsideOut = VE + 01-projections φ= ⊕ x1 ··· ⊕⊗ xn−1 n∈S / ψS (xS ) ⊕ ⊗ ⊗ ψS (xS ) ⊗ ψS|Un (xS∩Un ) S ∈∂(n) / S∩Un ̸=∅ xn S∈∂(n) ∏ Time ≈ m|Un | · (k) |ψS |λS = AGM(Un ) S∩Un ̸=∅ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . InsideOut = VE + 01-projections φ= ⊕ x1 ··· ⊕⊗ xn−1 n∈S / ψS (xS ) ⊕ ⊗ ⊗ ψS (xS ) ⊗ ψS|Un (xS∩Un ) S ∈∂(n) / S∩Un ̸=∅ xn S∈∂(n) Theorem (Runtime of InsideOut) For FAQ-SS, InsideOut runs in time Õ of n ∑ |{S | S ∩ Uk ̸= ∅}| · |Uk | · AGM(Uk ). k=1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . InsideOut = VE + 01-projections φ= ⊕ x1 ··· ⊕⊗ xn−1 n∈S / ψS (xS ) ⊕ ⊗ ⊗ ψS (xS ) ⊗ ψS|Un (xS∩Un ) S ∈∂(n) / S∩Un ̸=∅ xn S∈∂(n) Theorem (Runtime of InsideOut) For FAQ-SS, InsideOut runs in time Õ of n ∑ |{S | S ∩ Uk ̸= ∅}| · |Uk | · AGM(Uk ). k=1 Corollary (New (textbook?) result) For a “good” variable ordering v1 , . . . , vn , PGM inference can be done in time O(mn2 N w ) where w = fhtw(H). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . InsideOut = VE + 01-projections φ= ⊕ x1 ··· ⊕⊗ xn−1 n∈S / ψS (xS ) ⊕ ⊗ ⊗ ψS (xS ) ⊗ ψS|Un (xS∩Un ) S ∈∂(n) / S∩Un ̸=∅ xn S∈∂(n) Theorem (Runtime of InsideOut) For FAQ-SS, InsideOut runs in time Õ of n ∑ |{S | S ∩ Uk ̸= ∅}| · |Uk | · AGM(Uk ). k=1 Corollary (Grohe-Marx (SODA’06)) Join can be computed in time Õ(N fhtw(H) + |output|). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . InsideOut = VE + 01-projections φ= ⊕ x1 ··· ⊕⊗ xn−1 n∈S / ψS (xS ) ⊕ ⊗ ⊗ ψS (xS ) ⊗ ψS|Un (xS∩Un ) S ∈∂(n) / S∩Un ̸=∅ xn S∈∂(n) Theorem (Runtime of InsideOut) For FAQ-SS, InsideOut runs in time Õ of n ∑ |{S | S ∩ Uk ̸= ∅}| · |Uk | · AGM(Uk ). k=1 Corollary (Grohe-Marx (SODA’06)) CSP on instances with bounded fhtw are fixed-parameter tractable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . InsideOut = VE + 01-projections φ= ⊕ x1 ··· ⊕⊗ xn−1 n∈S / ψS (xS ) ⊕ ⊗ ⊗ ψS (xS ) ⊗ ψS|Un (xS∩Un ) S ∈∂(n) / S∩Un ̸=∅ xn S∈∂(n) Theorem (Runtime of InsideOut) For FAQ-SS, InsideOut runs in time Õ of n ∑ |{S | S ∩ Uk ̸= ∅}| · |Uk | · AGM(Uk ). k=1 Corollary (New?) Join cardinality can be computed in time Õ(N fhtw(H) ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . InsideOut = VE + 01-projections φ= ⊕ x1 ··· ⊕⊗ xn−1 n∈S / ψS (xS ) ⊕ ⊗ ⊗ ψS (xS ) ⊗ ψS|Un (xS∩Un ) S ∈∂(n) / S∩Un ̸=∅ xn S∈∂(n) Theorem (Runtime of InsideOut) For FAQ-SS, InsideOut runs in time Õ of n ∑ |{S | S ∩ Uk ̸= ∅}| · |Uk | · AGM(Uk ). k=1 Corollary (Pichler-Skritek 2011, Durand-Mengel (ICDT’2013)) For query graphs H with bounded fhtw, quantifier-free #CQ is polynomial-time solvable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . InsideOut for general FAQ φ = ··· ⊕(n) ⊗ xn ψS (xS ) S∈E . . . .... .... .... . . . . . InsideOut for general FAQ φ = ··· = ··· ⊕(n) ⊗ xn ψS (xS ) S∈E ⊕(n−1) xn−1 ( ⊕(n) ⊗ xn ) ψS (xS ) S∈E . . . .... .... .... . . . . . InsideOut for general FAQ φ = ··· = ··· ⊕(n) ⊗ xn ψS (xS ) S∈E ⊕(n−1) xn−1 ( ⊕(n) ⊗ xn ) ψS (xS ) S∈E . . . .... .... .... . . . . . InsideOut for general FAQ φ = ··· = ··· ⊕(n) ⊗ xn ψS (xS ) S∈E ⊕(n−1) ( ⊕(n) ⊗ xn−1 xn ) ψS (xS ) S∈E If (D, ⊕(n) , ⊗) is a semiring . . . .... .... .... . . . . . InsideOut for general FAQ φ = ··· = ··· ⊕(n) ⊗ xn ψS (xS ) S∈E ⊕(n−1) ( ⊕(n) ⊗ xn−1 xn ) ψS (xS ) S∈E If (D, ⊕(n) , ⊗) is a semiring φ = ··· ⊕(n−1) xn−1 ⊗ S ∈∂(n) / ⊕ ψS (xS ) (n) xn ⊗ ψS (xS ) S∈∂(n) . . . .... .... .... . . . . . InsideOut for general FAQ φ = ··· = ··· ⊕(n) ⊗ xn ψS (xS ) S∈E ⊕(n−1) xn−1 ( ⊕(n) ⊗ xn ) ψS (xS ) S∈E If ⊕(n) = ⊗ . . . .... .... .... . . . . . InsideOut for general FAQ φ = ··· = ··· ⊕(n) ⊗ xn ψS (xS ) S∈E ⊕(n−1) ( ⊕(n) ⊗ xn xn−1 ) ψS (xS ) S∈E If ⊕(n) = ⊗ φ = ··· ⊕(n−1) xn−1 ( ⊗ ⊕(n) S∈E xn ) ψS (xS ) . . . .... .... .... . . . . . InsideOut for general FAQ φ = ··· = ··· ⊕(n) ⊗ xn ψS (xS ) S∈E ⊕(n−1) ( ⊕(n) ⊗ xn xn−1 ) ψS (xS ) S∈E If ⊕(n) = ⊗ φ = ··· = ··· ⊕(n−1) xn−1 ( ⊕(n−1) ⊗ S ∈∂(n) / ( xn−1 [ψS (xS )] ⊗ ⊕(n) S∈E xn |Dom(Xn )| ) ψS (xS ) ) ⊗ ⊗ ⊕(n) S∈∂(n) xn ψS (xS ) . . . .... .... .... . . . . . InsideOut for general FAQ φ = ··· = ··· ⊕(n) ⊗ xn ψS (xS ) S∈E ⊕(n−1) ( ⊕(n) ⊗ xn xn−1 ) ψS (xS ) S∈E If ⊕(n) = ⊗ and ⊕(n) is not-idempotent φ = ··· = ··· ⊕(n−1) xn−1 ( ⊕(n−1) ⊗ S ∈∂(n) / ( xn−1 [ψS (xS )] ⊗ ⊕(n) S∈E xn |Dom(Xn )| ) ψS (xS ) ) ⊗ ⊗ ⊕(n) S∈∂(n) xn ψS (xS ) . . . .... .... .... . . . . . Table of Contents The FAQ problem Summary of Results and Approach The OutsideIn algorithm The InsideOut algorithm Choosing a variable ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ-width of a variable ordering Time ≈ incarnations of OutsideIn + output size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ-width of a variable ordering Time ≈ incarnations of OutsideIn + output size . [ ≤ Õ(mn) ∑ ] AGM(Uk ) + |φ| k∈K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ-width of a variable ordering Time ≈ incarnations of OutsideIn + output size . [ ] ∑ ≤ Õ(mn) AGM(Uk ) + |φ| k∈K Dynamic Programming for for Matrix Chain Multiplication and The FFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ-width of a variable ordering Time ≈ incarnations of OutsideIn + output size . [ ≤ Õ(mn) [ ≤ Õ(mn) ∑ ] AGM(Uk ) + |φ| k∈K ∑ ] N ρ∗H (Uk ) + |φ| k∈K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ-width of a variable ordering Time ≈ incarnations of OutsideIn + output size . [ ≤ Õ(mn) [ ≤ Õ(mn) ∑ ] AGM(Uk ) + |φ| k∈K ∑ ] N ρ∗H (Uk ) + |φ| k∈K Definition (FAQ-width of a variable ordering σ) faqw(σ) := max ρ∗H (Ukσ ). k∈K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ-width of a variable ordering Time ≈ incarnations of OutsideIn + output size . [ ≤ Õ(mn) [ ≤ Õ(mn) ∑ ] AGM(Uk ) + |φ| k∈K ∑ ] N ρ∗H (Uk ) + |φ| k∈K [ ] ≤ Õ(mn) nN faqw(σ) + |φ| . Definition (FAQ-width of a variable ordering σ) faqw(σ) := max ρ∗H (Ukσ ). k∈K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ-width of a query Definition (φ-equivalent variable ordering) Let φ be an FAQ-query. A φ-equivalent variable ordering is a vertex ordering σ = (v1 , . . . , vn ) that satisfies: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ-width of a query Definition (φ-equivalent variable ordering) Let φ be an FAQ-query. A φ-equivalent variable ordering is a vertex ordering σ = (v1 , . . . , vn ) that satisfies: (a) The set {v1 , . . . , vf } is exactly F = [f ]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ-width of a query Definition (φ-equivalent variable ordering) Let φ be an FAQ-query. A φ-equivalent variable ordering is a vertex ordering σ = (v1 , . . . , vn ) that satisfies: (a) The set {v1 , . . . , vf } is exactly F = [f ]. (b) The function φ′ defined by ⊕ f +1 ) ⊕ n) ⊗ φ′ (xF ) := (v · · · (v xv xvn S∈E ψS (xS ) f +1 is identical to the function φ no matter what the input factors are. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ-width of a query Definition (φ-equivalent variable ordering) Let φ be an FAQ-query. A φ-equivalent variable ordering is a vertex ordering σ = (v1 , . . . , vn ) that satisfies: (a) The set {v1 , . . . , vf } is exactly F = [f ]. (b) The function φ′ defined by ⊕ f +1 ) ⊕ n) ⊗ φ′ (xF ) := (v · · · (v xv xvn S∈E ψS (xS ) f +1 is identical to the function φ no matter what the input factors are. EVO(φ) denotes the set of all φ-equivalent variable orderings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ-width of a query Definition (φ-equivalent variable ordering) Let φ be an FAQ-query. A φ-equivalent variable ordering is a vertex ordering σ = (v1 , . . . , vn ) that satisfies: (a) The set {v1 , . . . , vf } is exactly F = [f ]. (b) The function φ′ defined by ⊕ f +1 ) ⊕ n) ⊗ φ′ (xF ) := (v · · · (v xv xvn S∈E ψS (xS ) f +1 is identical to the function φ no matter what the input factors are. EVO(φ) denotes the set of all φ-equivalent variable orderings. Definition (FAQ-width of an FAQ-query φ) faqw(φ) := min faqw(σ). σ∈EVO(φ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Roadmap Reminder FAQ-expr. σ for φ, hypergraph H EVO(φ) FAQ-expr. σ ∗ for φ InsideOut φ EVO(φ) = CWE(LinEx(P )) poly(|H|) LinEx(P ) ⊆ EVO(φ) min faqw(τ ) = min τ ∈LinEx(P ) τ ∈EVO(φ) faqw(τ ) ∑ x1 ,x4 poly(|H|) ∏ max x3 x2 ,x7 ∑ x5 Expression Tree Precedence Poset P poly(|H|) max x6 Tree Decomposition of H FAQ-expr. σ̄ for φ faqw(σ̄) ≤ opt + g(opt) g = approx. factor for fractional hypertree width of H . . . .... .... .... . . . . . Characterizing EVO(φ) We define a partially ordered set P on the variables of φ, called the Precedence Poset. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characterizing EVO(φ) We define a partially ordered set P on the variables of φ, called the Precedence Poset. Soundness LinEx(P ) ⊆ EVO(φ). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characterizing EVO(φ) We define a partially ordered set P on the variables of φ, called the Precedence Poset. Soundness LinEx(P ) ⊆ EVO(φ). Completeness Every σ ∈ EVO(φ) has the same faqw as some σ ′ ∈ LinEx(P ). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characterizing EVO(φ) We define a partially ordered set P on the variables of φ, called the Precedence Poset. Soundness LinEx(P ) ⊆ EVO(φ). Completeness Every σ ∈ EVO(φ) has the same faqw as some σ ′ ∈ LinEx(P ). faqw(φ) := faqw(σ). min σ ∈ EVO(φ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Characterizing EVO(φ) We define a partially ordered set P on the variables of φ, called the Precedence Poset. Soundness LinEx(P ) ⊆ EVO(φ). Completeness Every σ ∈ EVO(φ) has the same faqw as some σ ′ ∈ LinEx(P ). faqw(φ) := faqw(σ). min σ ∈ LinEx(P ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ with semiring variable aggregates φ(x[f ] ) = ⊕(f +1) xf +1 ··· ⊕(n) ⊗ xn S∈E . ψS (xS ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ with semiring variable aggregates φ(x[f ] ) = ▶ ⊕(f +1) xf +1 ··· ⊕(n) ⊗ xn S∈E ψS (xS ) Expression Tree defines the precedence poset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ with semiring variable aggregates φ(x[f ] ) = ▶ ⊕(f +1) xf +1 ··· ⊕(n) ⊗ xn S∈E ψS (xS ) Expression Tree defines the precedence poset ▶ ▶ Compartmentalization Step. Compression Step. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . φ= ∑∑ x1 x2 max x3 ∑∑ x4 x5 ) max max ψ12 ψ135 ψ14 ψ246 ψ27 ψ37 x6 5 x7 1 4 2 6 3 7 . . . .... .... .... . . . . . φ= ∑∑ x1 x2 max x3 ∑∑ x4 x5 ) max max ψ12 ψ135 ψ14 ψ246 ψ27 ψ37 x6 5 x7 1 4 2 6 3 7 . . . .... .... .... . . . . . φ= ∑∑ x1 x2 max x3 ∑∑ x4 x5 ) max max ψ12 ψ135 ψ14 ψ246 ψ27 ψ37 x6 5 x7 1 4 2 6 3 7 . . . .... .... .... . . . . . φ= ∑∑ x1 ( ψ12 x2 max x3 ∑ )( max ψ135 ψ27 ψ37 x7 x5 5 ∑ x4 ) max ψ14 ψ246 x6 1 4 2 6 3 7 . . . .... .... .... . . . . . φ= ∑∑ x1 ( ψ12 x2 max x3 ∑ )( max ψ135 ψ27 ψ37 x7 x5 5 ∑ x4 ) max ψ14 ψ246 x6 1 4 2 6 3 7 Expression Tree 1, 2 ∑ [Compartmentalization...] 3, 5, 7 4, 6 . . . .... .... .... . . . . . φ= ∑∑ x1 ( ψ12 x2 max x3 ∑ )( max ψ135 ψ27 ψ37 x7 x5 5 ∑ x4 ) max ψ14 ψ246 x6 1 4 2 6 3 7 Expression Tree 1, 2 ∑ [Compartmentalization...] 3, 5, 7 4, 6 . . . .... .... .... . . . . . φ= ∑∑ x1 ( ψ12 x2 max x3 ∑ )( max ψ135 ψ27 ψ37 x7 x5 5 ∑ x4 ) max ψ14 ψ246 x6 1 4 2 6 3 7 Expression Tree 1, 2 ∑ [Compartmentalization...] 3, 5, 7 4, 6 . . . .... .... .... . . . . . φ= ∑∑ x1 ( ψ12 x2 max x3 ∑ )( max ψ135 ψ27 ψ37 x7 x5 5 ∑ x4 ) max ψ14 ψ246 x6 1 4 2 6 3 7 Expression Tree 1, 2 ∑ [Compartmentalization...] 3, 5, 7 4, 6 . . . .... .... .... . . . . . φ= ∑∑ x1 ( max ψ12 x3 x2 ∑ )( ψ135 max ψ27 ψ37 x7 x5 ∑ x4 5 ) max ψ14 ψ246 x6 1 4 2 6 3 7 Expression Tree 1, 2 ∑ [Compartmentalization...] 3 5 ∑ 4, 6 max 7 max . . . .... .... .... . . . . . φ= ∑∑ x1 ( max ψ12 x3 x2 ∑ )( ψ135 max ψ27 ψ37 x7 x5 ∑ x4 5 ) max ψ14 ψ246 x6 1 4 2 6 3 7 Expression Tree 1, 2 ∑ [Compartmentalization...] 3 5 ∑ 4, 6 max 7 max . . . .... .... .... . . . . . φ= ∑∑ x1 ( max ψ12 x3 x2 ∑ )( ψ135 max ψ27 ψ37 x7 x5 ∑ x4 5 ) max ψ14 ψ246 x6 1 4 2 6 3 7 Expression Tree 1, 2 ∑ [Compartmentalization...] 3 5 ∑ 4, 6 max 7 max . . . .... .... .... . . . . . φ= ∑∑ x1 ( max ψ12 x3 x2 ∑ )( ψ135 max ψ27 ψ37 x7 x5 ∑ x4 5 ) max ψ14 ψ246 x6 1 4 2 6 3 7 Expression Tree 1, 2 ∑ [Compartmentalization...] 3 5 ∑ 4, 6 max 7 max . . . .... .... .... . . . . . φ= ∑∑ x1 ( max ψ12 x3 x2 ∑ )( ψ135 max ψ27 ψ37 x7 x5 ∑ ) ψ14 max ψ246 x6 x4 5 1 4 2 6 3 7 Expression Tree 1, 2 ∑ [Compartmentalization...] 3 5 ∑ 4 max 7 max ∑ 6 max . . . .... .... .... . . . . . φ= ∑∑ x1 ( max ψ12 x3 x2 ∑ )( ψ135 max ψ27 ψ37 x7 x5 ∑ ) ψ14 max ψ246 x6 x4 5 1 4 2 6 3 7 Expression Tree 1, 2 ∑ [Compartmentalization!] 3 5 ∑ 4 max 7 max ∑ 6 max . . . .... .... .... . . . . . φ= ∑∑ x1 ( max ψ12 x3 x2 ∑ )( ψ135 max ψ27 ψ37 x7 x5 ∑ ) ψ14 max ψ246 x6 x4 5 1 4 2 6 3 7 Expression Tree 1, 2 ∑ [Compression...] 3 5 ∑ 4 max 7 max ∑ 6 max . . . .... .... .... . . . . . φ= ∑∑ x1 ( max max ψ27 ψ37 ψ12 x3 x2 x7 ∑ )( ψ135 x5 5 ∑ ) ψ14 max ψ246 x6 x4 1 4 2 6 3 7 Expression Tree 1, 2 ∑ [Compression...] 3 5 ∑ 4 max 7 max ∑ 6 max . . . .... .... .... . . . . . φ= ∑∑ x1 ( ψ12 x2 max max ψ27 ψ37 x3 x7 ∑ )( ψ135 x5 5 ∑ ) ψ14 max ψ246 x6 x4 1 4 2 6 3 7 Expression Tree 1, 2 ∑ [Compression...] 3, 7 5 max ∑ 4 ∑ 6 max . . . .... .... .... . . . . . φ= ∑∑ x1 ( ψ12 x2 max max ψ27 ψ37 x3 x7 ∑ )( ψ135 x5 5 ∑ ) ψ14 max ψ246 x6 x4 1 4 2 6 3 7 Expression Tree 1, 2 ∑ [Compression...] 3, 7 5 max ∑ 4 ∑ 6 max . . . .... .... .... . . . . . φ= ∑∑∑ x1 x2 ( max max ψ27 ψ37 ψ12 ψ14 x3 x4 ∑ x7 5 )( ) max ψ246 ψ135 x6 x5 1 4 2 6 3 7 Expression Tree 1, 2 ∑ [Compression...] 3, 7 5 max ∑ 4 ∑ 6 max . . . .... .... .... . . . . . φ= ∑∑∑ x1 x2 ( max max ψ27 ψ37 ψ12 ψ14 x3 x4 x7 5 ∑ )( ) max ψ246 ψ135 x6 x5 1 4 2 6 3 7 Expression Tree 1, 2, 4 ∑ [Compression...] 3, 7 5 max 6 max ∑ . . . .... .... .... . . . . . φ= ∑∑∑ x1 x2 ( max max ψ27 ψ37 ψ12 ψ14 x3 x4 x7 5 ∑ )( ) max ψ246 ψ135 x6 x5 1 4 2 6 3 7 Expression Tree 1, 2, 4 ∑ [Compression!] 3, 7 5 max 6 max ∑ . . . .... .... .... . . . . . Approximating faqw(φ) Theorem Given an approximation algorithm for fhtw(H) within a bound g(fhtw(H)), we have an approximation for faqw(φ) within abound of faqw(φ) + g(faqw(φ)). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) Theorem Given an approximation algorithm for fhtw(H) within a bound g(fhtw(H)), we have an approximation for faqw(φ) within abound of faqw(φ) + g(faqw(φ)). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) Theorem Given an approximation algorithm for fhtw(H) within a bound g(fhtw(H)), we have an approximation for faqw(φ) within abound of OPT + g(OPT). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) Theorem Given an approximation algorithm for fhtw(H) within a bound g(fhtw(H)), we have an approximation for faqw(φ) within abound of OPT + g(OPT). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) Theorem Given an approximation algorithm for fhtw(H) within a bound g(fhtw(H)), we have an approximation for faqw(φ) within abound of OPT + g(OPT). Best known g(x)=O( x3 ) [Marx’12] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) Theorem Given an approximation algorithm for fhtw(H) within a bound O(fhtw(H)3 ), we have an approximation for faqw(φ) within abound of OPT + O(OPT3 ). Best known g(x)=O( x3 ) [Marx’12] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Corollaries Strictly subsumes a result by Durand-Mengel ([ICDT’13]) Corollary ( ( )) O faqw3 (φ) #CQ is solvable in time O poly(m, n) · N . Strictly subsumes a result by Chen-Dalmau (LICS’12). Corollary (QCQ tractability) QCQ is tractable when faqw is bounded. Answered an open question posed by Durand-Mengel (ICDT’13) Corollary (#QCQ tractability) #QCQ is tractable when faqw is bounded. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Many Thanks! Any FAQ? . . . .... .... .... . . . . . FAQ with two blocks of semiring aggregates φ= ⊕ ⊕ ¯ xL x[n]−L ⊗ S∈E ψS (xS ). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ with two blocks of semiring aggregates φ= ⊕ ⊕ ¯ xL x[n]−L ⊗ S∈E ψS (xS ). Example: #CQ φ= ∑ x1 ··· ∑ xl max · · · max xl+1 xn ∏ ψS (xS ). S∈E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ with two blocks of semiring aggregates φ= ⊕ ⊕ ¯ xL x[n]−L ⊗ S∈E ψS (xS ). Example: #CQ φ= ∑ x1 ··· ∑ xl max · · · max xl+1 xn ∏ ψS (xS ). S∈E Precedence Poset: u ≺ v whenever u ∈ L and v ∈ / L. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) Theorem Given an approximation algorithm for fhtw(H) within a bound g(fhtw(H)), we have an approximation for faqw(φ) within abound of faqw(φ) + g(faqw(φ)). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) Theorem Given an approximation algorithm for fhtw(H) within a bound g(fhtw(H)), we have an approximation for faqw(φ) within abound of faqw(φ) + g(faqw(φ)). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) Theorem Given an approximation algorithm for fhtw(H) within a bound g(fhtw(H)), we have an approximation for faqw(φ) within abound of OPT + g(OPT). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) Theorem Given an approximation algorithm for fhtw(H) within a bound g(fhtw(H)), we have an approximation for faqw(φ) within abound of OPT + g(OPT). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) Theorem Given an approximation algorithm for fhtw(H) within a bound g(fhtw(H)), we have an approximation for faqw(φ) within abound of OPT + g(OPT). Best known g(x)=O( x3 ) [Marx’12] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) Theorem Given an approximation algorithm for fhtw(H) within a bound O(fhtw(H)3 ), we have an approximation for faqw(φ) within abound of OPT + O(OPT3 ). Best known g(x)=O( x3 ) [Marx’12] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L C2 C1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L C2 C1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L C2 C1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L C2 C1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L C2 C1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L U (C1 ) C2 C1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L OPT C2 g(OPT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L C2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L C2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L C2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L C2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L C2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L U (C2 ) C2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L OPT g(OPT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) L . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) g(OPT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) Corollary FAQ with two block of semiring aggregates is solvable in time ( ( )) O faqw3 (φ) O poly(m, n) · N . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) Corollary #CQ is solvable in time ( ( )) O faqw3 (φ) O poly(m, n) · N . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Approximating faqw(φ) Corollary #CQ is solvable in time ( ( )) O faqw3 (φ) O poly(m, n) · N . Strictly subsumes Durand-Mengel Theorem (Durand-Mengel [ICDT’13]) #CQ is solvable in time ( ) O poly(|H|) · N poly(L-ss(H),fhtw(H)) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Completeness Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Completeness Background ¯ are commutative iff Two aggregates ⊕, ⊕ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Completeness Background ¯ are commutative iff Two aggregates ⊕, ⊕ a c ⊕ ¯ ⊕ ⊕ b d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Completeness Background ¯ are commutative iff Two aggregates ⊕, ⊕ a c ⊕ ¯ ⊕ ⊕ b = d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Completeness Background ¯ are commutative iff Two aggregates ⊕, ⊕ a c ⊕ ¯ ⊕ ⊕ b a b ¯ ⊕ ⊕ ¯ = ⊕ d c d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Completeness Background ¯ are commutative iff Two aggregates ⊕, ⊕ a 0 ⊕ ¯ ⊕ ⊕ 0 a 0 ¯ ⊕ ⊕ ¯ = ⊕ d 0 d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Completeness Background ¯ are commutative iff Two aggregates ⊕, ⊕ a a ¯ ⊕ = d ⊕ d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Completeness Background ¯ are commutative iff Two aggregates ⊕, ⊕ a a ¯ ⊕ = d ⊕ d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Completeness Background ¯ are commutative iff Two aggregates ⊕, ⊕ a a ¯ ⊕ = d ⊕ d ¯ are identical! Hence, ⊕ and ⊕ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Soundness and Completeness Soundness LinEx(P ) ⊆ EVO(φ). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Soundness and Completeness Soundness LinEx(P ) ⊆ EVO(φ). Completeness LinEx(P ) = EVO(φ) ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Soundness and Completeness Soundness LinEx(P ) ⊆ EVO(φ). Completeness LinEx(P ) = EVO(φ) ? ∑ φ = x2 x1 . ∑ max ψ12 ψ13 . . . . . . . . . x3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Soundness and Completeness Soundness LinEx(P ) ⊆ EVO(φ). Completeness LinEx(P ) = EVO(φ) ? ∑ φ = x2 x1 . ∑ max ψ12 ψ13 . . . . . . . . . x3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Soundness and Completeness Soundness LinEx(P ) ⊆ EVO(φ). Completeness LinEx(P ) = EVO(φ) ? 1 ∑ ∑ φ = x2 x1 2 max 3 ∑ ∑ max ψ12 ψ13 x3 ∑∑ = ψ13 maxψ12 x2 x1 x3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Soundness and Completeness Soundness LinEx(P ) ⊆ EVO(φ). Completeness LinEx(P ) = EVO(φ) ? 1, 3 ∑ ∑ φ = x2 x1 2 max ∑ max ψ12 ψ13 x3 ∑∑ = ψ13 maxψ12 x2 x1 x3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Soundness and Completeness Soundness LinEx(P ) ⊆ EVO(φ). Completeness LinEx(P ) = EVO(φ) ? 1, 3 ∑ ∑ φ = x2 x1 2 max ∑ max ψ12 ψ13 x3 ∑∑ = ψ13 maxψ12 x2 x1 x3 (1, 2, 3) ∈ / LinEx(P ) ! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Soundness and Completeness Soundness LinEx(P ) ⊆ EVO(φ). Completeness LinEx(P ) ̸= EVO(φ) . 1, 3 ∑ ∑ φ = x2 x1 2 max ∑ max ψ12 ψ13 x3 ∑∑ = ψ13 maxψ12 x2 x1 x3 (1, 2, 3) ∈ / LinEx(P ) ! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Soundness and Completeness Soundness LinEx(P ) ⊆ EVO(φ). Completeness LinEx(P ) ̸= EVO(φ) . 1, 3 ∑ ∑ φ = x2 x1 2 ∑ max ψ12 ψ13 x3 ∑∑ = ψ13 maxψ12 max x2 x1 x3 (1, 2, 3) ∈ / LinEx(P ) ! faqw(φ) := faqw(σ). min σ ∈ EVO(φ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Soundness and Completeness Soundness LinEx(P ) ⊆ EVO(φ). Completeness LinEx(P ) ̸= EVO(φ) . 1, 3 ∑ ∑ φ = ∑ max ψ12 ψ13 x2 x1 2 x3 ∑∑ = ψ13 maxψ12 max x2 x1 x3 (1, 2, 3) ∈ / LinEx(P ) ! Theorem faqw(φ) := faqw(σ). min σ ∈ LinEx(P ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ with idempotent product aggregates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ with idempotent product aggregates Let DI ⊇ {0, 1} be a set of idempotent elements of ⊗. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ with idempotent product aggregates Let DI ⊇ {0, 1} be a set of idempotent elements of ⊗. φ(x[f ] ) = ⊕(f +1) | xf +1 ··· {z ⊕(f +ℓ) ⊕(f +ℓ+1) xf +ℓ Semiring aggregates }| ··· {z xf +ℓ+1 ⊕(n) ⊗ xn S∈E ψS (xS ) } | {z } | {z } Products or semirings Closed closed under DI under DI . . . . . . . . . . . . . . ∈DI . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ with idempotent product aggregates Let DI ⊇ {0, 1} be a set of idempotent elements of ⊗. φ(x[f ] ) = ⊕(f +1) | xf +1 ··· {z ⊕(f +ℓ) ⊕(f +ℓ+1) xf +ℓ Semiring aggregates }| ··· {z xf +ℓ+1 ⊕(n) ⊗ xn S∈E ψS (xS ) } | {z } | {z } Products or semirings Closed closed under DI under DI . . . . . . . . . . . . . . ∈DI . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ with idempotent product aggregates Let DI ⊇ {0, 1} be a set of idempotent elements of ⊗. φ(x[f ] ) = ⊕(f +1) | xf +1 ··· {z ⊕(f +ℓ) ⊕(f +ℓ+1) xf +ℓ Semiring aggregates }| ··· {z xf +ℓ+1 ⊕(n) ⊗ xn S∈E ψS (xS ) } | {z } | {z } Products or semirings Closed closed under DI under DI . . . . . . . . . . . . . . ∈DI . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ with idempotent product aggregates Let DI ⊇ {0, 1} be a set of idempotent elements of ⊗. φ(x[f ] ) = ⊕(f +1) | xf +1 ··· {z ⊕(f +ℓ) ⊕(f +ℓ+1) xf +ℓ Semiring aggregates }| ··· {z xf +ℓ+1 ⊕(n) ⊗ xn S∈E ψS (xS ) } | {z } | {z } Products or semirings Closed closed under DI under DI . . . . . . . . . . . . . . ∈DI . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ with idempotent product aggregates Let DI ⊇ {0, 1} be a set of idempotent elements of ⊗. φ(x[f ] ) = ⊕(f +1) | xf +1 ··· {z ⊕(f +ℓ) ⊕(f +ℓ+1) xf +ℓ Semiring aggregates }| ··· {z xf +ℓ+1 ⊕(n) ⊗ xn S∈E ψS (xS ) } | {z } | {z } Products or semirings Closed closed under DI under DI . . . . . . . . . . . . . . ∈DI . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ with idempotent product aggregates Let DI ⊇ {0, 1} be a set of idempotent elements of ⊗. φ(x[f ] ) = ⊕(f +1) | xf +1 ··· {z ⊕(f +ℓ) ⊕(f +ℓ+1) xf +ℓ }| Semiring aggregates ··· {z xf +ℓ+1 ⊕(n) ⊗ xn S∈E ψS (xS ) } | {z } | {z } Products or semirings Closed closed under DI under DI ∈DI Examples: QCQ, φ(x[f ] ) = ⊕(f +1) xf +1 ··· ⊕(n) ∏ xn S∈E ψS (xS ). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FAQ with idempotent product aggregates Let DI ⊇ {0, 1} be a set of idempotent elements of ⊗. φ(x[f ] ) = ⊕(f +1) | xf +1 ··· {z ⊕(f +ℓ) ⊕(f +ℓ+1) xf +ℓ }| Semiring aggregates ··· {z xf +ℓ+1 ⊕(n) ⊗ xn S∈E ψS (xS ) } | {z } | {z } Products or semirings Closed closed under DI under DI ∈DI Examples: QCQ, #QCQ φ(x[f ] ) = ∑ ∑ φ= ··· x1 ⊕(f +1) xf +1 ··· xl+1 ··· ⊕(l+1) ⊕(n) ∏ xn S∈E ψS (xS ). xn S∈E ψS (xS ). ⊕(n) ∏ xl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . φ= ∑ x1 max x2 ∏ max max ψ123 ψ125 ψ14 ψ34 x3 2 x4 x5 ∏ ) x′3 1 4 5 3 . . . .... .... .... . . . . . φ= ∑ x1 max x2 ∏ max max ψ123 ψ125 ψ14 ψ34 x3 2 x4 x5 ∏ ) x′3 1 4 5 3 . . . .... .... .... . . . . . φ= ∑ x1 max x2 ∏ max max ψ123 ψ125 ψ14 ψ34 x3 2 x4 x5 ∏ ) x′3 1 4 5 3 . . . .... .... .... . . . . . φ= ∑ x1 max x2 ∏ max ψ123 ψ125 max ψ14 ψ34 x3 2 x5 x4 ∏ ) x′3 1 4 5 3 . . . .... .... .... . . . . . φ= ∑ x1 ( max x2 ∏ x3 )( max ψ123 ψ125 x5 ∏ x′3 ) max ψ14 ψ34 x4 1 2 4 5 3 3 . . . .... .... .... . . . . . φ= ∑ x1 ( max x2 ∏ x3 )( max ψ123 ψ125 x5 ∏ x′3 ) max ψ14 ψ34 x4 1 2 4 5 3 3 . . . .... .... .... . . . . . φ= ∑ x1 ( max x2 ∏ x3 )( max ψ123 ψ125 x5 ∏ x′3 ) max ψ14 ψ34 x4 1 2 4 5 3 Expression Tree 3 1∑ [Compartmentalization...] 2, 3, 5 3, 4 . . . .... .... .... . . . . . φ= ∑ x1 ( max x2 ∏ x3 )( max ψ123 ψ125 x5 ∏ x′3 ) max ψ14 ψ34 x4 1 2 4 5 3 Expression Tree 3 1∑ [Compartmentalization...] 2, 3, 5 3, 4 . . . .... .... .... . . . . . φ= ∑ x1 ( max x2 ∏ x3 )( max ψ123 ψ125 x5 ∏ x′3 ) max ψ14 ψ34 x4 1 2 4 5 3 Expression Tree 3 1∑ [Compartmentalization...] 2, 3, 5 3, 4 . . . .... .... .... . . . . . φ= ∑ x1 ( max x2 ∏ x3 )( max ψ123 ψ125 x5 ∏ x′3 ) max ψ14 ψ34 x4 1 2 4 5 3 Expression Tree 3 1∑ [Compartmentalization...] 2, 3, 5 3, 4 . . . .... .... .... . . . . . φ= ∑ x1 ( max x2 ∏ )( ψ123 max ψ125 x3 x5 ∏ x′3 ) max ψ14 ψ34 x4 1 2 4 5 3 3 1∑ Expression Tree [Compartmentalization...] 3, 4 2 max 5 max 3 ∏ . . . .... .... .... . . . . . φ= ∑ x1 ( max x2 ∏ )( ψ123 max ψ125 x3 x5 ∏ x′3 ) max ψ14 ψ34 x4 1 2 4 5 3 3 1∑ Expression Tree [Compartmentalization...] 3, 4 2 max 5 max 3 ∏ . . . .... .... .... . . . . . φ= ∑ x1 ( max x2 ∏ )( ψ123 max ψ125 x3 x5 ∏ x′3 ) max ψ14 ψ34 x4 1 2 4 5 3 3 1∑ Expression Tree [Compartmentalization...] 3, 4 2 max 5 max 3 ∏ . . . .... .... .... . . . . . φ= ∑ x1 ( max x2 ∏ )( ψ123 max ψ125 x3 x5 ∏ x′3 ) max ψ14 ψ34 x4 1 2 4 5 3 3 1∑ Expression Tree [Compartmentalization...] 3∏ 2 max 5 max 3 ∏ 4 max . . . .... .... .... . . . . . φ= ∑ x1 ( max x2 ∏ )( ψ123 max ψ125 x3 x5 ∏ x′3 ) max ψ14 ψ34 x4 1 2 4 5 3 3 1∑ Expression Tree [Compartmentalization!] 3∏ 2 max 5 max 3 ∏ 4 max . . . .... .... .... . . . . . φ= ∑ x1 ( max x2 ∏ )( ψ123 max ψ125 x3 x5 ∏ x′3 ) max ψ14 ψ34 x4 1 2 4 5 3 3 1∑ Expression Tree [Compression...] 3∏ 2 max 5 max 3 ∏ 4 max . . . .... .... .... . . . . . φ= ∑ x1 ( max max ψ125 x2 x5 ∏ )( ψ123 ∏ x′3 x3 ) max ψ14 ψ34 x4 1 2 4 5 3 3 1∑ Expression Tree [Compression...] 3∏ 2 max 5 max 3 ∏ 4 max . . . .... .... .... . . . . . φ= ∑ x1 ( max max ψ125 x2 x5 ∏ )( ψ123 ∏ x′3 x3 ) max ψ14 ψ34 x4 1 2 4 5 3 3 1∑ Expression Tree [Compression...] 2, 5 max 3 ∏ 3∏ 4 max . . . .... .... .... . . . . . φ= ∑ x1 ( max max ψ125 x2 x5 ∏ )( ψ123 ∏ x′3 x3 ) max ψ14 ψ34 x4 1 2 4 5 3 3 1∑ Expression Tree [Compression!] 2, 5 max 3 ∏ 3∏ 4 max . . . .... .... .... . . . . . Variable ordering and hypergraph sequence V8 = V 1 2 3 4 1 E8 = E 1 5 6 1 8 1 1 1 1 1 7 1 1 1 1 1 1 1 . . . .... .... .... . . . . . Variable ordering and hypergraph sequence V8 = V 1 2 3 4 1 E8 = E 1 5 6 1 8 1 1 1 1 1 7 ∂(8) 1 1 1 1 1 1 1 . . . .... .... .... . . . . . Variable ordering and hypergraph sequence V8 = V 1 2 3 4 1 E8 = E 1 5 6 1 8 1 1 1 1 1 U8 7 1 ∂(8) 1 1 1 1 1 1 1 1 1 1 . . . .... .... .... . . . . . Variable ordering and hypergraph sequence V7 1 2 3 1 4 5 6 7 1 1 1 E7 1 U8 − {8} 1 1 1 1 1 1 1 . . . .... .... .... . . . . . Variable ordering and hypergraph sequence V7 1 2 3 1 4 5 6 7 1 1 1 E7 1 1 1 1 1 1 1 1 . . . .... .... .... . . . . . Variable ordering and hypergraph sequence V7 1 2 3 1 4 5 6 7 1 1 1 E7 ∂(7) 1 1 1 1 1 1 1 1 . . . .... .... .... . . . . . Variable ordering and hypergraph sequence V7 1 2 3 1 4 5 6 7 1 1 1 E7 ∂(7) 1 U7 1 1 1 1 1 1 1 1 1 1 1 1 1 . . . .... .... .... . . . . . Variable ordering and hypergraph sequence V6 1 2 3 1 4 5 6 1 E6 U7 − {7} 1 1 1 1 1 1 1 1 . . . .... .... .... . . . . . Variable ordering and hypergraph sequence V6 1 2 3 1 4 5 6 1 E6 1 1 1 1 1 1 1 1 . . . .... .... .... . . . . . Variable ordering and hypergraph sequence V6 1 2 3 1 4 5 6 1 E6 1 1 1 1 1 1 1 1 ∂(6) . . . .... .... .... . . . . . Variable ordering and hypergraph sequence V6 1 2 3 1 4 5 6 1 E6 U6 1 1 1 1 1 1 1 1 1 1 1 1 1 ∂(6) . . . .... .... .... . . . . . Variable ordering and hypergraph sequence V5 1 2 3 1 4 5 1 E5 U6 − {6} 1 1 1 1 1 1 1 . . . .... .... .... . . . . . Variable ordering and hypergraph sequence ▶ Given H = (V, E), and a variable ordering v1 , . . . , vn ▶ Hn = H ▶ For k = n − 1, . . . , 1, define Hk = (Vk , Ek ) ∂(vk+1 ) = {S | S ∈ Ek+1 and vk+1 ∈ S} . . . .... .... .... . . . . . Variable ordering and hypergraph sequence ▶ Given H = (V, E), and a variable ordering v1 , . . . , vn ▶ Hn = H ▶ For k = n − 1, . . . , 1, define Hk = (Vk , Ek ) ∂(vk+1 ) = {S | S ∈ Ek+1 and vk+1 ∈ S} ∪ Uk+1 = S S∈∂(vk+1 ) . . . .... .... .... . . . . . Variable ordering and hypergraph sequence ▶ Given H = (V, E), and a variable ordering v1 , . . . , vn ▶ Hn = H ▶ For k = n − 1, . . . , 1, define Hk = (Vk , Ek ) ∂(vk+1 ) = {S | S ∈ Ek+1 and vk+1 ∈ S} ∪ Uk+1 = S S∈∂(vk+1 ) Vk = Vk+1 − {vk+1 } . . . .... .... .... . . . . . Variable ordering and hypergraph sequence ▶ Given H = (V, E), and a variable ordering v1 , . . . , vn ▶ Hn = H ▶ For k = n − 1, . . . , 1, define Hk = (Vk , Ek ) ∂(vk+1 ) = {S | S ∈ Ek+1 and vk+1 ∈ S} ∪ Uk+1 = S S∈∂(vk+1 ) Vk = Vk+1 − {vk+1 } Ek = (Ek+1 − ∂(vk+1 )) ∪ {Uk+1 − {vk+1 }} . . . .... .... .... . . . . . Tree decomposition of H = (V, E) {a,b,d}, {c, d}, {b, c, d), {b, e}, {c, e}, {b, e, f}, {b, e, g}, {g, f, h}, {i, j, h}, {e, g}, {e, g, b}, {e, b, h}. b c e bags b e f g h b c a d i h j e h g b . . . .... .... .... . . . . . Every hyperedge is covered by some bag {a,b,d}, {c, d}, {b, c, d), {b, e}, {c, e}, {b, e, f}, {b, e, g}, {g, f, h}, {i, j, h}, {e, g}, {e, g, b}, {e, b, h}. b c e b e f g h b c a d i h j e h g b . . . .... .... .... . . . . . Every hyperedge is covered by some bag {a,b,d}, {c, d}, {b, c, d), {b, e}, {c, e}, {b, e, f}, {b, e, g}, {g, f, h}, {i, j, h}, {e, g}, {e, g, b}, {e, b, h}. b c e b e f g h b c a d i h j e h g b . . . .... .... .... . . . . . Every hyperedge is covered by some bag {a,b,d}, {c, d}, {b, c, d), {b, e}, {c, e}, {b, e, f}, {b, e, g}, {g, f, h}, {i, j, h}, {e, g}, {e, g, b}, {e, b, h}. b c e b e f g h b c a d i h j e h g b . . . .... .... .... . . . . . Every hyperedge is covered by some bag {a,b,d}, {c, d}, {b, c, d), {b, e}, {c, e}, {b, e, f}, {b, e, g}, {g, f, h}, {i, j, h}, {e, g}, {e, g, b}, {e, b, h}. b c e b e f g h b c a d i h j e h g b . . . .... .... .... . . . . . Running intersection property (RIP) {a,b,d}, {c, d}, {b, c, d), {b, e}, {c, e}, {b, e, f}, {b, e, g}, {g, f, h}, {i, j, h}, {e, g}, {e, g, b}, {e, b, h}. b c e b e f g h b c a d i h j e h g b . . . .... .... .... . . . . . Running intersection property (RIP) {a,b,d}, {c, d}, {b, c, d), {b, e}, {c, e}, {b, e, f}, {b, e, g}, {g, f, h}, {i, j, h}, {e, g}, {e, g, b}, {e, b, h}. b c e b e f g h b c a d i h j e h g b . . . .... .... .... . . . . . Variable Ordering and Tree decomposition ▶ Given H = (V, E), and a variable ordering v1 , . . . , vn ▶ Hn = H ▶ For k = n − 1, . . . , 1, define Hk = (Vk , Ek ) ∂(vk+1 ) = {S | S ∈ Ek+1 and vk+1 ∈ S} ∪ Uk+1 = S S∈∂(vk+1 ) Vk = Vk+1 − {vk+1 } Ek = (Ek+1 − ∂(vk+1 )) ∪ {Uk+1 − {vk+1 }} Proposition (Folklorish) There is a tree decomposition whose bags are the sets Uk and vice versa. . . . .... .... .... . . . . .