Presentation is loading. Please wait.

Presentation is loading. Please wait.

Answering Queries Using Views LMSS’95 Laks V.S. Lakshmanan Dept. of Comp. Science UBC.

Similar presentations


Presentation on theme: "Answering Queries Using Views LMSS’95 Laks V.S. Lakshmanan Dept. of Comp. Science UBC."— Presentation transcript:

1 Answering Queries Using Views LMSS’95 Laks V.S. Lakshmanan Dept. of Comp. Science UBC

2 6/1/20162 Problem & Motivation Given a query Q: p  q1, …, qm and a set of (materialized) views v1, …, vn (presumably defined in terms of the q’s and/or other base relations), can we answer Q using the views? Can we do so while removing the maximal set of redundant subgoals (q’s) from the rewrite? Why care? –q’s may be just logical – not stored anywhere (information integration) –q’s may be expensive to access (data warehousing) –Additional option for classical QO.

3 6/1/20163 Key contributions Main focus – CQs with possible builtins. Characterization of when Q is answerable using the views. Intractability results. Sufficient condition (=> PTIME algo.) for special cases. Investigation of effect of builtins.

4 A Motivating Example [Halevy01] DB Schema: Prof(name, area), Course(c-number, title) Teaches(prof, c-number, quarter, evaluation) Registered(student, c-number, quarter), Major(student, dept) WorksIn(prof, dept), Advises(prof, student). Q: select R.student, C.title from Teaches T, Prof P, Registered R, Course C where P.name=T.prof and T.c-number=R.c-number and T.quarter=R.quarter and R.c-number= C.c-number and C.c-number ≥ 500 and P.area="DB". 6/1/20164

5 Motivating Example (contd.) Materialized view: create view Graduate as select R.student, C.title, C.c-number, R.quarter from Registered R, Course C where R.c-number=C.c-number and C.c-number ≥ 400. 6/1/20165 Q can be answered (rewritten) using V as: select G.student, G.title from Teaches T, Prof P, Graduate G where P.name=T.prof and T.c-number=G.c-number and T.quarter=G.quarter and G.c-number ≥ 500 and P.area="DB".

6 Motivating Example (contd.) Why does it work? –V contains required attributes for output. –Conditions imposed in Q are stronger than those imposed in V. –V contains attributes needed to enforce remaining conditions in Q. We’ll look at the underlying theory next. 6/1/20166

7 7 An example (1) X YZ W U p p0 p1 p2 Q V A CB D p p0 p1 Q X Z W U p2 v Not leveraged. Is it leverageable?

8 6/1/20168 Some definitions Def.: Given a CQ Q, conjunctive views v1, …, vn, a CQ Q’ is a rewriting of Q provided: –Q’ is equiv. to Q. –Q’ contains one or more v’s. (revisit e.g.) Note: –Only “pure” CQ for now. –When builtins allowed, may lose closure.

9 6/1/20169 More definitions Def.: A rewriting Q’ is locally minimal if no subgoals can be removed w/o losing equivalence. It’s globally minimal if it has the fewest (database) subgoals among all rewritings. It is complete if it only contains v’s and builtins. Which is an easier objective? Why only count DB subgoals? Should we always remove subgoals?

10 6/1/201610 Another example (2) Q: p(X,Y)  a(X,Z), b(X,W), a(Y,Z). V: v(A)  a(A,B), b(A,C). Q’: p(X,Y)  v(X), a(X,Z), b(X,W), a(Y,Z). No subgoals removed; yet, v() acts as a filter and cuts down size of intermediate result early.

11 6/1/201611 Example of complete rewriting (3) Revisit e.g. (1). Add another view v’(A,B)  p1(A,C), p2(C,B), p0(H,K). Q”: p(X,U)  v(X,Z), v’(X,U). Note: –Even without p0 complete rewriting works. –Presence of p0 shows sometimes we have to do “parallel” reasoning.

12 6/1/201612 First Key Proposition Prop.: Q, V – CQs. Q is rewritable using V iff on every DB D, whenever V(D) is empty, then so is Q(D). Intuition: head(Q)  body(Q) & body(V) is a legal rewriting. In some sense the most “loose” rewriting. This rewriting is equiv. to Q iff the above property holds. []

13 6/1/201613 Some complexity remarks CQ containment is NP-complete even w/o builtins. Previous prop ==> when Q is CQ [+ builtins] and V is CQ, complexity of testing existence of a rewriting is NP-complete. When both can contain builtins, complexity shoots up to  p 2 -complete.

14 6/1/201614 Key Result Lemma 3.3: Q, V – CQ and set of CQs w/o builtins. Then 1.If Q’ is a locally minimal rewriting of Q using V, then the set of DB subgoals in Q’ is isomorphic to a subset of such subgoals in Q. 2.For every rewriting,  a corresp. rewriting which introduces no new variables. 3.Similar results when builtins present, except need union of CQs in the rewrite.

15 6/1/201615 Proof – Main ideas Q: p  q1, …, qm. Views: v1  …, vk  …. Q’: p  qi, …, qj, vl, …, vn. Q”: p  qi, …, qj, q’s q’s Q: p  q1,..., qm. Assume wlog that Q has no redundant subgoals. Can always throw them out. 

16 6/1/201616 Proof (contd.) Q”: p  qi, …, qj, q’s q’s S Q: p  q1,..., qm. C C = core of body of Q;  S =  (C); C’ =  (S). C’ must be isomorphic to C. (Why?) ==>  is an iso from C to S.

17 6/1/201617 Proof (contd.) If Q’ contains DB subgoals not iso to some in S, remove them. Q’ remains equiv. to Q. (Why?) So, every DB subgoal in Q’ is iso some in S, i.e., iso to some in C (aka Q). So, Q’ has no DB subgoal outside of Q. Proof of 2 and 3 – similar reasoning. []

18 6/1/201618 How large is a minimal rewrite? Lemma 3.5: A locally minimal complete rewriting contains at most as many subgoals as there are in the body of Q. Proof: Q: p  q1, …, qm. Q’: p  v1, …, vn (where n > m). Q”: p  exp(v1), …, exp(vn). Q and Q” are equiv. Consider a c.m. from Q to Q”. Each qi maps to (some subgoal inside) exactly one exp(vj). By pigeon hole principle, nothing in exp(vk) is mapped to, for some vk. Remove that vk, yielding a smaller rewrite than Q’. Contradiction. []

19 6/1/201619 Answering queries using views in general When builtins are allowed, complexity goes up. Need to consider union of CQs in the rewriting, in general. Finding (locally) minimal rewriting – several efficient algorithms have been developed. One of the best known – Minicon Algorithm (Rachel’s thesis).

20 6/1/201620 Example illustrating subtleties source1(E,P,M)  emp(E), phone(E,P), mgr(E,M). source2(E,O,D)  emp(E), office(E,O), dept(E,D). source3(E,P)  emp(E), phone(E,P), dept(E,`toy’). Q: q1(O,P)  phone(E,P), office(E,O). q1(O,P)  source1(E, P, M), source2(E, O, D). –l–locally minimal. q1(O,P)  source3(E, P), source2(E, O, D). –A–Another LM rewriting. neither is equivalent to Q so each is a contained rewriting. Equivalent rewritings – for classical QO. (maximally) contained rewriting – for data integration.


Download ppt "Answering Queries Using Views LMSS’95 Laks V.S. Lakshmanan Dept. of Comp. Science UBC."

Similar presentations


Ads by Google