940 Chapter 26 Enhanced Data Models for Advanced Applications
problem briefly, consider the rules in Figure 26.4. Here, rule R1 is triggered by an
INSERT event on TABLE1 and its action includes an update event on Attribute1 of
TABLE2. However, rule R2’s triggering event is an UPDATE event on Attribute1 of
TABLE2, and its action includes an INSERT event on TABLE1. In this example, it is
easy to see that these two rules can trigger one another indefinitely, leading to non-
termination. However, if dozens of rules are written, it is very difficult to determine
whether termination is guaranteed or not.
If active rules are to reach their potential, it is necessary to develop tools for the
design, debugging, and monitoring of active rules that can help users design and
debug their rules.
26.1.3 Examples of Statement-Level Active Rules
in STARBURST
We now give some examples to illustrate how rules can be specified in the STAR-
BURST experimental DBMS. This will allow us to demonstrate how statement-level
rules can be written, since these are the only types of rules allowed in STARBURST.
The three active rules
R1S, R2S, and R3S in Figure 26.5 correspond to the first three
rules in Figure 26.2, but they use STARBURST notation and statement-level seman-
tics. We can explain the rule structure using rule
R1S. The CREATE RULE statement
specifies a rule name—
Total_sal1 for R1S. The ON clause specifies the relation on
which the rule is specified—
EMPLOYEE for R1S. The WHEN clause is used to spec-
ify the events that trigger the rule.
8
The optional IF clause is used to specify any
conditions that need to be checked. Finally, the
THEN clause is used to specify the
actions to be taken, which are typically one or more SQL statements.
In STARBURST, the basic events that can be specified for triggering the rules are the
standard SQL update commands:
INSERT, DELETE, and UPDATE. These are speci-
fied by the keywords
INSERTED, DELETED, and UPDATED in STARBURST nota-
tion. Second, the rule designer needs to have a way to refer to the tuples that have
been modified. The keywords
INSERTED, DELETED, NEW-UPDATED, and OLD-
UPDATED
are used in STARBURST notation to refer to four transition tables (rela-
tions) that include the newly inserted tuples, the deleted tuples, the updated tuples
before they were updated, and the updated tuples after they were updated, respec-
tively. Obviously, depending on the triggering events, only some of these transition
tables may be available. The rule writer can refer to these tables when writing the
condition and action parts of the rule. Transition tables contain tuples of the same
type as those in the relation specified in the
ON clause of the rule—for R1S, R2S,
and
R3S, this is the EMPLOYEE relation.
In statement-level semantics, the rule designer can only refer to the transition tables
as a whole and the rule is triggered only once, so the rules must be written differ-
ently than for row-level semantics. Because multiple employee tuples may be
8
Note that the WHEN keyword specifies events in STARBURST but is used to specify the rule condition
in SQL and Oracle triggers.