where does time go ?. applications abound temporal database systems provide built-in support for...

43
Where does time go ?

Upload: teresa-anderson

Post on 18-Jan-2018

215 views

Category:

Documents


0 download

DESCRIPTION

Applications abound It is difficult to identify applications that do not need support for temporal data Temporal database systems provide built-in support for recording and querying time-varying information Temporal applications would benefit from built-in support at the data model and query language layers

TRANSCRIPT

Page 1: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Where does time go ?

Page 2: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Applications abound

• Temporal database systems provide built-in support for recording and querying time-varying information

• Application areas– Media: planning advertisements– Accounting: cash flow analysis– Financial: stock market– GIS: land use– Medical: patient records– Academic: course attendance– Scientific: archeological findings

Page 3: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Applications abound

• It is difficult to identify applications that do not need support for temporal data

• Temporal database systems provide built-in support for recording and querying time-varying information

• Temporal applications would benefit from built-in support at the data model and query language layers

Page 4: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

What time ?

Page 5: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Time ontology

• Time is an ordered sequence of points– Linear time– Branching time (futures)– Partial time ordering (DAG)– Cyclic times

• Bounded or unbounded time lines– Bounded: origin exist and it ends– Unbounded: only partial order is known

Page 6: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Time ontology

• Time density– Discrete

• Time line is isomorphic to the integers• Time line is composed of a sequence of non-decomposable

time periods of some fixed, minimal duration, termed chronons

• Between each pair of chronons is a finite number of other chronons

– Dense• Time line is isomorphic to rational numbers• Between each pair of chronons is a finite number of other

chronons– Continuous

• Time line is isomorphic with the real numbers• Between each pair of chronons is a finite number of other

chronons

Page 7: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Time ontology

• A time instant is a time point on the real time line– An event is an instantaneous fact, i.e something occurring at an

instant. The event occurrence time of an event is the instant at which the event occurs in the real world

– An instant set is a set of instants

– A time period is the time between two instants• [also called interval]

– A time interval is a directed duration of time. A duration is an amount of time with a known length, but no specific starting or endings instants. It is also called a span.

– A temporal element is a finite union of periods

Page 8: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Clocks

• A clock is a physical process coupled with a method of measuring that process– The units of measurement are the chronons of the clock– Clocks provide the semantics of the timestamp

representation

– Clocks can be defined over various calendar structures

Page 9: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Times and facts

• Valid time of a fact: when the fact is true in the modeled reality

• Transaction time of a fact: when the fact is current in the database and may be retrieved

• Four kinds of temporal tables:– Snapshot : table without time– Valid-time– Transaction-time :append only tables– Bi-temporal

Page 10: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Transaction and valid time tables

• Transaction time tables– Append only: corrections to previous snapshot states is

not permitted– Support of transaction time – Support rollback queries

• Valid time tables– May be modified– Support valid time– Short historical queries

Page 11: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Can’t we use SQL for temporal support ?

Page 12: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Time Specification in SQL-92

• date: four digits for the year (1--9999), two digits for the month (1--12), and two digits for the date (1--31).

• time: two digits for the hour, two digits for the minute, and two digits for the second, plus optional fractional digits.

• timestamp: the fields of date and time, with six fractional digits for the seconds field.

• Times are specified in the Universal Coordinated Time, abbreviated UTC (from the French); supports time with time zone.

• interval: refers to a period of time (e.g., 2 days and 5 hours), without specifying a particular time when this period starts; could more accurately be termed a span.

Page 13: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

A case study

• Consider a simple university database– Employee(Name,Salary,Title)

• Finding an employee’s salary is easySelect SalaryFrom EmployeeWhere name= ‘Bob’

Page 14: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

A case study

• Now consider addition of a Date-of-birth field– Employee(Name,Salary,Title, Dob DATE)

• Finding the employee’s date of birth is easySelect DobFrom EmployeeWhere Name=‘Bob’

Page 15: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

A case study

• Extend the database with an employee history– Employee(Name,Salary,Title, Dob,

Start DATE, stop DATE)

• To the datamodel these columns are identical to Dob

Name Salary Title Dob Start Stop

Bob 40000 UD 1953-10-25 1985-01-01 1993-06-01

Bob 50000 UDH 1953-10-25 1993-06-01 1996-01-01

Bob 50000 Prof 1953-10-25 1997-01-01 1998-01-01

Bob 60000 Prof 1953-10-25 1998-01-01 2000-01-01

Bob 70000 Prof 1953-10-25 2000-01-01 now

Page 16: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

A case study

• Find the current salarySelect SalaryFrom EmployeeWhere Name=‘Bob’and Start <= current_time_stampAnd current_time_stap <= Stop

Name Salary Title Dob Start Stop

Bob 40000 UD 1953-10-25 1985-01-01 1993-06-01

Bob 50000 UDH 1953-10-25 1993-06-01 1997-01-01

Bob 50000 Prof 1953-10-25 1997-01-01 1998-01-01

Bob 60000 Prof 1953-10-25 1998-01-01 2000-01-01

