On Active Deductive

The Statelog Approach

Georg Lausen Bertram Ludascher Wolfgang May

Institut fur Informatik Universitat Freiburg Germany

flausenludaeschmayginfo rmat ikun ifr eibur gde

Abstract After briey reviewing the basic notions and terminology of

active rules and relating them to pro duction rules and deductive rules

resp ectively we survey a number of formal approaches to active rules

Subsequentlywe present our own stateoriented logical approach to ac

tive rules which combines the declarative semantics of deductive rules

with the p ossibility to dene up dates in the style of pro duction rules

and active rules The resulting language Statelog is surprisingly simple

yet captures many features of active rules including comp osite eventde

tection and dierent coupling mo des Thus it can b e used for the formal

analysis of rule prop erties like termination and expressivepo wer Finally

weshowhow nested transactions can b e mo deled in Statelog b oth from

the op erational and the mo deltheoretic p ersp ective

Intro duction

Motivated by the need for increased expressiveness and the advent of new appli

cations rules have b ecome very p opular as a paradigm in programming

since the late eighties Min Today there is a plethora of quite dierent appli

cation areas and semantics for rules From a birdseye view deductive and active

rules may b e regarded as two ends of a sp ectrum of database rule languages

Deductive Rules Production Rules Active Rules

higher level lower level

stratied well RDL pro

ARDL Ariel Starburst Postgres

founded cedural Datalog

Fig Sp ectrum of database rule languages adapted from Wid

On the one end of the sp ectrum deductive rules provide a concise and elegant

representation of intensionally dened data Recursive views and static integrity

constraints can be sp ecied in a declarative and uniform way using deductive

rules thereby extending the query capabilities of traditional relational languages

like SQL Moreover the semantics develop ed for deductive rules with negation

are closely related to languages from the eld of knowledge representation and

In Transactions and Change in Logic Databases B Freitag H Decker

M Kifer and A Voronkov editors LNCS Springer

nonmonotonic reasoning whichsubstantiates the claim that deductive rules are

rather highlevel and mo del a kind of natural reasoning pro cess However

deductive rules do not provide enough expressivenessorcontrol to directly sup

p ort the sp ecication of up dates or active b ehavior Since up dates play a crucial

role even in traditional database applications numerous approaches have b een

intro duced to incorp orate up dates into deductive rules

In contrast to deductive rules active rules supp ort reactive b ehavior like

triggering of up dates as a resp onse to external or internal events Conceptually

most rule languages for active database systems ADBs are comparatively low

level and often allow to exert explicit control on rule execution While such

additional pro cedural control increases the expressive power of the language

considerably this is also the reason why the b ehavior of active rules is usually

much more dicult to understand or predict than the meaning of deductive

rules Not surprisingly researchers continue to complain ab out the unpredictable

b ehavior of active rules and the lack of a uniform and clear semantics

Production rules constitute an intermediate family of languages and provide

facilities to express up dates and some asp ects of active b ehavior yet avoid overly

detailed control features of active rules at the right end of the sp ectrum

Contributions and Overview In this pap er we intro duce to the dierent

rule paradigms in databases in Figure and survey a number of formal and

logical approaches to activerulesWe then present a sp ecic stateoriented logical

approach to active rules called Statelogwhich yields a precise formal semantics

for active rules It can b e shown that certain pro duction rules and deductiverules

are sp ecial cases of Statelog rules and that many but not all features of active

rules like comp osite event detection and dierent coupling mo des can b e sp ecied

in Statelog Thus Statelog can serveas a unied logical framework for active

and deductive rules in which fundamental prop erties of rules like termination

b ehavior complexity and expressiveness can b e studied in a rigorous wayThe

main technical contribution of this pap er is the continuation and renement

of LML where a mo deltheoretic Kripkestyle semantics for Statelog in the

context of a nested transaction mo del has b een presented

The pap er is organized as follows In Section werstintro duce the basic

terminology and features of active rules and then briey relate them to pro

duction rules and deductive rules resp ectively Section is a short survey on

some formal approaches to active rules In Section we intro duce Statelog a

stateoriented extension of Datalog and summarize the main results A key idea

of the approach is to add a state argument to every predicate for example

s px y intuitively means that px y holds in state s this idea has come

up several times see Section Starting from a simple mo del for at transac

tions the framework is extended subsequently to incorp orate nested transactions

Section Section develops an abstract conceptual mo del for Statelog with

nested transactions by a mo deltheoretic Kripkestyle semantics Some conclud

ing remarks are given in Section

Rules in Databases

Rules in database programming languages come in many dierentavors In this

section we discuss language issues of the ab ovementioned rule sp ectrum and

highlight dierences b etween the paradigms

Active Rules

Active rules are typically expressed as EventConditionAction ECA rules of

the form

on heventi if hcondition i then haction i

Whenever the sp ecied event o ccurs the rule is triggered and the corresp onding

action is executed if the condition is satised in the current database state Rules

without the event part are sometimes called production rules rules without the

condition part are sometimes referred to as triggers

Events Events can be classied as internal or external Internal events are

caused by database op erations like retrieval or up date insertion deletion mo d

ication of tuples or transactional events like commit or ab ort In ob ject

oriented systems such internal events may take place through metho d invo

cations External events o ccurring outside the database system may also be

declared and have to b e monitored by the ADB

Starting from primitive external or internal events more complex composite

events can b e sp ecied using an event algebra typical op erators are disjunction

E jE sequence E E conjunction E E etc cf CKAKSin

  

may be Alternatively logics like past temp oral logic see eg LSChob

used for the sp ecication of comp osite events Several event detection algorithms

havebeendevelop ed which allow to detect comp osite events without storing the

complete database history for instance by applying temp oral reduction rules

LSChob or residuation Sin

A question arising from the use of comp osite events is which of the constituent

events take part in the comp osite event and how they are consumed bythe

comp osite event This event consumption policy is elab orated using parameter

contexts whichwere intro duced for the SNOOP algebra in CKAKCM In

order to illustrate the dierent parameter contexts consider the comp osite event

E F G H which o ccurs if H o ccurs after b oth F and G have o ccurred

Assume the following event history is given

G F F G F H H

   

j j j j j j j

t

Here the F s denote several o ccurrences of the same primitiveevent F similarly

j

for G and H

k l

Dierent parameter contexts are motivated by applications where constituent

events should b e consumed by the comp osite event in a certain way The following

parameter contexts have b een prop osed CKAK

Recent In this context only the most recent o ccurrences of constituent

events are used all previous o ccurrences are lost In the ab ove event his

tory E will b e raised twice for the constituentevents fG F H g and for

 

fG F H g

  

Chronicle In this context events are consumed in their chronological order

In a sense this corresp onds to a rstinrstout strategy E will b e rep orted

H g and for fF G H g for fG F

  

Continuous In this context each event which may initiate a comp osite

event starts a new instance of the comp osite event A constituentevent can

b e shared byseveral simultaneous o ccurrences of the comp osite event In the

example each G and each F starts a new instance Thus the comp osite

i j

o ccurrences fG F H g fF G H g fF G H g and fG F H g are

    

rep orted The comp osite event initiated at F is still to b e completed



Cumulative In this context all o ccurrences of constituentevents are accu

mulated until and consumed when the comp osite event is detected In the

example E is raised once for the constituentevents fG F F G F H g

  

Unrestricted In this context constituentevents are not consumed but are

reused arbitrarily many times For the ab ove history E is rep orted for all

twelve p ossible combinations of fF G H g

j k l

Conditions If the triggering event of an active rule has been detected the

rule b ecomes eligible and the condition part is checked The condition can b e

a conventional SQLlike query on the current state of the database or it may

include transition conditions ie conditions over changes in the database state

The p ossibility to refer to dierent states or delta relations is essential in order

to allow for active statechanging rules

Actions If the condition of the triggered rule is satised the action is executed

Internal actions are database up dates insert delete mo dify and transactional

commands commit ab ort external actions are executed by pro cedure calls

to application programs and can cause applicationsp ecic actions outside the

database system eg sendmail turnonsensor Usually it is necessary to pass

parameters between the dierent parts of ECArules ie from the triggering

event to the condition and to the action part In logicbased approaches this can

b e mo deled very naturally using logical variables while this issue maybemore

involved under the intricacies of certain execution mo dels

Execution Mo dels The basic execution mo del of active rules is similar to the

recognizeact cycle of pro duction rule languages like OPS BFKM one or

more triggered rules ie whose triggering event and condition are satised are

selected and their action is executed This pro cess is rep eated until some termi

nation condition is reachedfor example when no more rules can b e triggered

or a xp oint is reached Clearly there are a lot of p ossible choices and details

whichhave to b e elab orated in order to precisely sp ecify the semantics of rule

execution

One issue is the granularity of rule pro cessing which sp ecies when rules are

executed This may range from execution at any time during the ADBs op era

tion nest granularity over execution only at statement b oundaries to trans

action b oundary execution coarsest granularity Another imp ortant asp ect is

whether rules are executed in a tupleoriented or setoriented way Setoriented

execution conforms more closely to the standard mo del of querying in relational

databases and is in a sense more declarative than tupleoriented execution In

contrast tupleoriented execution adds another degree of nondeterminism to the

language since the outcome maynow dep end on the order in which individual

rule instances are red

Finally several coupling modes have b een prop osed which describ e the re

lationship b etween rule pro cessing and database transactions Under immediate

and deferred coupling the triggering event as well as condition evaluation and

action execution o ccur within the same transaction In the former case the ac

