Copyright 2007 Pearson Education Inc Publishing as Pearson

  • Slides: 60
Download presentation
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1

Chapter 24 Enhanced Data Models for Advanced Applications Copyright © 2007 Pearson Education, Inc.

Chapter 24 Enhanced Data Models for Advanced Applications Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Outline n n Active database & triggers Temporal databases Spatial and Multimedia databases Deductive

Outline n n Active database & triggers Temporal databases Spatial and Multimedia databases Deductive databases Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 3

Active Database Concepts and Triggers Generalized Model for Active Databases and Oracle Triggers n

Active Database Concepts and Triggers Generalized Model for Active Databases and Oracle Triggers n Triggers are executed when a specified condition occurs during insert/delete/update n Triggers are action that fire automatically based on these conditions Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4

Event-Condition-Action (ECA) Model Generalized Model (contd. ) n Triggers follow an Event-condition-action (ECA) model

Event-Condition-Action (ECA) Model Generalized Model (contd. ) n Triggers follow an Event-condition-action (ECA) model n Event: n Database modification n n Condition: n Any true/false expression n n E. g. , insert, delete, update), Optional: If no condition is specified then condition is always true Action: n Sequence of SQL statements that will be automatically executed Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5

Trigger Example Generalized Model (contd. ) n When a new employees is added to

Trigger Example Generalized Model (contd. ) n When a new employees is added to a department, modify the Total_sal of the Department to include the new employees salary Condition n Logically this means that we will CREATE a TRIGGER, let us call the trigger Total_sal 1 n n This trigger will execute AFTER INSERT ON Employee table It will do the following FOR EACH ROW n n n WHEN NEW. Dno is NOT NULL The trigger will UPDATE DEPARTMENT By SETting the new Total_sal to be the sum of n old Total_sal and NEW. Salary n WHERE the Dno matches the NEW. Dno; Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6

Example: Trigger Definition Can be CREATE or ALTER CREATE TRIGGER Total_sal 1 Can be

Example: Trigger Definition Can be CREATE or ALTER CREATE TRIGGER Total_sal 1 Can be FOR, AFTER, INSTEAD AFTER INSERT ON Employee OF Can be INSERT, FOR EACH ROW UPDATE, DELETE WHEN (NEW. Dno is NOT NULL) The condition UPDATE DEPARTMENT SET Total_sal = Total_sal + NEW. Salary WHERE Dno = NEW. Dno; The action Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 7

CREATE or ALTER TRIGGER Generalized Model (contd. ) n CREATE TRIGGER <name> n n

CREATE or ALTER TRIGGER Generalized Model (contd. ) n CREATE TRIGGER <name> n n ALTER TRIGGER <name> n n Creates a trigger Alters a trigger (assuming one exists) CREATE OR ALTER TRIGGER <name> n n Creates a trigger if one does not exist Alters a trigger if one does exist n Works in both cases, whether a trigger exists or not Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8

Conditions Generalized Model (contd. ) n AFTER n n BEFORE n n Executes after

Conditions Generalized Model (contd. ) n AFTER n n BEFORE n n Executes after the event Executes before the event INSTEAD OF n Executes instead of the event n Note that event does not execute in this case n E. g. , used for modifying views Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 9

Row-Level versus Statement-level Generalized Model (contd. ) n Triggers can be n Row-level n

Row-Level versus Statement-level Generalized Model (contd. ) n Triggers can be n Row-level n n Statement-level n n Default (when FOR EACH ROW is not specified) Row level triggers n n FOR EACH ROW specifies a row-level trigger Executed separately for each affected row Statement-level triggers n Execute once for the SQL statement, Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 10

Condition Generalized Model (contd. ) n Any true/false condition to control whether a trigger

Condition Generalized Model (contd. ) n Any true/false condition to control whether a trigger is activated on not n n Absence of condition means that the trigger will always execute for the even Otherwise, condition is evaluated n n before the event for BEFORE trigger after the event for AFTER trigger Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 11

Action Generalized Model (contd. ) n Action can be n n n One SQL

Action Generalized Model (contd. ) n Action can be n n n One SQL statement A sequence of SQL statements enclosed between a BEGIN and an END Action specifies the relevant modifications Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 12

Triggers on Views Generalized Model (contd. ) n INSTEAD OF triggers are used to

Triggers on Views Generalized Model (contd. ) n INSTEAD OF triggers are used to process view modifications Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 13

Active Database Concepts and Triggers Design and Implementation Issues for Active Databases n An

Active Database Concepts and Triggers Design and Implementation Issues for Active Databases n An active database allows users to make the following changes to triggers (rules) n n n Activate Deactivate Drop Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 14

