Query Decompositions survey Nicola Onose January 19, 2007 Nicola - - PowerPoint PPT Presentation

query decompositions survey
SMART_READER_LITE
LIVE PREVIEW

Query Decompositions survey Nicola Onose January 19, 2007 Nicola - - PowerPoint PPT Presentation

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions Query Decompositions survey Nicola Onose January 19, 2007 Nicola Onose Query Decompositions


slide-1
SLIDE 1

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Query Decompositions survey

Nicola Onose January 19, 2007

Nicola Onose Query Decompositions

slide-2
SLIDE 2

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Outline

1

Speeding Up Query Evaluation

Nicola Onose Query Decompositions

slide-3
SLIDE 3

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Outline

1

Speeding Up Query Evaluation

2

Graphs & Queries

Nicola Onose Query Decompositions

slide-4
SLIDE 4

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Outline

1

Speeding Up Query Evaluation

2

Graphs & Queries

3

Back to Hypergraphs

Nicola Onose Query Decompositions

slide-5
SLIDE 5

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Outline

1

Speeding Up Query Evaluation

2

Graphs & Queries

3

Back to Hypergraphs

4

Computing Decompositions and Widths

Nicola Onose Query Decompositions

slide-6
SLIDE 6

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Outline

1

Speeding Up Query Evaluation

2

Graphs & Queries

3

Back to Hypergraphs

4

Computing Decompositions and Widths

5

Related Concepts & Conclusions

Nicola Onose Query Decompositions

slide-7
SLIDE 7

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

1

Speeding Up Query Evaluation

2

Graphs & Queries

3

Back to Hypergraphs

4

Computing Decompositions and Widths

5

Related Concepts & Conclusions

Nicola Onose Query Decompositions

slide-8
SLIDE 8

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Query Evaluation

The eternal problem: given Q and DB, compute Q(DB). Need to run Q over DB as efficiently as possible. Classical DB approach: build a query plan . . . and optimize it How far can we get?

Nicola Onose Query Decompositions

slide-9
SLIDE 9

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Complexity

Evaluating a conjunctive query is NP-complete in the combined complexity [Chandra & Merlin, 1977] In general, evaluating a FO query is PSPACE in the combined complexity However, certain (acyclic) conj. queries can be evaluated in PTIME [Yannakakis, 1981]

Nicola Onose Query Decompositions

slide-10
SLIDE 10

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Complexity

Evaluating a conjunctive query is NP-complete in the combined complexity [Chandra & Merlin, 1977] In general, evaluating a FO query is PSPACE in the combined complexity However, certain (acyclic) conj. queries can be evaluated in PTIME [Yannakakis, 1981] Can this result be generalized to other classes of CQ?

Nicola Onose Query Decompositions

slide-11
SLIDE 11

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Example

Schema Example teaches(Professor,Course) enrolled(Student,Course,GradeOption) parent(Person1, Person2) Query Q1 ∃ a professor who has a child enrolled in some course? ans() ← teaches(P,C), enrolled (S,C’,G), parent(P,S)

Nicola Onose Query Decompositions

slide-12
SLIDE 12

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Example 1

teaches parent enrolled > <Person2=Student > <Person1=Professor π∅

Figure: Evaluation Plan for Q1

Nicola Onose Query Decompositions

slide-13
SLIDE 13

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Example 1

parent enrolled teaches π∅ > <Person1=Professor > <Person2=Student π{Person1}

Figure: A Better Plan for Q1

Now, we keep only a table with 1 attribute after the 1st join. The size of the left branch of the 2nd join decreases.

Nicola Onose Query Decompositions

slide-14
SLIDE 14

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Example 2

Query Q2 ∃ a student enrolled in a course taught by his parent? ans() ← enrolled(S,C,G), teaches(P,C), parent(P,S)

Nicola Onose Query Decompositions

slide-15
SLIDE 15

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Example 2

Query Q2 ∃ a student enrolled in a course taught by his parent? ans() ← enrolled(S,C,G), teaches(P,C), parent(P,S)

parent enrolled teaches ⊲ ⊳Person2=Student ⊲ ⊳Person1=Professor,Course=Course π∅ π{Person1, Course} Figure: Evaluation Plan for Q2