tion is executed immediately after the condition has b ecome true while in the

latter case action execution is deferred to the end of the current transaction

Under decoupled sometimes called detached or concurrent execution mo de a

separate transaction is spawned for condition evaluation and action execution

Decoupled execution may b e further divided into dep endent or indep endent de

coupled in the former case the separate transaction is spawned only after the

original transaction commits while in the latter case the new transaction is

started indep endently In the most sophisticated mo dels one may even have

distinct coupling mo des for eventcondition coupling and for conditionaction

coupling

Systems Most of the active database systems provide a lowlevel procedural se

mantics of rules see eg WCaforanoverview on a numb er of systems Early

precursors of active rules havebeen intro duced in CODASYL System R and

t systems include Postgres Starburst Ariel Heraclitus ODE OPS More recen

and SAMOS HiPAC has b een inuential by establishing the ECArule paradigm

followon pro jects are Sentinel CKAK with its p owerful event sp ecication

language SNOOP and REACH Regarding commercial systems the current

SQL prop osal oers socalled declarative constraints used sp ecically for main

taining referential integrity and generalpurp ose triggers CPMISO

ARDL SK is closely related to deductive databases intensional relations

are dened by means of deductive rules Delta relations record the net eect of

changes to edb relations during execution of a transaction Active behavior is

enco ded via rules in an ifthen style

Chimera CFPT distinguishes b etween declarative and pro cedural expres

sions Declarative expressions are used in query primitives integrity constraints

and view declarations transactions are sp ecied using pro cedural expressions

for actions and declarative expressions in conditions

Pro duction Rules

Pro duction rules can b e viewed as ECArules without the event part However

pro duction rules have been around long b efore the ECA paradigm has b een

established In particular the pro duction rule language OPS BFKM has

b een used in the AI community since the seventies From a more abstract p oint

of view one can regard general ECArules also as pro duction rules since the

event detection part can b e enco ded in the condition This abstraction is very

useful as it allows to apply techniques and results develop ed for pro duction rules

to active rules

Acharacteristic feature of pro duction rule semantics is the forward chaining

execution mo del The conditions of all rules are matched against the current

state From the set of triggered rules candidate set one rule is selected using

some conict resolution strategy and the corresp onding actions are executed

This pro cess is rep eated until there are no more triggered rules

In the database community such a forward chaining or xpoint semantics

has been studied for a number of Datalog variants see eg AV thereby

providing a logicbased formalization of pro duction rules

Let Datalog denote the class of Datalog programs which allow negated atoms

in rule b o dies The inationary Datalog semantics IDatalog turns the well

known immediate consequence op erator T develop ed for denite logic pro

P



grams into an inationary op erator T bykeeping all tuples whichhave b een

P



derived b efore ie T I IT I where I is the set of ground atoms

P

P

derived in the previous round Starting with a set of facts I the initial state



T is iterated until a xp oint the nal state is reached Since the computation

P



is inationary deletions cannot be expressed directly In contrast Datalog

has a noninationary semantics by allowing negative literals to o ccur also in

the head of rules and interpreting them as deletions if a negative literal A

is derived a previously inferred atom A is removed from I If b oth A and A

are inferred in the same round several options exists prioritymaybegiven ei

ther to insertion or to deletion or a noop may b e executed using the truth

alue of A from the previous state or the whole computation may b e ab orted v

Via While for IDatalog termination is guaranteed this is no longer the case

of Datalog it is undecidable whether a Datalog program reaches a xp oint

for all databases moreover conuence is no longer guaranteed if instead of the

presented semantics a nondeterministic semantics is used AS On the other

hand nondeterminism can b e a p owerful programming paradigm which increases

the theoretical and practical expressiveness of a language AVGGSZ

For eciency reasons however the distinction b etween events and conditions may

b e crucial in practice



Another noninationary semantics called PDatalog is obtained by only keeping the

newly derived tuples in each iteration see also Section

A problem with these pro cedural Datalog semantics is that the handling

of negation can lead to quite unintuitive results

Example Under the inationary semantics the program

tcXY eXY

tcXY eXZ tcZY

non tcXY tcXY

tc the complement of the transitive closure of a given do es not compute in non

edgerelation e The reason is that the last rule is applied to o early ie b efore

the computation of the xp ointfortc is completed Thus despite the fact that

the derivation of non tcxy maybeinvalidated by a subsequent derivation of

tcxy this unjustied tuple remains in non tc

Although the given program may be rewritten using a somewhat intricate

technique for delaying rules a b etter solution is to use one of the declarativese

mantics develop ed for logic programs whenever the use of negation is imp ortant

see Section

RDL KdMS is a deductive database language with pro duction rule se

mantics a rule algebra is used as an additional control mechanism ARDL

SK extends RDL by active database concepts in particular delta relations

and a mo dule concept

Deductive Rules

The logic programming and deductive databases communities have studied in

depth the problem of assigning an appropriate semantics to logic programs with

negation and have come up with nowwellestablished solutions The stratied

wel lfoundedandstable semantics ABWVGGL are generally accepted

as intended and intuitive semantics of logic programs with negation For strat



ied programs like the one in Example all three semantics coincide For

nonstratied programs the wellfounded semantics yields a unique threevalued

mo del whereas the stable semantics consists of a p ossibly empty set of two

valued stable mo dels each of them extending the wellfounded mo del

For relational databases ie nite structures termination and conuence of

declarative rules can b e guaranteed For example under the stratied semantics

rules are partitioned into strata according to the dep endencies between rule

denitions Thus the strata induce a partial order on rules which is used to

evaluate programs Within each stratum the rules are red simultaneously in

a setoriented way Since the computation within strata is monotonic the rules

may also b e evaluated in arbitrary order andor tupleoriented within a stratum

without sacricing conuence Termination is guaranteed since it is not p ossible

to add and removethe same fact rep eatedly as is the case for Datalog and

noninationary Datalog



A program is stratied if no relation denition negatively dep ends on itself thus

there is no recursion through negation

In principle although Datalog is primarily a it could be

used as a relational up date language for example byinterpreting relations like

old R and new R as the old and new values of a relation R resp ectively or

by assuming that R R etc refer to dierent states of R However such an

approach has several drawbacks First part of the semantics is enco ded into

relation names and thus outside of the logical framework More imp ortantlythe

language do es not incorp orate the notion of state which is central to up dates

and active rules In particular only a xed numb er of state transitions can b e

mo deled by priming relation names as describ ed ab ove

Anumb er of deductive database prototyp es with declarative semantics exist

including Aditi Coral FLORID GlueNail LDL LOLA and XSBProlog cf

RHMinSP

Formal Approaches to Active Rules

Whereas the meaning of deductive rules is based on solid logical foundations

the meaning of the more lowlevel and op erationally intricate active rules is

often hard to understand and predictesp ecially if the semantics is only given

informally This has lead to numerous research towards formal foundations of

active rules In the sequel we discuss some of these approaches due to lackof

space and the fo cus on logicbased approaches we can only provide a rough and

necessarily incomplete summary

Analysis of Rule Prop erties

Although there is a great variety of execution mo dels for active rules certain

fundamental prop erties like termination and complexity come up rep eatedly and

have b een studied in the context of the resp ective execution mo dels

Termination Conuence and Determinism AWH develop static anal

ysis techniques for active rules which guarantee termination conuence and ob

h program pro duces a unique stream of servable determinism ie whether eac

observable actions under the Starburst execution model Rule analysis is based

on a triggering graph whichcontains an edge b etween rules r and r if the for

i j

mer may trigger the latter Termination is guaranteed if the triggering graph

is acyclic conuence is guaranteed if all unrelated rules commute pairwise Re

lated work on static rule analysis using triggering and dep endency graphs or

techniques from term rewriting include ZHBWBCPKCKU

ExpressivePower and Complexity PV develop a generic formal frame

work for the sp ecication of active databases A trigger program consists of rules

of the form condition action where condition is a rstorder sentence and

action is an external program Eac h rule is assigned a coupling mo de either

immediate or deferred and a set of database events insertion deletion on

which it reacts It is assumed that a priority is assigned to rules and that the

semantics is deterministic Existing active database prototyp es can b e obtained

by sp ecializing certain parameters of the framework which allows to compare

their relative expressiveness Moreover the impact of active database features

on expressivepower and complexity is studied In the presented framework the

complexity of immediate triggering is essentially EXPTIMEeven without delta

relations and PSPACE if there is a b ound on the nesting of immediate queues

Deferred triggering is more expressive and captures PSPACE EXPSPACEor

all computations on ordered databases dep ending on the allowed op erations for

queue management

LogicBased Formalizations of Rule Semantics

Whereas the ab ovementioned works fo cus on analysing rule prop erties in some

sp ecic execution mo del a lot of research aims at formalizing and characterizing

the semantics of active rules in the rst place Once a formal mo del has b een

established abstract prop erties like termination or expressiveness can b e studied

Situation Calculus Based In BLBLT a language L for active

activ e

rules is develop ed which allows to formalize and reason ab out the b ehavior of

active rules The language b orrows from L BGP an extension of the ac

tion description language A GL used for mo deling actual and hyp othetical

actions and situations which in turn is based on the situation calculus The

main constructs of L are causal laws describing which uents are added

activ e

or deleted by an action executability conditions stipulating when actions can

b e executed and active rules dening a triggering event an evaluation mo de a

conjunctive precondition and a sequence of actions The automatonbased se

mantics of L uses transition diagrams with states lab eled bysetsofuents

activ e

and transitions lab eled by actions to sp ecify the meaning of an active database

