Download presentation

Presentation is loading. Please wait.

Published byCarlie Varco Modified over 2 years ago

1
1 Extended Conjunctive Queries Unions Arithmetic Negation

2
2 Containment of Unions of CQ’s uTheorem: P 1 … P k Q 1 … Q n if and only if for each P i there is some Q j such that P i Q j. uProof (if): Obvious.

3
3 Proof of “Only-If” uAssume P 1 … P k Q 1 … Q n. uLet D be the canonical (frozen) DB for P i. uSince the containment holds, and P i (D) includes the frozen head of P i, there must be some Q j such that Q j (D) also includes the frozen head of P i. uThus, P i Q j.

4
4 CQ Contained in Datalog Program uLet Q be a CQ and P a Datalog program. uEach returns a relation for each EDB database D, so it makes sense to ask if Q P. wThat is, Q(D) P(D) for all D.

5
5 The Containment Test uLet D be the canonical DB for Q. uCompute P(D), and test if it contains the frozen head of Q. uIf so, Q P ; if not, D is a counterexample.

6
6 Example Q : p(X,Y) :- a(X,Z) & a(Z,W) & a(W,Y) P : p(X,Y) :- a(X,Y) p(X,Y) :- p(X,Z) & p(Z,Y) uIntuitively: Q = paths of length 3; P = all paths. uFrozen Q : D = {a(x,z), a(z,w), a(w,y)}.

7
7 Example --- Continued D = {a(x,z), a(z,w), a(w,y)} P : p(X,Y) :- a(X,Y) p(X,Y) :- p(X,Z) & p(Z,Y) uInfer by first rule: p(x,z), p(z,w), p(w,y). uInfer by second rule: p(x,w), p(z,y), p(x,y). Frozen head of Q, so Q P.

8
8 Other Containments uIt is doubly exponential to tell if a Datalog program is contained in a CQ. uIt is undecidable whether one Datalog program is contained in another.

9
9 CQ’s With Negation uAllow negated subgoals. uExample: Q1: p(X,Y) :- a(X,Z) & a(Z,Y) & NOT a(X,Y) Q2: p(X,Y) :- a(X,Y) & NOT a(Y,X) Paths of length 2 not “short- circuited.” Unidirectional arcs.

10
10 Levy-Sagiv Test uTest Q1 Q2 by: 1.Consider the set of all canonical databases D such that the tuples of D are composed of only symbols 1,2,…,n, where n is the number of variables of Q1. 2.If there is such a D for which Q1(D) Q2(D), then Q1 Q2. 3.Otherwise, Q1 Q2.

11
11 Example Q1: p(X,Y) :- a(X,Z) & a(Z,Y) & NOT a(X,Y) Q2: p(X,Y) :- a(X,Y) & NOT a(Y,X) uTry D = {a(1,2), a(2,3)}. uQ1(D) = {p(1,3)}. uQ2(D) = {p(1,2), p(2,3)}. uThus, Q1 Q2.

12
12 Intuition uIt is not sufficient to consider only the frozen body of Q1. uThe reason is that sometimes, containment is only violated when certain variables are assigned the same constant.

13
13 CQ’s With Interpreted Predicates uImportant special case: arithmetic predicates like <. wA total order on values. uGeneral case: predicate has some specific meaning, but may not be like arithmetic comparisons. wExample: set-valued variables and a set- containment predicate.

14
14 CQ’s With < uTo test Q1 Q2, consider all canonical DB’s formed from the ordinary (not arithmetic) subgoals of Q1, by assigning each variable to one of 1,2,…,n. uEquivalently: partition the variables of Q1 and order the blocks of the partition by <.

15
15 Example Q1: p(X,Z) :- a(X,Y) & a(Y,Z) & X

16
16 Example --- Continued uConsider one ordered partition: {X,Z}{Y}; i.e., let X =Z =1 and Y =2. uThen the body of Q1: p(X,Z) :- a(X,Y) & a(Y,Z) & X

17
17 Example --- Concluded Q2: p(A,C) :- a(A,B) & a(B,C) & A

18
18 Arithmetic Makes Some Things Go Wrong uUnion-of-CQ’s theorem no longer holds. uContainment-mapping theorem no longer holds.

19
19 Union of CQ’s With Arithmetic P : p(X) :- a(X) & 10

20
20 CM Theorem Doesn’t Hold Q1: panic :- a(X,Y) & a(Y,X) Q2: panic :- a(A,B) & A**
{
"@context": "http://schema.org",
"@type": "ImageObject",
"contentUrl": "http://images.slideplayer.com/11/3256962/slides/slide_20.jpg",
"name": "20 CM Theorem Doesn’t Hold Q1: panic :- a(X,Y) & a(Y,X) Q2: panic :- a(A,B) & A
**

21
21 CM Theorem --- Continued Q1: panic :- a(X,Y) & a(Y,X) Q2: panic :- a(A,B) & A**
{
"@context": "http://schema.org",
"@type": "ImageObject",
"contentUrl": "http://images.slideplayer.com/11/3256962/slides/slide_21.jpg",
"name": "21 CM Theorem --- Continued Q1: panic :- a(X,Y) & a(Y,X) Q2: panic :- a(A,B) & A
**

22
22 CM Theorem for Interpreted Predicates 1.“Rectified” rules --- a normal form for CQ’s with interpreted predicates. 2.A variant of the CM theorem holds for rectified rules. uThis theorem holds for predicates other than arithmetic comparisons, but rectification uses “=” at least.

23
23 Rectification 1.No variable may appear more than once among all the argument positions of the head and all ordinary subgoals. 2.No constant may appear in the head or an ordinary subgoal.

24
24 Rectifying Rules uIntroduce new variables to replace constants or multiple occurrences of the same variable. uForce the new variables to be equal to old variables or constants using additional equality subgoals.

25
25 Example panic :- a(X,Y) & a(Y,X) becomes panic :- a(X,Y) & a(U,V) & X=V & Y=U

26
26 Another Example p(X) :- q(X,Y,X) & r(Y,a) becomes p(Z) :- q(X,Y,W) & r(V,U) & X=W & X=Z & Y=V & U=a

27
27 Gupta-Zhang-Ozsoyoglu Test uLet Q1 and Q2 be rectified rules. uLet M be the set of all CM’s from the ordinary (uninterpreted) subgoals of Q2 to the ordinary subgoals of Q1. wNote: for rectified rules, any mapping of subgoals to subgoals with the same predicate is a CM.

28
28 GZO Test --- (2) uTheorem: Q1 Q2 if and only if the interpreted subgoals of Q1 logically imply the OR over all CM’s m in M of m applied to the interpreted subgoals of Q2.

29
29 Example Q2: panic :- r(X,Y) & X

30
30 Example --- Continued Q2: panic :- r(X,Y) & X

31
31 Example --- Concluded uA=D & B=C implies (A**
{
"@context": "http://schema.org",
"@type": "ImageObject",
"contentUrl": "http://images.slideplayer.com/11/3256962/slides/slide_31.jpg",
"name": "31 Example --- Concluded uA=D & B=C implies (A
**

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google