Bob 70000 Prof 1953-10-25 2000-01-01 now

Page 17: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

A case study

• Find the salary historySelect Salary, start, stopFrom EmployeeWhere Name=‘Bob’and Start <= current_time_stamp

Salary Start Stop

40000 1985-01-01 1993-06-01

50000 1993-06-01 1997-01-01

50000 1997-01-01 1998-01-01

60000 1998-01-01 2000-01-01

70000 2000-01-01 now

Coalesce these tuples

Page 18: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

A case study

• Find the salary history but take into account the title– Give the user a print out– Or combine intervals with the same function and salary,

I.e. compress the table as much as possible

Name Salary Title Dob Start Stop

Bob 40000 UD 1953-10-25 1985-01-01 1993-06-01

Bob 50000 UDH 1953-10-25 1993-06-01 1996-01-01

Bob 50000 Prof 1953-10-25 1997-01-01 1998-01-01

Bob 60000 Prof 1953-10-25 1998-01-01 2000-01-01

Bob 70000 Prof 1953-10-25 2000-01-01 now

Page 19: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

A case study

• Find the salary history but take into account the title– Or combine intervals with the same function and salary, I.e.

compress the table as much as possibleCreate table Temp(salary,start,stop) as select Salary,Start,Stop from

Employee where Name = ‘Bob’ RepeatUpdate Temp as T1Set t1.stop= (select max(T2.stop) from Temp as T2 where

T1.salary=T2.salary and T1.start<T2.start and T1.Stop>=T2.Start and T1.stop<T2.stop)

Where exist( select * from Temp as T2 where T1.salary=T2.salary and T1.Start <T2.start and T1.start<T2.start and T1.Stop>=T2.Start and T1.stop<T2.stop)

Until no tuples are updated

Page 20: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

A case study

• Find the salary history but take into account the title– Or combine intervals with the same function and salary,

I.e. compress the table as much as possible– Use standard SQL leads to triple nested queries– Use SQL cursor methods and rely on iterations

Page 21: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Objectives of a temporal model

• Conclusion: It would be nice if the datamodel and query language understood the intended temporal behavior– Capture the semantics of time-varying information– Retain simplicity of the relational model– Strict super-set of relational model– Present information in a coherent fashion– Ensure ease of implementation– Ensure high performance

– Design your own extension to the relational model

Page 22: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Temporal Relational Model and algebra

• What kind of temporal data would you introduce in the relational model ?• Where would you introduce temporal components?• How would you define the interpretation of the relational primitives, I.e.

– Temporal selection– Temporal projection– Temporal join– Temporal union

• How would your extend the integrity rules ?

Name Salary Title Dob Start Stop

Bob 40000 UD 1953-10-25 1985-01-01 1993-06-01

Bob 50000 UDH 1953-10-25 1993-06-01 1996-01-01

Bob 50000 Prof 1953-10-25 1997-01-01 1998-01-01

Bob 60000 Prof 1953-10-25 1998-01-01 2000-01-01

Bob 70000 Prof 1953-10-25 2000-01-01 now

Page 23: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Temporal Relational Model and algebra

• What kind of temporal data would you introduce in the relational model ?– Calender information

• Timezones• Accuracy

– Time administration• Points on a time axe• Intervals• Sets of points• Sets of intervals• Fake time

Page 24: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Temporal Relational Model and algebra

• Where would you introduce temporal components?– AT the schema level– At the table– At the column level– At the attribute level– At the tuple level

Name Salary Title Dob

Bob 40000 {-1993} UD{-1993} 1953-10-25

50000{1993-1998} UDH {1993-1966}

60000{1998-2000} Prof {1997-now}

70000{2000-now}

Temporal tuple

Page 25: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Temporal Relational Model and algebra

• What kind of integrity rules ?– The key property is extended to include the temporal

semantics– No two tuples defined at the same time have identical

values– Referential constraints should obey the temporal

relationships as well

Page 26: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Temporal Relational Model and algebra

• How would you define the interpretation of the relational primitives?– When time is a tuple attribute, then the tuples are

coalesced on their temporal attribute– Duplicate elimination respects the temporal dimension– Relational joins are only defined for the same time

intervals, outerjoins should be used otherwise.

Page 27: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Temporal Query Languages

• Predicates precedes, overlaps, and contains on time intervals.• Intersect can be applied on two intervals, to give a single (possibly

empty) interval; the union of two intervals may or may not be a single interval.

• A snapshot of a temporal relation at time t consists of the tuples that are valid at time t, with the time-interval attributes projected out.

• Temporal selection: involves time attributes• Temporal projection: the tuples in the projection inherit their time-

intervals from the tuples in the original relation.• Temporal join: the time-interval of a tuple in the result is the

intersection of the time-intervals of the tuples from which it is derived. It intersection is empty, tuple is discarded from join.

Page 28: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

TSQL

• Over 40 temporal datamodels have been studied over the last two decades. The clear winner has been TSQL, a temporal extension that is part of the SQL’99 standard

• TSQL supports a bitemporal data model