description in L A translation of L into logic programs is presented

activ e activ e

using a situation calculus notation The generated rules are nonstratied and

the choice op erator of SZ which is based on stable mo dels is used for nonde

terministically selecting one rule among all rules that may b e red in a situation

Like the situation calculus L fo cuses more on reasoning ab out the eect of

activ e

actions than on the computationally easier task of executing them

StateOriented Datalog Extensions By extending Datalog with a notion of

state reactive pro duction rules and deductive rules can b e handled in a unied

way therebycombining the advantages of active and deductive rules Twosuch

closely related Datalog extensions are XYDatalog ZanZanMZ and

Statelog LHLLML see KLS for an early precursor of the latter The

sp ecication of op erational asp ects like comp osite event detection and coupling

mo des is p ossible in the logical language since the rules allow access to dierent

database stateseven complex execution mo dels for nested transactions can

be handled in this wayasshown in detail for Statelog in subsequent sections

However the more pro cedural asp ects are intro duced into the language the more

intricate the representation of these features in the logical framework b ecomes

XYDatalog and Statelog are themselves closely related to Datalog Choa

S

a query language for temp oral databases

LogicBased Formalization of Op erational Semantics In FWP a

framework for the integration of the dierent operational semantics of active

and deductive rules is develop ed The meaning of ECA rules is sp ecied using

distinct sp ecication languages for events conditions and actions resp ectively

The op erational semantics for these ECA sublanguages and their interplay is

formalized by means of deductive rules More precisely the database history

ie the ordered set of database states is mo deled using timestamp ed atoms

and the meaning of events conditions and actions is dened based on the event

calculus in Kow The approach has b een used for the formalization of the

active rule comp onent which is added to the deductive ob jectoriented database



system ROCK R OLL BFP

In contrast to Statelog and XYDatalog whichprovide a single uniedlan

guage for active and deductive rules FWP integrate the dierent operational

semantics of active and deductive rules using a common deductive sp ecication

formalism

Another approach to logicbased formalization of active rule semantics is pre

sented in FT where socalled Extended ECA rules are used to enco de the

op erational semantics of an ADB Using these userreadable EECA rules exist

ing ADBs can b e compared and classied The precise meaning of EECA rules

is obtained by translating them into a logical core language which sp ecies pro

cedural details likeevent consumption coupling mo des etc Unlike in Statelog

this logical language is not meant to b e handled by the rule programmer but is

considered as an internal representation whichisusedby the execution mo del

and thus is on a lowerlevel than the EECA rules

Pro duction Rule Semantics Many approaches to active rules are based on a

forward chaining execution mo del in the style of pro duction rules eg AWH



ve This is particularly true also for the PARK PV and ZanLHLabo

semantics of active rules GMS which can be conceived as an inationary

xp oint semantics extended by a mechanism to handle up date literals L and

L denoting insertion and deletion of L resp ectively Similar as in Statelog

Section up date literals corresp ond to events if they o ccur in the b o dyand

to actions if they o ccur in the head A main b enet of the approach is the simple

and precise semantics with its exible conict resolution p olicy the latter b eing

a parameter to the PARK semantics The Statelog approachalsoallows exible

conict resolution p olicies however they are not treated as a black boxas in



Due to their declarative semantics with explicit states the latter may also b e eval

uated topdown say in XSBProlog SSW however the b ottomup view is more

natural in this context

GMS but can b e programmed within the logical rule language Section

and Lud

Up date Languages vs Active Rules

Since active b ehavior can b e sp ecied by dening new up dates as an automatic

resp onse to previous up dates active rule languages and languages for up dates

share essential features A prominent logical framework for up dates is Transac

tion Logic T BK a language that deals on a high level of abstraction with

R

the phenomenon of state change in logic databases The fo cus is on the comp osi

tion of complex up dates whereas primitive up dates socalled elementary tran

sitions are not part of T but regarded as parameters which are supplied bya

R

transition oracle In T like in most languages based on topdown evaluation

R

up dates are expressed in the body These approaches are often tupleoriented

so the sp ecication of setoriented up dates bulkup dates b ecomes an issue

WF present an up date language based on deferredupdates whichsolves this

problem Other wellknown approaches in the deductive database community

subsumable under the up dates in the b o dy paradigm are the early works on

DLP MW based on dynamic logic and LDL up dates NT In con trast

frameworks with semantics similar to pro duction rules typically express up dates

in the head of rules cf Sections and A main dierence b etween up date

languages and active rules is that in the former up dates are initiated explicitly

by the user whereas the latter sp ecify how rules initiate up date transactions

automatically in resp onse to o ccurring events

Bibliographic Notes

A go o d starting p oint for further reading is WCa whichcontains a nice in

tro duction to active rules WCb and describ es the essentials of a number of

prototyp es DHW is another intro ductory text Cha contains a sp ecial



issue on active databases PDW discusses dimensions of active behavior

such as structure and execution mo del of active rules whichallow to examine

and classify ADBs according to their distinctive features FT contains an

other classication of ADBs the dierent p ossible options in rule b ehavior are

enco ded using Extended ECA rules expressing the ab ovementioned semantic

dimensions which are then translated into an internal core language PCFW

surveys work on formal sp ecication of active database functionality DGG

presents the active database management system manifesto In Day a survey

on the accomplishments of research in active databases is given The workshops

WC and BH were dedicated particularly to active rules the workshop

series PWSelGB also has ma jor sections on active rules

Extending Datalog with States Flat Statelog

Although there has been lot of work in active databases no single generally

accepted framework for active rules has evolved the ECA paradigmthough

widely used and acceptedonly gives avery rough idea of rule execution and

leaves most issues unresolved The semantics of active rules is often dened

only in an informal and pro cedural way making it very dicult to understand

and predict the behavior of rules Not surprisinglyit is required in the active

database manifesto DGGthat rule execution must have a clear seman

tics ie must dene when how and on what database state conditions are

evaluate d and actions executed

In the sequel weintro duce Statelog a logical framework for active rules which

precisely and unambiguously denes the meaning of rules Moreover it allows

to study fundamental prop erties of active rules like termination conuence and

expressivepower The framework do es not account for all facets of activerules

which may be useful in practice eg tuplelevel execution but covers many

essential features including immediate and deferred execution and comp osite

events

In this section we present at Statelog which is based on a linear state

space and corresp onds to a at transaction mo del Using a hierarchical state

space a framework incorp orating nested transactions is develop ed in Section

For simplicity of presentation we p ostp one a detailed description of the signa

ture delta relations control relations etc to Section the intended use of

relations will b e clear from the context

Basic Execution Mo del

The basic execution mo del of Statelog is illustrated in Figure States are iden

tied b y the natural numbers IN thek th nal state is denoted by f IN

k

Assume f is the current nal state of the database The database remains

i

in this state as long as no new external events o ccur Queries are executed

against f and mayinvolve base relations derived relations ie lo cal views on

i

the current state or historical information using certain auxiliary relations

see Section Observethatintermediate states are depicted as small circles

whereas bigger circles corresp ond to nal states ie which are materialized

and directly accessible to the user External actions corresp ond to outputs of

the active rule program and are rep orted at nal states As describ ed b elow a

of sets of stream of incoming external events is conceived as a sequence E E



events which induces i a sequence of transactions b etween uservisible nal

states f f and ii a stream of outgoing external actions A A

 

The simultaneous o ccurrence of a set of external events E is mo deled by

i



asserting at the ith nal state f a nite set of facts

i

E ff ex j event ex has o ccurredg

i i



For clarity relations for external events input and external actions output



are prexed with and resp ectively states are often bracketed s

In general using this new seed information the rules of a Statelog program

dene a sequence of intermediate transitions

f  f  f   f k f

i i i i i

until the transaction starting at f ends in the next nal state f Events

i i

o ccurring b etween f and f are mapp ed to the new nal state f It should

i i i

b e clear from Figure that the logic mo del of P D E E where D

 k

denotes the initial database is addonly ie past states cannot b e changed

and new events inuence only the current and future states Systemdened

predicates BOT and EOT can b e used to distinguish b etween the dierentkinds

space or temporal domain over which the of states In this mo del the state

database evolves is isomorphic to the natural numb ers IN ie a linear time

mo del is used Another more general mo del is presented in Section

incoming

E E E

 i

external events

Classication of states

state BOT EOT

initial true false

f f f f

i i

intermediate false false

BOT EOT EOT EOT

BOT BOT

true true past nal

actual nal false true

outgoing

  

A A A

 i

external actions

Fig Mapping of external events to nal states and classication of states

Syntax

In Statelog access to dierent database states is accomplished via state terms of

the form S k where S k denotes the k fold application of the unary function

symbol to the state variable S Since the database evolves over a linear

state space S may only b e b ound to some n IN

A Statelog database D k at state k IN is a nite set of facts of the form

k px x where p is an nary relation symbol and x are constants from

n i

the underlying domain If k or is understo o d from the context wesimply

write D

A Statelog rule r is an expression of the form

H S k B S k B S k

n n 

where the head H is a Datalog atom B are Datalog literals atoms A or negated

i

atoms A and k IN Theleap l k k of B is the distance b etween the

i i  i i

state referred to in the head and the state for B in the b o dyIfseveral literals

i

share the same state term S k then S k can b e factored out eg the

body S B S B S B may b e abbreviated as S B S B B

   

We require that Statelog rules are progressive since the current state cannot

be dened in terms of future states nor should it be p ossible to change past

states A rule r is called progressiveifk k for all i nIfk k for

 i  i

