Top Banner
20

The PARK semantics for active rules

May 14, 2023

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The PARK semantics for active rules

The PARK Semantics for Active RulesGeorg Gottlob Guido MoerkotteInstitut f�ur Informationssysteme Lehrstuhl f�ur Informatik IIITechnische Universit�at Wien RWTH-AachenA-1040 Wien, Austria 52056 [email protected] [email protected]. SubrahmanianDepartment of Computer ScienceUniversity of MarylandCollege Park, MD [email protected] 26, 1995AbstractActive databases are an important topic of current database research. However, the se-mantics of the underlying mechanism, event-condition-action rules (or ECA rules for short),is unclear so far. In order to de�ne a clear semantics for sets of active rules, we �rst derivethe requirements such a semantics must ful�ll. Since currently no semantics ful�lls theserequirements, we continue with the de�nition of the PARK semantics adhering to all re-quirements. The PARK semantics is a smooth integration of in ationary �xpoint semantics[6] with con ict resolution. Through this approach, the PARK semantics is powerful enoughto deal with recursive active rules. Furthermore, the actual con ict resolution strategy is aparameter of the PARK semantics. This guarantees a wide range of applicability.1 IntroductionDuring the last few years, there has been increasing interest in active database systems. In-dependent of the underlying data model, event-condition-action rules [7] are at the core of allapproaches. Since the introduction of ECA rules, many di�erent languages for ECA rules havebeen proposed and quite a few prototype systems have been built. (For an overview see [2, 1].)Nevertheless, current research falls short of supplying a clean semantics for these systems. It isour intention to �ll this gap.When it comes to de�ning a semantics for active rule systems, several challenges have tobe met. Besides recursion, the most striking challenge is inconsistency, i.e., the possibility ofsituations where two con icting rules are �rable. Whereas this situation can naturally occurin active databases, it does not occur in pure deductive rule systems. Hence, their semanticscannot directly be applied to active rule systems.1

Page 2: The PARK semantics for active rules

Nevertheless, research in semantics for deductive rule systems should not be neglected: if notwo con icting rules are ever �rable, some �xpoint semantics maybe appropriate. It is only in thecase of con icts that deviations become necessary. These deviations, i.e., the special treatmentnecessary to deal with con icts, are typically referred to as the con ict resolution strategy.Following these lines, our approach to de�ne a semantics for active rule systems o�ers a smoothintegration of an existing well-known semantics for deductive rule systems (the in ationarysemantics [6]) with con ict resolution. Furthermore, since con ict resolution strategies arehighly system and application dependent, any semantics should be parameterizable with a specialcon ict resolution strategy. This avoids the necessity to de�ne a new semantics each time thecon ict resolution strategy changes. The PARK semantics for active rule systems as de�ned inthis paper provides this modularity.Before one can study the semantics of active rule systems, the requirements and obstaclesshould be made clear. Section 3 gives a list of requirements a semantics for active rule systemsshould ful�ll. Further, this section lists existing semantics for deductive and active rule systemstogether with the requirements they fail on. Keeping these requirements in mind, we discuss, bymeans of examples, the obstacles of active semantics (Sec. 4.1). Then, we are well prepared tointroduce the PARK semantics of active rule systems in Section 4.2 for condition action rules. Ina later step, the semantics is enhanced in order to capture full ECA rules (Sec. 4.3). Several moreinvolved examples demonstrate the exibility and naturalness of the PARK semantics (Sec. 5).Section 6 concludes the paper. Before we start with the requirements, let us �rst introduce thebasic concepts used throughout the paper.2 Basic ConceptsAn active rule is a rule of the form l1; l2; : : : ; ln ! � l0where the following holds:� The body literals li for 1 � i � n may be positive or negated atoms. Negation :a of anatom a is understood as negation by failure and not as classical negation.� The head literal l0 is positive and pre�xed by a \+" or \�". The intuition is that it shouldbe inserted into the database or deleted from the database, respectively.So far, active rules do not allow the speci�cation of events within their body. That is, the rulesare restricted to a condition-action form. At the end of Section 4 we give a treatment for eventspeci�cations within rule bodies, thus yielding full event-condition-action rules.As an example of a condition-action rule, consider the rulesemp(X); :active(X); payroll(X;SALARY )!� payroll(X;SALARY )which speci�es that if a non-active employee has a record in the salary relation, then this recordshould be deleted. 2

Page 3: The PARK semantics for active rules

