Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Answering Queries Using Views Alon Y. Halevy Based on Levy et al. PODS ‘95.

Similar presentations


Presentation on theme: "1 Answering Queries Using Views Alon Y. Halevy Based on Levy et al. PODS ‘95."— Presentation transcript:

1

2 1 Answering Queries Using Views Alon Y. Halevy Based on Levy et al. PODS ‘95

3 2 Conjunctive queries zSafe - each variable in the head appears in the body. headbody subgoal

4 3 Views zA view is a derived relation defined in terms of stored base relations. zA materialized view is a view stored in the DB (like a cache).

5 4 Query Containment  iff for any DB, any answer to Q 2 is an answer to Q 1. zContainment is NP-complete. zEquivalence is defined as two-way containment.

6 5 The problem Definition: Given a query Q and views V 1,V 2,…,V m, find an equivalent query Q’ (a rewriting) that uses one or more of the views.

7 6 Variants of the problem  Q’ is a complete rewriting of Q if it uses just the views (and built-in predicates).  Q’ is a locally minimal rewriting if we cannot remove a subgoal from Q’ and retain equivalence.  Q’ is a globally minimal rewriting if there is no other rewriting with less subgoals.

8 7 Containment mapping Definition: A containment mapping (CM) from Q 1 to Q 2 is a mapping from the variables of Q 1 to those of Q 2 such that every subgoal in Q 1 is mapped to a subgoal in Q 2. Example: Q 1 : q(X):-p(X,Y),p(Y,Z),p(Z,W). Q 2 : q(X):-p(X,Y),p(Y,X). CM: X/X, Y/Y, Z/X, W/Y

9 8 Rewriting vs. containment Proposition 1: Let Q and V be conjunctive queries. There is a rewriting of Q using V iff i.e. if V is empty for a DB then so is Q.

10 9 Corollaries zProposition 1 provides a complete characterization of the rewriting problem. zWe can use known results from containment to the rewriting problem: yComplexity results yPractical techniques for finding rewritings

11 10 Results z Complexity: Proposition 2: If Q but not V may contain built-in predicates, then finding a rewriting of Q using V is NP-complete. z Practical solution using Containment Mappings (Chandra & Merlin 1977)

12 11 Using containment mappings Theorem: For conjunctive queries (without built-in predicates), there is a containment mapping between Q 1 and Q 2 iff z Finding a CM is NP-complete.  We can find a rewriting by finding a CM from V to Q that only maps the bodies.  Then, just add V’ s head to Q ’s body.

13 12 Minimal rewriting Lemma 3 (technical):  If Q’ is a locally minimal rewriting of Q using V, then Q’ contains no new relation subgoals.  If Q has a rewriting then it has a rewriting with no new variables. Lemma 4: A locally minimal rewriting Q’ of Q has no more subgoals than Q.

14 13 Complexity of complete rewriting Proposition 5: Finding a complete rewriting is NP-complete. the problem of exact-cover by 3-sets

15 14 The picture so far zTo find a rewriting: 1. Seek a CM from the views to the query. Add these view heads to the query. 2. Minimize by removing redundant subgoals. zBoth problems are independently NP- complete.

16 15 Conclusions zUsing views to answer queries is an important problem. Especially for information integration on the web. zQuery containment and containment mappings provide the key for solving the problem. zThe variants of the problem are NP-complete. This is not too bad, since queries are usually short.


Download ppt "1 Answering Queries Using Views Alon Y. Halevy Based on Levy et al. PODS ‘95."

Similar presentations


Ads by Google