all i n then r is called local and corresp onds to the usual query rules

On the other hand if k and k for all i r is called progressive

 i

and denotes a transition rule A Statelog program is a nite set of progressive

Statelog rules

Semantics

Every Statelog program may b e conceived as a standard logic program by view



ing the Statelog atom S k pt t assyntactic sugar for pS k t t

n n

In this way notions eg local stratication and declarative semantics eg per

fect model M develop ed for deductive rules can b e applied directly to Statelog

P

Here we adopt the statestratied semantics as the canonical mo del of a

Statelog program P with database D P is called statestratied if there are no

negative cyclic rule dep endencies within a single state LHL More precisely

statestratication is based on the extended dependency graph G of P Its no des

P

l

are the rules of P Given tworules r r there is an edge r r G if the

  P

relation symb ol in the head of r o ccurs p ositively negatively in the b o dy of

r Here l is the leap of the corresp onding literal in r P is statestratied

 

P

if G contains no local cycle C ie where l involving a

l

P

r C r

negative edge This notion is closely related to XYstratication Zan and

ELSstratication KRS Together with the requirement of progressiveness

statestratication implies lo cal stratication Lud

Theorem StateStratication

Let P beaconstantfree and progressive Statelogprogram Then

P is statestratied P is local ly stratied

Thus if P is lo cally stratied there exists a unique perfect model M Prz

P D

for any Statelog database D D

Example Consider the follo wing progressive Statelog program whichdeletes

all employees E from a department D which is deleted

empESalD r S delempESalD S deldeptD

r S empESalD S empESalD delempESalD



On o ccurrence of a delete eventtodept r checks whether there is an employee

E working at department D and if so this employee is put in a sp ecial delta

relation delemp cf Section r is a frame rule sp ecifying that only those





Here p denotes anytyp e of relation base control see Section



See Section for a mo deltheoretic Kripkestyle semantics

tuples are copied to the instance of emp at the next state which are not in

delempThus logically no real deletion o ccurs but a smaller copy of the old

database state is created Note that although the program is not stratied it is



statestratied since the negative cycle r r r is not lo cal ie do es not

 

o ccur within a single state

Note that statestratication do es not imply lo cal stratication for non

progressive rules hence the progressiveness requirement in Theorem

Example NonProgressive Rules The program

P S p S p

is statestratied since it contains no lo cal cycle However the truthvalue of

n p dep ends negatively on the unfounded sequence n n soP is

not lo cally stratied in the wellfounded mo del p is undened

Comp osite Events

Although the Statelog language is surprisingly simple various kinds of comp osite

events and consumption mo des can be expressed as shown in MZ using a

closely related variant of Datalog Assume for instance that wewant to detect

S

the comp osite event

E X Y F X GY

ie F X followed by GY for some external or internal events F and G

Under an unrestrictedcontext this can b e expressed by temporal reduction rules

similar to LSChob

S detdF X S F X

S detd F X S detdF X

S detd E X Y S detdF X S GY

Auxiliary relations detd R store detected events Using slight mo dications of

these rules dierentevent consumption mo des can b e accomplished

If one adds the goal F to the second rule only the most recent o ccur

rences of F are used thereby mo deling event consumption with recent context

Note that in this variant the most recent o ccurrence of F can take part in several

o ccurrences of E However if F and E are added to the second rule

then every o ccurrence of E consumes all constituentevents so F can takepart

only in one o ccurrence of E

Under the chronicle contextevents are pro cessed in a rstinrstout man

ner and thus make use of a queue in an essential way Therefore one can show

see Lud that comp osite events with chronicle contexts are not expressible

in pure Statelog and require appropriate extensions eg timestamping as in

MZ

Formal Results

Using Statelog as a unied logical language for active and deductive rules allows

to study abstract rule prop erties like termination expressivepower and com

plexity see also Section Here we only sketch the main results see LLM

and Lud for details

For notational convenience we do not distinguish b etween base relations and

external events b elow but assume wlog that a Statelog database D k includes

the set of external events o ccurring in state k as a set of facts

Termination We say that a Statelog program P terminates for D if the

sequence of database states induced by P and D b ecomes stationarymore

precisely if for some n and all n n M n M n where the

  P D P D

n at state n of the p erfect mo del M is dened as snapshot M

D P D P

M n fpx j M jn pxg

P D P D

If P terminates for D then M is used as a generic notation for the unique

P D

nal state otherwise we agree to set M

P D

Let Term denote the set of pairs P D such that P terminates for D

PD

Term and Term denote the set of Statelog programs which terminate

D P D P

for some and al l databases D resp ectively Then one can show Lud

Theorem Termination Term and Term areundecidable

D P D P

Term is PSPACEcomplete with n jD j

PD

Term can be decided using a Statelog program P which i terminates

PD

for al l D and ii is eectively constructible from P

Note that means in a sense that Statelog programs allow to sp eak ab out

their termination b ehavior at runtime ie for given D However since testing

for termination may b e prohibitively exp ensive it is desirable to identify ecient

classes of terminating programs

One such class is GStatelog guarded Statelog where each up date rule is

required to have a p ositive o ccurrence of an external eventinthebodythereby

guaranteeing that such rules can be applied only once at the b eginning of a

transaction Another more p owerful class is Statelog monotonic Statelog

here the basic idea is to enforce termination bypreventing oscillation of up dates

ie rep eated insertion and deletion of the same tuple Since Statelog programs

op erate on nite structures the corresp onding constructions guarantee termina

tion in PTIME

Dierent Rule Semantics in Statelog As shown ab oveandin Section

Statelog allows to handle typical features of active rules at the right end of the

sp ectrum in Figure like comp osite event detection and reactive programming

of up dates Moreover several of the more declarative languages in the middle

and further to the left of the sp ectrum turn out to b e special cases of Statelog

rules

Production rules Let IDatalog and PDatalog denote the inationary and

noninationary or partial semantics for Datalog resp ectively

Deductive rules The declarative semantics for Datalog programs are de

noted by SDatalog stratied Datalog and WFDatalog wellfounded Dat

alog resp ectively

These semantics have a very natural representation in Statelog Lud see

Figure Observethat the noninationary PDatalog semantics only transfers

those tuples to the new state which are derived anew In contrast the ina

tionary IDatalog semantics propagates all previously derived tuples through all

states SDatalog rules can b e represented directly by lo cal statestratied rules

Finally one way to represent the alternating xp oint computation VG of

WFDatalog is as shown in Figure this enco ding yields a terminating pro

gram i the wellfounded mo del is total however using a doubled enco ding

it is easy to obtain a program which explicitly computes the true false and

undened atoms and always terminates

S H S B S C PDatalog

IDatalog S H S B S C

S H S H

H B C

SDatalog S H S B S C

WFDatalog S H S B S C

Fig Enco ding schema for dierent rule semantics

Expressive Power and Complexity With every Statelog program P one

can asso ciate dierent database mappings The most imp ortant one describ es

the transaction expressiveness ie the mapping D M from

P D

P

the initial database state to the nal state

A natural question is What kind of database mappings can be expressed

using Statelog wrt transactions For languages involving intermediate states

expressiveness like XYDatalog and Statelog one can also consider transition

ie the class of database mappings from one state to the immediate successor

state

Figure summarizes the main results wrt transition and transaction ex

pressiveness In the middle wellknown classes of database transformations are

depicted cf AHV To the left and right the equivalent wrt transitions

and transactions resp ectively Statelog variants are depicted

Transition Expressiveness Transaction Expressiveness

All

fPjNFjWFjgStatelog

While

XYDatalog

WFStatelog

Fixp oint

fIjgStatelog

fGjjNFjgStatelog

SDatalog

GStatelog

FO

XYDatalog

Datalog

FO

fPjIgStatelog

posFO

Conjunctive

DBPSPACE

Data Complexity

DBPTIME

Fig Summary of expressiveness results Lud

WFStatelog is a Statelog variant where rules need not be stratied but

mayinvolvewellfounded negation G NF P I and Statelog denote

guarded monotonic normal form noninationary inationary and unre

stricted Statelog resp ectively LLMLud In NFStatelog for example rules

mayonly be progressiveor lo cal The expressiveness results in Figure can

be established using rewritings into NFStatelog and the ab ove enco dings of

dierent Datalog semantics The nice matchbetween Statelog classes and the

known query classes also yields the corresp onding complexity results Statelog

transitions are always evaluable in PTIME whereas transactions may require

PSPACE in general An ecient ie PTIMEevaluable class of transactions

is given by Statelog a class of terminating Statelog programs whichunlike

inationary languagesallows b oth insertions and deletions

Nested Transactions in Statelog

The Statelog programs considered so far dene a single transaction from the

current state to the new nal state for anygiven database which includes a set

of external events External events o ccurring subsequently corresp ond to new

facts b eing added and initiate the next transaction Thus the Statelog execution

mo del depicted in Figure corresp onds to a at transaction mo del In the se

quel we showhow Statelog can b e extended to mo del nestedtransactions With

nested transactions Statelog provides a unied framework for mo deling several

advanced concepts in active databases eg sophisticated coupling mo des event

consumption p olicies and trigger ring p olicies

The following example adapted from MWChe motivates why struc

turing capabilities and a rened transaction mo del may b e useful

Example To Hire or Not to Hire

Consider relation emp from Example We want to hire an employee only if

the average salary after the up date do es not exceed a certain limit Such a

p ostconditional up date may b e expressed in at Statelog as follows

S insempESalD S checksalD S hire if p ossibleESalD