Active Database Concepts and Triggers Design and Implementation Issues for Active Databases n An

Active Database Concepts and Triggers Design and Implementation Issues for Active Databases n An event can be considered in 3 ways n n n Immediate consideration Deferred consideration Detached consideration Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 15

Active Database Concepts and Triggers Design and Implementation Issues (contd. ) n Immediate consideration

Active Database Concepts and Triggers Design and Implementation Issues (contd. ) n Immediate consideration n Part of the same transaction and can be one of the following depending on the situation n n Deferred consideration n n Before After Instead of Condition is evaluated at the end of the transaction Detached consideration n Condition is evaluated in a separate transaction Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 16

Active Database Concepts and Triggers Potential Applications for Active Databases n Notification n n

Active Database Concepts and Triggers Potential Applications for Active Databases n Notification n n Automatic notification when certain condition occurs Enforcing integrity constraints n n Triggers are smarter and more powerful than constraints Maintenance of derived data n Automatically update derived data and avoid anomalies due to redundancy n E. g. , trigger to update the Total_sal in the earlier example Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 17

Active Database Concepts and Triggers in SQL-99 n Can alias variables inside the REFERENCINFG

Active Database Concepts and Triggers in SQL-99 n Can alias variables inside the REFERENCINFG clause Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 18

Active Database Concepts and Triggers n Trigger examples Copyright © 2007 Pearson Education, Inc.

Active Database Concepts and Triggers n Trigger examples Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 19

Temporal Database Concepts Time Representation, Calendars, and Time Dimensions n Time is considered ordered

Temporal Database Concepts Time Representation, Calendars, and Time Dimensions n Time is considered ordered sequence of points in some granularity n Use the term choronon instead of point to describe minimum granularity Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 20

Temporal Database Concepts Time Representation, … (contd. ) n A calendar organizes time into

Temporal Database Concepts Time Representation, … (contd. ) n A calendar organizes time into different time units for convenience. n Accommodates various calendars n n n Gregorian (western) Chinese Islamic Hindu Jewish Etc. Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 21

Temporal Database Concepts Time Representation, … (contd. ) n Point events n Single time

Temporal Database Concepts Time Representation, … (contd. ) n Point events n Single time point event n n n E. g. , bank deposit Series of point events can form a time series data Duration events n Associated with specific time period n Time period is represented by start time and end time Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 22

Temporal Database Concepts Time Representation, … (contd. ) n Transaction time n n The

Temporal Database Concepts Time Representation, … (contd. ) n Transaction time n n The time when the information from a certain transaction becomes valid Bitemporal database n Databases dealing with two time dimensions Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 23

Temporal Database Concepts Incorporating Time in Relational Databases Using Tuple Versioning n Add to

Temporal Database Concepts Incorporating Time in Relational Databases Using Tuple Versioning n Add to every tuple n n Valid start time Valid end time Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 24

Temporal Database Concepts Different types of temporal relational database Copyright © 2007 Pearson Education,

Temporal Database Concepts Different types of temporal relational database Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 25

Temporal Database Concepts Tuple versioning Copyright © 2007 Pearson Education, Inc. Publishing as Pearson

Temporal Database Concepts Tuple versioning Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 26

Temporal Database Concepts Incorporating Time in Object-Oriented Databases Using Attribute Versioning n A single

Temporal Database Concepts Incorporating Time in Object-Oriented Databases Using Attribute Versioning n A single complex object stores all temporal changes of the object n Time varying attribute n An attribute that changes over time n n E. g. , age Non-Time varying attribute n An attribute that does not changes over time n E. g. , date of birth Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 27

Spatial and Multimedia Databases n n Spatial Database Concepts Multimedia Database Concepts Copyright ©

Spatial and Multimedia Databases n n Spatial Database Concepts Multimedia Database Concepts Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 28

Spatial Databases Spatial Database Concepts n Keep track of objects in a multi-dimensional space

Spatial Databases Spatial Database Concepts n Keep track of objects in a multi-dimensional space n n Maps Geographical Information Systems (GIS) Weather In general spatial databases are n-dimensional n This discussion is limited to 2 -dimensional spatial databases Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 29

Spatial Databases Spatial Database Concepts n Typical Spatial Queries n Range query: Finds objects

Spatial Databases Spatial Database Concepts n Typical Spatial Queries n Range query: Finds objects of a particular type within a particular distance from a given location n n Nearest Neighbor query: Finds objects of a particular type that is nearest to a given location n n E. g. , Taco Bells in Pleasanton, CA E. g. , Nearest Taco Bell from an address in Pleasanton, CA Spatial joins or overlays: Joins objects of two types based on some spatial condition (intersecting, overlapping, within certain distance, etc. ) n E. g. , All Taco Bells within 2 miles from I-680. Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 30

