Professional Documents
Culture Documents
Active DB
Active DB
Active DB
Part 1: Introduction
CS561
Active Databases
n
Brief History
n
SQL-92: constraints
Event-Condition-Action (ECA)
n
condition
+ procedures
All data actions performed by the trigger execute
within the same transaction in which the trigger fires,
4
Triggers
n
Trigger Components
n
Three components
Event: When this event happens, the trigger is activated
Condition (optional): If the condition is true, the trigger
executes, otherwise skipped
Action: The actions performed by the trigger
Semantics
Granularity of Event
n
10
ENAME
7839
KING
30
7698
BLAKE
30
7788
SMITH
30
Trigger name:
Timing:
Triggering event:
Target:
Trigger action:
increase_salary_trg
AFTER executing the statement
UPDATE of sal column
emp table
INSERT values INTO sal_hist table
12
13
Define variables
Trigger name:
Timing:
Triggering event:
Filtering condition:
Target:
Trigger parameters:
Trigger action:
derive_commission_trg
BEFORE executing the statement
UPDATE of sal column
job = SALESMAN
emp table
old, new
calculate the new commission
to be updated
15
n Disable
database trigger
DISABLE | ENABLE
table
ALTER TABLE table_name
n Removing
DISABLE | ENABLE
ALL TRIGGERS
Tracking
Table Operations
Record Value Changes
Maintenance
Storing
Derived Data
Security
of Semantic Integrity
Access Control
17
TABLE_NAME COLUMN_NAME
EMP
EMP
SAL
EMP
INS
1
0
UPD
1
1
0
DEL
1
1
continuation
MAX_INS
5
5
MAX_UPD
5
5
0
MAX_DEL
5
1
18
19
TIMESTAMP
12-SEP-04
ID OLD_LAST_NAME NEW_LAST_NAME
7950 NULL
HUTTON
NGREENBE
10-AUG-04
7844 MAGEE
TURNER
continuation
OLD_TITL
E
NULL
CLERK
NEW_TITLE OLD_SALARY
NULL
ANALYST
NEW_SALARY
3500
1100
1100
SALESMAN
20
21
22
ERROR at line 1:
ORA-04091: table CGMA2.EMP is mutating, trigger/
function may not see it
23
WHERE
deptno = 30;
Summary
n
Event: I/U/D
Timing: Before/After
Granularity: Row-level/Statement-level
Usage:
Active Databases
Part 2: Classifications &
Scalability
CS561
26
Types of Triggers
n
Idea:
Trigger
Automatic
Guaranteed
Correctness
Classification of Usage
n
Generated Triggers
Handcrafted Triggers
Referential integrity
If foreign key in a table is deleted or updated, it causes an action
usually specified by user: set null/cascade
Primary keys, Unique columns, etc
Materialized views
management
Handcrafted Triggers
n
External Applications
Examples:
Challenges
Challenge : Semantics ?
n
n
n
ENAME
7839
KING
30
7698
BLAKE
30
7788
SMITH
30
36
Termination:
Confluence : terminates and produces a final state that does not depend
on order of execution
Termination :
Find cycles
Examine rules in cycle for behavior
Could determine that terminate in some cases
Data dependent : even if at compile-time has cycle, still may be useful
In practice (Oracle) :
Optimistic solution
Terminate after 25 trigger invocations, and rollback
Scalable Trigger
Processing
Discussion of publication by
Eric N. Hanson et al
Int Conf Data Engineering 1999
CS561
Motivation
n
constraint checking
Alerting, logging, etc.
n
triggering capabilities
few trigger/update-type on table; or at best 100.
n
n
Problem Definition
Assumptions:
n
n
Number
Expression Signature
n
Expression Signature:
n
Signature:
Main Idea
n
Main Structures
n A-treat
Network
Network
n For
n Expression
Common
n
Signature
structure in a trigger
n Constant
Tables
Constants
Predicate Index
hash(src-ID)