
158 Chapter 5. Deductive Databases
§24. Integrity Constraints
159
Proof
Let D have type theory
<1>.
By lemma 23.3, eis a correct answer for
comp(D*
u
<1»
u {Q*}. By theorem 14.6, e is a correct answer for
D*
u
<I>
u {Q*}. By theorem 9.5, there exists an R-computed answer
cr
for
D*
u
<I>
u
{Q*}
and a substitution
'Y
such that
e=cry.
Since
cr
is a ground
substitution for all the variables in
W,
it follows that
e=cr.
That is, e is an
R-
computed answer for D u {Q}. I
The requirement in theorem 23.4 that e be a ground substitution for all
variables in W cannot be omitted, since every computed answer for D
u
{Q}
has
this property. From a database viewpoint, theorem 23.4 is a rather weak
completeness result. It would be preferable to have conditions under which a query
had only finitely many answers and the query evaluation process was guaranteed to
find all these answers and then terminate. One rather strong condition, which
ensures these properties hold, is that the database be hierarchical. We now present
this completeness result for hierarchical databases, which is the database version
of
theorem 18.9.
Theorem
23.5 (Completeness
of
Query Evaluation for Hierarchical Databases)
Let D be a database,
<I>
its type theory, Q a query
f-W,
and R a safe
computation rule. Suppose that both D and
<I>
are hierarchical. Then the following
properties hold.
(a)
Each SLDNF-tree for D u
{Q}
via R exists and is finite.
(b)
If
eis a correct answer for comp(D) u
{Q}
and eis a ground substitution for
all free variables in W, then
eis
an
R-computed answer for D u {Q}.
Proof
By lemma 22.7,
D*
u
<I>
u
{Q*}
is allowed. Also D* u
<I>
is
hierarchical. By lemma 23.3,
e is a correct answer for comp(D* u
<1»
u {Q*}.
Hence the result follows from theorem 18.9. I
§24.
INTEGRITY
CONSTRAINTS
In this section, we study integrity constraints in deductive database systems
and prove the correctness
of
a simplification method for checking integrity
constraints.
A number
of
proofs in this section use typed versions
of
results from earlier
chapters.
In each case, it will be clear from the context that the reference to the
earlier result is actually a reference to the appropriate typed version
of
the result.
The standard method
of
determining whether a database satisfies or violates an
integrity constraint W is by evaluating the query
f-W.
The following two
theorems, due to Lloyd and Topor [61], [62], show that this method is sound.
Theorem
24.1 Let D be a database and W an integrity constraint. Suppose
that comp(D) is consistent.
If
there exists
an
SLDNF-refutation
of
D u {f-W},
then D satisfies
W.
Proof
The theorem follows immediately from theorem 22.6. I
Theorem
24.2 Let D be a database and W
an
integrity constraint. Suppose
that comp(D) is consistent.
If
D u
{f-
W}
has a finitely failed SLDNF-tree, then
D violates
W.
Proof
The theorem follows easily from theorem 18.6 and lemma 22.1.
III
Now we turn to the simplification theorem for integrity constraint checking.
From a theoretical viewpoint, it is highly desirable for a database to satisfy its
integrity constraints at all times. However, from a practical viewpoint, there
are
serious difficulties in finding efficient ways
of
checking the integrity constraints
after each update. The problem is especially difficult for deductive databases, since
the addition
of
a single fact can have a substantial impact on the logical
consequences
of
the database because
of
the presence
of
rules.
In spite
of
these difficulties, it is possible to reduce the amount
of
computation
if
advantage is taken
of
the fact that, before the update was made, the database was
known to satisfy its integrity constraints. The simplification theorem shows that it
is only necessary to check certain
instances
of
each integrity constraint. For a very
large database, this can lead to a dramatic reduction in the amount
of
computation
required. This idea
is
originally due to Nicolas [78] in the context
of
relational
database systems. A method related to the one given in this chapter was presented
by Decker [27].
An alternative "theorem proving" approach was given
by
Sadri
and Kowalski [90].
To cover the most general situation by a single theorem, we use the concept
of
a transaction. A transaction is a finite sequence
of
additions
of
statements
to
a
database and deletions
of
statements from a database.
If
D is a database and t is a
transaction, then the application
of
t
to
D produces a new database D', which is