Spatial Databases Spatial Database Concepts n R-trees n n Technique for typical spatial queries

Spatial Databases Spatial Database Concepts n R-trees n n Technique for typical spatial queries Group objects close in spatial proximity on the same leaf nodes of a tree structured index Internal nodes define areas (rectangles) that cover all areas of the rectangles in its subtree. Quad trees n Divide subspaces into equally sized areas Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 31

Multimedia Databases Multimedia Database Concepts n In the years ahead multimedia information systems are

Multimedia Databases Multimedia Database Concepts n In the years ahead multimedia information systems are expected to dominate our daily lives. n n Our houses will be wired for bandwidth to handle interactive multimedia applications. Our high-definition TV/computer workstations will have access to a large number of databases, including digital libraries, image and video databases that will distribute vast amounts of multisource multimedia content. Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 32

Multimedia Databases n Types of multimedia data are available in current systems n n

Multimedia Databases n Types of multimedia data are available in current systems n n Text: May be formatted or unformatted. For ease of parsing structured documents, standards like SGML and variations such as HTML are being used. Graphics: Examples include drawings and illustrations that are encoded using some descriptive standards (e. g. CGM, PICT, postscript). Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 33

Multimedia Databases n Types of multimedia data are available in current systems (contd. )

Multimedia Databases n Types of multimedia data are available in current systems (contd. ) n Images: Includes drawings, photographs, and so forth, encoded in standard formats such as bitmap, JPEG, and MPEG. Compression is built into JPEG and MPEG. n n These images are not subdivided into components. Hence querying them by content (e. g. , find all images containing circles) is nontrivial. Animations: Temporal sequences of image or graphic data. Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 34

Multimedia Databases n Types of multimedia data are available in current systems (contd. )

Multimedia Databases n Types of multimedia data are available in current systems (contd. ) n n Video: A set of temporally sequenced photographic data for presentation at specified rates– for example, 30 frames per second. Structured audio: A sequence of audio components comprising note, tone, duration, and so forth. Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 35

Multimedia Databases n Types of multimedia data are available in current systems (contd. )

Multimedia Databases n Types of multimedia data are available in current systems (contd. ) n Audio: Sample data generated from aural recordings in a string of bits in digitized form. Analog recordings are typically converted into digital form before storage. Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 36

Multimedia Databases n Types of multimedia data are available in current systems (contd. )

Multimedia Databases n Types of multimedia data are available in current systems (contd. ) n Composite or mixed multimedia data: A combination of multimedia data types such as audio and video which may be physically mixed to yield a new storage format or logically mixed while retaining original types and formats. Composite data also contains additional control information describing how the information should be rendered. Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 37

Multimedia Databases n Nature of Multimedia Applications: n n Multimedia data may be stored,

Multimedia Databases n Nature of Multimedia Applications: n n Multimedia data may be stored, delivered, and utilized in many different ways. Applications may be categorized based on their data management characteristics. Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 38

Introduction to Deductive Databases n n n n Overview of Deductive Databases Prolog/Datalog Notation

Introduction to Deductive Databases n n n n Overview of Deductive Databases Prolog/Datalog Notation Clausal Form and Horn Clauses Interpretation of Rules Datalog Programs and Their Safety Use the Relational Operations Evaluation of Non-recursive Datalog Queries Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 39

Overview of Deductive Databases n Declarative Language n n Language to specify rules Inference

Overview of Deductive Databases n Declarative Language n n Language to specify rules Inference Engine (Deduction Machine) n n Can deduce new facts by interpreting the rules Related to logic programming n n Prolog language (Prolog => Programming in logic) Uses backward chaining to evaluate n Top-down application of the rules Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 40

Overview of Deductive Databases n Speciation consists of: n Facts n n Similar to

Overview of Deductive Databases n Speciation consists of: n Facts n n Similar to relation specification without the necessity of including attribute names Rules n Similar to relational views (virtual relations that are not stored) Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 41

Prolog/Datalog Notation n Predicate has n n a name a fixed number of arguments

Prolog/Datalog Notation n Predicate has n n a name a fixed number of arguments n Convention: n n n Constants are numeric or character strings Variables start with upper case letters E. g. , SUPERVISE(Supervisor, Supervisee) n States that Supervisor SUPERVISE(s) Supervisee Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 42

Prolog/Datalog Notation n Rule n Is of the form head : - body n

Prolog/Datalog Notation n Rule n Is of the form head : - body n n n where : - is read as if and only iff E. g. , SUPERIOR(X, Y) : - SUPERVISE(X, Y) E. g. , SUBORDINATE(Y, X) : - SUPERVISE(X, Y) Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 43

