Answering Queries Using Views - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Answering Queries Using Views

Description:

A view is a derived relation defined in terms of stored base relations. ... Practical solution using Containment Mappings (Chandra & Merlin 1977) 11 ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 16
Provided by: dagwoo
Category:

less

Transcript and Presenter's Notes

Title: Answering Queries Using Views


1
Answering Queries Using Views
Alon Y. Halevy
Based on Levy et al. PODS 95
2
Conjunctive queries
head
body
  • Safe - each variable in the head appears in the
    body.

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

4
Query Containment
  • iff for any DB, any answer to Q2 is an answer
    to Q1.
  • Containment is NP-complete.
  • Equivalence is defined as two-way containment.

5
The problem
  • Definition Given a query Q and views V1,V2,,Vm,
    find an equivalent query Q (a rewriting) that
    uses one or more of the views.

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.

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

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.

9
Corollaries
  • Proposition 1 provides a complete
    characterization of the rewriting problem.
  • We can use known results from containment to the
    rewriting problem
  • Complexity results
  • Practical techniques for finding rewritings

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

11
Using containment mappings
  • Theorem For conjunctive queries (without
    built-in predicates), there is a containment
    mapping between Q1 and Q2 iff
  • 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 Vs head to Qs body.

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.

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

14
The picture so far
  • To 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.
  • Both problems are independently NP-complete.

15
Conclusions
  • Using views to answer queries is an important
    problem. Especially for information integration
    on the web.
  • Query containment and containment mappings
    provide the key for solving the problem.
  • The variants of the problem are NP-complete. This
    is not too bad, since queries are usually short.
Write a Comment
User Comments (0)
About PowerShow.com