Need to keep 2 attributes after the 1st join.

Nicola Onose Query Decompositions

slide-16
SLIDE 16

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

1

Speeding Up Query Evaluation

2

Graphs & Queries

3

Back to Hypergraphs

4

Computing Decompositions and Widths

5

Related Concepts & Conclusions

Nicola Onose Query Decompositions

slide-17
SLIDE 17

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

The Hypergraph of a Query

Vertices are the const.&vars. of the query. There is a hyperedge between the terms from each atom.

P C S C’ G

Figure: Hypergraph of Q1

Nicola Onose Query Decompositions

slide-18
SLIDE 18

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Acyclic Queries

Elimination Tree: order of removing edge e1 in favor of e2, where e1 does not intersect any other edge but e2. A query having an elimination tree is called acyclic.

S C’ G P C P S enrolled teaches parent

Figure: Elimination tree for Q1

Nicola Onose Query Decompositions

slide-19
SLIDE 19

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Query Decomposition

A query decomposition [Chekuri&Rajaraman, 1997] of Q is a tree (I, F) plus a map X : I → {variables & subgoals of Q} such that any subgoal appears in some X(i) for any subgoal s, {i | s ∈ X(i)} is connected for any var. V , {i | V ∈ X(i)} ∪ {i | V appears in s and s ∈ X(i)} is connected

Nicola Onose Query Decompositions

slide-20
SLIDE 20

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Query Width

The width of a decomposition is max |X(i)| The query width of Q is the min. width over all decompositions of Q. A query is acyclic iff its query width is 1.

enrolled parent teaches(P, C) (S, C’, G) (P , S)

Figure: Query decomposition for Q1

Nicola Onose Query Decompositions

slide-21
SLIDE 21

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Evaluating Queries of Bounded Querywidth

For an acyclic query, the decomposition gives a join tree (one atom / node) In general, |X(i)| ≥ 1 Efficient evaluation (Chekuri&Rajaraman):

create a new relation for each node bottom-up: semijoin it with the children

Nicola Onose Query Decompositions

slide-22
SLIDE 22

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Evaluating Queries of Bounded Querywidth

For an acyclic query, the decomposition gives a join tree (one atom / node) In general, |X(i)| ≥ 1 Efficient evaluation (Chekuri&Rajaraman):

create a new relation for each node bottom-up: semijoin it with the children

For a fixed query width k and a given query decomposition, query evaluation is polynomial in the combined complexity and exponential in k. Query containment can be decided similarly.

Nicola Onose Query Decompositions

slide-23
SLIDE 23

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Problems with Query Width

Deciding whether the query width of a CQ is ≤ 4 is NP-complete [Gottlob,Leone,Scarcello, 1999]. Contrast with Yannakakis’s linear time algorithm for deciding if a query is acyclic. Results from graph theory proved useful for defining alternative decompositions.

Nicola Onose Query Decompositions

slide-24
SLIDE 24

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Treewidth

Treewidth of a graph: previous applications in CSP, networks etc. Tree decomposition of G = (V , E): tree T = (I, F) and X : I → 2V s.t.

∀ vertex v ∈ V , ∃i ∈ I, v ∈ X(i) ∀ edge e ∈ E, ∃i ∈ I, e ⊂ X(i) The subset of I where a vertex v ∈ V appears is connected

The width of a tree decomposition is maxi |X(i)| − 1 The treewidth of G is the min. width over all tree decompositions of G.

Nicola Onose Query Decompositions

slide-25
SLIDE 25

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Incidence Graph

Incidence graph of a query [Chekuri&Rajaraman,1997] The treewidth of a query is the treewidth of its incidence graph.

  • C

P S G enrolled teaches parent(P,S) (S,C,G) (P,C) Figure: Incidence graph of Q2

Nicola Onose Query Decompositions

slide-26
SLIDE 26

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Tree Decomposition

(P,S) parent S, C, (P,S) parent P, C, teaches(P,C) P, C, S, C, enrolled(S,C,G) G, enrolled(S,C,G)

