Lesson02-Active Databases
Lesson02-Active Databases
Email: [email protected]
1 / 47
Active Databases
Active Databases
Preliminary definition
• Active Database: is a DBMS that supports an integrated
subsystem for the definition and management of
production rules – active rules.
• Event Condition Action (ECA) Paradigm
– each rule reacts to some events, evaluates a condition and,
based on the truth value of the condition, might carry out an
action.
• Rule Engine: an autonomous subsystem which keeps
track of the events that have occurred and schedules the
rules for execution.
• An active database system can execute either transactions,
which are initiated by the users, or rules, which are under
the control of the system.
2 / 47
Active Databases
Active Databases
3 / 47
Active Databases
Passive Database
• Periodically polling
– Too frequent: expensive
– Infrequent: miss the right time to reach
• The polling must be done for all items in stock
4 / 47
Active Databases
Active Database
5 / 47
Active Databases
6 / 47
Active Databases
Event-Condition-Action
• Event
– Normally a modification of the state of the database: insert, delete,
update
– When the event occurs, the trigger is activated
• Condition
– A predicate identifying the situations in which the application of a
trigger is necessary
– When the condition is evaluated, the trigger is considered
• Action
– A generic update statement or a stored procedure
– When the action is elaborated, the trigger is executed
• DBMSs already provide all the required components. One only
needs to integrate them
7 / 47
Active Databases
8 / 47
Active Databases
9 / 47
Active Databases
10 / 47
Active Databases
A Simple Example
11 / 47
Active Databases
12 / 47
Active Databases
13 / 47
Active Databases
Update of a Tuple in T1
14 / 47
Active Databases
15 / 47
Active Databases
• Execution mode:
1 BEFORE
The trigger is considered and possibly executed before the action that
activated it is applied
Normally this mode is used when one wants to check a modification
before it takes place
1 AFTER
The trigger is considered and possibly executed after the action that
activated it is applied
It’s the most common mode, suitable for most applications
It’s the simplest one to be used correctly
16 / 47
Active Databases
17 / 47
Active Databases
Granularity of Events
18 / 47
Active Databases
19 / 47
Active Databases
20 / 47
Active Databases
21 / 47
Active Databases
Execution Model
• SQL:1999 states that triggers are handled within a Trigger
Execution Context (TEC)
• The execution of a trigger action may produce events that
activate other triggers, which will have to be evaluated within a
new, internal TEC
• In every moment there may be several, nested TECs for a
transaction, but only one may be active
• For row-level triggers, the TEC considers which tuples have
already been considered and which ones are to be considered
• The structure is therefore stack-like:
– TEC0 → TEC1 → ... → TECn
• When a trigger has considered all the events, the TEC closes and
the system moves to the next trigger
• The model is complex, but precise and relatively easy to
implement
22 / 47
Active Databases
Employee
RegNum Name Salary DeptN ProjN
50 Smith 59.000 1 20
51 Black 56.000 1 10
52 Jones 50.000 1 20
Project
Department ProjNum Objective
DeptNum MGRRegNum 10 NO
1 50 20 NO
23 / 47
Active Databases
24 / 47
Active Databases
25 / 47
Active Databases
26 / 47
Active Databases
Activation of T1
update Project
set Objective = ’yes’ where ProgNum = 10
27 / 47
Active Databases
Activation of T2
Employee
RegNum Name Salary DeptN ProjN
50 Smith 59.000 1 20
51 Black 59.000 1 10
52 Jones 50.000 1 20
28 / 47
Active Databases
Activation of T3
Employee
RegNum Name Salary DeptN ProjN
50 Smith 59.000 1 20
51 Black 59.752 1 10
52 Jones 50.000 1 20
29 / 47
Active Databases
Activation of T2
Employee
RegNum Name Salary DeptN ProjN
50 Smith 59.000 1 20
51 Black 59.000 1 10
52 Jones 50.000 1 20
Activation of T3
• The trigger condition is false
– Salary was decreased by less than 3%
• Trigger activation has reached termination
30 / 47
Active Databases
31 / 47
Active Databases
Termination Analysis
32 / 47
Active Databases
33 / 47
Active Databases
34 / 47
Active Databases
35 / 47
Active Databases
36 / 47
Active Databases
38 / 47
Active Databases
39 / 47
Active Databases
40 / 47
Active Databases
Deletion of a Product
41 / 47
Active Databases
42 / 47
Active Databases
• Definition of priority
– Allows specifying the execution order of triggers when there are several
triggers activated at the same time
– SQL:1999 states an order based on the execution mode and granularity;
when these coincide, the choice depends on the implementation
• Activation/deactivation of triggers
– Not in the standard, but often available
43 / 47
Active Databases
Execution Modes
• 3 classical alternatives
1 Immediate: the trigger is considered and executed with the activating
event
Example: triggers that immediately check satisfaction of integrity
constraints
2 Deferred: handled at the end of the transaction
Example: triggers that check satisfaction of integrity constraints that
require the execution of several operations
3 Detached: the trigger is handled in a separate transaction
Example: efficient management of variations of stock indices values
after several exchanges
44 / 47
Active Databases
45 / 47
Active Databases
46 / 47
Active Databases
The End
47 / 47