S check ok S checksalD avgD AvgSal AvgSal

S delempESalD S hire if p ossibleESalD S check ok

On o ccurrence of the external event hire if p ossibleESalD employee E is

preliminarily inserted and the new average salary is checked in S If it

exceeds the admissible amount the insertion is undone by the last rule

The ab ove program sp ecies the desired transaction yet there are some p otential

pitfalls and drawbacks with this solution

Undoing the eect of changes here the comp ensation of insertions by corre

sp onding deletions has to b e programmed by the rule designer However it

is often desirable to automatical ly propagate the failure of a subtransaction

like checksal

There is no structure whichallows grouping of semantically closely related

rules

The eects of ephemeral changes Zan ie changes whose eect is undone

later within the same transaction and hypothetical changes are visible to

other rules since there is no encapsulation of eects of semantically related

rules Eg if hire if p ossible o ccurs in S the delete request insemp

may trigger other active rules although in S the up date is revoked This

may lead to unjustied reactions by other rules similar to those describ ed

in Zan

To avoid these problems the transaction concept considered so far has to be

rened First sp ecic systemdened rules can be used to automatically undo

the eect of failed transactions Moreover the second and third item can be

resolved by grouping rules into certain mo dules which encapsulate rule eects

In principle a at transaction mo del would be sucient here However it is

often natural and more adequate to mo del certain tasks as subtransactions which

For simplicitywe view the predicate holding the average salary avgDAvgSal of a

department D as a builtin

are nested within the calling transaction For example hireESalD maybea

subtransaction of a toplevel transaction main the salary checkinturnmaybe

a subtransaction of hire see Example

Hierarchical State Space

In order to mo del nested transactions and handle the problems describ ed ab ove

LML prop ose the concept of Statelog procedures A Statelog pro cedure is

a named and p ossibly parameterized set of Statelog user rules In this sense the

at Statelog programs considered so far can be seen as parameterless anony

mous Statelog pro cedures When is called at runtime it denes a transaction

T by issuing primitive up dates through delta relations andor calling other

pro cedures whichinturnmay dene subtransactions etc T either terminates

successfully indicated by a sp ecial predicate committed or ab orts When

calls another pro cedure a subtransaction T is started whose results are either

incorp orated into T ifT commits or discarded otherwise From the p ointof

view of the calling transaction T the subtransaction T is atomic therefore

requests derived directly within T and those submitted by T should b e indis

tinguishable This is achieved by certain systemdened rules

The b ehavior of is encapsulated since deltas dened by T are only visible

within T but not in other concurrent transactions Subtransactions execute

in isolation and in an al lornothing manner ie no results of T will b e visible

in T if T ab orts Note that this do es not mean that T also ab ortson the

contrary can detect the failure of T via ab orted and issue alternativeor

comp ensating actions or retry the execution of later

In order to mo del the isolated execution of a Statelog pro cedure as a

subtransaction T a unique name space for each parameterized invo cation

of x has to b e intro duced This is accomplished by extended state terms and

frame terms The latter provide the tr ansaction frame in which executes

The execution of Statelog pro cedures as nested transactions induces a hier

archical structure of the state space instead of the linear structure considered

b efore cf Figure Every state term enco des the complete transaction hierar

chy from the toplevel transaction down to the current transaction States on the

same level are group ed into transaction frames The mo deltheoretic foundation

of this concept is given by Kripke structures with dierent accessibility relations

see Section

Given a xed set of pro cedure names of a Statelog program the set of

state identiers S and frame identiers F are dened as the least sets such

that

F

fn S iff F and n IN



ifs S and x U s x F

S

i

U U

iIN

n

m

m

k

Fig States and frames

Here the arity of matches that of x x x and U is the underlying

k

domain State terms and frame terms are dened similarly but may also involve

variables State and frame identiers induce a hierarchically structured state

space The initial frame denotes the toplevel transaction its initial state is

Let s denote the current state Then for a pro cedure call x the frame

of the subtransaction induced by the execution of x isf s x and the

rst state of the transaction is f s x The successor state of fn

on the same levelisfn The grouping of states into a frame f F

is dened as

f f fn j n IN g

which implies that every state fn b elongs to exactly one frame f Using this

representation the frames s x and sy induced by dierent parallel

pro cedure calls of and in the same state s can b e uniquely identied if the

name of the pro cedure is the same at least the parameters are dierent Sim

ilarly frames of transactions induced bythesame procedurecal l from dierent

statess x and s x can also b e distinguished The constructor is



leftasso ciative eg s s s s

 

Signature

In order to mo del the sp ecic features of active rules weintro duce several typ es

of relations their precise semantics and interplaywill be sp ecied by system

dened Statelog rules b elow The set of relation symb ols of a given schema R

is given as the disjoint union of the following sets



R ctl R R edb R idb R R R R prot R

Base and Derived Relations The extensional database edb R comprises

the base relations which are stored in the database In userdened rules edb

relations may only o ccur in the b o dy they are up dated via delta relations from

R In contrast derived relations belong to the intensional database idb R

and dene views Thus idb relations may o ccur in rule heads and b o dies but

may not be changed directly Typically idb relations are not materialized but

computed on demand

External Events and Actions Relations from R represent external events

of interest which are monitored by the ADB Consequently external events can

only o ccur in rule b o dies External actions are dened by the relations from



R and represent requests to execute certain actions outside the ADB system

Relation symb ols denoting external events and actions are prexed with the



symb ols and resp ectively

Delta Relations For every base relation p edb R there are delta relations

delp insp R Delta relations or just deltas denote up date requests to

delete or insert the corresp onding tuples into p resp ectivelyFor simplicitywe

write mo dpxy instead of delpx ins py

Pro cedure Calls R denotes the set of procedure names A pro cedure

with parametersx is called by deriving x in the head of a rule

Proto col Relations For every base relation p edb R there are protocol

relations deldp insdp prot R for ins erted and deleted resp which store

the accumulated net eect of a sequence of up dates They can b e used for sev

eral purp oses eg to enforce termination as an auxiliary store for ab orting

transactions or for returning the net eect of a subtransaction Lud

Note that from the ab ovementioned relations only those from idb R R



R and R are userdenable the relations from edb Randprot Rare

maintained by the system

Control Relations ctl Rcontains sp ecial control relations like BOT EOT

running and ab ort for transaction control and auxiliary relations for the detec

tion of comp osite events Additionally ab orted x orcommitted x indicate

if a subtransaction has b een ab orted or committed

UserDened vs SystemDened Rules

In the Statelog core language there is no distinction between userdened and

systemdened rules eg the program given in Example explicitly contains

the frame rule r However an ADB system should provide the user with a



predened intuitive programming environment which takes care of lowlevel

asp ects of the execution mo del like frame rules and transaction control In par

ticular one may hide the explicit handling of states from the user by forcing

her to use only lo cal rules If the user really needs to refer to dierent states

syntactic sugaring in the form of predened op erators can b e used Example

UserDened Rules

We require that all userdened Statelog rules are lo cal thus state terms may



b e omitted Moreover only relations from idb R R R R and cer

tain distinguished relations from ctl R are allowed to o ccur in rule heads of a

user program For example the usual integrity constraints from databases like

functional join and inclusion dep endencies can b e enco ded in the form of de

nials ie as a set of lo cal rules st ab ort is derived by these rules if an integrity

violation is detected

nite collection of Programs and Pro cedures A Statelog program is a

Statelog pro cedures A Statelog procedure is an expression of the form

pro c X X fH B H B g

n k k

where X X are the parameters of whichmay o ccur in the Statelog user

n

rules H B Every program contains a distinguished pro cedure main

i i

As in the case of at Statelog the meaning of rules is given by the declarative

semantics of their representation as a logic program Esp ecially if rules are lo cally



stratied a unique p erfect mo del exists

Dep ending on the relation symb ol in the head of a rule the following cases

can b e distinguished

Views pX if p idb R

Change Requests inspX if insp R

delpX if delp R

Procedure Cal ls X if R

  

External Actions aX if a R

Transaction Control ab ort

External events are allowed only in the b o dy of rules of main whereas actions

may o ccur in all pro cedures but are only allowed in rule heads Since edb

relations are not directly userdenable all changes to base relations havetobe

accomplished through insert and delete requests The materialization of these

requests is implemented by frame rules as describ ed b elow



A logic programming semantics for Statelog with nested transactions is presented

in LML Note that in order to guarantee lo cal stratication also dep endencies

through subtransactions have to b e considered

Visibility of UserDened Rules Let P denote the userdened rules

of a pro cedure Apart from P the visible userdened rules P S x in

frame S x include idb relations of the calling transaction

Denition The set of visible rules P F of a frame is dened as

P P main

P F n x P fp B P F j p idb Rg

for all n IN R



Thus idb relations are communicated to subtransactions by passing their den

ing rules whereas edb relations are communicated to subtransactions bycopying

their extensions into the initial state of a subtransaction

SystemDened Rules

Systemdened frame and pro cedure rules implementtheintended semantics of

request relations proto col relations and pro cedure calls All changes are encap

sulated within the current transaction frame and invisible everywhere else until

the transaction commits State terms are used in the sp ecication of transitions

and transaction management

Starting a Transaction If one or more external events ex o ccur the

b eginning of a transaction is signaled

S BOT S eX

We assume that all external events which are detected within a certain time

interval are raised only in the initial state of the toplevel transaction which

coincides with the nal state of the previous transaction All events o ccurring

subsequently are asso ciated with the next initial state

