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

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Advertisements

From Handbook of Temporal Reasoning in Artificial Intelligence By Jan Chomicki & David Toman Temporal Databases Presented by Leila Jalali CS224 presentation.
1 Efficient Temporal Coalescing Query Support in Relational Database Systems Xin Zhou 1, Carlo Zaniolo 1, Fusheng Wang 2 1 UCLA, 2 Simens Corporate Research.
CS240A: Databases and Knowledge Bases Temporal Applications and SQL:1999 Carlo Zaniolo Department of Computer Science University of California, Los Angeles.
BCDM Temporal Domains - Time is linear and totally ordered - Chronons are the basic time unit - Time domains are isomorphic to subsets of the domain of.
Advanced Databases Temporal Databases Dr Theodoros Manavis
Temporal and Real-Time Databases: A Survey by Gultekin Ozsoyoglu and Richard T. Snodgrass Presentation by Didi Yao.
Time in Databases CSCI 6442 With thanks to Richard Snodgrass, 1985 ACM /85/005/0236.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Introduction to Structured Query Language (SQL)
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
CS240A: Databases and Knowledge Bases Time Ontology and Representations Carlo Zaniolo Department of Computer Science University of California, Los Angeles.
Temporal Databases. Outline Spatial Databases Indexing, Query processing Temporal Databases Spatio-temporal ….
Modification Statements in TSQL2 INSERT INTO Prescription %Executed on VALUES ('Melanie','Dr. Beren','Proventil','30 mg', INTERVAL '8:00' MINUTE)
Introduction to Structured Query Language (SQL)
CS240A: Databases and Knowledge Bases A Taxonomy of Temporal DBs Carlo Zaniolo Department of Computer Science University of California, Los Angeles.
Temporal Databases. Outline Spatial Databases Indexing, Query processing Temporal Databases Spatio-temporal ….
Time Chapter 10 © Worboys and Duckham (2004)
Database Systems More SQL Database Design -- More SQL1.
Introduction to Structured Query Language (SQL)
CS240A: Databases and Knowledge Bases Time Ontology and Representations Carlo Zaniolo Department of Computer Science University of California, Los Angeles.
CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E) 1.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
Retrievals & Projections Objectives of the Lecture : To consider retrieval actions from a DB; To consider using relational algebra for defining relations;
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Chapter 9 Designing Databases Modern Systems Analysis and Design Sixth Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
CODD’s 12 RULES OF RELATIONAL DATABASE
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Fushen Wang, XinZhou, Carlo Zaniolo Using XML to Build Efficient Transaction- Time Temporal Database Systems on Relational Databases In Time Center, 2005.
IS 230Lecture 6Slide 1 Lecture 7 Advanced SQL Introduction to Database Systems IS 230 This is the instructor’s notes and student has to read the textbook.
CS 338The Relational Model2-1 The Relational Model Lecture Topics Overview of SQL Underlying relational model Relational database structure SQL DDL and.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
CS240A: Databases and Knowledge Bases Time Ontology and Representations Carlo Zaniolo Department of Computer Science University of California, Los Angeles.
SPATIO-TEMPORAL DATABASES Temporal Databases. Temporal Data. Modeling Temporal Data Temporal Semantics Temporal density: the time is seen as being: 
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 1.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Data Models and Query Languages of Spatio-Temporal Information Cindy Xinmin Chen Computer Science Department UCLA February 28, 2001.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 9 A First Course in Database Systems.
CS240A: Databases and Knowledge Bases Temporal Applications and SQL Carlo Zaniolo Department of Computer Science University of California, Los Angeles.
Temporal Data Modeling
44271: Database Design & Implementation Physical Data Modelling Ian Perry Room: C49 Tel Ext.: 7287
CS240A: Databases and Knowledge Bases TSQL2 Carlo Zaniolo Department of Computer Science University of California, Los Angeles Notes From Chapter 6 of.
1 The T4SQL Temporal Query Language Presented by 黃泰豐 2007/12/26.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 4: Intermediate.
CPT-S Advanced Databases 11 Yinghui Wu EME 49.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Data Types COMP3211 Advanced Databases Dr Nicholas Gibbins
SPECIAL PURPOSE DATABASES 13/09/ Temporal Database Concepts  Time is considered ordered sequence of points in some granularity Use the term choronon.
CS240A: Databases and Knowledge Bases Temporal Databases Carlo Zaniolo Department of Computer Science University of California, Los Angeles.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Logical Database Design and the Rational Model
COMP3211 Advanced Databases
Databases We are particularly interested in relational databases
Database Fundamentals
Temporal Databases.
The Relational Model Textbook /7/2018.
Data Model.
CS240A: Databases and Knowledge Bases TSQL2
Database.
CS240A: Databases and Knowledge Bases A Taxonomy of Temporal DBs
Presentation transcript:

Where does time go ?

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

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

What time ?

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

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

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

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

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

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

Can’t we use SQL for temporal support ?

Time Specification in SQL-92 date: four digits for the year ( ), 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.

A case study Consider a simple university database –Employee(Name,Salary,Title) Finding an employee’s salary is easy Select Salary From Employee Where name= ‘Bob’

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 easy Select Dob From Employee Where Name=‘Bob’

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 NameSalaryTitleDobStartStop Bob40000UD Bob50000UDH Bob50000Prof Bob60000Prof Bob70000Prof now

A case study Find the current salary Select Salary From Employee Where Name=‘Bob’and Start <= current_time_stamp And current_time_stap <= Stop NameSalaryTitleDobStartStop Bob40000UD Bob50000UDH Bob50000Prof Bob60000Prof Bob70000Prof now

A case study Find the salary history Select Salary, start, stop From Employee Where Name=‘Bob’and Start <= current_time_stamp SalaryStartStop now Coalesce these tuples

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 NameSalaryTitleDobStartStop Bob40000UD Bob50000UDH Bob50000Prof Bob60000Prof Bob70000Prof now

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 Create table Temp(salary,start,stop) as select Salary,Start,Stop from Employee where Name = ‘Bob’ Repeat Update Temp as T1 Set t1.stop= (select max(T2.stop) from Temp as T2 where T1.salary=T2.salary and T1.start =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.stop<T2.stop) Until no tuples are updated

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

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

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 ? NameSalaryTitleDobStartStop Bob40000UD Bob50000UDH Bob50000Prof Bob60000Prof Bob70000Prof now

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

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 NameSalaryTitleDob Bob40000 {-1993}UD{-1993} { }UDH { } 60000{ }Prof {1997-now} 70000{2000-now} Temporal tuple

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

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.

Time In Databases While most databases tend to model reality at a point in time (at the ``current'' time), temporal databases model the states of the real world across time. Facts in temporal relations have associated times when they are valid, which can be represented as a union of intervals. The transaction time for a fact is the time interval during which the fact is current within the database system. In a temporal relation, each tuple has an associated time when it is true; the time may be either valid time or transaction time. A bi-temporal relation stores both valid and transaction time.

Time In Databases (Cont.) Example of a temporal relation: Temporal query languages have been proposed to simplify modeling of time as well as time related queries.

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.

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

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.

TSQL case TSQL supports the following (temporal) tables –Snapshot : nothing after the attributes –Valid-time state : as valid [state] –Valid-time event :as valide event –Transaction-time : as transaction –Bitemporal: as valid [state] and transacion The type of the table can be altered at any time –Semantics is not irreversable

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’

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.

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.drug From Prescription as P1, Prescription as P2 Where 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.

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, Drug From Prescription(Name,Drug) as P Where 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

TSQL restructuring Restructuring is syntactic sugar From A(B,C) as A2 Is equivalent to From (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

TSQL example Who has been on Proventil throughout their drug regime? Select snapshot P1.Name From Prescription(Name) as P1, P1(Drug) as P2 Where 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

Valid time projections What drugs was Melanie prescribed during 1994? Select Drug Valid intersect(valid(Prescription), period ‘[1994]’day) From Prescription Where Name=‘Melanie’ The result is a list of drugs, each associated with a set of periods during 1994 that they were prescribed to Melanie

Valid time modifications Insert into Prescription Values (‘Sally’,’dr Green’,Proventil’,’100mg’, Interval ‘8:00’ minute Valid period ‘[1993/01/ /06/03]’ Inserted values will be coalesced with existing value equivalent rows Default valid clause Valid period(current_timestamp, nobind(timestamp ‘now’))

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 Prescription Where Name=‘Melanie’ Valid period ‘[1993/06/01-now]’

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

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 Drug From Prescription as P Where Name =‘Melanie’ And transaction(P) overlaps date ‘1994’;

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.

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?]