Prolog/Datalog Notation n Query n Involves a predicate symbol followed by y some variable

Prolog/Datalog Notation n Query n Involves a predicate symbol followed by y some variable arguments to answer the question n where : - is read as if and only iff E. g. , SUPERIOR(james, Y)? E. g. , SUBORDINATE(james, X)? Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 44

Figure 24. 11 n (a) Prolog notation (b) Supervisory tree Copyright © 2007 Pearson

Figure 24. 11 n (a) Prolog notation (b) Supervisory tree Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 45

Datalog Notation n Datalog notation n Program is built from atomic formulae n Literals

Datalog Notation n Datalog notation n Program is built from atomic formulae n Literals of the form p(a 1, a 2, … an) where n n n Built-in predicates are included n n p predicate name n is the number of arguments E. g. , <, <=, etc. A literal is either n n An atomic formula preceded by not Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 46

Clausal Form and Horn Clauses n A formula can have quantifiers n n Universal

Clausal Form and Horn Clauses n A formula can have quantifiers n n Universal Existential Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 47

Clausal Form and Horn Clauses n In clausal form, a formula must be transformed

Clausal Form and Horn Clauses n In clausal form, a formula must be transformed into another formula with the following characteristics n n n All variables are universally quantified Formula is made of a number of clauses where each clause is made up of literals connected by logical ORs only Clauses themselves are connected by logical ANDs only. Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 48

Clausal Form and Horn Clauses n Any formula can be converted into a clausal

Clausal Form and Horn Clauses n Any formula can be converted into a clausal form n n A specialized case of clausal form are horn clauses that can contain no more than one positive literal Datalog program are made up of horn clauses Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 49

Interpretation of Rules n There are two main alternatives for interpreting rules: n n

Interpretation of Rules n There are two main alternatives for interpreting rules: n n Proof-theoretic Model-theoretic Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 50

Interpretation of Rules n Proof-theoretic n n n Facts and rules are axioms Ground

Interpretation of Rules n Proof-theoretic n n n Facts and rules are axioms Ground axioms contain no variables Rules are deductive axioms Deductive axioms can be used to construct new facts from existing facts This process is known as theorem proving Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 51

Proving a new fact n Figure 24. 12 Copyright © 2007 Pearson Education, Inc.

Proving a new fact n Figure 24. 12 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 52

Interpretation of Rules n Model-theoretic n n Given a finite or infinite domain of

Interpretation of Rules n Model-theoretic n n Given a finite or infinite domain of constant values, we assign the predicate every combination of values as arguments If this is done fro every predicated, it is called interpretation Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 53

Interpretation of Rules n Model n n Model-theoretic proofs n n An interpretation for

Interpretation of Rules n Model n n Model-theoretic proofs n n An interpretation for a specific set of rules Whenever a particular substitution to the variables in the rules is applied, if all the predicated are true under the interpretation, the predicate at the head of the rule must also be true Minimal model n Cannot change any fact from true to false and still get a model for these rules Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 54

Minimal model n Figure 24. 13 Copyright © 2007 Pearson Education, Inc. Publishing as

Minimal model n Figure 24. 13 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 55

Datalog Programs and Their Safety n Two main methods of defining truth values n

Datalog Programs and Their Safety n Two main methods of defining truth values n Fact-defined predicates (or relations) n n Listing all combination of values that make a predicate true Rule-defined predicates (or views) n Head (LHS) of 1 or more Datalog rules, for example Figure 24. 15 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 56

Datalog Programs and Their Safety n A program is safe if it generates a

Datalog Programs and Their Safety n A program is safe if it generates a finite set of facts n Fact-defined predicates (or relations) n n Listing all combination of values that make a predicate true Rule-defined predicates (or views) n Head (LHS) of 1 or more Datalog rules, for example Figure 24. 15 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 57

Use the Relational Operations n Many operations of relational algebra can be defined in

Use the Relational Operations n Many operations of relational algebra can be defined in the for of Datalog rules that defined the result of applying these operations on database relations (fact predicates) n Relational queries and views can be easily specified in Datalog Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 58

Evaluation of Non-recursive Datalog Queries n Define an inference mechanism based on relational database

Evaluation of Non-recursive Datalog Queries n Define an inference mechanism based on relational database query processing concepts n See Figure 24. 17 on predicate dependencies for Figs 24. 14 and 24. 15 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 59

Recap n n Active database & triggers Temporal databases Spatial and Multimedia databases Deductive

Recap n n Active database & triggers Temporal databases Spatial and Multimedia databases Deductive databases Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 60