Frame Rules sp ecify the correct handling of up date requests and transitions

For all p edb R there are the following frame rules

S pX S inspX EOT

S pX S pX delpX EOT

Thus up dates to base relations are executed immediately in the transition to

the successor state unless the end of transaction is detected Clearly instead

of this immediate coupling b etween condition evaluation and action execution

one could also sp ecify deferred execution Then a dierent set of frame rules

accumulates delete requests and executes all of them at the end of transaction

Frame rules also propagate the edb to the subsequent transaction

S pX S inspX BOT

S pX S pX delpX BOT

Proto col relations insdp deldp prot R store the accumulated net eect of

changes during a transaction

S insdpX S inspX EOT

S insdpX S insd pX delpX EOT

S deldpX S delpX EOT

S deldpX S deldpX inspX EOT

While there are p ending change requests a transaction is running

S running S inspX pX

S running S delpX pX

A xp oint is reached when there are no more changes so EOT is signaled

S BOT running S EOT

S EOT S running ab ort S running

The internal event ab ort terminates a transaction prematurely

S EOT S ab ort

Apart from userdened ab orts a transaction ab orts if inconsistent requests are

raised

S ab ort S inspX delpX

Other conict resolution p olicies can also be easily sp ecied For example if

the previous rule is omitted the ab ove frame rules give priority to insertions

whenever insertions and deletions o ccur simultaneously Similarly if one adds

the goal delpX to the ab ove frame rules with inspX in the body then

deletions will have higher priority

Pro cedure Rules implement the semantics of pro cedure calls ie the execu

tion of subtransactions

For all Rp edb R there are the following rules

A pro cedure call creates the initial state of a new frame signals BOT and

initializes the edb relations

S X BOT S X

S X pY S pY X

The pro cessing of the results is implemented by rules checking the successful

termination of the subtransactions and evaluating their proto col relations Since

these contain the changes made by the subtransactions their extensions are

copied into the request relations of the parent transaction

N insdpY EOT ab ort S inspY S X S X

S delpY S X S X N deldpY EOT ab ort

Thus up date requests rep orted to the parent by are indistinguishable from

those derived directly provided commits ie EOT ab ort holds

Parent transactions also p erform some bookkeeping ab out committed and

ab orted subtransactions

S committed X S X S X N EOT ab ort

ab ort S ab orted X S X S X N EOT

The user can formulate applicationsp ecic asp ects of transaction management

eg that the parent transaction should ab ort if the child ab orts

ab ort X ab orted X

Serial Conjunction It is sometimes convenient esp ecially in the context of

pro cedures and nested transactions to provide the user with a sp ecial connective

denoting a serial version of conjunction To this end we dene

A A B B

 n  m

as a shorthand notation for the Statelog rule

S m A S mn A S runningS mn running

 n

S B S m B

 m

For example a rule of the form A A B where A and A are primitive

 

actions like insp delp or pro cedure calls informally means if B is true then

do A fol lowed by A Conversely the rule A B B intuitively says if

 

B was previously true and B holds now then do A



Examples

Example Hyp othetical Up dates In order to implement ahyp othetical

deletion of an employee we can use the rule

delempESalD insempESalD hyp del empE empESalD

del empE o ccurs employee E is removed from the database and im When hyp

mediately inserted afterwards If wewant to determine if E is an indisp ensable

employee ie one whose deletion would result in an unp opulated department

we can use the rule

insindisp ensableE hyp del empE empESalD emp D

The hierarchical transaction mo del allows a exible treatmentofseveral inter

esting features of databases like the following

The symbol isborrowed from BK where it denotes a similar connective

Static integrity constraints can be implemented by ab orting transactions

Example

Checking the admissibility of changes and blo cking inadmissible ones for

any fact px that should be guaranteed derive inspx Every request to

delete it causes an inconsistency

Ephemeral up dates every transaction can try some up dates check their

results and decide whether it should commit or ab ort Example

Hyp othetical up dates every transaction can work on relations which are

deleted b efore committing without having any eect at committime By

this it can create a hyp othetical scenario check the outcome and rep ort the

consequences This can b e used to ev aluate several alternatives in parallel

Finallywe are suciently equipp ed to revisit Example in the extended frame

work Observe that the problems of the at approachmentioned at the b eginning

of Section are resolved here

Example To Hire or Not to Hire Contd

We sp ecify the hire and checksal transactions by pro cedures

pro c main fhireESalD hire if p ossibleESalDg

pro c hireESalD finsempESalD checksalD BOT

ab ortab ortedchecksalDg

pro c checksalD fab ortavgDAvgSalg

Whenever hire if p ossible o ccurs a subtransaction hire is initiated Atthe

b eginning of transaction and only then hire adds the new employee followed

by a call to checksal If checksal ab orts then hire also ab orts resulting in an

unchanged database Otherwise hire commits and the insertion is realized The

following signatures are dened

edb Rfempg Rfinsemp delempg

prot Rfinsdemp deldempg Rfmain hire checksalg

ab ortedchecksal ab ortedhireg ctl RfBOT running EOT ab ort

Figure depicts the state space which is created when hirejohnd is

called and eventually ab orted since the average after the hyp othetical up date

exceeds

Frames are represented by shadowed b oxes states are represented by ordinary

boxes In all states the upp er entry denotes the state term the data b elowthe

rst horizontal line are facts which are derived by frame rules or lo cal rules and

the data below the second line if it exists are facts which are derived from

results of subtransactions

Example The ChristmasProblem

Consider a relation empE BirthDay Sal with the obvious meaning We want

to implement the following informally given pro cedure Every employee shal l be

given a salary raise by at her birthday on Christmas every employee shal l

get an extra This is accomplished in at Statelog as follows LHL

n

hirejohnd running

n n

ab ortedhirejohnd

nhirejohnd

nhirejohnd

emp johnd insdemp johnd

BOT

checksald

insempjohnd checksald

insempjohnd running

ab ortedchecksald ab ort EOT

nhirejohnd

nhirejohnd

checksald

BOT avgd ab ort EOT

nhirejohndchecksald 

Fig Frames and Database States

S mo dempEBdaySalSal

S dailydateDay DayBday empEBdaySal Sal Sal

S mo dempEBdaySalSal

S dailydateDay xmasDay empEBdaySal Sal Sal

These rules work ne unless there is some employee whose birthdayisonChrist

mas Then two inconsistent mo difyrequests are generated and the subsequent

state is not welldened In a at mo del the problem could b e solved by complete

case splitting or by a rule using three states however this raises the problem

that the intermediate state should not trigger other rules In the structured

mo del the sequential comp osition inc xmas inc bday can b e used by the top

level transaction incsal to sp ecify the order of execution

pro c main fincsalDay daily dateDayg

pro c incsalDay finc xmasDay inc bdayDay BOTg

pro c inc xmasDay fmo dempEBdaySalSal

BOTxmasDayempEBdaySal Sal Salg

pro c inc bdayDay fmo dempEBdaySalSal

BOT DayBday empEBdaySal Sal Salg

If inc xmasDay inc bdayDay were replaced by the simultaneous conjunction

inc xmasDay inc bdayDay then two conicting requests would b e derived and

the transaction would be ab orted automatically by the corresp onding system

dened rules

Using the nested transaction mo del dierent rule schemata for mo deling

certain coupling mo des event consumption p olicies and trigger ring p olicies

can b e dened therebyproviding a concise formal sp ecication of these features

Example Control Features Insteadtriggers can b e mo deled by replacing

a pro cedure call x by another call x when a call x is derived it is

discarded immediately and the call x is derived instead The pro cedure rules

from Section are mo died for every R as follows

S X BOT S X discard X

S X pY S pY X discard X

Now the insteadtrigger x instead of x is expressed by the lo cal rule

X discardX X

Before and aftertriggers can be mo deled as sp ecialized instances of instead

triggers based on serial conjunction Consider a trigger of the form before x

do x This can b e accomplised by the following rules contains the same

rules as

X discardX x

pro c X f X X BOTg

Other control features which can be handled include dierent event consump

tion mo des see Section and deferred instead of immediate coupling cf

Section

Op erational Semantics

The ab ove rule system denes a partial order on state identiers Within a

frame fn fm if nm additionallyfn f n k fn for

R and all k IN With the additional requirement on userdened rules

that there are no negative dep endencies from relations of R to any other

relation of the same state can serve as a base for computing the individual

database states as follows

compute fiedb R prot R from fi edb R R prot R

compute fiidb R R R

compute ff i xIN j fi x holdsg recursively

add the resulting requests from

ffixn prot R j fi x andfix n EOT holdsg to fi R

extend fiidb R R R based on the additions to fi Rfrom

step addonly since these relations do not dep end negatively on R

compute ff i xIN j fi x has b een derived in the previous stepg

iterate steps until a xp ointisreached

if not fi EOT pro ceed with step for i

Note that with the ab oveschema fiedb R prot R are computed once in

the rst step Therefore the database in the initial state fix of subframes

is identical for all subframes fix indep endent from the iteration step in

which the pro cedure call has b een derived

R

R R

Q

S

R

R R

S

Q

R

R R

Fig Hierarchical Kripke Structure

KripkeStyle Semantics

A conceptual mo del for Statelog with nested transactions is established using a

Kripkestyle semantics thereby providing states as rstclass citizens of the

logical framework State identiers are mapp ed to states of a Kripke structure

which formalizes the relationships b etween individual states in terms of accessi

bility relations The Kripke semantics yields an abstract and natural mo del of

the hierarchical state space and can serve as a basis for the sp ecication and