• It provides condense representation of temporal queries• The TSQL project is part of the ACM Anthology• The language is illustrated through a few examples

Page 29: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

TSQL case

• Consider a Patient database with records of information about prescribed drugs

Create table Prescription (Name, Physician, Drug, Dosage,Frequency interval minute)

as valid day and transaction

• A valid time specifies the period(s) during which the drug is prescribed

• The valid time granularity is a day• The transaction time records when the information was

added to the database• The transaction time granularity is system defined.

Page 30: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

TSQL case

• TSQL supports the following (temporal) tables– Snapshot : nothing after the attributes– Valid-time state : as valid [state]<granularity>– Valid-time event :as valide event<granularity>– Transaction-time : as transaction– Bitemporal: as valid [state]<granularity> and

transacion

• The type of the table can be altered at any time– Semantics is not irreversable

Page 31: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

TSQL example

• Who has been prescribed drugs?Select snapshot Name from Prescription

– Result in a list of names of those with current or past prescriptions

• Who is or was taking the drug Proventil?– Select snapshot Name from Prescription where

Drug=‘Proventil’

Page 32: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

TSQL examples

• Snapshot reducibility, converts a temporal relation to its ordinary RDBMS equivalent. Temporal components loose their additional meaning

• Who has been prescribed drugs, and when?Select Name From Prescription

• Results in a list of names, each associated with one or more maximal periods.

Page 33: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

TSQL examples

• Snapshot reducibility, converts a temporal relation to its ordinary RDBMS equivalent. Temporal components loose their additional meaning

• What drugs have been prescribed with Proventil?Select P1.name, P2.drugFrom Prescription as P1, Prescription as P2Where P1.drug= ‘Proventil’

And P2.drug <> ‘Proventil’And P1.Name= P2.Name

– Results in a list of patient names and drugs, along with their associated maximal periods.

Page 34: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

TSQL examples

• Operators are provided to reason about validity property• Who has been on drug for more than a total of 6 months

Select Name, DrugFrom Prescription(Name,Drug) as PWhere cast(valid(P)) as interval month >interval ‘6’month

• Result will contain the maximal interval(s) when the patient has been on the drug

• Restructuring of tables as part of the from clause helps keeping queries concise

Page 35: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

TSQL restructuring

• Restructuring is syntactic sugarFrom A(B,C) as A2

• Is equivalent toFrom (select B,C from A) as A2

Nested select projects on the specified attributes and coalesces the result on its temporal properties

Other attributes in A are not accessible via A2 and A is not accessible in the enclosing select

Page 36: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

TSQL example

• Who has been on Proventil throughout their drug regime?Select snapshot P1.NameFrom Prescription(Name) as P1, P1(Drug) as P2Where P2.Drug= ‘Proventil’And valid(P2) = valid(P1)

• P1 contains all the times that any drug has been prescribed to a patient

• P2 is coalesced on the Name and Drug columns

Page 37: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Valid time projections

• What drugs was Melanie prescribed during 1994?Select DrugValid intersect(valid(Prescription), period ‘[1994]’day)From PrescriptionWhere Name=‘Melanie’

• The result is a list of drugs, each associated with a set of periods during 1994 that they were prescribed to Melanie

Page 38: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Valid time modifications

• Insert into Prescription• Values (‘Sally’,’dr Green’,Proventil’,’100mg’,

Interval ‘8:00’ minuteValid period ‘[1993/01/01-1993/06/03]’

• Inserted values will be coalesced with existing value equivalent rows

• Default valid clauseValid period(current_timestamp,

nobind(timestamp ‘now’))

Page 39: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Valid time modifications

• The delete statement removes period(s) from the temporal element of the qualifying rows

• Only if the temporal element becomes empty, the row is deleted

Delete from PrescriptionWhere Name=‘Melanie’Valid period ‘[1993/06/01-now]’

Page 40: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Event tables

• Event tables are timestamped with instant sets

• Each row identifies a particular kind of (instantaneous) event, with the timestamp of the row specifying the instant(s) when that event occurred

• The attribute valid(P) now produces a set of time points

• Event tables may also be associated with transaction time

Page 41: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Transaction tables

• The transaction timestamp is a system defined counter

• If transaction time is not mentioned in the query, the results includee only the information currently believed to be true.

• Transaction tables can be used to ‘rollback’Select DrugFrom Prescription as PWhere Name =‘Melanie’And transaction(P) overlaps date ‘1994’;

Page 42: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Temporal aggregation

• The standard aggregate operators are re-defined for TSQL to imply an automatic group on distinctive temporal periods.

• Idea: break the tuples on the smallest possible non-overlapping periods, thereafter perform aggregate and coalesce the result back into periods.

Page 43: Where does time go ?. Applications abound Temporal database systems provide built-in support for recording and querying time-varying information Application

Conclusion

• The possibilities to enhance the relational model with the notion of time has been widely studied (>40 variants)

• A consensus model has been included in SQL’99

• Time is an instantiation of a sequence, as in time-series. But temporal support to sequences is still rather mininal.– [how to extend the relational model with sequences?]