Figure: A tree decomposition for Q2

Nicola Onose Query Decompositions

slide-27
SLIDE 27

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Treewidth: Properties

  • tw. is an approximation of qw.:

tw(Q)/a ≤ qw(Q) ≤ tw(Q) + 1 where a is the max. arity of a predicate of Q There are PTIME algorithms that decide if tw(G) ≤ k and

  • utput a corresponding tree decomposition

Evaluating queries of bounded treewidth: a tree decomposition is also a query decomposition, so same results apply.

Nicola Onose Query Decompositions

slide-28
SLIDE 28

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Treewidth and Acyclicity

Unfortunately, treewidth does not tell us anything about the acyclicity of the query.

Nicola Onose Query Decompositions

slide-29
SLIDE 29

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Treewidth and Acyclicity

Unfortunately, treewidth does not tell us anything about the acyclicity of the query. Example Rn(x1, x2, . . . xn) is acyclic, but has treewidth = n − 1.

Nicola Onose Query Decompositions

slide-30
SLIDE 30

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Treewidth and Acyclicity

Unfortunately, treewidth does not tell us anything about the acyclicity of the query. Example Rn(x1, x2, . . . xn) is acyclic, but has treewidth = n − 1. Example Q2 is cyclic, but has treewidth only 2.

Nicola Onose Query Decompositions

slide-31
SLIDE 31

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

1

Speeding Up Query Evaluation

2

Graphs & Queries

3

Back to Hypergraphs

4

Computing Decompositions and Widths

5

Related Concepts & Conclusions

Nicola Onose Query Decompositions

slide-32
SLIDE 32

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Hypertrees

Main problem: treewidth is a property of graphs, while acyclicity is a property of the hypergraph. Solution: instead of trees, look for hypertrees [Gottlob,Leone,Scarcello] Hypertree: < T, X, L >

T = (N, E) is a tree p ∈ N, X(p) ⊆ var(Q) p ∈ N, L(p) ⊆ atoms(Q)

Nicola Onose Query Decompositions

slide-33
SLIDE 33

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Hypertree decomposition

Hypertree decomposition: < T =(N, E), X, L > such that

∀ atom A, ∃ vertex p s.t. var(A) ⊆ X(p) The subset of N where a variable of Q appears is connected ∀p ∈ N, X(p) ⊆ var(L(p)) ∀p ∈ N, X(p) ⊇ var(L(p)) ∩ X(subtree rooted at p)

Nicola Onose Query Decompositions

slide-34
SLIDE 34

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Hypertree decomposition

Hypertree decomposition: < T =(N, E), X, L > such that

∀ atom A, ∃ vertex p s.t. var(A) ⊆ X(p) The subset of N where a variable of Q appears is connected ∀p ∈ N, X(p) ⊆ var(L(p)) ∀p ∈ N, X(p) ⊇ var(L(p)) ∩ X(subtree rooted at p)

Hypertree-width

The width of a hypertree decomposition is maxp |L(p)| The hypertree-width of Q is the min. width over all hypertree decompositions of Q.

Nicola Onose Query Decompositions

slide-35
SLIDE 35

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Hypertree-Width

Query Q2 Q2 has a hypertree decomposition of width 2.

{ {P, C} {C, P , S} {parent(P,S), teaches(P,C)} teaches(P,C) } {enrolled(S,C,G)} {S, C, G}

Nicola Onose Query Decompositions

slide-36
SLIDE 36

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Hypertree-Width

Another decomposition for Q2:

{enrolled(S,C,G)} {S, C, G} {C, P , S} { parent(P,S), teaches(P,C) }

Nicola Onose Query Decompositions

slide-37
SLIDE 37

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Hypertree-Width: Properties

∀ CQ Q, hw(Q) ≤ qw(Q) In particular, Q is acyclic iff hw(Q) = 1 ∃ Q s.t. hw(Q) < qw(Q) For a fixed k, deciding hw(Q) ≤ k and computing the decomposition is PTIME Evaluating a CQ of bounded hw. is PTIME (combined complexity) The tight bounds are in fact better than PTIME (LOGCFL-completeness)

Nicola Onose Query Decompositions