verication of prop erties of a database system Weshow that the rules given in

the previous section where states are reied ie enco ded into the language

are correct wrt the abstract Kripke semantics

Denition Statelog Kripke Structure A Statelog Kripke structure over

agiven Statelog signature R is a tuple K G U R Q S M P cf Figure

where

G is a set of states

U is the universe

R GG is an accessibility relation mo deling the temp oral successor relation

Q S G R U G are two lab eled accessibility relations b etween states

representing the pro cedurecall and return relation resp ectively

M is a function which maps every state to a rstorder interpretation over R

with universe U

P is a function which maps every g G to a set of lo cal rules the rules visible

in g

Here the Statelog Kripke frame G R Q S mo dels the relationships b etween

states and frames Every computation path g g in a Statelog Kripke struc



ture st Rg g for all i corresp onds to a frame in the hierarchical state space

i i

note that Rg g denotes that a subtransaction has reached a xp oint ie then

M g j EOT holds Q denotes the framesubframerelation ie Qg x g

means that the rst state of the subtransaction induced by a call of pro cedure

with arguments x is g S g x g means that g is the nal state of the

subtransaction induced by a call of pro cedure with arguments x in g Thus

results of subtransactions are communicated along S

The following characterization covers the intended semantics of the Statelog

frame rules

Denition A Statelog Kripke structure K G U R Q S M P over a

signature R is a model of a Statelog program P over R and an initial database

D if

U is the active domain of P and D

There is a g G st Mg j D andMg j and there

  

edb R prot R

g orRg g existence of an initial state is no g st Qg

 

External events are only mapp ed to the initial state of transactions on the

only if R g gand g g highest hierarchical level ie Mg j

 

R



or Mg j EOT

The relation R mo dels the temp oral successor relation ie

Rg h PhP g

and the following relationship between edb R and R in g and edb R

and prot Rinh holds

R g h for all p edb R

MhpMg p Mg insp nMg delp and

MhinsdpMg insdp Mg insp nMg delp and

MhdeldpMg deldp Mg delp nMg insp

and R is total ie for every g G there is a g G st Rg g

Q mo dels the subtransaction calls for all g G R u U

Mg j u there is an h st Qg uh

and Qg uh implies that Mh j BOT Mhj Mg j

edb R edb R

Mhj and

prot R

P hP fp B Pg j p idb Rg

S mo dels the returnfromsubtransaction relation

for all g g h G R u U

Qg ug andR g h andMh j EOT S h ug

For ev ery g G

Mg M Mg j Cg

P g

edb R prot R R

where C g is the set of requests which are contributed to g by subtransac

tions and communicated along S given as

C g inspfu j there are g G R v U st S g v gand

rt and u Mg insdpg Mg j ab o

C g delpfu j there are g G R v U st S g v g and

Mg j ab ort and u Mg deldpg

 

as usual R denotes the transitive closure of R

Prop osition In every Statelog Kripke structure which is a model of a Statelog

program P the fol lowing holds

The temporal successor relation R is deterministic modulo external events

for al l g h h G

Rg h and Rg h Mhj Mh j

Rn R Rn R

For every g G in a nontop level frame ie on a level where there are

no external events st Mg j BOT there is a unique computation path

g g g with g j EOT for al l in and g j EOT

 n i n

for every Statelogprogram P database D and sequence E E E of sets

 

of external events there is a unique Kripke model of P with an initial state

Mg M DE and a toplevel computation path g g st

 main  

Mg j EOT i ff f g f denotes the ith nal state see

i  i

Section in this case Mg j E

f i

i

S can also b e regarded as a relation describing the eects of subtransactions

For Rand u U

ug h G st h g S u

is the result of executing u in state g The relationship b etween Mg and

M ug is imp ortant for expressing correctness prop erties of subtransac

can be characterized in terms of the eects of the sub tions With this C g

transactions which are issued in g

C g ins pfu j there is a R v U stv Mg and

M y g j ab ort and u M y g insd pg

C g delpfu j there is a R v U stv Mg and

M y g j ab ort and u M y g deldpg

Equipp ed with a notion of states computation sequences and subtransactions

the semantics of the individual subsets of a Statelog signature cf Section

can b e describ ed in terms of state transitions and subtransactions

Theorem Adequacy Statelog Kripke structures areanadequate model of

the intended semantics of nested transactions based on the elementary actions

ins and del

R models the temporal successor relation

edb relations are changed exactly via requests for al l p edb R g h

R then G ifg h

MhpMg p nMg delp Mg insp

In al l states the protocol relations contain the nonrevoked changes of the

corresponding subtransactions For al l g h QR and al l p edb R

MhpMg p Mhinsdp nMhdeldp

Q models the subtransaction cal ls

In the initial states of subtransactions the edb is the same as in the

cal ling state and the protocol relations procedureknowledge are empty

The denition of the IDB in a subtransaction contains the denition of

the IDB in the cal ling transaction

S models the returnfromsubtransaction relation

For al l g h Gif S h g and Mh j ab ort then for al l p edb R

Mg insp Mhinsdp and Mg delp Mhdeldp

Internal semantics of states Perfect model of P g

Insertdelete requests are derived by userdened rules or contributedby

subtransactions

IDB and subtransaction cal ls are derived by userdened rules

The declarative semantics of the p erfect mo del of a Statelog program and the

op erational semantics given in Section for computing a Statelog mo del state

bystate coincide with the presented Kripke semantics

Statelog program P an initial database D Theorem Equivalence Fix a

and a sequence E E E of sets of external events For every Statelog



Kripke structure K G U R Q S M P which is a model of P there is a

partial mapping S G such that

dom fs j M js running EOTg ie the used states

P D E

For al l literals L over R M s j L i M js L

P D E

For every n IN fn dom P fn P f

Summary and Conclusion

Active rules extend the traditional passive database technology and are a p ow

erful programming paradigm with a large numb er of application areas While an

increasing numb er of systems b ecomes available and active rule programming is

carried out in real world applications theoretical foundations of active rules are

still rare In the rst part of the pap er wehaveintro duced the basics of active

rules and related them to pro duction rules and deductive rules resp ectively Af

ter discussing a numb er of formal approaches to active rules wehave elab orated

hintegrates active and deductive rules on a stateoriented logical framework whic

The underlying core language Statelog precisely sp ecies the meaning of a set

of active rules and allows to investigate fundamental prop erties like termination

and expressive power LLMLud Although the basic execution mo del of

at Statelog is relatively straightforward and corresp onds to at transactions

dealing only with immediate and deferred coupling on the statementlevel it

captures many essential features of active rules including comp osite events It

can be shown Lud that some features like chronicle contexts of comp osite

directly but require certain extensions like event events cannot be expressed

queues or timestamping as presented in MZ While the prop osed frame

work enjoys the desirable feature of a deterministic semantics it is sometimes

useful to consider nondeterministic extensions in particular to mo del existing

nondeterministic systems A p ossible extension is to use the choice construct of

SZ which can be integrated seamlessly with a stateoriented language like

Statelog or XYDatalog see eg GGSZ Finally wehave shown how the

at transaction mo del can be extended to handle nested transactions using a

hierarchical state space In this extended framework lowlevel pro cedural con

structs like before and insteadtriggers can b e formalized in an intuitivewayFi

nally a mo deltheoretic semantics based on lab eled Kripkestructures has b een

develop ed for Statelog with nested transactions which provides a conceptual

implementationindep endent mo del for active rule b ehavior

References

ABW K R Apt H Blair and A Walker Towards a Theory of Declarative

Knowledge In J Minker editor Foundations of Deductive Databases and

Logic Programming pp Morgan Kaufmann

AHV S Abiteb oul R Hull and V Vianu Foundations of Databases Addison

Wesley

AS S Abiteb oul and E Simon Fundamental Prop erties of Deterministic and

Nondeterministic Extensions of Datalog Theoretical Science

AV S Abiteb oul and V Vianu Datalog Extensions for Database Queries and

Up dates Journal of Computer and System Sciences

AWH A Aiken J Widom and J M Hellerstein Static Analysis Techniques for

Predicting the Behavior of Active Database Rules A CM Transactions on

Database Systems TODS March

BCP E Baralis S Ceri and S Parab oschi Improving Rule Analysis byMeans

of Triggering and Activation Graphs In Sellis Sel pp

BFKM L Brownston R Farrel E Kant and N Martin Programming Expert

Systems in OPS AnIntroduction to RuleBasedProgramming Addison

Wesley

BFP M L Barja A A A Fernandes N W Paton M H Williams A Dinn and

A I Ab delmoty Design and implementation of ROCK R OLL a deduc

tive ob jectoriented database system Information Systems

BGP C Baral M Gelfond and A Provetti Representing Actions Laws Obser

vations and Hyp otheses Journal of Logic Programming

BH M Berndtsson and J Hansson editors st Intl Workshop on Active and

RealTime Database Systems ARTDBWorkshops in Computing Skovde

Springer

erview of Transaction Logic Theoretical BK A J Bonner and M Kifer An Ov

Computer Science

BL C Baral and J Lob o Formal Characterization of Active Databases In

Pedreschi and Zaniolo PZ pp

BLT C Baral J Lob o and G Tra jcevski Formal Characterization of Active

Databases Part II In F Bry K Ramamohanarao and R Ramakrish

nan editors Intl ConferenceonDeductive and ObjectOriented Databases

DOODnumb er in LNCS pp Montreux Switzerland

Springer

BW E Baralis and J Widom An Algebraic Approach to Rule Analysis in

