Bài giảng Temporal Databases

There are two commonly used methods to implement a temporal database application:  Method 1: Firstly, build a software layer which support the temporal data model and its temporal query language on top of a RDBMS (That means the layer can analyze and process the temporal queries. The main advantage of this method is the possibility of reusing the services of the RDBMS). Then develop the database application by utilizing the layer. Method 2: After understanding all the complexity of temporal databases, the developer develops the application using directly the SQL language and the host language supplied by RDBMS. That means he has to deal with all the complexity of temporal databases in the application programs.

ppt90 trang | Chia sẻ: vutrong32 | Lượt xem: 838 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Bài giảng Temporal Databases, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
*Temporal Databases VALID-TIME TEMPORAL DATA MODEL TIME NORMALIZATION TEMPORAL QUERY LANGUAGE CONCEPTUAL DESIGN AND LOGICAL DESIGN*What is temporal DB?Temporal databases, encompass all DB applications that require some aspect of time when organizing their information. They exhibit the need for developing a set of unifying concepts for application developers to use. Temporal DB applications have been developed since the early days of database usage. However, in creating these applications, it was mainly left to the application developers to discover, design, program, and implement the temporal concepts.*Applications of temporal dbThere are many examples of applications where some aspect of time is needed to maintain the information in a DB.Health care: patient histories need to be maintainedInsurance: claims and accident histories are requiredFinance: stock price histories need to be maintained.Personnel management: salary and position history need to be maintainedBanking: credit histories*This chapter will introduce some of the concepts that have been developed to deal with the complexity of temporal database applications.TerminologyValid time. The valid time denotes when facts are true with respect to the real world.Transaction time. The transaction time of a database fact is the time when the fact is current in the database. *Unlike valid time, transaction time may be associated with any database entity. Although time is a continuous value in the real world, for database application, time is usually discretized as timepoints on a timeline.Chronon. A chronon is the shortest duration of time supported by a temporal DBMS. It is a non-decomposable unit of time.*1. VALID-TIME TEMPORAL DATA MODELTemporal database systems typically use relational databases, which provide well-defined data models and query languages. However, the relational model has two significant shortcomings regarding temporal data: 1. The relational model provides poor support for storing complex temporal information. An example of this shortcoming is that the relational model does not support automatic merging of temporally overlapping data. * 2. The SQL query language provides very limited support for expressing temporal queries.Therefore, applications that work with complex temporal data should define their own (1) temporal models and (2) query systems.*Intervals, state tables and event tablesSeveral extensions to the relational model have been proposed to deal with two above shortcomings. Valid-time databases: time factor is attached to all tuples in a temporal table. In valid time databases, two-dimensional relational tables are extended to incorporate time as a third dimension. In these tables, every tuple holds temporal information denoting the information’s valid time.*Two types of temporal tables: - event tables, which hold instant timestamps, and - state tables, which hold interval timestamps. EX: laboratory-test values are always stored in event tables. Information about drug treatments can be held in state tables. Temporal data in state table can be represented as intervals, which are bounded by start and stop timepoints. EX: [d04:d10] is the interval with start timepoint d04 denoting the 4th day and stop timepoint d10 denoting the 10th day.*Interval-extended relational modelSince temporal data in both state tables and event tables can be represented as intervals, we have an interval-stamping method for modeling a temporal DB. A relation in such a database is called a history. Each tuple will store the temporal dimension of an entity over a closed interval; a pair of columns will be required to represent the endpoints of the interval. This temporal data model is also called the interval-extended relational model, or historical data model.*Example temporal tableA temporal table SALARY that holds information about employees and their salaries. EmpnoSalTETS521859522010205225213852313947523848Now97301217973518Now*Point Type of intervalsIn our temporal data model, timepoints will have only a single granularity, which is at the smallest level of interest in the DB applications. EX: If granularity is one day, then we can say that the timepoints are all values of type DATE, and type DATE is the point type of intervals.When we consider an interval value, [d04:d10], the interval includes its begin and end points d04 and d10, by definition. The interval consists of a set of points arranged in according to some agreed ordering. *A given type T is usable as a point type of all the following are defined for it:  A total ordering, according to which the infix operator “>” is defined for every pair of values v1 and v2 of type T.  “first” and “last” operators, which return the smallest and the largest value of T, respectively, according to the above ordering.  “next” and “prior” operators, which return the successor and the predecessor, respectively, of any given value of type T.*Interval operationsSince intervals are represented as pairs of timepoints, comparisons between intervals are based on timepoint comparisons of the upper and lower bounds. The interval comparison operators are BEFORE, AFTER, DURING, CONTAINS, OVERLAPS, MEETS, STARTS, FINISHES, and EQUAL. This set of comparisons was originally defined by Allen. Let I1, I2 be two intervals, and begin(I), end(I) be respectively the lower bound and upper bound of the interval I. The definitions of 13 interval comparisons are given in Table 1. *Comparison operatorMeaning1I1 before I2I1E I2S  I1E  I2E)(I1SI2S  I1E I1S  I2E  I1E) (I2SI1S  I2E I2S I1E I1S I2E I2S  I1E=I2EI2S > I1S  I1E=I2E13I1 equivalent I2I1S = I2S  I1E=I2EWe say I1 MERGES I2 if I1 and I2 satisfy any of the comparison operators from (3) to (13) in Table 1.*Fold operationOperators such as Union, Difference, Projection, and Cartesian product of the standard relational model remain the same in the valid-time temporal data model. Besides, there one important operator that works on temporal relations: fold. Tuples in a temporal relation that agree on the explicit attribute values and that have adjacent or overlapping time intervals are candidates for folding.*Definition (Fold Operation). When an n-ary relation R is folded on interval attribute Ai, 1  i  n, all its tuples whose Aj components match j  i and whose Ai components can merge, are replaced in the resulting relation by a single tuple with the same Aj components, but in its ith component is formed by a merging of the ith component of these tuples.Ex: let R be a table. After folding the table R on the Duration column, we get the table RF as in Figure 1.*NameDosageDurationJohnWadaine[4,6]JohnWadaine[1,2]PaulWadaine[1,9]JohnWadaine[6,Now]PaulWadaine[7,12]NameDosageDurationJohnWadaine[1,2]JohnWadaine[4,Now]PaulWadaine[1,12]*Folding the relation R on temporal attribute Ai can be defined procedurally as.begin S:= R; while there exist distinct tuples t1 and t2 such that (t1[Ai] MERGES t2[Ai]) and (t1[Aj] = t2[Aj] for all Aj  Ai) do S:= (S –{t1,t2})  {(t1[A1],,t1[Ai-1], t1[Ai]  t2[Ai], t1[Ai+1],,t1[An])}end.where the operator  is defined so that if I1  I2 = I3 then begin(I3) = min(begin(I1), begin(I2))  end(I3) = max(end(I1), end(I2)).*Unfolded relations can arise in many ways, e.g. via a projection or union operator, or on update or insertion without enforcing folding.Some other authors use the term pack ([4]) or coalese ([2]) for fold. Navathe & Admed ([7]) provided the first algorithm: sort the relation on a composite key of explicit attributes and time start, and then scan the relation, extending the period of some tuples and deleting other tuples. Lorentzos ([5]) uses a similar algorithm for folding. Bohlen et al. ([2]) also suggest some iterative and non-iterative approaches for efficiently performing folding.*TIME NORMALIZATIONThis section defines different types of synchronism among time-varying attributes. It is valid to maintain synchronous attributes in a single relation. We define the concept of temporal dependence, which is used to define the notion of time normalization.Synchronism and Temporal DependenceA set of time-varying attributes (TAVs) in a given relation is called synchronous if every TVA can be uniformly associated with and be directly applied to the timestamp values in each tuple of the relation.*. Example 1: The Employee Relation. Here, an employee gets a raise in salary if and only if he or she gets a promotion, and an employee is never demoted. Thus, the Salary and Position form a set of synchronous attributes. EmpnoSalaryPositionTSTE3320KTypist12243325KSecretary25354527KJr Engr28374530KSr Engr3842*Example 2: The relation Maintenance. All time-varying attributes Part, Cond, Place and Cost collectively describe the maintenance event. These TVAs form a quasi synchronous set.Plane#PartCondPlaceCostTSTE91WheelDetachedAtlanta10001020105DoorBrokenN.Y.20003547105DoorUnhingedL.A.25003562142WingCrackedBoston70006072*The relation Sal-MgrEmpnoSalaryManagerTSTE5218KSmith595220KSmith10205225KSmith21295225KJones30385231KJones39425231KSmith43475238KSmith48Now9730KBradford12179735KBradford18Now*Consider the relation Sal-Mgr. The relation shows the manager and salary of employees over a period of time. In this relation, the attributes Salary and Manager form two singleton synchronous. They change in an asynchronous fashion. Such asynchronism leads to the fragmentation of the lifespan information of a TVA over several tuples and create update and retrieval anomalies. *Definition (Temporal dependence). Let R be a time-varying relation, where K is its temporal invariant key, and let Xi, for i  [1,n], be its TVAs and TS and TE be its timestamp attributes. In a relational schema R, for any two TVAs Xi and Xj (i != j), R is said to have a temporal dependency, Xi  T  Xj, iff there exists an instance of R such that it contain 2 tuples t1 and t2 such that:t1(K) = t2(K)t1(Xi) = t2(Xi) XOR t1(Xj) = t2(Xj)intervals [t1(TS),t1(TE)] and [t2(TS), t2(TE)] are adjacent.*In Sal-Mgr, the attributes Salary and Manager, according to the above definition, have a temporal dependency (consider two tuples and or two tuples and ).Temporal dependency arise when two or more temporally unrelated facts are mixed in one time-varying relation.*Time NormalizationA relation is in time normal form (TNF) iff it is in BCNF and there exists no temporal dependency among non-key attributes.It is always possible to decompose a relation, if a temporal dependency exists, into two or more time-normalized relations by partitioning the attributes and merging the relevant time intervals.EX: Sal-Mgr can be decomposed into two relations, Manager and Salary.*EmpnoMgrTSTE52Smith52952Jones304252Smith43Now97Bradford12NowEmpnoSalrTSTE5218K595220K10205225K21385231K39475238K48Now9730K12179735K18Now*The Need for Time Normalization The idea for time normalization is the requirement that tuples be semantically independent of one another. By definition, a relation is a set; hence, its elements (tuples) must be independent of one another. In an unnormalized TVR, every tuple has incomplete information about the lifespan of its attributes; therefore, it becomes dependent on other tuples for the determination of such information.In Sal-Mgr relation, the tuple does not represent the start time and end-time of the attribute value “Smith” for Manager. This tuple has incomplete information regarding the lifespan of attribute value “Smith”.An asynchronous change in the value of one attribute splits the lifespan information of other attributes over different tuples.* Another anomaly is a simple query may retrieve a completely meaningless result.Ex: “When did Smith become the manager of employee 52?”  [Empno, Mgr, Ts]  Empno = 52 AND Mgr = ‘Smith’The following result is incorrectEmpno Manager Ts-------------------------------------------52 Smith 552 Smith 1052 Smith 2152 Smith 4352 Smith 48*The correct result should beEmpno Manager Ts---------------------------------------52 Smith 552 Smith 43  Different time varying attributes may change at entirely different rates. Therefore, there is a redundant repetition of the values of a TVA that is varying at a rate slower than that of the other.Time normalization avoids these redundancies and update and retrieval anomalies.*3.TEMPORAL QUERY LANGUAGEA query language called TSQL, which has been designed for querying a temporal database. TSQL was proposed by S.B. Navathe and R. Ahmed, 1993. TSQL is a superset of SQL and introduces several new semantics and syntactic components.TSQL add the following new constructs to standard SQL: - Conditional temporal expressions using the WHEN clause - Retrieval of timestamp values with or without computation * - Retrieval of temporally ordered information - Specification of time domain using the TIME-SLICE clause - Modified aggregate functions and the GROUP BY clauseThe formal syntax of a TSQL retrieval statement: SELECT [FIRST| SECOND|THIRD| Nth |LAST] select_item_list FROM table_name_list WHEN temporal_comparison_list WHERE search_condition_list*Example DatabaseTSQL will be illustrated by examples on a database with the following relational schema: E(eno, name, address, date-of-birth) S(eno, salr, TS, TE) M(eno, mgr, TS, TE) T(eno, city, country, cost, TS, TE)E stands for Employee, S for Salary, and M for Manager, T for travel.*Temporal Query Semantics Syntax of temporal query language is an extension of standard SQL syntax. The semantics of a temporal query are based on the temporal relational model outlined in section 1. The temporal semantics contained in a temporal query cannot be translated in to standard relational algebra. We modify and extend standard relational algebra to create a version that incorporates temporal operations on timepoints and intervals.A set of algebraic operators that support temporal querying requirements: temporal projection, selection, and joins*Assumption: well-defined tablesAssume that the valid time component in temporal table(s) must be well-defined before performing the operation. That means temporal tables do not contain tuples with the same non-temporal attribute values but overlapping or consecutive time intervals. Such tuples are automatically folded in advance by merging their time intervals.*Temporal projectionTemporal projection is similar to standard projection, except that the restriction applies to only the non-temporal attributes. Both timestamp columns cannot be excluded in the resultant history. After temporal projection, folding is enforced in order that adjoining intervals should be merged into a single interval in the resultant relation.*Temporal selectionTSQL adds the following new construct to standard SQL: selection based on temporal comparisons of timepoints and intervals using terms in a WHEN clause. The WHEN clause is used to express the temporal part of a query. The temporal comparison in the WHEN clause has the following form: WHEN a interval_compare_operator b where a,b are intervals and interval_compare_operator can be one of the keywords: BEFORE, AFTER, DURING, EQUIVALENT, ADJACENT, OVERLAPS, PRECEDES, and FOLLOWS.*[a,b] BEFORE [c,d] iff b d[a,b] DURING [c,d] iff (a  c) & (b  d)[a,b] EQUIVALENT [c,d] iff ( a = c ) & (b = d )[a,b] ADJACENT [c,d] iff (c – b =1) | (a – d = 1)[a,b] OVELAP [c,d] iff ( a  d) & (c  b)[a,b] FOLLOWS [c,d] iff (a – d = 1)[a,b] PRECEDES [c,d] iff (c – b = 1)The comparison operators BEFORE, AFTER, DURING, PRECEDES, and FOLLOWS are not commutative, whereas EQUIVALENT, ADJACENT, and OVELAP are. *Q1: Find the salary of employee 125 when Smith was his manager. SELECT salr FROM S, M WHERE S.eno = M.eno and M.eno = 125 and M.mgr = ‘Smith’ WHEN S.INTERVAL OVERLAP M.INTERVALQ2: Find the manager of employee 23 who immediately succeeded manager Jones and also the time of the occurrence of this event. SELECT B.mgr, B.TIME-START FROM M A, M B WHERE A.eno = B.eno AND A.eno = 23 AND A.mgr = ‘Jones’ WHEN B.INTERVAL FOLLOWS A.INTERVAL*Temporal join This join has the most special semantics: the valid-time intervals of the resultant table are created from the intersection of the overlapping valid-time elements of the tables specified in the join. Assumption: The valid time component in each temporal table must be well-defined before performing such joins.*To perform joining two temporal tables, we must first assemble the non-temporal columns. The columns are assembled by generating the cross product of the non-temporal columns from the operand tables, and then excluding rows that do not satisfy the conditions in the WHERE and WHEN.Then, we must examine the source tuples for each candidate tuple in the reduced cross product to see if their valid time periods overlaps. - If they overlap, the candidate tuple is included in the final join and the result of the intersection of two valid time periods is used as the valid time period of the new tuple. - If they do not ovelap, this tuple is excluded from the result of the join. *An example of temporal joinPROBLEMLISTPatient Problem TS TE----------------------------------------------------------------------J. Smith P1 14/Feb/1998 1/Mar/1998J. Smith P2 10/Mar/1998 NowP. Jones P3 1/Apr/1998 12/May/1998R. Franks P3 13/Feb/1998 1/Jun/1998DRUGSPatient Drug VS VE-----------------------------------------------------------------------J. Smith D1 20/Mar/1998 12/May/1998P. Jones D1 1/Apr/1998 6/Jun/1998R. Franks D2 4/Feb/1998 14/May/1998“Show all problem and drug comibinations for patient”*TEMPORALSELECT T1.Patient, T1.Problem, T2.DrugFROM PROBLEMLIST AS T1, DRUGS AS T2WHERE T1.Patient = T2.PatientThe resultant table:Patient Problem Drug TS TE------------------------------------------------------------------------------J. Smith P2 D1 20/Mar/1998 12/May/1998P. Jones P2 D1 1/Apr/1998 12/May/1998R. Franks P3 D2 13/Feb/1998 14/May/1998*Retrieval of TimestampsWe showed how to retrieve data values based on temporal conditions. Now we show how to retrieve time points or intervals that correspond to certain condition. For retrieving the timestamp values, the target list of timestamps is specified in the SELECT clause.This target list contains the unary postfix operators TIME-START or TIME-END, which must be qualified by the relation name if two or more relations participate in the query; otherwise the relation name is implicit.*If more than one relation participates in the query, however, then new timestamp values may have to be computed from those of the participating tuples. TSQL allows an operation called inter (i.e. intersect) to be applied on the timestamps in the target list. The operator inter takes two intervals and returns another interval which is their intersection. [a,b] inter [c,d] = [max(a,c), min(b,d)] The underlying condition is that the time intervals must overlap.*Q1. List the manager and salary history of all employees while their salary was less than 40K. Retrieve the intersecting (overlapping) time intervals. SELECT M.eno, mgr, sal, (M inter S).TIME-START, (M inter S). TIME-END FROM S, M WHERE S.eno = M.eno AND salr 30K*The TIME-SLICE Clause The TIME-SLICE clause specifies the time period or time point. These specifications imply that only those tuples are selected from the underlying relations that are (fully or partially) valid for the specified time period or time point.The syntax of this clause requires the keyword TIME-SLICE followed by either - an interval expressed by temporal constants enclosed within square brackets or - a time point expressed by a temporal constant.*Q1. List all changes of salary during the years 1972-1978 for all employees whose manager was Bradford. SELECT S.eno, salr, S.TIME-START FROM S, M WHERE S.eno = M.eno AND mgr = ‘Bradford’ WHEN M.INTERVAL OVERLAP S.INTERVAL TIME-SLICE year [1972, 1978]*The current values of underlying relations can be retrieved by specifying the temporal constant NOW in the TIME-SLICE clause.Q2. List the manager history of all employees in the last five years. SELECT eno, mgr, TIME-START FROM M TIME-SLICE year [NOW –5, NOW]*Aggregate Functions and GROUP BY In a temporal database, only time-start and time-end are recorded for each tuple. However, a query may refer to the length of a time interval given by [TE – TS]. In TSQL, this is referred to simply as DURATION. TSQL allows the usual aggregate functions – max, min, count, avg, and sum – to be applied on the duration of time intervals.Q1. Find the period of time for which employee 45 worked under manager Jones. SELECT eno, SUM (DURATION) FROM M WHERE mgr = ‘Jones’ AND eno = 45 *GROUP BY clauseTSQL’s GROUP BY clause is an extension of the conventional GROUP BY. TSQL allows timestamps to be used in the GROUP BY clause. Since in most cases timestamps are a combination of several fields (e.g. year, month, date, hour, minute, etc.), one or more of these fields can be specified in the GROUP BY clause.*The following examples assume that the timestamps of the relations have only these fields: year, month, date.Q2. Find the calendar years during which an employee made more foreign (other than U.S.) visits than domestic visits. SELECT A.eno, A.TIME-START.year FROM T A, T B WHERE A.eno = B.eno AND A.country = ‘U.S.’ AND B.country != ‘U.S.’ WHEN A.TIME-START.year = B. TIME-START.year GROUP BY A.eno, A.TIME-START.year HAVING COUNT(UNIQUE B.TIME-START) > COUNT(UNIQUE A.TIME-START)*Q3. For every employee and for every year, list the city that was visited most often in that year, and the number of times it was visited. SELECT eno, TIME-START.year, city, MAX(COUNT(*)) FROM T GROUP BY eno, TIME-START.year, city*Insertion of data A new tuple can be inserted to a temporal table with the specified attribute values including an interval [V_end, V_begin] which builds the initial tuple lifespan. The syntax of the INSERT statement: INSERT INTO () VALUES When a new tuple is inserted into table, then the Fold operator is enforced in order to merge the intervals, if necessary.*Example:INSERT INTO SALARY(eno, salr, TS, TE) VALUES (97, 28K, 5, 11)SALARYENOSALRTSTE5218K595220K10205225K21385231K39475238K48Now9728K5119730K12179735K18Now*Modification of data. When updating a temporal table, a WHEN clause can be used to indicate the valid time associated with the update. The syntax of the UPDATE statement: UPDATE SET = WHEN WHERE Only tuples that have a valid-time intersecting with the specified period in the WHEN clause are updated by the above command. *Modification of data (cont.)Notice that using UPDATE command may result in a relation with more tuples than the original one. The explanation for this is as follows.The new value y is assigned to a specific attribute A of a given tuple in an interval [t1,t2]. Value y is specified in SET clause, [t1, t2] is given in the WHEN clause. Time t1 must be specified. If t2 is omitted then [t1, t2] means [t1,]. Assuming that, the specified attribute A has the value x at the time t1. Depending on [t1, t2], there are 4 cases that may happen. *Modification of data (tt.) ts _______________________ te t1 ___________ t2ts _______________________ tet1 ______________ t2ts ________________________ te t1 ___________ t2*Example:UPDATE SALARY SET salr = 34WHEN [18,25]WHERE eno = 97 AND salr = 35ENO SALR TS TE52 18K 5 952 20K 10 2052 25K 21 3852 31K 39 4752 38K 48 Now97 30K 12 1797 34K 18 2597 35K 26 Now*Deletion of Data When deleting data from a temporal table, a WHEN clause can be used to indicate the valid time associated with the deletion. The syntax of the DELETE statement : DELETE FROM WHEN WHERE Only tuples that have a valid-time intersecting with the specified period are affected by the above command *Deletion of Data (cont.)Note: Similar to UPDATE, using DELETE command may result in a relation with more tuples than the original one. ts te _______________________ t1 __________ t2*Example:DELETE FROM SALARYWHEN [13,16]WHERE eno = 52 AND salr = 20ENO SALR TS TE52 18K 5 952 20K 10 1252 20K 17 2052 25K 21 3852 31K 39 4752 38K 48 Now97 30K 12 1797 34K 18 2597 35K 26 Now*Algorithm for Fold Operation The algorithm of Fold operation was first developed by Lorentzos, 1993. This is a nested-loop algorithm, similar to the algorithm used to duplicate elimination in conventional databases. The algorithm of fold algorithm for a relation R (A1,,An, TS, TE) is given below:*R is sorted on all its attribute and written to Swhile not eof(S) dobegin read(S, a, TS, TE); while not eof(S) do begin read(S, a1, T1S, T1E); if a1 = a then if [TS,TE] OVERLAPS [T1S,T1E] then TE := T1E else begin write(T, a, TS, TE); TS := T1S; TE := T1E end else // a1  a // begin write(T, a, TS, TE); a:= a1; TS := T1S; TE := T1E end; write(T, a, TS, TE) end end // T keeps the resultant relation//*CONCEPTUAL DESIGN AND LOGICAL DESIGN FOR TEMPORAL DATABASESConceptual DesignThere’re some approaches in conceptual design for temporal DB. Snodgrass advocates the following approach:“ Conceptual design initially ignores the time-varying nature of the application. We focus on capturing the currently reality and temporarily ignore any history that may be useful. Only after the full design is complete, we augment the ER schema with the time-varying semantics of the application. We consider each component of ER schema in turn, annotating that component with its temporal semantics, if any. Entity types, relationship types, attributes, and keys are each individually considered.”*Nontemporal ER Schema        Strong Entity Types         Weak Entity Types         Entity Type Identifiers (Key Attributes)         Attributes         Relationship Types Integrity Constraints *Adding Temporal AnnotationsEntity LifespansEntities have a lifespan denoting when they existed. Entities are instantaneous or have a lifespan with a duration. If the entities of an entity type exist for all of time, there may be no need to record the lifespan explicitly. (They are non-temporal).Otherwise, the entity types are temporal. In this case, the designer should also specify the granularity of the lifespan.*Adding Temporal Annotations (cont.)Relationship Valid TimeA relationship type can either model instantaneous or it can model relationships that have a duration. The valid time for any specific relationship must be a subset of the intersection of the lifespans of the associated entities. *Adding Temporal Annotations (cont.)Valid Time of Attributes The value of an attribute may change over the lifespan of the associated entity or the valid time of the associated relationship, or may not vary over time. The valid time of an attribute’s value for any specific entity (or relationship) must be a subset of the lifespan of that entity (relationship).Key Attributes A time-varying key uniquely identifies a particular entity at each point in time. A nontemporal key (time-invariant key) identifies a particular entity over all time.*Logical Design for Temporal DBLogical Design proceeds in two stages. First, the nontemporal ER schema is mapped to a nontemporal relation schema, a collection of tables. Here again we ignore the temporal aspects of the application. In the second stage, each of the annotations is applied to the logical schema, modifying the tables (or the integrity constraints) to accommodate that temporal aspect. We proceed in a disciplined fashion, dealing with each annotation in turn.Mapping to Relational Schema. The nontemporal ER schema is mapped to a nontemporal relation schema, a collection of tables. *Applying Temporal Annotations User-Defined-Time Attributes Each attribute is mapped to a column in the associated table. Attributes that record user-defined-time values can be of type: an instant, and an interval or a period. All temporal values have a granularity. Entity Lifespan To each table corresponding to an entity type for which the lifespan or valid time of an associated attribute is captured, there are two alternatives for timestamps:-         instant-         period (represented with two instants) *Applying Temporal Annotations (cont.)Relationship Valid Time To each table corresponding to a relationship type with a recorded valid-time extent or having attribute(s) whose valid time is recorded, we add either instant or period timestamps. In short, for tables corresponding to entity and relationship types for which valid time is to be recorded, add either - a single instant timestamp column or - a period timestamp, represented with two instant timestamp columns. *Applying Temporal Annotations (cont.)Valid Time of AttributesIf some attributes have a valid time and if the lifespan of the associated entity or the valid time of the associated relationship is not recorded, the time-varying columns should be placed in a separate table, along with the primary key of the original table, which also serves as a foreign key to that table. This task is termed temporal support decomposition. Example: EMPLOYEE(empno, sal, sex, addr, birth-of-date,) in which sal is an attribute with valid time, should be separated into two tables: EMPLOYEE(empno, sex, addr, birth-of-date,) SALARY(empno, sal, ts, te)*Applying Temporal Annotations (cont.)Note: When the granularity of the attribute is finer than that of the entity or relationship type to which the attribute is attached, there are two possible ways: (1)   We change the granularity of the associated table (entity type) to that of the column (attribute). (2)   We can break off those columns into a separate table, termed precision decomposition. In short, we should decompose tables so that all attributes of a table have an identical temporal support and precision.*Applying Temporal Annotations (cont.)Temporal Keys The first consequence of adding valid-time support to a table is that the primary key of such tables needs to take the timestamp into consideration. Remember that the primary key of a table must be unique.Some times, we should add one or both of the new temporal columns to the key. Example 1: POSITION(empno, pos, ts, te) The key can be (empno, pos)Example 2: SALARY(empno, sal, ts, te) The key can be (empno, ts).*ExamplesExample 1: teacher career management database.*Example 1: Teacher career management database- TEACHER, THESIS, COURSE: nontemporal entity types- RESEARCH_PROJ: an entity type with a lifespan.- TEACH: a relationship type with valid-time.-  -   PARTICIPATE: a relationship type with valid-time.-   -  SUPERVISE: a relationship type with valid-time.- Position: an attribute of TEACHER , this attibute is with a valid time.- Trainning: an attribute of TEACHER , this attibute is with a valid time.- Publication: an attribute of TEACHER , this attibute is with a valid time.- Working_exp: an attribute of TEACHER , this attibute is with a valid time. *Example 1 (cont.)Relational Schema TEACHER(empno, name, addr,.)COURSE(course_no, title, credits,)RESEARCH_PROJ(proj_no, proj_name, budget, time_start, time_end, chief)THESIS(thesisno, title, student,)TEACH(empno, course_no, ts, te)PARTICIPATE(empno, proj_no, role, ts, te)SUPERVISE(empno, thesisno, role, ts, te)TEACHER_POSTION(empno, pos, ts, te, result)TEACHER_TRAINING(empno, training_course, ts, te)TEACHER_PUBLICATION(empo, title, type, detail, timeofprint)WORKING_EXPERIENCE(empno, job-title, orgnization, ts, te)*Example 2: Banking database- ACCOUNT: nontemporal entity type- INTEREST_TYPE: entity type with valid time- TRANSACTION: event entity type. - BELONGS_TO: relationship type with valid time- Balance: an attribute (of ACCOUNT) with valid time *Example 2 (cont.)Relational Schema: ACCOUNT(acc-no, date_opened,)INTEREST_TYPE(int-type, int_rate, ts, te)TRANSACTION(transaction-no, event-time, event_date, type, amount, from-acc-no, to-acc-no, )BELONGS_TO(acc_no, int_type, ts, te)BALANCE(acc-no, ts, te, balance)*Example 3. Clinical Temporal Database*Example 3. (cont.)- PATIENT: non-temporal entity type- TREATMENT: an entity type with a lifespan- DRUG_MEDICATION: an entity type with a lifespan- SURGERY an entity type with a lifespan- LAB_TEST: an event entity type.Note: SURGERY, DRUG_MEDICATION, LAB_TEST are weak entity types dependent on the TREATMENT entity type.- Bed-no: an attribute (of TREATMENT) with valid time.*Example 3. (cont.)Relational Schema: PATIENT(p-id, name, addr, sex, age,)TREATMENT(file-no, p-id, disease, ts, te)DRUD_MEDICATION(file-no, drug, dosage, ts, te)SURGERY(file-no, op-name, op-room, ts, te)LAB_TEST(file-no, test-name, event-time,)BED(file-no, bed-number, ts, te)*HOW TO IMPLEMENT A TEMPORAL DATABASE APPLICATION There are two commonly used methods to implement a temporal database application: Method 1: Firstly, build a software layer which support the temporal data model and its temporal query language on top of a RDBMS (That means the layer can analyze and process the temporal queries. The main advantage of this method is the possibility of reusing the services of the RDBMS). Then develop the database application by utilizing the layer.Method 2: After understanding all the complexity of temporal databases, the developer develops the application using directly the SQL language and the host language supplied by RDBMS. That means he has to deal with all the complexity of temporal databases in the application programs.

Các file đính kèm theo tài liệu này:

  • ppttempor_1_6943.ppt