As is common for datalog, we require active rules to ful�ll the following safety conditions:1. Each variable occurring in a rule head should also occur in the body of the same rule.2. Each variable occurring in a negated literal in the rule body must also occur in somepositive literal in the rule body.A database instance, D, is a set of (positive) ground atoms. The semantics of a set of activerules w.r.t. a database instance D will be de�ned in Section 4, after discussing the requirementsfor a semantics of active rules in the next section.3 Desired Properties of Active Rule SemanticsIn this section we will discuss the desired properties of a good active rule semantics and concludethat none of the existing semantics has these properties:Unambiguous Semantics. Since the evaluation of active rules implies updates to the databaseinstance D, we do not want to end-up with two or more di�erent database states. This is possiblein logic programming (e.g. stable model semantics) or for query answering, but inconceivable inthe case of active databases.Independence from Con ict Resolution Policies. In all known active database systems,con icts may arise naturally. A con ict is a situation where two or more active rules are�rable and one of these rules requires the insertion of some atom a while (at least) one ofthe others requires the deletion of a. A con ict resolution policy is a method of determiningwhich of these con icting actions is to be performed and which is to be suppressed. Each existingapproach to active databases has a �xed con ict resolution policy which is an integral part ofthe semantics. We postulate that given any con ict resolution policy SELECT, there must be auniform method of de�ning a semantics of active databases based on that policy. In other words,the overall semantics of active databases has two components: an inference component and acon ict resolution component that work together. The design of these two components shouldbe largely independent. This will ensure that it is not necessary to rede�ne the semantics ofactive databases over and over again just because new con ict resolution policies are requiredin new domains. Instead, when designing the inference engine, the con ict resolution policy canbe treated as a \black-box" or an \oracle."Flexible Con ict Resolution. Consider a situation where two active rules are �rable { oneof these requires addition of a, while the other requires the deletion of a. As we shall demonstratelater in the paper (through an example), which of these two actions must be performed maydepend critically upon the atom in question. Therefore, con ict resolution must be exibleand allow for the articulation of sophisticated policies that vary from atom to atom depending,perhaps, on other properties in the database and the program, or via interactive input from theuser. This means that in the formal semantics for active databases, a con ict resolution policy3

Page 4: The PARK semantics for active rules

may be viewed as a function, SELECT, which, given all the context information of the con ictyields for a ground atom either insert or delete. The context information includes the databaseinstance D, the program P , the current state of the computation I , and a description of a con ictc. (The constituents I and c will be formalized later on.) Intuitively, SELECT(D;P; I; c) = insertmeans that in the event of a con ict about whether to insert or delete a, a should be inserted.The actual implementation of the function can be logical, or procedural, depending upon theneeds of the application.Basic Inference Engine. In the absence of con icts, the basic inference engine which com-putes the updates must be compatible with some well-understood semantics, e.g., for Datalog.Further, it must be powerful enough to deal with recursive active rules.The semantics should preferably be explained by a �xed-point construction which can bedirectly implemented. We believe that a �xed point semantics combines the advantages of beingboth mathematically clean and directly implementable.Summarizing, we can state the following:ActiveDBSemantics = DeclarativeSemantics + Con ictResolutionPolicy:Further, the semantics has to treat full event-condition-action rules.Polynomial Tractability. The method should be tractable, i.e., the result database stateshould be computable in time polynomial in the size of the input database instance. Thisimmediately implies that they should at least terminate.Implementability on top of commercial DBMS. The method should be easily imple-mentable on the top of a commercial DBMS.All existing semantics fall short on at least one of the above requirements. Those developedfor deductive rules do not have any con ict resolution strategy [6, 4]. Special semantics for activedatabases are not only rare but also fail on the requirements above. Some do not necessarilyterminate [3, 11], are not polynomial [8], or do not always result in a unique state [3, 8].4 The PARK semantics4.1 Introductory ExamplesThe major problem with the semantics of active rules is that the straightforward processingof rules may lead to con icting actions, i.e. insertion and deletion of the same data item. Inthis subsection we use examples to illustrate how the in ationary semantics of Kolaitis andPapadimitriou [6] may be used in conjunction with appropriate con ict resolution policies tode�ne a semantics for active databases. 4

Page 5: The PARK semantics for active rules

In order to simplify discussion, in this section we will use a speci�c �xed con ict resolutionpolicy called the principle of inertia. This principle ignores con icting actions. For instance ifactions +a and �a are both implied by some �rable rules r1 and r2, respectively, then bothactions are ignored as they are con icting commands, and the status of a in the result remainsthe same as in the input database (hence the name inertia). A con ict c of the above kind isdescribed by a triple (a; fr1g; fr2g) where a is the atom for which the con ict arizes and thesecond (third) component is the set of all ground rule instances with valid body that requirethe addition (deletion) of a. Here, the validity of the body of the rule depends on the validityof the literals with respect to a given state of computation I (see below for a formalization).In other words, the principle of inertia corresponds to the case where the function SELECTis de�ned as follows: SELECT(D;P; I; (a; ins; del)) = insert i� a was present in the originaldatabase instance D; SELECT(D;P; I; (a; ins; del)) = delete otherwise.It is important to note that the con ict resolution policy (whatever it may be) is enforcedeven if +a and �a are not computed in the same computation step. For example, consider thefollowing rule-set P1 operating on a database D = fpg:1. p!+ q2. p!� a3. q!+ aDuring the computation, we will mark added facts with + and deleted facts with � whilefacts that were present in the original database remain unmarked in order to distinguish themlater from computed actions.If we envisage, as usual, a step by step computation which at each step applies all rulesin parallel (producing immediate consequences), then, after the �rst step, we would get theintermediate result fp;+q;�ag and after the second step the �nal �xed point fp;+q;�a;+ag.This includes a con ict which must be resolved using the con ict resolution policy (which in ourcase, happens to be the principle of inertia). This causes us to eliminate +a;�a getting fp;+qg.Finally, we e�ectively apply the remaining non con icting actions, in our case, the unique action+q, getting the result database state fp; qg. Note that by eliminating the con icting pair +a,�a, the status of a remains the one of the original database (namely, \absent"), since no actionwhatsoever on a is executed.So far so good. However, a slightly more complicated program may create considerableconfusion. This confusion is due to the fact that some intermediately asserted (or deleted) factswhich will later become obsolete entail some further deletions or insertions.Consider, for instance, the same database D = fpg and the program P21. p!+ q2. p!� a3. q!+ a 5

Page 6: The PARK semantics for active rules

4. :a! + r5. a!+ sIf we stubbornly apply the immediate consequence operator, we get the following interme-diate results after each step:after step 1: fp;+q;�a;+rgafter step 2: fp;+q;�a;+r;+agafter step 3: fp;+q;�a;+r;+a;+sg = �nal �xed point.Now, in this �nal �xed point, as before, we recognize that �a and +a are con icting andeliminate these two marked atoms using the principle of inertia as the con ict resolution policy.We are thus left with fp;+q;+r;+sg. After e�ectively incorporating the updates, we get theresult database state fp; q; r; sg.But is this what we really want? Note that +s was obtained by rule (5) based on the presenceof +a. However, +a was afterwards recognized to be con icting and was eliminated. Since awas not present in the original database and is not present in the result, rule (5) should not �re.As a consequence, s should not stay in the �nal result.In a similar manner, atom r is introduced based on rule (4) whose body depends on thecon icting atom a. However, in this case, since a is not present in the original nor in the �naldatabase, rule (4) may well �re and produce r. The desired result database state is thus fp; q; rg.In summary, in order to get the correct result, we cannot just compute the �xed point ofthe immediate consequence operator and then eliminate con icting marked literals. Whethera marked fact will stay in the result or not should depend on the reasons why it was asserted.Basically, if the reason for existence of such a literal is solely grounded on con icting literals thatare afterwards invalidated, then the literal should stay out. If, however, there are valid reasonsfor the literal, such as nondeleted atoms of the original database or noncon icting marked literals,etc., then it should stay in.Yet another problem is the problem of false con icts.Consider, for example, the following program P3 on database instance D = fpg.1. p! + q2. p!� q3. q! + a4. q!� a5. p! + aApplying the immediate consequence operator, we get the following intermediate results aftereach step: 6

Page 7: The PARK semantics for active rules

after step 1: fp;+q;�q;+agafter step 2: fp;+q;�q;+a;�ag = �nal �xed point.It would thus seem that a is ambiguous. However, the ambiguity of a is a false ambiguity!Since q, which is derived before a is ambiguous, and thus maintains its original status (=absentfrom the database according to the principle of inertia), we should not use q to derive +a or �a.Therefore, �a should not be derivable and thus a should not be an ambiguous literal. However,since we can derive +a by rule (5), +a should stay in the �nal �xed point. The correct result istherefore fp;+ag, or, after incorporating the updates, fp; ag.The last example shows that it is very important to forbid that any consequences are drawnfrom ambiguous marked literals. But how are we to achieve this? The algorithm in the nextsubsection will show that this is e�ectively { and easily { possible.4.2 The PARK �xed-point semanticsIn this subsection we give a complete formal de�nition of the PARK semantics. The semanticsis illustrated by means of two examples with di�erent con ict resolution strategies in Section 5.Let us start with the de�nition of some relevant concepts. The Herbrand base H(P;D) of adatabase instance D and a program P is de�ned as usual. It consists of all ground positiveliterals made from predicate and constant symbols found in P and D.Extended Herbrand base. The extended Herbrand base H�(P;D) corresponding to a set ofactive rules P operating on a database instance D is de�ned by:H�(P;D) = fa;+a;�a j a 2 H(P;D)g:If P and D are understood, we just write H�.Intermediate interpretations. An intermediate interpretation (shortly i-interpretation) con-sists of a set of positive atoms plus a set of atoms marked by + or �. We say that ani-interpretation is consistent if it does not contain a pair of literals +a, �a. If I is an i-interpretation, then I� denotes all atoms in I marked by �, I+ denotes all atoms in I markedby +, and I? denotes all unmarked atoms in I . If P is a set of active rules and D a database,then an i� interpretation of (P;D) is a subset of H�(P;D).Literal validity. The validity of a ground literal a in an i-interpretation I is de�ned as follows.If a is positive, then a is valid in I i� I \ fa;+ag 6= ;, thus, i� at least one, a or +a is containedin I . If a = :b is a negative literal, then a is valid in I i� one of the following conditions applies:(1) �b 2 I or (2) I \fb;+bg = ;, in words, i� either there exists a delete action on b or neither bnor +b appear in I (and hence, :b is true by negation as failure or the closed world assumption).If a literal a is valid in an i-interpretation I , we write valid(a; I).Con icts. A tuple (r; �) where r is a rule and � is a ground substitution for r is called a rulegrounding . Let P be a set of active rules and I an i-interpretation. Then conflicts(P; I) is aset of maximal triples of the form (a; ins; del) such that a is a ground atom and ins and del aresets of rule groundings. For each such triple the following conditions must hold:7

Page 8: The PARK semantics for active rules

1. a is a ground atom and there exist2. rules r and r0 in P and ground substitutions � and �0 such that� valid(li�; I) for all body literals li of r,� valid(l0i�0; I) for all body literals l0i of r0, and� for the heads +l0 of r and �l00 of r0, l0� = l00�0 = a holds.3. For all possible r; r0 and �; �0 ful�lling 2), (r; �) 2 ins and (r0; �0) 2 del.Each tuple (a; ins; del) 2 conflicts(P; I) is called a con ict .Consider the program P containing the rules r1 : p(x)! + q(x) and r2 : p(x)!� q(x)together with the i-interpretation I = fp(a)g. Thenconflicts(P; I) = f(q(a); f(r1; [x a])g; f(r2; [x a])g)g:Note that con icts looks one step into the future. That is, con icts detected need not be presentin I .Con ict resolution policy. A con ict resolution policy is a map SELECT from1. a database instance D,2. a program P ,3. an i-interpretation I , and4. a con ict cto insert, delete. Intuitively, SELECT(D;P; I; (a; ins; del)) = delete (resp. insert) meansthat for the current con ict, the action to take on atom a is deletion (resp. insertion).The subsequent de�nition is motivated as follows. Whenever a con ict arises, its derivationmust be hindered. In order to do so, we block rule instances from being �red.Blocked Rule Instances. Let P be a set of active rules, SELECT be a con ict resolution policy,and I an i-interpretation. Suppose we setX = fdel j (a; ins; del) 2 conflicts(P; I) and SEL(D;P; I; (a; ins; del)) = insertgY = fins j (a; ins; del) 2 conflicts(P; I) and SEL(D;P; I; (a; ins; del)) = deleteg:Then blocked(D;P; I;SELECT) = 0@ [del2X del1A [ [ins2Y ins! :8

Page 9: The PARK semantics for active rules

As an example, suppose D = fp(a)g and P consists of the rulesr1 : p(x)!+ q(x)r2 : p(x)!� q(x)and I = fp(a);+q(a);�q(a)g. Then� con icts(P,I) = f(q(a); f(r1; [x a])g; f(r2; [x a])g)gand for SELECT(D;P; I; (q(a); f(r1; [x a])g; f(r2; [x a])g)) = insertwe have� blocked(D,P,I,SELECT) = f(r2; [x a])gThe incorporate operator. The operator incorp transforms a consistent i-interpretation intoa traditional (2-valued) Herbrand interpretation by incorporating the updates:incorp(I) := (I? [ faj+ a 2 I+g)� faj � a 2 I�g= (I? � faj � a 2 I�g) [ faj+ a 2 I+g):Immediate consequence operator �P;B . After these important de�nitions, we are readyto de�ne the immediate consequence operator �P;B for a set P of active rules and a set ofblocked rule instances B. For each i-interpretation I , �P;B(I) is the smallest set U satisfyingthe following conditions:� I � U� If r = l1; : : : ; ln! � l0 is a rule in P and � a ground substitution for r such that{ (r; �) 62 B and{ valid(li�; I) for all body literals li of rthen �l0� 2 U .So far, this is an almost traditional de�nition of the immediate consequence operator exceptthat in the traditional de�nition1. the �rst condition is omitted and2. certain rule instances can not be blockedin classical LP. However, as we have seen in the last section, we can not just compute its least�xed-point due to con icts without paying attention to con icting rules. So far, B captures partof the mechanism to cope with con icts. As already indicated by the de�nition of �, it does not9

Page 10: The PARK semantics for active rules

su�ce to compute a �xpoint starting from some i-interpretation. Instead of i-interpretations,we have to work on bi-structures which we introduce next.Bi-structures. A bi-structure < B; I > consists of a set B of blocked rule instances and ani-interpretation I . Bi-structures are ordered according to the ordering �:< B; I >�< B0; I 0 > i� ( B � B0 orB = B0 and I � I 0:For two bi-structures A and B, let us write A � B if either A = B or A � B. Note that � is apartial ordering on bi-structures.For a bi-structure A = (B; I) we write int(A) to denote I .The idea is now to operate on bi-structures instead of operating on i-interpretations. Wetherefore de�ne a transition operator � from bi-structures to bi-structures as follows. LetA = (B; I) be a bi-structure and SELECT be a con ict resolution policy. Then we de�ne �P (A)by �P (A) = ( < B; �P;B(I) > if �P;B(I) is consistent< B [ blocked(P; I; SELECT); I? > otherwise:Strictly speaking, the operator � should be subscripted with SELECT { however, for the sakeof simplicity, we will omit such subscripts whenever this is clear from context.Note that as shown in the theorem below, the � operator is growing; this means that for eachbi-structure A, A � �(A). Let us denote the repeated applications of � as follows: �0P (A) = A;�i+1P (A) = �P (�iP (A)); as there are only �nitely many pairs (B; I), it follows that there mustbe a minimal integer k such that �kP (A) = �k+1P (A); instead of explicitly talking of this minimalinteger k, we will usually denote �kP (A) by �!P (A). It follows immediately from the fact that�P is growing that �!P (A) is a well-de�ned bi-structure and that �!P (A) is a �xed-point of �P .Moreover, if �!P (A) = (B; I), then I = lfp(�P ).Let us discuss the relationship of � with the in ationary �xpoint operator [6]. If no con ictarises � does not change the program P ; only the i-interpretation of the bistructure is changed by�. This is done the following way. The � operator successively applies � to some i-interpretationand unions the result with the original i-interpretation. This strongly resembles the in ationary�xpoint [6]. On the other hand, as soon as a con ict arises, the � operator immediately stopsits in ationary computation and performs instead a con ict resolution step. Thus, the PARKsemantics | building on � | may be viewed as a smooth cycle integrating in ationary �xpointcomputation and con ict resolution policies.Theorem 4.1 Suppose P is a set of active rules, and A = (B; I) is a bi-structure. Then:1. A � �P (A), and2. �!P (A) is a �xed-point of �P , and3. if �!P (A) = (B0; I 0), then I 0 = lfp(�P 0;B0).10

Page 11: The PARK semantics for active rules

Proof. (1) Let �P (A) = (B0; I 0). If I 0 is a consistent i-interpretation, then B0 = B andI 0 = �P;B(I) � I ; hence, (B; I) � (B0; I 0). On the other hand, if I 0 is an inconsistent i-interpretation, then B0 is obtained from B by adding one or more blocked rule instances to B,i.e. B � B0; therefore, (B; I) � (B0; I 0).(2) Immediate consequence of (1) above.(3) As �!P (A) is a �xed-point of �P , �P (B0; I 0) = (B0; I 0). As the P 0 component of the pair(P 0; I 0) remains unchanged upon application of the � operator, it follows that I 0 = �P;B0(I 0),by de�nition of the � operator. Thus, I 0 is a �xed-point of �P;B0 .Suppose now that I 0 is not the least �xed-point of �P;B0 , i.e there is a J � I 0 such thatJ is a �xed-point of �P;B0 . Since �P;B0 is monotonic, �P;B0(J) � �P;B0(I 0). Thus, �P 0(J) is aconsistent i-interpretation. Then�P (B0; J) = (B0;�P;B0(J)) = (B0; J);i.e. (B0; J) is a �xed-point of �, contradicting the fact that (B0; I 0) is the least �xed-point of �.2We are now ready for de�ning the PARK semantics. To a given set of active rules P , databaseinstance D, and a con ict resolution policy SELECT, the result database instance PARK(P;D)is de�ned as follows: PARK(P;D) = incorp(int(�!P ((;; D)))):Clearly, if P is a �nite rule set and if D is a �nite database, then �!P is computable inpolynomial time in the size of D when the con ict resolution policy SELECT is implementablein polynomial time. Notice that any con ict that arises during the PARK computation does sobecause of two atoms of the form +A and �A occurring in the �xpoint computation procedure.For any given atom A involved in such a con ict, the sets ins and del are bounded by the sizeof P . Thus, the total complexity of identifying all con icts is bounded by the product of thesizes of D and P . It is now clear that when the con ict resolution policy is implementable inpolynomial-time, the PARK semantics is implementable in polynomial time as well because theabove iterative procedure is only executed at most size(P ) times where size(P ) is the numberof rules in P { to see this recall that at each step of the iteration,. after con ict resolution, atleast one rule from P is eliminated. A good example of a polynomial-time con ict resolutionpolicy is the principle of inertia.Informally, PARK(P;D) is computed as follows: apply all rules in parallel (operator �) andrepeat this process until some con icting literals are computed. When these literals, say +a and�a, are detected, the computation is interrupted. All blocked rule instances are collected. Thismeans that in the course of the further computation these rule instances will not be allowed toderive any updates. The computation is then resumed with a larger set of blocked rule instancesand the initial database instance (D = I?). We must resort to the initial database instancebecause some facts depending on �a or +a may have been computed which are now obsolete.The process is repeated until the �nal �xed-point is reached. Again, note the similarity betweenin ationary �xpoint and PARK in the case that no con ict occurs. The PARK semantics is il-lustrated by the subsequent example. The next section contains two more examples illuminatingthe PARK semantics for two di�erent select strategies.11

Page 12: The PARK semantics for active rules

Consider a database instance D = fp(a); p(b); p(c)g together with the program P containingthe rulesr1: p(x); p(y)! +q(x; y)r2: q(x; x)! �q(x; x)r3: q(x; y); q(x; z); q(z; y)! �q(x; y)The intuition is that we want to build some irre exive graph not containing any arc implied bytransitivity of existing edges. The �rst application of �P;; to D results in I1I1 = fp(a); p(b); p(c);+q(a; a);+q(a; b);+q(a; c);+q(b; a);+q(b; b);+q(b; c);+q(c; a);+q(c; b);+q(c; c)gSince �P;;(I1) = fp(a); p(b); p(c);+q(a; a);+q(a; b);+q(a; c);+q(b; a);+q(b; b);+q(b; c);+q(c; a);+q(c; b);+q(c; c);�q(a; a);�q(a; b);�q(a; c);�q(b; a);�q(b; b);�q(b; c);�q(c; a);�q(c; b);�q(c; c)gis inconsistent, we have to follow the second case of �P . We �rst compute conflicts(P; I1) whichis (q(a; a); f (r1; [x a; y a])g;f (r2; [x a])(r3; [x a; y a; z a])(r3; [x a; y a; z b])(r3; [x a; y a; z c])g)(q(b; b); : : : )(q(c; c); : : : )(q(a; b); f (r1; [x a; y b])g;f (r3; [x a; y b; z a])(r3; [x a; y b; z b])(r3; [x a; y b; z c])g)(q(a; c); f (r1; [x a; y c])g;f (r3; [x a; y c; z a])(r3; [x a; y c; z b])(r3; [x a; y c; z c])g): : :In order to get blocked(D;P; I1; SELECT), we have to �x the con ict resolution strategy SELECT.We decide to block all instances of rule r1 with x = y and those connecting a and c. In all other12

Page 13: The PARK semantics for active rules

cases, the instances of r3 are blocked. This results in B := blocked(D;P; I1; SELECT) =(r1; [x a; y a])(r1; [x b; y b])(r1; [x c; y c])(r1; [x a; y c])(r1; [x c; y a])(r3; [x a; y b; z a])(r3; [x a; y b; z b])(r3; [x a; y b; z c]): : :Then I2 := �B;P (I?1 ) =fp(a); p(b); p(c);+q(a; b);+q(b; a);+q(b; c);+q(c; b)g:Further, (B; I2) is the �nal �xpoint of �P and PARK(P;D) =fp(a); p(b); p(c); q(a; b); q(b; a); q(b; c); q(c; b)g:Note that we had to block the rule instances of rule r3 unnecessarily, since they can no longerbe involved in any con ict. This minor disadvantage of the PARK semantics can be overcomeby allowing to include only (a non-empty) part of conflicts into blocked.4.3 Full ECA-rulesLast in this section, we discuss the extensions necessary to capture full event-condition-actionrules. We de�ne an event as the occurrence of an update, i.e., the insertion or deletion of aliteral. As before, updates for a literal l are denoted by +l or �l. In order to allow an activerule to be triggered by an event and not just a condition, we allow update literals to occur withinthe rules body. In order to capture the semantics of full ECA-rules some extensions on the wayto the PARK semantics are necessary.We extend the PARK semantics for the case that during the user's transaction a set U ofupdates, i.e. of insertions +l and deletions �l for positive ground literals l, occurred. Thereexist several possibilities to capture these initial updates. One could argue that these cannot beoverwritten by some rules but this unnecessarily constrains the semantics. But remembering thegenerality of the con ict resolution mechanism, it is easy to code the semantics where transactionupdates cannot be overwritten into the con ict resolution policy. Hence, we allow a transaction'supdate to be overwritten. Nevertheless, some care has to be taken in case a con ict arises. Thereare two major points to consider:1. In case of a con ict | witness the de�nition of � | we restart with I?. This results indiscarding not only con icting updates but all the transaction's updates. This clearly isnot what we want.2. Con icts may not only occur between rules but also between transaction updates andrules. This case is not covered by the de�nition of con icts .13

Page 14: The PARK semantics for active rules

To solve these problems, we model the transaction updates U by a set of new rules ! �afor all �a 2 U . These rules then enhance the program P . More formally, we de�ne for a givenprogram P and a set of transaction updates U the modi�ed programPU := P [ f�aj � a 2 Ug:The second extension necessary concerns the de�nition of validity of a literal. In order toallow an event to trigger a rule with �l in its body, we must enhance the original de�nition ofvalid for events by two cases. For an i-interpretation and a positive ground literal a, we de�ne� valid(+a; I) if and only if +a 2 I and� valid(�a; I) if and only if �a 2 I .Now, we can state the PARK semantics for a database instance D, a program P and a setof transaction updates U :PARK(D;P; U) := incorp(int(�!PU ((;; D))))We illustrate the semantics for full event-condition-action rules by the following example.The database instance under consideration is D = fp(a); s(a); s(b)g and the program P consistsof the rulesr1: p(x)! +q(x)r2: q(x)! +r(x)r3: +r(x)! �s(x)The transaction update is U = f+q(b)g. Then, PU becomesr1: p(x)! +q(x)r2: q(x)! +r(x)r3: +r(x)! �s(x)r4: ! +q(b)and I1 := �;;PU (D) = fp(a);+q(a);+q(b); s(a); s(b)gI2 := �;;PU (I1) = fp(a);+q(a);+q(b);+r(a);+r(b); s(a); s(b)gI3 := �;;PU (I2) = fp(a);+q(a);+q(b);+r(a);+r(b); s(a); s(b);�s(a);�s(b)g(;; I3) is the �nal �xpoint of �PU and after incorporating the updates, we obtainPARK(D;P; U) = fp(a); q(a); q(b); r(a); r(b)g:14

Page 15: The PARK semantics for active rules

The preceding example does not contain any con icts. Let us consider yet another exampleto see how con icts are handled; for this example, we assume that the con ict resolution policybeing used is the principle of inertia.Suppose D = fp(a; a); p(a; b); p(a; c)g and program P has three rules:r1: q(x; a)! �p(x; a)r2: q(a; x)! +r(a; x).r3: +r(x; y)! +p(x; y).Suppose the transaction update is f+q(a; a)g. Then PU becomesr1: q(x; a)! �p(x; a)r2: q(a; x)! +r(a; x).r3: +r(x; a)! +p(x; a).r4: ! +q(a; a).The PARK-�xpoint construction procedure now works as follows:I1 := �;;PU (D) = fp(a; a); p(a; b); p(a; c); q(a; a)gI2 := �;;PU (I1) = fp(a; a); p(a; b); p(a; c); q(a; a);�p(a; a);+r(a; a)gI3 := �;;PU (I2) = fp(a; a); p(a; b); p(a; c); q(a; a);�p(a; a)+ r(a; a);+p(a; a)gAt this point, an inconsistency is detected involving rules r1 and r3 { so we re-start the compu-tation with I4 := �fr1;r3g;PU (D) = fp(a; a); p(a; b); p(a; c); q(a; a)gI5 := �fr1;r3g;PU (I4) = fp(a; a); p(a; b); p(a; c); q(a; a);+r(a; a)g:This is the �nal �xpoint; after incorporating the updates, we getPARK(D;P; U) = fp(a; a); p(a; b); p(a; c); r(a; a)g:5 Examples of di�erent con ict resolution strategiesA con ict resolution strategy is a means to resolve con icts by making a choice between twosets of rule groundings | one voting for the insertion and one voting for the deletion of aground atom. It is important to note that the con ict resolution strategy is orthogonal to the�xpoint computation. This point is illuminated by the two subsequent examples where the samedatabase instances and programs are used. The same �xpoint procedure | as de�ned by thePARK semantics | is applied. Nevertheless, the outcome is di�erent due to the di�erent con ictresolution strategies is applied. This by itself is not surprising, but the major point here is thatthe �xpoint procedure is exible enough to capture this.15

Page 16: The PARK semantics for active rules

In order to keep the discussion simple, we restrict ourselves to the propositional case ofcondition-action rules. Both examples are based on the same database instance D and programP . The only di�erence is the con ict resolution strategy.The database instance is D = fpg and P consists of the following rules:r1: p! +ar2: p! +qr3: a! +br4: a! �qr5: b! +qThe Principle of Inertia: The con ict resolution strategy in this paragraph is the alreadydiscussed principle of inertia.The �rst application of � results in(1) fp;+a;+qgwhich is consistent. However, the next iteration yields(2) fp;+a;+q;+b;�qgwhich is inconsistent. Hence, the second case in the de�nition of � takes place. Since we dealwith the propositional case only, we can neglect the substitutions for blocked rule instances.Instead, we can deal with rules directly. Since we apply the principle of inertia, we haveblocked(D;P; fp;+a;+q;+b;�qg; SELECT ) = fr2gNow, the iteration starts over with B = fr2g and I? = fpg. The next two applications of �yield (3) fp;+ag(4) fp;+a;+b;�qgThe next step again results in an inconsistent i-interpretation:(5) fp;+a;+b;�q;+qgThe set B of blocked rule instances is supplemented byblocked(D;P; fp;+a;+b;�q;+qg; SELECT ) = fr5g16

Page 17: The PARK semantics for active rules

The last iterations are(6) fp;+ag(7) fp;+a;�q;+bg.At this state the �nal �xpoint< fr2; r5g; fp;+a;�q;+bg>is reached letting fp; a; bg be the new database instance.Consider yet another example, where the principle of inertia leads to counterintuitive results.Let the database instance D be D = fag and the program P contain the following rules:r1: a! +br2: a! +dr3: b! +cr4: b! �dr5: c! �bDue to the con ict in the chain a! +b! +c! �b one would expect this chain to be withdrawn,and by the principle of inertia assume :b within the �nal result. Further, any o�spring of thiscontradictory chain should be neglected. In this case �d should not be considered. However,this is not what happens under the principle of inertia: The �rst two applications of � resultin fa; b; c;+d;�dg. A con ict concerning d arises and, by the principle of inertia is resolvedby assuring �d since d was not present within D. The rule a ! +d is blocked. Resuming thecomputation the next con ict, now due to the contradictory chain shows up at fa; b; c;�d;�bg.The resolution is by blocking a ! b, since b 62 D. The �nal result is fag and di�ers from theexpected | more intuitive | fa;+dg.Rule Priority: The next con ict resolution strategy is based on rule priorities. Rule prioritiescan be found in several proposals for active rules processing. Among these are the proposals forthe systems Ariel [5], Postgres [9], and Starburst [10]. For our example, we assume that rule rihas priority i. Within the sets ins and del of the set of con icts , the set containing the rulewith the highest priority is chosen by SELECT.As above, the �rst two applications of � result in(1) fp;+a;+qg(2) fp;+a;+q;+b;�qgSince +q is derived by a rule with priority 2 and �q by a rule with priority 4,17

Page 18: The PARK semantics for active rules

blocked(D;P; fp;+a;+q;+b;�qg; SELECT ) = fr2gWe proceed as above with(3) fp;+ag(4) fp;+a;+b;�qg(5) fp;+a;+b;�q;+qgSince �q has been derived by a rule with priority 4 and +q has been derived by a rule withpriority 5, we enhance the set of blocked rule instances B byblocked(D;P; fp;+a;+b;�q;+qg; SELECT ) = fr4gThe computation resumes at I? and subsequent applications of � yield(6) fp;+ag(7) fp;+a;+bg(8) fp;+a;+b;+qg.resulting in the �nal database instance fp; a; b; qg.In addition to the above con ict resolution strategies, it is possible to develop several othersas well { we brie y describe four more strategies below { due to space restrictions, we are unableto give a comprehensive description in this paper.Speci�city-based Con ict Resolution: An old AI principle says that more \speci�c" rules(i.e., rules dealing with a more speci�c subset of facts) should be given priority over more generalrules. For example bird(X)! +flies(X) is more general than penguin(X)! �flies(X), hencein the case of a penguin, even though both rules apply, the second should be preferred. Thisprinciple is not a complete con ict resolution strategy, since there may exist con icting rulesof equal or of incomparable speci�city, but this principle may be combined with other con ictresolution strategies.Interactive Con ict Resolution: In this scheme, as soon as a con ict is found, the user isqueried and may resolve the con ict by choosing one among the con icting rules.Voting Scheme: In this scheme, it is assumed that a set of critics are available to the system.A critic is a program that takes as input, a con ict (as de�ned earlier), and returns the valueinsert or delete. When a con ict occurs, the PARK semantics invokes the set of critics andasks each of them for \its vote". The majority opinion of the critics is then adopted to resolvethe con ict. An interesting aspect of critics is that each critic may use a di�erent intuition inorder to resolve a con ict. For instance, one critic may use background information it possesseson when various tuples were placed in the database (e.g. later information may be preferredby this critic). Another critic may use source-based approach (it may know that the two rules18

Page 19: The PARK semantics for active rules

that are involved in the con ict came from two di�erent sources, and that one of these sourcesis \more reliable" than the other). The Interactive con ict resolution scheme above is a specialcase of the voting scheme where there is one critic { viz. the human user.Random Con ict-Resolution: In some cases it may be convenient that the system justrandomly chooses one from the con icting rules in order to resolve the con ict.Which of the above strategies is picked for a particular application depends critically uponthe declarative needs of the application as well as e�ciency concerns.Declarative Needs: For instance, in banking applications, the principle of inertia may beused by the system, delaying a transaction, until the human banker can be queried. In manycases where the preconditions of rules de�ne classes and a clear object-class hierarchy exists,then the principle of speci�city may be used. The voting scheme can be used when goodcritics are available for the application at hand. In databases that monitor critical systems(e.g. power plants, machine tools, etc.), the interactive con ict resolution scheme is perhapsthe most appropriate strategy. Furthermore, in many applications, humans may prefer to adoptthis strategy anyway.E�ciency Needs: From the point of e�ciency, the principles of inertia, rule priority, inter-active con ict resolution and random con ict resolution are all easy to implement and can beviewed as constant time operations (i.e., operations that require a constant number of databaseaccesses).In contrast, the principle of speci�city may be more intensive computationally, in particular,if speci�city of rules is not determined a-priori, but is determined on the y by computingand comparing the sets of ground factsd to which the rules apply. (There may be, howevercompletely di�erent and much simpler ways of de�ning and determining rule speci�city).Lastly, the voting scheme's computational properties are constant-time modulo the complex-ity of the critics themselves. If the critics take large amounts of time for their processing, thenthis scheme could be time-consuming.6 ConclusionOver the last few years, there has been extensive work on active database systems { [2] providesa nice summary of this work. However, most of the formal treatments of active databases havebeen ad-hoc, and have failed to satisfy at least one of the following criteria that we considercritical to active databases { either they result in an update generate a multiplicity of databasestates, or they take non-polynomial (exponential) time to compute, or they are unable to resolvecon icts.In this paper, we �rst outlined the requirements for a semantics of active rule systems.Subsequently, we de�ned the PARK semantics for active rules { this semantics satis�es the19

Page 20: The PARK semantics for active rules

previously articulated criteria. The PARK semantics can be seen as a smooth integration ofin ationary �xpoint semantics [6] and con ict resolution. It ful�lls all our requirements includingthe treatment of recursive rules.References[1] A. Buchmann. Active object systems. In A. Dogac, M. �Ozsu, A. Biliris, and T. Sellis,editors, Advances in Object-Oriented Database Systems, pages 201{224, 1994.[2] U. Dayal, E. Hanson, and J. Widom. Active database systems. In W. Kim, editor, ModernDatabase Systems, pages 434{456. Addison Wesley, 1995.[3] P. Fraternelli and L. Tanca. A toolkit for the design of active database semantics. RapportoInterno 93-078, Politecnico di Milano, Milano, Italy, 1993.[4] A. Van Gelder, K. Ross, and J. S. Schlipf. The well-founded semantics for general logicprograms. Journal of the ACM, 38(3):620{650, July 1991.[5] E. Hanson. Rule condition testing and action execution in ariel. In Proc. of the ACMSIGMOD Conf. on Management of Data, pages 49{58, San Diego, CA, Jun. 1992.[6] P. Kolaitis and C. Papadimitriou. Why not negation by �xpoint? Journal of Computerand System Sciences, 43:125{144, 1991.[7] A.M. Kotz. Trigger Mechanisms for Maintaining Design Data Consistency in DatabaseSystems. PhD thesis, Univ. of Karlsruhe, 1988.[8] W. Marek and M. Truszczy�nski. Revision Programming, Database Updates, and IntegrityConstraints. In Int. Conf. on Database Theory, pages 368{382, Prague, Jan. 1995. Springer.[9] M. Stonebraker, A. Jhingran, J. Goh, and S. Potamianos. On rules, procedures, cachingand views in data base systems. In Proc. ACM SIGMOD Int. Conf. on Management ofData, pages 281{290, 1990.[10] J. Widom and S. Finkelstein. Set-oriented production rules in relational databases. InProc. of the ACM SIGMOD Conf. on Management of Data, pages 259{270, 1990.[11] C. Zaniolo. On the uni�cation of active databases and deductive databases. In Rules inDatabase Systems, (N. Paton, ed.), Springer Verlag, 1994.20