Exp ert Database Systems In Intl ConferenceonVery Large Data Bases

pp Santiago Chile

CFPT S Ceri PFraternali S Parab oschi and L Tanca Active Rule Manage

ment in Chimera In Widom and Ceri WCa chapter pp

Cha S Chakravarthy editor Bul letin of the Technical Committee on Data En

gineering Special Issue on Active Databasesvolume IEEE Com

puter So ciety

Che W Chen Programming with Logical Queries Bulk Up dates and Hyp othet

Workshop Semantics in Databases ical Reasoning In B Thalheim editor

Prague January Technische Universitat Cottbus

Choa J Chomicki DepthBounded BottomUp Evaluation of Logic Programs

Journal of Logic Programming Octob er

Chob J Chomicki Ecient Checking of Temp oral Integrity Constraints Us

ing Bounded History Enco ding ACM Transactions on Database Systems

TODS

CKAK S Chakravarthy V Krishnaprasad E Anwar and SK Kim Comp osite

Events for Active Databases Semantics Contexts and Detection In J B

Bo cca M Jarke and C Zaniolo editors Intl Conference on Very Large

Data Bases pp Santiago de Chile

CM S Chakravarthy and D Mishra Sno op An ExpressiveEvent Sp ecication

Language for Active Databases Data Know ledge Engineering

CPM R Co c hrane H Pirahesh and N Mattos Integrating Triggers and Declar

ative Constraints in SQL Database Sytems In Intl Conference on Very

Large Data Bases pp Mumbai Bombay India

Day U Dayal Ten Years of Activity in Active Database Systems What HaveWe

Accomplished In M Berndtsson and J Hansson editors st Intl Work

shop on Active and RealTime Database Systems ARTDBWorkshops in

Computing pp Skovde Springer

DGG K R Dittrich S Gatziu and A Gepp ert The Active Database Manage

ment System Manifesto A Rulebase of ADBMS Features In Sellis Sel

pp

DHW U Dayal E Hanson and J Widom Active Database Systems In W Kim

editor Modern Database Systems The Object Model Interoperability and

Beyondchapter pp ACM Press

FT PFraternali and L Tanca A Structured Approach for the Denition of the

Semantics of Active Databases ACM Transactions on Database Systems

FWP A A A Fernandes M H Williams and N W Paton A LogicBased In

tegration of Active and Deductiv e Databases New Generation Computing

GB A Gepp ert and M Berndtsson editors Proc of the nd Intl Workshop on

Rules in Database Systems RIDSnumb er in LNCS Skovde Sweden

GGSZ F Giannotti S Greco D Sacca and C Zaniolo Programming with Non

Determinism in Deductive Databases Annals of Mathematics and Articial

Intel ligence II I

GL M Gelfond and V Lifschitz The Stable Mo del Semantics for Logic Pro

gramming In R Kowalski and K Bowen editors Intl ConferenceonLogic

Programming ICLP pp

GL M Gelfond and V Lifschitz Representing Action and Change by Logic

Programs Journal of Logic Programming

GMS G Gottlob G Mo erkotte and V S Subrahmanian The PARK Semantics

for Active Rules In PM G Ap ers M Bouzeghoub and G Gardarin

editors Intl Conference on Extending Database Technologynumb er

in LNCS Avignon France Springer

ISO ISOANSI Working draft SQL ISOIEC JTC SC WG

KC SK Kim and S Chakravarthy A Conuent Rule Execution Mo del for Ac

tive Databases Technical Rep ort UFCISTR University of Florida

h ttpwwwcisuedusharma

KdMS G Kiernan C de Maindreville and E Simon Making Deductive Database

a Practical Technology a step forward In ACM Intl Conference on Man

agement of Data SIGMOD pp

KLS M Kramer G Lausen and G Saake Up dates in a RuleBased Language

for Ob jects In Intl Conference on Very Large Data Bases VLDB pp

Vancouver

Kow R A Kowalski Database Up dates in the Event Calculus Journal of Logic

Programming

KRS D B Kemp K Ramamohanarao and P J Stuckey ELS Programs and

the EcientEvaluation of NonStratied Programs byTransformation to

ELS In Ling et al LMV pp

KU A P Karadimce and S D Urban Rened Triggering Graphs A Logic

Based Approach to Termination Analysis in an Active Ob jectoriented

Database In th International Conference on Data Engineering ICDE

pp

LHL B Ludascher U Hamann and G Lausen A Logical Framew ork for Active

Rules In Proc th Intl Conference on Management of Data COMAD

pp Pune India Tata McGrawHill

LLM G Lausen B Ludascher and W May On Logical Foundations of Active

Databases In J Chomicki and G Saake editors Logics for Databases and

Information Systemschapter pp Kluwer Academic Publish

ers

LML B Ludascher W May and G Lausen Nested Transactions in a Logical

Language for Active Rules In Pedreschi and Zaniolo PZ pp

LMV T W Ling A O Mendelzon and L Vieille editors Intl Conferenceon

Deductive and ObjectOriented Databases DOODnumb er in LNCS

Singap ore Springer

LS U W Lip eck and G Saake Monitoring Dynamic Integrity Constraints

Based on Temp oral Logic Information Systems pp

Lud B Ludascher Integration of Active and Deductive Database RulesPhDthe

inxVerlag Sankt sis Institut fur Informatik Universitat Freiburg

Augustin ISBN

Min J Minker Logic and Databases a Year Retrosp ective In Pedreschi and

Zaniolo PZ pp

MW S Manchanda and D S Warren A LogicBased Language for Database

Up dates In J Minker editor Foundations of Deductive Databases and

Logic Programming pp MorganKaufmann Los Altos CA

MZ I Motakis and C Zaniolo Comp osite Temp oral Events in Active Database

Rules A LogicOriented Approach In Ling et al LMV pp

MZ I Motakis and C Zaniolo Temp oral Aggregation in Active Database Rules

In ACM Intl Conference on Management of Data SIGMOD pp

Tucson Arizona

NT S Naqvi and S Tsur ALogical Language for Data and Know ledge Bases

Computer Science Press New York

PCFW N W Paton J Campin A A A Fernandes and M H Williams Formal

Sp ecication of Active Database Functionality A Survey In Sellis Sel

pp

PDW N W Paton O Daz M H Williams J Campin A Dinn and A Jaime

Dimensions of ActiveBehaviour In Paton and Williams PW pp

Prz T C Przymusinski On the DeclarativeSemantics of Deductive Databases

and Logic Programs In J Minker editor Foundations of Deductive

Databases and Logic Programming pp Morgan Kaufmann

PV P Picouet and V Vianu Semantics and Expressiveness Issues in Ac

tive Databases In ACM Symposium on Principles of Database Systems

PODS

PV P Picouet and V Vianu Expressiveness and Complexity of Active

Databases In F Afrati and P Kolaitis editors th Intl Conference on

Database Theory ICDT number in LNCS pp Delphi

Greece Springer

PW N W Paton and M H Williams editors st Intl Workshop on Rules in

Database Systems RIDSWorkshops in Computing Edinburgh Scotland

Springer

PZ D Pedreschi and C Zaniolo editors Intl Workshop on Logic in Databases

LIDnumb er in LNCS San Miniato Italy Springer

RH K Ramamohanarao and J Harland An Intro duction to Deductive

Database Languages and Systems The VLDB Journal April

Sel T K Sellis editor nd Intl Workshop on Rules in Database Systems

RIDSnumb er in LNCS Athens Greece Springer

Sin M P Singh Semantical Considerations on Workows An Algebra for

Intertask Dep endencies In Intl Workshop on Database Programming Lan

guages electronic Workshops in Computing Gubbio Italy Springer

SK E Simon and J Kiernan The ARDL System In Widom and Ceri WCa

chapter pp

SP P Sampaio and N Paton Deductive Ob jectOriented Database Systems

A Survey In Gepp ert and Berndtsson GB pp

SSW K F Sagonas T Swift and D S Warren XSB as an Ecient Deduc

ACM Intl Conference on Management of Data tive Database Engin In

SIGMOD pp

SZ S Sacca and C Zaniolo Stable Mo dels and NonDeterminism in Logic

Programs with Negation In Proc of the th ACM Symposium on Principles

of Database Systems pp

VG A Van Gelder The Alternating Fixp oint of Logic Programs with Negation

In ACM Symposium on Principles of Database Systems PODS pp

Via V Vianu RuleBased Languages Annals of Mathematics and Articial

Intel ligence II I

WC J Widom and S Chakravarthy editors th Intl Workshop on Research

Issues in Data Engineering RIDE IEEE Computer So ciety Press

WCa J Widom and S Ceri editors Active Database Systems Triggers and Rules

for Advanced Database Processing Morgan Kaufmann

WCb J Widom and S Ceri Intro duction to Active Database Systems In Active

Database Systems Triggers and Rules for Advanced Database Processing

WCa chapter pp

WF CA Wichert and B Freitag Capturing Database Dynamics by Deferred

Up dates In Intl ConferenceonLogic Programming ICLPLeuven Bel

gium MIT Press

Wid J Widom Deductive and Active Databases TwoParadigms or Ends of a

Sp ectrum In Paton and Williams PW

Zan C Zaniolo A Unied Semantics for Active and Deductive Databases In

Paton and Williams PW pp

Zan C Zaniolo Active Database Rules with Transaction Conscious Stable

Mo del Semantics In Ling et al LMV pp

ZH Y Zhou and M Hsu A Theory for Rule Triggering Systems In Intl Conf

on Extending Database Technology pp