Proc. of 1990 VLDB Conference, pages 566{577
Deriving Pro duction Rules for Constraint Maintenance
Stefano Ceri
Jennifer Widom
IBM Almaden Research Center
650 Harry Road
San Jose, CA 95120
ceri@cs.stanford.edu, widom@ibm.com
Abstract.
Traditionally, integrity constraints in database
systems are maintained either by rolling back any transac-
tion that produces an inconsistent state or by disallowing
or mo difying operations that may produce an inconsistent
state. An alternative approach is to provide automatic e-
pair" of inconsistent states using production rules. For each
constraint, a pro duction rule is used to detect constraint
violation and to initiate database operations that restore
consistency.
We describe an SQL-based language for dening integrity
constraints and a framework for translating these constraints
into constraint-maintaining pro duction rules. Some parts of
the translation are automatic while other parts require user
intervention. Based on the semantics of our set-oriented pro-
duction rules language and under certain assumptions, we
prove that at the end of each transaction the rules are guar-
anteed to produce a state satisfying all dened constraints.
We apply our approach to a go od-sized example.
1 Intro duction
In database systems, an
integrity constraints
facility
permits logical specication of those database states
that are considered acceptable, or
consistent
. In cur-
rent systems, mechanisms for dening and enforcing in-
tegrity constraints are limited. Most relational database
systems support only sp ecic types of constraints, such
as uniqueness of keys and referential integrity, rather
than supp orting arbitrary predicates. Furthermore,
when constraints are violated, epair" of the database
state usually is limited to xed reversal actions, such as
rolling back the current op eration or the entire transac-
tion. (Consequently, for increased exibility, integrity
constraints often are enco ded within applications, usu-
ally in an ad-ho c manner.) An improved approach to
constraint enforcement allows denition of compensat-
ing actions that correct violation of each constraint ac-
cording to a well-understoo d, application-dependent se-
mantics.
Most research in the area of integrity constraints has
focused on eciently determining actual or potential
On leave from University of Modena
constraint violation, sometimes considering quite gen-
eral constraints (such as arbitrary predicates). In this
paper, we also consider general constraints, but we fo-
cus on the issue of constraint enforcement. A lan-
guage is prop osed for sp ecifying constraints on relational
databases. We then provide a framework for translat-
ing constraint specications into
production rules
that
maintain the constraints. Pro duction rules in database
systems allow sp ecication of data manipulation opera-
tions that are automatically executed whenever certain
events o ccur and/or certain conditions are met [DE89,
Han89,KdMS90, SJGP90, WF90]. The usefulness of in-
corporating pro duction rules into database systems is
well accepted [EC75, MD89, Mor83], particularly in the
context of constraint enforcement. However, we know of
no automatic (or semi-automatic) method for specifying
general constraints in a high-level, non-pro cedural lan-
guage, then deriving lower-level production rules that
maintain the constraints. We describe such a method.
The constraint and rule languages we use are based
on an extended version of SQL [HFLP89, IBM88], al-
though our work could easily be adapted for alternate
languages. Constraints are expressed as predicates over
the database state: if the predicate is true in a partic-
ular state, then the constraint is
violated
and the state
is
inconsistent
.
1
Constraints may b e ordered, sp ecify-
ing that certain constraints will be enforced earlier than
(and therefore may b e assumed valid by) other con-
straints. The pro duction rule language is describ ed in
[WF90]. Prior familiarity with this rule language is not
necessary; an overview is provided.
Production rules enforce constraints by issuing ac-
tions to correct violation. In many cases, several p ossi-
ble actions may correct a given constraint violation, and
which action is most appropriate may depend on the ap-
plication. Thus, for each constraint, the compensating
actions are specied by the application designer. How-
ever, several other necessary comp onents of the deriva-
tion can be performed automatically. We envision an
interactive system for deriving rules from constraints
with a structure as illustrated in Fig. 1. The automatic
portions of the derivation include:
Producing
rule templates
from constraints: Rule
templates enumerate all op erations that may cause
constraint violation (these form the triggering com-
1
For our framework, it is more convenient for constraints
to sp ecify the inconsistent rather than the consistent states.
This choice does not aect expressiveness, since the alter-
native semantics can b e achieved simply by negating each
constraint.