slide-38
SLIDE 38

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Hypertree-Width vs. Query Width

Q4 : ans ← a(S, X, X ′, C, F) ∧ b(S, Y , Y ′, C ′, F ′) ∧ c(C, C ′, Z) ∧d(X, Z) ∧ e(Y , Z) ∧ f (F, F ′, Z) ∧ g(X ′, Z ′) ∧h(Y ′, Z ′) ∧ j(J, X, Y , X ′, Y ′) [Gottlob,Leone,Scarcello, 1999] show that qw(Q4) = 3 and hw(Q4) = 2

Nicola Onose Query Decompositions

slide-39
SLIDE 39

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Evaluating Queries of Bounded Hypertree-Width

{enrolled(S,C,G)} {S, C, G} {C, P , S} { parent(P,S), teaches(P,C) }

Build a join tree, where each node joins its local atoms Evaluate the tree bottom-up, by upward semijoins (` a la Yannakakis).

enrolled (S,C,G) parent(P,S) ⊲ ⊳ teaches(S,C)

Nicola Onose Query Decompositions

slide-40
SLIDE 40

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

1

Speeding Up Query Evaluation

2

Graphs & Queries

3

Back to Hypergraphs

4

Computing Decompositions and Widths

5

Related Concepts & Conclusions

Nicola Onose Query Decompositions

slide-41
SLIDE 41

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Algorithms for Computing Treewidth

computing treewidth efficiently: algorithms from graph theory (see especially works by Arnborg and by Bodlaender) preprocessing techniques can be very useful:

reduction rules [Arnborg,Prokurowski] splitting [Bodlaender,Koster]

approximation algorithms: contracting edges, min-max etc

Nicola Onose Query Decompositions

slide-42
SLIDE 42

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Algorithms for Computing Treewidth (cont’d)

exact algorithms:

reduction is enough to test k ≤ 3 algorithms based on dynamic programming (such as Arnborg’s triangulation algo. applied by [Shoikhet,Geiger] to treewidth) [Bodlaender,Kloks, 1991]: linear time algorithm, which given a

  • decomp. of width l, det. if ∃ one of width k and computes it.

[Bodlaender, 1993]: linear time algorithm for finding tree

  • decomp. (sometimes attacked for being slow in practice)
  • ther methods: elimination ordering, branch and bound etc

Nicola Onose Query Decompositions

slide-43
SLIDE 43

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Computing the Hypertree-Width

[Gottlob,Leone,Scarcello] give two versions of an algorithm for computing hw and a corresponding decomp.:

a LOGCFL parallel version a deterministic polynomial version

Important result: there exists a normal form for a hypertree

  • decomp. that preserves the hypertree-width.

The normal form allows to characterize each child of a node by a tree component and to break the problem into smaller subproblems. The optimal decomp. is computed by assigning weights and building a tree in dynamic prog. style.

Nicola Onose Query Decompositions

slide-44
SLIDE 44

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

1

Speeding Up Query Evaluation

2

Graphs & Queries

3

Back to Hypergraphs

4

Computing Decompositions and Widths

5

Related Concepts & Conclusions

Nicola Onose Query Decompositions

slide-45
SLIDE 45

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Extensions

Extensions of treewidth to other classes of queries [Flum,Frick,Grohe, 2002] MSO queries nonrecursive stratified Datalog CQ with negation tractable fragments of FOL

Nicola Onose Query Decompositions

slide-46
SLIDE 46

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Other Approaches

Other decomposition methods (for CQ & CSP): biconnected components [Freuder] cycle cutset [Dechter] tree clustering [Dechter, Pearl] queries of bounded degree of cyclicity [Gyssens, Paredaens]

Nicola Onose Query Decompositions

slide-47
SLIDE 47

Speeding Up Query Evaluation Graphs & Queries Back to Hypergraphs Computing Decompositions and Widths Related Concepts & Conclusions

Conclusions

qw tw hw Characterizes acyclicity yes no yes Computable in PTIME no yes yes Efficiently computable on || machines no ? yes Applications other than CQ no yes yes (with modifs.)

Nicola Onose Query Decompositions