Professional Documents
Culture Documents
CHAPTER 8
TO DESIGN A TRIGGER MECHANISM, WE MUST: : Specify the conditions under which the trigger is to be executed. : Specify the actions to be taken when the trigger executes.
**The condition for executing the trigger is an update to the account relation that results in a negative balance value.
TRIGGER IN SQL
Triggering event can be insert, delete or update. Triggers on update can be restricted to specific attributes : E.g. create trigger overdraft trigger after update of balance on account. Values of attributes before and after an update can be referenced : Referencing old row as : for deletes and updates : Referencing new row as : for inserts and updates Triggers can be activated before an event, which can serve as extra constraints. E.g. convert blanks to null.
Contd.
TRIGGER IN SQL
Instead of executing a separate action for each affected row, a single action can be executed for all rows affected by a transaction
: Use referencing old table or referencing new table to refer to temporary tables (called transition tables) containing the affected rows
: Can be more efficient when dealing with SQL statements that update a large number of rows
Assume relational data model Replication : System maintains multiple copies of data, stored in different sites, for faster retrieval and fault tolerance.
Fragmentation
:Relation is partitioned into several fragments stored in distinct sites Replication and fragmentation can be combined : Relation is partitioned into several fragments: system maintains several identical replicas of each such fragment.
DATA REPLICATION
A relation or fragment of a relation is replicated if it is stored redundantly in two or more sites.
Full replication of a relation is the case where the relation is stored at all sites.
Fully redundant databases are those in which every site contains a copy of the entire database.
contd..
Disadvantages of Replication Increased cost of updates: each replica of relation r must be updated.
Increased complexity of concurrency control: concurrent updates to distinct replicas may lead to inconsistent data unless special concurrency control mechanisms are implemented.
DATA FRAGMENTATION
Division of relation r into fragments r1, r2, , rn which contain sufficient information to reconstruct relation r. Horizontal fragmentation: each tuple of r is assigned to one or more fragments Vertical fragmentation: the schema for relation r is split into several smaller schemas : All schemas must contain a common candidate key (or super key) to ensure lossless join property. : A special attribute, the tupleid attribute may be added to each schema to serve as a candidate key.
ADVANTAGE OF FRAGMENTATION
Horizontal: Allows parallel processing on fragments of a relation. Allows a relation to be split so that tuples are located where they are most frequently accessed. Vertical: Allows tuples to be split so that each part of the tuple is stored where it is most frequently accessed. Tuple-id attribute allows efficient joining of vertical fragments. Allows parallel processing on a relation. Vertical and horizontal fragmentation can be mixed. Fragments may be successively fragmented to an arbitrary depth.
DATA TRANSPARENCY
Data transparency: Degree to which system user may remain unaware of the details of how and where the data items are stored in a distributed system. Consider transparency issues in relation to : Fragmentation transparency Replication transparency Location transparency
Assumptions:
System has only reusable resources Only exclusive access to resources Only one copy of each resource States of a process: running or blocked Running state: process has all the resources Blocked state: waiting on one or more resource
DEADLOCKS
Resource Deadlocks
A process needs multiple resources for an activity. Deadlock occurs if each process in a set request resources held by another process in the same set, and it must receive all the requested resources to move further.
Communication Deadlocks
Processes wait to communicate with other processes in a set. Each process in the set is waiting on another processs message, and no process in the set initiates a message until it receives a message for which it is waiting.
GRAPH MODELS
Nodes of a graph are processes. Edges of a graph the pending requests or assignment of resources. Wait-for Graphs (WFG): P1 -> P2 implies P1 is waiting for a resource from P2. Transaction-wait-for Graphs (TWF): WFG in databases. Deadlock: directed cycle in the graph. Cycle example:
AND, OR MODELS
AND Model A process/transaction can simultaneously request for multiple resources. Remains blocked until it is granted all of the requested resources. OR Model A process/transaction can simultaneously request for multiple resources. Remains blocked till any one of the requested resource is granted.
DISTRIBUTED DEADLOCKS
Centralized Control
A control site constructs wait-for graphs (WFGs) and checks for directed cycles. WFG can be maintained continuously (or) built on-demand by requesting WFGs from individual sites.
Distributed Control
WFG is spread over different sites. Any site can initiate the deadlock detection process.
Hierarchical Control
Sites are arranged in a hierarchy. A site checks for cycles only in descendents.