Docsity

Containment of Conjunctive Queries in Database Systems, Slides of Conjunctive Queries

Partial preview of the text

Download Containment of Conjunctive Queries in Database Systems and more Slides Conjunctive Queries in PDF only on Docsity!

Conjunctive Queries

Containment Mappings

Canonical Databases

Sariaya’s Algorithm

docsity.com

Conjunctive Queries

A CQ is a single Datalog rule, with all subgoals assumed to be EDB.

Meaning

of a CQ is the mapping from

databases (the EDB) to the relationproduced for the head predicate byapplying that rule to the EDB.

docsity.com

Example --- Continued

Whenever there is a path from

X

to

Y,

it must be that

X

has an arc out, and

Y

an arc in.

Thus, every fact (tuple) produced by Q1 is also produced by Q2.

That is, Q

Q2.

docsity.com

Why Care About CQ Containment?

Important optimization: if we can break a query into terms that are CQ’s, wecan eliminate those terms contained inanother.

Š

Especially important when we deal withintegration of information: CQ containmentis almost the only way to tell whatinformation from sources we don’t

need.

docsity.com

Why Care --- Concluded

Although CQ theory first appeared at a database conference, the AI communityhas taken CQ’s to heart.

CQ’s, or similar logics like description logic, are used in a number of AIapplications.

Š

Again --- their design theory is reallycontainment and equivalence.

docsity.com

Testing Containment

Two approaches:

Containment mappings.

Canonical databases.

Really the same in the simple CQ casecovered so far.

Containment is NP-complete, but CQ’stend to be small so here is one casewhere intractability doesn’t hurt you.

docsity.com

Important Theorem

There is a containment mapping from Q2 to Q1 if and only if Q

Q2.

Note that the containment mapping is opposite the containment --- it goesfrom the larger (containing CQ) to thesmaller (contained CQ).

docsity.com

Example

Q1:

p(X,Y):-r(X,Z)

g(Z,Z)

r(Z,Y)

Q2:

p(A,B):-r(A,C)

g(C,D)

r(D,B)

Q1 looks for: Q2 looks for:

X

Y

Z

A

B

D

C

Since C=D is possible,expect Q

⊆

Q2.

docsity.com

Example ---Concluded

Q1:

p(X,Y):-r(X,Z)

g(Z,Z)

r(Z,Y)

Q2:

p(A,B):-r(A,C)

g(C,D)

r(D,B)

No containment mapping from Q1 to Q2.

Š

g(Z,Z) can only be mapped to g(C,D).

  • No other

g

subgoals in Q2.

Š

But then Z

must map to both C and D ---

impossible.

Thus, Q1 properly contained in Q2.

docsity.com

Another Example

Q1:

p(X,Y):-r(X,Y)

g(Y,Z)

Q2:

p(A,B):-r(A,B)

r(A,C)

Q1 looks for:Q2 looks for:

X

Z

Y

A

B C

docsity.com

16

Example ---Concluded

Q1:

p(X,Y):-r(X,Y)

g(Y,Z)

Q2:

p(A,B):-r(A,B)

r(A,C)

No containment mapping from Q1 to Q2.

Š

g(Y,Z) cannot map anywhere, since there is no

g

subgoal in Q2.

Thus, Q1 properly contained in Q2.

docsity.com

Proof of Containment-Mapping

Theorem --- (1)

First, assume there is a CM

m : Q2->Q1.

Let

D

be any database; we must show

that Q1(

D)

Q2(

D).

Suppose

t

is a tuple in Q1(

D); we must

show

t

is also in Q2(

D).

docsity.com

19

Proof --- (3)

Consider the effect of applying

m

and

then

s

to Q2.

head of Q2 :-

subgoal of Q

m

m

head of Q1 :-

subgoal of Q

s

s

t

tuple of

D

s

°

m

maps

each sub-goal of Q2to a tupleof

D.

And the head of Q2 becomest, proving

t is also in Q2(

D); i.e., Q

⊆

Q2.

docsity.com

Proof of Converse --- (1)

Now, we must assume Q

Q2, and

show there is a containment mappingfrom Q2 to Q1.

Key idea --- frozen

CQ

Q :

For each variable of

Q, create a

corresponding, unique constant.

Frozen

Q is a DB with one tuple formed

from each subgoal of

Q, with constants in

place of variables.

docsity.com