SlideShare a Scribd company logo
1 of 62
Download to read offline
Temporal Databases: Data Models
Kristian Torp
Department of Computer Science
Aalborg University
people.cs.aau.dk/˜torp
torp@cs.aau.dk
November 2, 2015
daisy.aau.dk
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 1 / 50
Outline
1 State and Event Tables
2 State Tables
Valid Time
3 Uniqueness
4 Temporal Keys
Primary Keys
Foreign Keys
5 Summary
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 2 / 50
Learning Goals
Learning Goals
Understand event versus state tables
Understand how temporal information is stored
Understand temporal integrity constraints
Note
Core temporal ideas, not specific DBMS product
We will use integers for timestamps
simply because it takes up less space on slides
Will focus on state tables
Most expressive
Hardest to understand (compared to event)
Supported by IBM, Microsoft, and Teradata
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 3 / 50
Purpose of Temporal Data Model
Benefits
Understand and measure changes (over time)
Tracking/traceability
Avoid being sued
Predictions (mostly about the future :-))
Legal reasons (Sarbanes-Oxley Act)
Example (Dell/Toyota/VW Recalls)
2006-08-16 Dell recalls 4.1 million lithium-ion batteries
2013-03-19 VW recalls 384,181 vehicles with gearbox issues
2013-10-17 Toyota recalls 885,000 vehicles with airbag issues
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 4 / 50
Outline
1 State and Event Tables
2 State Tables
Valid Time
3 Uniqueness
4 Temporal Keys
Primary Keys
Foreign Keys
5 Summary
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 5 / 50
Event versus State Tables
Example (Event: Stock Prices)
StockID DateTime Price
IBM 2013-11-11 12:33:44 47
Apple 2013-11-11 12:33:47 161
IBM 2013-11-12 10:20:45 48
IBM 2013-11-13 23:59:00 51
Apple 2013-11-13 08:01:02 148
Example (State: CEO)
StockID CEO DateFrom DateTo
Apple Steve Jobs 1997 2011
Apple Tim Cook 2011 now
IBM Louis V. Gerstner 1993 2002
IBM Samuel J. Palmisano 2002 2011
IBM Virginia M. Rometty 2011 now
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 6 / 50
Transaction-Time Event (log)
Example (Web-Server Log)
session id url tt
11 main.htm 1
11 main.htm 3
22 main.htm 8
11 about.htm 12
22 order.htm 15
22 download.htm 15
33 about.htm 15
Note
Only a single timestamp column
Append-only, i.e., only inserts and no deletes or updates
Sorted on the timestamp column (tt)
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 7 / 50
Quiz: Event or State?
Examples
Your IT certifications?
A personal monthly qualification bonus for a year?
A permanent monthly qualification bonus?
The period for your mortgage loans?
The daily police report?
The owner of a land property? (BBR in Denmark)
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 8 / 50
Summary: Event vs. State Tables
Main Points
State is intervals, e.g., [2015-11-20 08:00:00, 2015-11-26 16:00:00)
State is single timestamps, e.g., 2015-11-20 12:00:00
State is most often used
Can convert between event and state in many cases
The SQL statements are non-trivial!
Note
IBM DB2 uses state data model for both valid-time and
transaction-time
Microsoft uses state data model for transaction time
TeraData uses state data model for both valid-time and
transaction-time
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 9 / 50
Outline
1 State and Event Tables
2 State Tables
Valid Time
3 Uniqueness
4 Temporal Keys
Primary Keys
Foreign Keys
5 Summary
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 10 / 50
Outline
1 State and Event Tables
2 State Tables
Valid Time
3 Uniqueness
4 Temporal Keys
Primary Keys
Foreign Keys
5 Summary
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 11 / 50
Valid-Time State Tables
Example (AllEmps)
Name Dept vts vte
Joe Shoe 7 10
Kim Toy 7 11
Joe Toy 10 now
Kim Sports 11 13
Kim Shoe 13 now
Note
Name and Dept are explicit columns
vts and vte are implicit columns
Handled like plain columns in the DBMS
In some DBMS modeled as a single column of type period
Explicit and implicit columns pure syntax!
now = the variable now (or nobind-now)
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 12 / 50
Visualization of the Database Variable now
Example (AllEmps at time 15)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Kim, Shoe
Kim, Sports
Joe, Toy
Kim, Toy
Joe, Shoe
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 13 / 50
Visualization of the Database Variable now
Example (AllEmps at time 15)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Kim, Shoe
Kim, Sports
Joe, Toy
Kim, Toy
Joe, Shoe
Example (AllEmps at time 20)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Kim, Shoe
Kim, Sports
Joe, Toy
Kim, Toy
Joe, Shoe
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 13 / 50
The Database Variable now
Example (Using now)
Name Dept vts vte
Joe Toy 10 now
Kim Shoe 13 now
Note
now indicates that the content of the row is valid
now is a database variable
Variables not supported in relational DBMSs
Uses a value like 9999-12-30 or 9999-12-31
now only allowed in the vte column (not in the vts column)
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 14 / 50
Explicit Timestamps and now
Example (Explicit Timestamping Current-Time is 8)
Name vts vte
Anna 2 6
Bart 4 12
Curt 14 20
Dan 2 now
Eric 8 now
Finn 14 now
Note
Anna is data in the past
Bart overlaps current-time
Curt and Finn are into the future
Dan is from the past and forward (now)
Eric if from now and forward (now)
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 15 / 50
Timeslicing and now
Example (Explicit Timestamping Current-Time is 8)
Name vts vte
Anna 2 6
Bart 4 12
Curt 14 20
Dan 2 now
Eric 8 now
Finn 14 now
Example (Emp as of Time 8)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Finn
Eric
Dan
Curt
Bart
Anna
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 16 / 50
Timeslicing and now
Example (Explicit Timestamping Current-Time is 8)
Name vts vte
Anna 2 6
Bart 4 12
Curt 14 20
Dan 2 now
Eric 8 now
Finn 14 now
Example (Emp as of Time 12)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Finn
Eric
Dan
Curt
Bart
Anna
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 16 / 50
Timeslicing and now
Example (Explicit Timestamping Current-Time is 8)
Name vts vte
Anna 2 6
Bart 4 12
Curt 14 20
Dan 2 now
Eric 8 now
Finn 14 now
Example (Emp as of Time 16)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Finn
Eric
Dan
Curt
Bart
Anna
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 16 / 50
Timeslicing and now
Example (Explicit Timestamping Current-Time is 8)
Name vts vte
Anna 2 6
Bart 4 12
Curt 14 20
Dan 2 now
Eric 8 now
Finn 14 now
Example (Emp as of Time 20)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Finn
Eric
Dan
Curt
Bart
Anna
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 16 / 50
Timeslicing and now
Example (Explicit Timestamping Current-Time is 8)
Name vts vte
Anna 2 6
Bart 4 12
Curt 14 20
Dan 2 now
Eric 8 now
Finn 14 now
Example (Emp as of Time 24)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Finn
Eric
Dan
Curt
Bart
Anna
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 16 / 50
Quiz: now
Example (Are these two rows the same?)
Name Dept vts vte
Joe Shoe 7 12
Joe Shoe 7 now
Hints
At time 8: How many employees do we have the 14th?
How long will Joe work for us? (Asked at times 5, 10, and 15)
Example (Which Rows are Valid?)
Name Dept vts vte
Ann Toy 10 now
Bar Shoe now 20
Curt Toy 10 30
Dan Shoe now now
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 17 / 50
Quiz: Any Double Agents?
Example (List of Spies)
SID Country vts vte
007 UK 5 now
008 UK 5 15
008 USSR 15 now
009 UK 5 20
009 USSR 10 20
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 18 / 50
Quiz: Any Double Agents?
Example (List of Spies)
SID Country vts vte
007 UK 5 now
008 UK 5 15
008 USSR 15 now
009 UK 5 20
009 USSR 10 20
Example (Spies at time 25)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
009, USSR
009, UK
008, USSR
008, UK
007, UK
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 18 / 50
Interval Types
Definition (Closed Interval)
An interval i [a, b] is closed if c ∈ i for a ≤ c ≤ b
Definition (Half-open Interval)
An interval i [a, b) is half-open if c ∈ i for a ≤ c < b
Example (Closed Intervals)
[4, 8] - [2, 6] = [7, 8]
Example (Half-open Intervals)
[4, 8) - [2, 6) = [6, 8)
Note
Half-open intervals are more convenient to work with
You avoid a lot of +/− 1
Do not need to worry about granularity (seconds, hours)
+/- on half-open intervals always results in half-open intervals
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 19 / 50
Quiz: Conceptual Difference?
Example (Departments)
Name Dept vts vte
Ann HR 1 10
Ann RD 10 20
Ann HR 20 40
Name Dept vts vte
Ann HR 1 15
Ann RD 10 20
Ann HR 20 40
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 20 / 50
Quiz: Conceptual Difference?
Example (Departments)
Name Dept vts vte
Ann HR 1 10
Ann RD 10 20
Ann HR 20 40
Name Dept vts vte
Ann HR 1 15
Ann RD 10 20
Ann HR 20 40
Example (Salaries)
Name Salary vts vte
Ann 40 1 10
Ann 50 10 20
Ann 70 20 40
Name Salary vts vte
Ann 40 1 15
Ann 50 10 20
Ann 70 20 40
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 20 / 50
Summary: Valid-Time State
Main Points
Two implicit columns vts and vte
Timestamp value can be
System supplied, called implicit timestamping
User supplied, called explicit timestamping
The vte column can contain the database variable now
The value of now changes with the wall-clock
Impemented using large value, e.g., 9999-12-31
Intervals are typically half-open [4, 10)
Makes computations easier
Timestamp intervals are typically not coalesced
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 21 / 50
Outline
1 State and Event Tables
2 State Tables
Valid Time
3 Uniqueness
4 Temporal Keys
Primary Keys
Foreign Keys
5 Summary
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 22 / 50
Value-Equivalent Rows
Definition (Value-Equivalent)
Two rows r1 and r2 are value-equivalent if their explicit columns values are
all equal.
Example
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
(Ann, HR)
(Ann, HR)
(Bart, RD)
(Bart, RD)
(Curt, RD)
(Curt, RD)
The Ann rows are value-equivalent
The Bart rows are value-equivalent
The Curt rows are value-equivalent
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 23 / 50
Quiz: Value-Equivalent Rows
Example (Which Table contains Value-Equivalent Rows?)
Name Dept vts vte
Ann HR 2 8
Ann RD 8 15
Ann HR 15 now
Name Dept vts vte
Ann HR 2 6
Ann RD 6 12
Bart RD 12 now
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 24 / 50
Quiz: Value-Equivalent Rows
Example (Which Table contains Value-Equivalent Rows?)
Name Dept vts vte
Ann HR 2 8
Ann RD 8 15
Ann HR 15 now
Name Dept vts vte
Ann HR 2 6
Ann RD 6 12
Bart RD 12 now
Example (Which Table contains Value-Equivalent Rows?)
Name Dept vts vte
Ann HR 2 8
Ann RD 8 15
Ann AD 15 now
Name Dept vts vte
Ann HR 2 12
Bart HR 2 12
Curt HR 2 12
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 24 / 50
Sequenced Duplicate
Definition (Sequenced Duplicate)
Two rows r1 and r2 are sequenced duplicates if they are value-equivalent
in overlapping time periods.
Example
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
(Ann, HR)
(Ann, HR)
(Bart, RD)
(Bart, RD)
(Curt, RD)
(Curt, RD)
The Ann rows are sequenced-duplicates in the interval [6, 12)
The Bart rows are not sequenced-duplicates
The Curt rows are value-equivalent in the period [6, 14)
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 25 / 50
Quiz: Sequenced Duplicate
Example (Which Table contains Sequenced Duplicate Rows?)
Name Dept vts vte
Ann HR 2 8
Ann RD 8 15
Ann HR 5 now
Name Dept vts vte
Ann HR 2 6
Ann RD 2 12
Bart RD 12 now
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 26 / 50
Quiz: Sequenced Duplicate
Example (Which Table contains Sequenced Duplicate Rows?)
Name Dept vts vte
Ann HR 2 8
Ann RD 8 15
Ann HR 5 now
Name Dept vts vte
Ann HR 2 6
Ann RD 2 12
Bart RD 12 now
Example (Which Table contains Sequenced Duplicate Rows?)
Name Dept vts vte
Ann HR 2 8
Ann RD 8 15
Ann AD 15 now
Name Dept vts vte
Ann HR 2 12
Bart HR 2 12
Ann HR 2 12
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 26 / 50
Current-Duplicate Rows
Definition (Current-Duplicate)
Two rows r1 and r2 are value current-duplicate rows if their explicit columns
values are all equal in the current-time timeslice.
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 27 / 50
Current-Duplicate Rows
Definition (Current-Duplicate)
Two rows r1 and r2 are value current-duplicate rows if their explicit columns
values are all equal in the current-time timeslice.
Example (Which Table contains Current-Duplicate Rows?)
Name Dept vts vte
Ann HR 2 8
Ann RD 8 now
Ann HR 5 now
Name Dept vts vte
Ann HR 2 now
Ann HD 16 now
Bart RD 12 now
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 27 / 50
Current-Duplicate Rows
Definition (Current-Duplicate)
Two rows r1 and r2 are value current-duplicate rows if their explicit columns
values are all equal in the current-time timeslice.
Example (Which Table contains Current-Duplicate Rows?)
Name Dept vts vte
Ann HR 2 8
Ann RD 8 now
Ann HR 5 now
Name Dept vts vte
Ann HR 2 now
Ann HD 16 now
Bart RD 12 now
Example (Which Table contains Current-Duplicate Rows?)
Name Dept vts vte
Ann HR 2 8
Ann RD 8 15
Ann AD 15 now
Name Dept vts vte
Ann HR 2 12
Bart HR 2 12
Curt HR 2 12
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 27 / 50
Non-Sequenced Duplicate
Definition (Non-Sequenced Duplicate)
Two rows r1 and r2 are non-sequenced duplicates if all their columns
(explicit and implicit) are identical.
Example
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
(Ann, HR)
(Ann, HR)
(Bart, RD)
(Bart, RD)
(Curt, RD)
(Curt, RD)
The Ann rows are not non-sequenced-duplicates
The Bart rows are not non-sequenced-duplicates
The Curt rows are non-sequenced-duplicates
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 28 / 50
Quiz: Non-Sequenced Duplicate
Example (Which Table contains Non-Sequenced Duplicate Rows?)
Name Dept vts vte
Ann HR 2 8
Ann RD 2 now
Ann HR 2 now
Name Dept vts vte
Ann HR 2 10
Ann RD 2 now
Ann HR 2 10
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 29 / 50
Quiz: Non-Sequenced Duplicate
Example (Which Table contains Non-Sequenced Duplicate Rows?)
Name Dept vts vte
Ann HR 2 8
Ann RD 2 now
Ann HR 2 now
Name Dept vts vte
Ann HR 2 10
Ann RD 2 now
Ann HR 2 10
Example (Which Table contains Non-Sequenced Duplicate Rows?)
Name Dept vts vte
Ann HR 2 8
Ann RD 2 8
Ann AD 2 8
Name Dept vts vte
Ann HR 2 12
Ann HR 2 10
Ann HR 10 12
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 29 / 50
Summary: Uniqueness
Example
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
(Ann, HR)
(Ann, HR)
(Bart, RD)
(Bart, RD)
(Curt, RD)
(Curt, RD)
Value Equi. Seq. Duplicate Non-Seq. Duplicate
Ann rows
Bart rows
Curt rows
Note
If non-sequenced duplicates then also sequenced duplicates
It sequenced duplicates then also value equivalent
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 30 / 50
Outline
1 State and Event Tables
2 State Tables
Valid Time
3 Uniqueness
4 Temporal Keys
Primary Keys
Foreign Keys
5 Summary
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 31 / 50
Outline
1 State and Event Tables
2 State Tables
Valid Time
3 Uniqueness
4 Temporal Keys
Primary Keys
Foreign Keys
5 Summary
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 32 / 50
Uniqueness over Time
Cases
Your DNA profile remains constant over time
Your cell-phone number varies slowly over time, but always one
Your checking balances varies almost daily, but always one
The IBM stock value changes every second but always exactly one
value
Note
The notaion of a primary key caries over to temporal databases
The notaion of a foreign key caries over to temporal databases
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 33 / 50
Primary Keys Informally
Cases
You have been working for a company for eight years. In this time
interval you salary has changed several times. However, at any point
in time you have always had exactly one salary.
You have been married three times. However at any point in time you
have had either zero or one spouse.
Your car has driven 56,000 kilometers but for all millimeters driven
there has been exactly one driver.
You have a house that is 34 years old. Since the house was build
there has at any time only been one owner of the house.
Note
There is a general concept of time-varying uniqueness
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 34 / 50
Temporal Primary Key Example
Example (trainer at time 19)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
2, Bo, 302, Bo, 20
1, Ann, 251, Ann, 201, Ann, 10
Example (As Valid-Time Table)
tid tname salary vts vte
1 Ann 10 1 7
1 Ann 20 9 15
1 Ann 25 15 now
2 Bo 20 2 13
2 Bo 30 13 18
Note
At any point in time is tid a unique value!
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 35 / 50
Not Temporal Primary Key
Example (tid not a Temporal Primary Key)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
2, Bo, 20
2, Bo, 302, Bo, 20
1, Ann, 25
2, Ann, 20
1, Ann, 10
Example (tid a Temporal Primary Key?)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
5, Dan, 20
4, Dan, 20
3, Cho, 40
2, Bo, 402, Bo, 302, Bo, 20
1, Ann, 251, Ann, 10
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 36 / 50
Summary: Primary Key
Main Points
A temporal primary-key is a straight-forward extension of snapshot
primary keys
A temporal primary-key much more computation intesive
Note
Limited or no support for temporal primary keys in DBMSs
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 37 / 50
Outline
1 State and Event Tables
2 State Tables
Valid Time
3 Uniqueness
4 Temporal Keys
Primary Keys
Foreign Keys
5 Summary
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 38 / 50
Foreign Keys Informally
Cases
You cannot have a contract to rent a house in the period April to
October if the house is first built in September
You cannot call your friend after the subscription of her/his cell-phone
has expired
You expect that the cinema has a copy of the movie Blade Runner II
available during the entire period where you have bought a ticket to
see this movie in the cinema
Note
There is a constraint between the time interval associated with the
phenomenon stored in the database.
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 39 / 50
Temporal Foreign Key Example
Example (emp and dept at time 19)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
2, Bo, 102, Bo, 10
1, Ann, 101, Ann, 201, Ann, 10
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
20, RD20, RD20, RD
10, HR10, HR
Example (As Tables)
tid tname did vts vte
1 Ann 10 1 9
1 Ann 20 10 13
1 Ann 10 16 now
2 Bo 10 2 6
2 Bo 10 13 18
did dname vts vte
10 HR 1 9
10 HR 11 now
20 RD 1 6
20 RD 8 13
20 RD 16 now
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 40 / 50
Idea in Foreign-Key Solution
Requirements
The emp vts value must be covered by an interval in dept
The emp vte value must be covered by an interval in dept
There cannot be any ”holes” in the coverage of the interval for emp
Example (emp and dept at time 19)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Emp
Dept Dept
“Hole”
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 41 / 50
Part 1 as a Figure
Example (Overlap of vts)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Emp
Case 1
Case 2
Case 3
Case 4
Case 5
Case 6
Case 7
Case 8
Case 9
Case 10
Case 11
Case 12
Case 13
Note
Allen’s operators
13 cases because interval to interval comparison
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 42 / 50
Part 1 in SQL
Example
where not exists ( select ∗ −− vts i s not covered
from dept as s
where s . did = emp. did
and s . vts <= emp. vts and emp. vts < s . vte )
Note
≤ when comparing vts values
< when comparing a vts value to a vte value
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 43 / 50
Part 2 as a Figure and SQL
Example (Overlap of vte)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Emp
Case 1
Case 2
Case 3
Case 4
Case 5
Example (Overlap vte in SQL)
or not exists (
select ∗ −− vte i s not covered
from dept as e
where e . did = emp. did
and e . vts < emp. vte and emp. vte <= e . vte )
Note
< when comparing a vts value to a vte value
≤ when comparing vte values
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 44 / 50
Part 3 Example as a Figure
Example (Overlap of vts)
VT
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Emp
s
e
b1
b2
Conditions
s overlaps emp.vts
e overlaps emp.vte
Exist
A b1 that fills the “holes” towards emp.vte
A b2 that exists the filling of the “hold” towards emp.vte
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 45 / 50
Part 3 in SQL
Example
or exists ( −− there i s a hole
select ∗
from dept as b1
where b1 . did = emp. did
and emp. vts < b1 . vte and b1 . vte < emp. vte
and not exists (
select ∗
from dept as b2
where b2 . did = emp. did
and b2 . vts <= b1 . vte and b1 . vte < b2 . vte ) )
Note
There exists a row in dept where the vte is in the interval [emp.vts,
emp.vte),
and there is no row in dept that has an interval that extends towards
emp.vte
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 46 / 50
Entire Solution
Example
select ∗
from emp
where exists ( select ∗
from dept as s
where s . did = emp. did
and s . vts <= emp. vts and emp. vts < s . vte )
and exists ( select ∗
from dept as e
where e . did = emp. did
and e . vts < emp. vte and emp. vte <= e . vte )
and not exists ( select ∗
from dept as b1
where b1 . did = emp. did
and emp. vts < b1 . vte and b1 . vte < emp. vte
and not exists
( select ∗
from dept as b2
where b2 . did = emp. did
and b2 . vts <= b1 . vte and b1 . vte < b2 . vte ) )
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 47 / 50
Summary: Foreign Key
Main Points
A temporal foreign-key is a straight-forward extension of non-temporal
foreign-keys
A temporal foreign-key is very expensive to enforce
Note
Limited or no support for temporal foreign-keys in DBMSs
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 48 / 50
Outline
1 State and Event Tables
2 State Tables
Valid Time
3 Uniqueness
4 Temporal Keys
Primary Keys
Foreign Keys
5 Summary
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 49 / 50
Summary: Temporal Data Model
Main Points
Event single timestamp
State two timestamps (from and to)
What is supported by IBM, Microsoft, and Teradata
now = nobind-now (in column vte)
Implemented by large timestamp, e.g., 9999-12-31
UC = until-changed (in column tte)
Implemented by large timestamp, e.g., 9999-12-31
Temporal primary-key and foreign-key
Can be hard to understand
Note
UC is sometimes all so called now or nobind now
Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 50 / 50

More Related Content

Viewers also liked

ppt spatial data
ppt spatial datappt spatial data
ppt spatial dataRahul Kumar
 
SQL/XML on Oracle
SQL/XML on OracleSQL/XML on Oracle
SQL/XML on Oracletorp42
 
An Overview of Temporal Features in SQL:2011
An Overview of Temporal Features in SQL:2011An Overview of Temporal Features in SQL:2011
An Overview of Temporal Features in SQL:2011Craig Baumunk
 
Spark's Role in the Big Data Ecosystem (Spark Summit 2014)
Spark's Role in the Big Data Ecosystem (Spark Summit 2014)Spark's Role in the Big Data Ecosystem (Spark Summit 2014)
Spark's Role in the Big Data Ecosystem (Spark Summit 2014)Databricks
 
JupyterHub for Interactive Data Science Collaboration
JupyterHub for Interactive Data Science CollaborationJupyterHub for Interactive Data Science Collaboration
JupyterHub for Interactive Data Science CollaborationCarol Willing
 
Jupyter, A Platform for Data Science at Scale
Jupyter, A Platform for Data Science at ScaleJupyter, A Platform for Data Science at Scale
Jupyter, A Platform for Data Science at ScaleMatthias Bussonnier
 
Big data ecosystem
Big data ecosystemBig data ecosystem
Big data ecosystemmagda3695
 
Big Data Ecosystem - 1000 Simulated Drones
Big Data Ecosystem - 1000 Simulated DronesBig Data Ecosystem - 1000 Simulated Drones
Big Data Ecosystem - 1000 Simulated DronesEspeo Software
 
Building New Data Ecosystem for Customer Analytics, Strata + Hadoop World, 2016
Building New Data Ecosystem for Customer Analytics, Strata + Hadoop World, 2016Building New Data Ecosystem for Customer Analytics, Strata + Hadoop World, 2016
Building New Data Ecosystem for Customer Analytics, Strata + Hadoop World, 2016Caserta
 
BDE-SC6 Hangout - “Insight into Virtual Currency Ecosystems”
BDE-SC6 Hangout - “Insight into Virtual Currency Ecosystems”BDE-SC6 Hangout - “Insight into Virtual Currency Ecosystems”
BDE-SC6 Hangout - “Insight into Virtual Currency Ecosystems”BigData_Europe
 
1° Sessione Oracle CRUI: Analytics Data Lab, the power of Big Data Investiga...
1° Sessione Oracle CRUI: Analytics Data Lab,  the power of Big Data Investiga...1° Sessione Oracle CRUI: Analytics Data Lab,  the power of Big Data Investiga...
1° Sessione Oracle CRUI: Analytics Data Lab, the power of Big Data Investiga...Jürgen Ambrosi
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbmsNaresh Kumar
 
Relational database management system (rdbms) i
Relational database management system (rdbms) iRelational database management system (rdbms) i
Relational database management system (rdbms) iRavinder Kamboj
 
Building a Dataset Search Engine with Spark and Elasticsearch: Spark Summit E...
Building a Dataset Search Engine with Spark and Elasticsearch: Spark Summit E...Building a Dataset Search Engine with Spark and Elasticsearch: Spark Summit E...
Building a Dataset Search Engine with Spark and Elasticsearch: Spark Summit E...Spark Summit
 
Overview - IBM Big Data Platform
Overview - IBM Big Data PlatformOverview - IBM Big Data Platform
Overview - IBM Big Data PlatformVikas Manoria
 

Viewers also liked (20)

ppt spatial data
ppt spatial datappt spatial data
ppt spatial data
 
SQL/XML on Oracle
SQL/XML on OracleSQL/XML on Oracle
SQL/XML on Oracle
 
An Overview of Temporal Features in SQL:2011
An Overview of Temporal Features in SQL:2011An Overview of Temporal Features in SQL:2011
An Overview of Temporal Features in SQL:2011
 
Chapter24
Chapter24Chapter24
Chapter24
 
Spark's Role in the Big Data Ecosystem (Spark Summit 2014)
Spark's Role in the Big Data Ecosystem (Spark Summit 2014)Spark's Role in the Big Data Ecosystem (Spark Summit 2014)
Spark's Role in the Big Data Ecosystem (Spark Summit 2014)
 
Data models
Data modelsData models
Data models
 
JupyterHub for Interactive Data Science Collaboration
JupyterHub for Interactive Data Science CollaborationJupyterHub for Interactive Data Science Collaboration
JupyterHub for Interactive Data Science Collaboration
 
Jupyter, A Platform for Data Science at Scale
Jupyter, A Platform for Data Science at ScaleJupyter, A Platform for Data Science at Scale
Jupyter, A Platform for Data Science at Scale
 
Big data ecosystem
Big data ecosystemBig data ecosystem
Big data ecosystem
 
Bde euro proworkshop
Bde euro proworkshopBde euro proworkshop
Bde euro proworkshop
 
Big Data Ecosystem - 1000 Simulated Drones
Big Data Ecosystem - 1000 Simulated DronesBig Data Ecosystem - 1000 Simulated Drones
Big Data Ecosystem - 1000 Simulated Drones
 
Building New Data Ecosystem for Customer Analytics, Strata + Hadoop World, 2016
Building New Data Ecosystem for Customer Analytics, Strata + Hadoop World, 2016Building New Data Ecosystem for Customer Analytics, Strata + Hadoop World, 2016
Building New Data Ecosystem for Customer Analytics, Strata + Hadoop World, 2016
 
BDE-SC6 Hangout - “Insight into Virtual Currency Ecosystems”
BDE-SC6 Hangout - “Insight into Virtual Currency Ecosystems”BDE-SC6 Hangout - “Insight into Virtual Currency Ecosystems”
BDE-SC6 Hangout - “Insight into Virtual Currency Ecosystems”
 
Spatial databases
Spatial databasesSpatial databases
Spatial databases
 
Visual pathway
Visual pathwayVisual pathway
Visual pathway
 
1° Sessione Oracle CRUI: Analytics Data Lab, the power of Big Data Investiga...
1° Sessione Oracle CRUI: Analytics Data Lab,  the power of Big Data Investiga...1° Sessione Oracle CRUI: Analytics Data Lab,  the power of Big Data Investiga...
1° Sessione Oracle CRUI: Analytics Data Lab, the power of Big Data Investiga...
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbms
 
Relational database management system (rdbms) i
Relational database management system (rdbms) iRelational database management system (rdbms) i
Relational database management system (rdbms) i
 
Building a Dataset Search Engine with Spark and Elasticsearch: Spark Summit E...
Building a Dataset Search Engine with Spark and Elasticsearch: Spark Summit E...Building a Dataset Search Engine with Spark and Elasticsearch: Spark Summit E...
Building a Dataset Search Engine with Spark and Elasticsearch: Spark Summit E...
 
Overview - IBM Big Data Platform
Overview - IBM Big Data PlatformOverview - IBM Big Data Platform
Overview - IBM Big Data Platform
 

Similar to Temporal Databases: Data Models

The DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQLThe DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQLtorp42
 
Introduction to XPath
Introduction to XPathIntroduction to XPath
Introduction to XPathtorp42
 
Spatial Indexing
Spatial IndexingSpatial Indexing
Spatial Indexingtorp42
 
Introduction to DTD
Introduction to DTDIntroduction to DTD
Introduction to DTDtorp42
 
Entity-Relationship Diagrams ERD
Entity-Relationship Diagrams ERDEntity-Relationship Diagrams ERD
Entity-Relationship Diagrams ERDtorp42
 
CSE545 sp23 (2) Streaming Algorithms 2-4.pdf
CSE545 sp23 (2) Streaming Algorithms 2-4.pdfCSE545 sp23 (2) Streaming Algorithms 2-4.pdf
CSE545 sp23 (2) Streaming Algorithms 2-4.pdfAlexanderKyalo3
 

Similar to Temporal Databases: Data Models (7)

The DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQLThe DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
 
Introduction to XPath
Introduction to XPathIntroduction to XPath
Introduction to XPath
 
Spatial Indexing
Spatial IndexingSpatial Indexing
Spatial Indexing
 
Introduction to DTD
Introduction to DTDIntroduction to DTD
Introduction to DTD
 
Entity-Relationship Diagrams ERD
Entity-Relationship Diagrams ERDEntity-Relationship Diagrams ERD
Entity-Relationship Diagrams ERD
 
Anton Dignös - Towards a Temporal PostgresSQL
Anton Dignös - Towards a Temporal PostgresSQLAnton Dignös - Towards a Temporal PostgresSQL
Anton Dignös - Towards a Temporal PostgresSQL
 
CSE545 sp23 (2) Streaming Algorithms 2-4.pdf
CSE545 sp23 (2) Streaming Algorithms 2-4.pdfCSE545 sp23 (2) Streaming Algorithms 2-4.pdf
CSE545 sp23 (2) Streaming Algorithms 2-4.pdf
 

Recently uploaded

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 

Recently uploaded (20)

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

Temporal Databases: Data Models

  • 1. Temporal Databases: Data Models Kristian Torp Department of Computer Science Aalborg University people.cs.aau.dk/˜torp torp@cs.aau.dk November 2, 2015 daisy.aau.dk Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 1 / 50
  • 2. Outline 1 State and Event Tables 2 State Tables Valid Time 3 Uniqueness 4 Temporal Keys Primary Keys Foreign Keys 5 Summary Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 2 / 50
  • 3. Learning Goals Learning Goals Understand event versus state tables Understand how temporal information is stored Understand temporal integrity constraints Note Core temporal ideas, not specific DBMS product We will use integers for timestamps simply because it takes up less space on slides Will focus on state tables Most expressive Hardest to understand (compared to event) Supported by IBM, Microsoft, and Teradata Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 3 / 50
  • 4. Purpose of Temporal Data Model Benefits Understand and measure changes (over time) Tracking/traceability Avoid being sued Predictions (mostly about the future :-)) Legal reasons (Sarbanes-Oxley Act) Example (Dell/Toyota/VW Recalls) 2006-08-16 Dell recalls 4.1 million lithium-ion batteries 2013-03-19 VW recalls 384,181 vehicles with gearbox issues 2013-10-17 Toyota recalls 885,000 vehicles with airbag issues Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 4 / 50
  • 5. Outline 1 State and Event Tables 2 State Tables Valid Time 3 Uniqueness 4 Temporal Keys Primary Keys Foreign Keys 5 Summary Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 5 / 50
  • 6. Event versus State Tables Example (Event: Stock Prices) StockID DateTime Price IBM 2013-11-11 12:33:44 47 Apple 2013-11-11 12:33:47 161 IBM 2013-11-12 10:20:45 48 IBM 2013-11-13 23:59:00 51 Apple 2013-11-13 08:01:02 148 Example (State: CEO) StockID CEO DateFrom DateTo Apple Steve Jobs 1997 2011 Apple Tim Cook 2011 now IBM Louis V. Gerstner 1993 2002 IBM Samuel J. Palmisano 2002 2011 IBM Virginia M. Rometty 2011 now Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 6 / 50
  • 7. Transaction-Time Event (log) Example (Web-Server Log) session id url tt 11 main.htm 1 11 main.htm 3 22 main.htm 8 11 about.htm 12 22 order.htm 15 22 download.htm 15 33 about.htm 15 Note Only a single timestamp column Append-only, i.e., only inserts and no deletes or updates Sorted on the timestamp column (tt) Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 7 / 50
  • 8. Quiz: Event or State? Examples Your IT certifications? A personal monthly qualification bonus for a year? A permanent monthly qualification bonus? The period for your mortgage loans? The daily police report? The owner of a land property? (BBR in Denmark) Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 8 / 50
  • 9. Summary: Event vs. State Tables Main Points State is intervals, e.g., [2015-11-20 08:00:00, 2015-11-26 16:00:00) State is single timestamps, e.g., 2015-11-20 12:00:00 State is most often used Can convert between event and state in many cases The SQL statements are non-trivial! Note IBM DB2 uses state data model for both valid-time and transaction-time Microsoft uses state data model for transaction time TeraData uses state data model for both valid-time and transaction-time Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 9 / 50
  • 10. Outline 1 State and Event Tables 2 State Tables Valid Time 3 Uniqueness 4 Temporal Keys Primary Keys Foreign Keys 5 Summary Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 10 / 50
  • 11. Outline 1 State and Event Tables 2 State Tables Valid Time 3 Uniqueness 4 Temporal Keys Primary Keys Foreign Keys 5 Summary Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 11 / 50
  • 12. Valid-Time State Tables Example (AllEmps) Name Dept vts vte Joe Shoe 7 10 Kim Toy 7 11 Joe Toy 10 now Kim Sports 11 13 Kim Shoe 13 now Note Name and Dept are explicit columns vts and vte are implicit columns Handled like plain columns in the DBMS In some DBMS modeled as a single column of type period Explicit and implicit columns pure syntax! now = the variable now (or nobind-now) Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 12 / 50
  • 13. Visualization of the Database Variable now Example (AllEmps at time 15) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Kim, Shoe Kim, Sports Joe, Toy Kim, Toy Joe, Shoe Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 13 / 50
  • 14. Visualization of the Database Variable now Example (AllEmps at time 15) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Kim, Shoe Kim, Sports Joe, Toy Kim, Toy Joe, Shoe Example (AllEmps at time 20) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Kim, Shoe Kim, Sports Joe, Toy Kim, Toy Joe, Shoe Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 13 / 50
  • 15. The Database Variable now Example (Using now) Name Dept vts vte Joe Toy 10 now Kim Shoe 13 now Note now indicates that the content of the row is valid now is a database variable Variables not supported in relational DBMSs Uses a value like 9999-12-30 or 9999-12-31 now only allowed in the vte column (not in the vts column) Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 14 / 50
  • 16. Explicit Timestamps and now Example (Explicit Timestamping Current-Time is 8) Name vts vte Anna 2 6 Bart 4 12 Curt 14 20 Dan 2 now Eric 8 now Finn 14 now Note Anna is data in the past Bart overlaps current-time Curt and Finn are into the future Dan is from the past and forward (now) Eric if from now and forward (now) Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 15 / 50
  • 17. Timeslicing and now Example (Explicit Timestamping Current-Time is 8) Name vts vte Anna 2 6 Bart 4 12 Curt 14 20 Dan 2 now Eric 8 now Finn 14 now Example (Emp as of Time 8) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Finn Eric Dan Curt Bart Anna Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 16 / 50
  • 18. Timeslicing and now Example (Explicit Timestamping Current-Time is 8) Name vts vte Anna 2 6 Bart 4 12 Curt 14 20 Dan 2 now Eric 8 now Finn 14 now Example (Emp as of Time 12) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Finn Eric Dan Curt Bart Anna Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 16 / 50
  • 19. Timeslicing and now Example (Explicit Timestamping Current-Time is 8) Name vts vte Anna 2 6 Bart 4 12 Curt 14 20 Dan 2 now Eric 8 now Finn 14 now Example (Emp as of Time 16) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Finn Eric Dan Curt Bart Anna Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 16 / 50
  • 20. Timeslicing and now Example (Explicit Timestamping Current-Time is 8) Name vts vte Anna 2 6 Bart 4 12 Curt 14 20 Dan 2 now Eric 8 now Finn 14 now Example (Emp as of Time 20) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Finn Eric Dan Curt Bart Anna Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 16 / 50
  • 21. Timeslicing and now Example (Explicit Timestamping Current-Time is 8) Name vts vte Anna 2 6 Bart 4 12 Curt 14 20 Dan 2 now Eric 8 now Finn 14 now Example (Emp as of Time 24) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Finn Eric Dan Curt Bart Anna Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 16 / 50
  • 22. Quiz: now Example (Are these two rows the same?) Name Dept vts vte Joe Shoe 7 12 Joe Shoe 7 now Hints At time 8: How many employees do we have the 14th? How long will Joe work for us? (Asked at times 5, 10, and 15) Example (Which Rows are Valid?) Name Dept vts vte Ann Toy 10 now Bar Shoe now 20 Curt Toy 10 30 Dan Shoe now now Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 17 / 50
  • 23. Quiz: Any Double Agents? Example (List of Spies) SID Country vts vte 007 UK 5 now 008 UK 5 15 008 USSR 15 now 009 UK 5 20 009 USSR 10 20 Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 18 / 50
  • 24. Quiz: Any Double Agents? Example (List of Spies) SID Country vts vte 007 UK 5 now 008 UK 5 15 008 USSR 15 now 009 UK 5 20 009 USSR 10 20 Example (Spies at time 25) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 009, USSR 009, UK 008, USSR 008, UK 007, UK Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 18 / 50
  • 25. Interval Types Definition (Closed Interval) An interval i [a, b] is closed if c ∈ i for a ≤ c ≤ b Definition (Half-open Interval) An interval i [a, b) is half-open if c ∈ i for a ≤ c < b Example (Closed Intervals) [4, 8] - [2, 6] = [7, 8] Example (Half-open Intervals) [4, 8) - [2, 6) = [6, 8) Note Half-open intervals are more convenient to work with You avoid a lot of +/− 1 Do not need to worry about granularity (seconds, hours) +/- on half-open intervals always results in half-open intervals Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 19 / 50
  • 26. Quiz: Conceptual Difference? Example (Departments) Name Dept vts vte Ann HR 1 10 Ann RD 10 20 Ann HR 20 40 Name Dept vts vte Ann HR 1 15 Ann RD 10 20 Ann HR 20 40 Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 20 / 50
  • 27. Quiz: Conceptual Difference? Example (Departments) Name Dept vts vte Ann HR 1 10 Ann RD 10 20 Ann HR 20 40 Name Dept vts vte Ann HR 1 15 Ann RD 10 20 Ann HR 20 40 Example (Salaries) Name Salary vts vte Ann 40 1 10 Ann 50 10 20 Ann 70 20 40 Name Salary vts vte Ann 40 1 15 Ann 50 10 20 Ann 70 20 40 Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 20 / 50
  • 28. Summary: Valid-Time State Main Points Two implicit columns vts and vte Timestamp value can be System supplied, called implicit timestamping User supplied, called explicit timestamping The vte column can contain the database variable now The value of now changes with the wall-clock Impemented using large value, e.g., 9999-12-31 Intervals are typically half-open [4, 10) Makes computations easier Timestamp intervals are typically not coalesced Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 21 / 50
  • 29. Outline 1 State and Event Tables 2 State Tables Valid Time 3 Uniqueness 4 Temporal Keys Primary Keys Foreign Keys 5 Summary Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 22 / 50
  • 30. Value-Equivalent Rows Definition (Value-Equivalent) Two rows r1 and r2 are value-equivalent if their explicit columns values are all equal. Example VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 (Ann, HR) (Ann, HR) (Bart, RD) (Bart, RD) (Curt, RD) (Curt, RD) The Ann rows are value-equivalent The Bart rows are value-equivalent The Curt rows are value-equivalent Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 23 / 50
  • 31. Quiz: Value-Equivalent Rows Example (Which Table contains Value-Equivalent Rows?) Name Dept vts vte Ann HR 2 8 Ann RD 8 15 Ann HR 15 now Name Dept vts vte Ann HR 2 6 Ann RD 6 12 Bart RD 12 now Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 24 / 50
  • 32. Quiz: Value-Equivalent Rows Example (Which Table contains Value-Equivalent Rows?) Name Dept vts vte Ann HR 2 8 Ann RD 8 15 Ann HR 15 now Name Dept vts vte Ann HR 2 6 Ann RD 6 12 Bart RD 12 now Example (Which Table contains Value-Equivalent Rows?) Name Dept vts vte Ann HR 2 8 Ann RD 8 15 Ann AD 15 now Name Dept vts vte Ann HR 2 12 Bart HR 2 12 Curt HR 2 12 Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 24 / 50
  • 33. Sequenced Duplicate Definition (Sequenced Duplicate) Two rows r1 and r2 are sequenced duplicates if they are value-equivalent in overlapping time periods. Example VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 (Ann, HR) (Ann, HR) (Bart, RD) (Bart, RD) (Curt, RD) (Curt, RD) The Ann rows are sequenced-duplicates in the interval [6, 12) The Bart rows are not sequenced-duplicates The Curt rows are value-equivalent in the period [6, 14) Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 25 / 50
  • 34. Quiz: Sequenced Duplicate Example (Which Table contains Sequenced Duplicate Rows?) Name Dept vts vte Ann HR 2 8 Ann RD 8 15 Ann HR 5 now Name Dept vts vte Ann HR 2 6 Ann RD 2 12 Bart RD 12 now Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 26 / 50
  • 35. Quiz: Sequenced Duplicate Example (Which Table contains Sequenced Duplicate Rows?) Name Dept vts vte Ann HR 2 8 Ann RD 8 15 Ann HR 5 now Name Dept vts vte Ann HR 2 6 Ann RD 2 12 Bart RD 12 now Example (Which Table contains Sequenced Duplicate Rows?) Name Dept vts vte Ann HR 2 8 Ann RD 8 15 Ann AD 15 now Name Dept vts vte Ann HR 2 12 Bart HR 2 12 Ann HR 2 12 Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 26 / 50
  • 36. Current-Duplicate Rows Definition (Current-Duplicate) Two rows r1 and r2 are value current-duplicate rows if their explicit columns values are all equal in the current-time timeslice. Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 27 / 50
  • 37. Current-Duplicate Rows Definition (Current-Duplicate) Two rows r1 and r2 are value current-duplicate rows if their explicit columns values are all equal in the current-time timeslice. Example (Which Table contains Current-Duplicate Rows?) Name Dept vts vte Ann HR 2 8 Ann RD 8 now Ann HR 5 now Name Dept vts vte Ann HR 2 now Ann HD 16 now Bart RD 12 now Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 27 / 50
  • 38. Current-Duplicate Rows Definition (Current-Duplicate) Two rows r1 and r2 are value current-duplicate rows if their explicit columns values are all equal in the current-time timeslice. Example (Which Table contains Current-Duplicate Rows?) Name Dept vts vte Ann HR 2 8 Ann RD 8 now Ann HR 5 now Name Dept vts vte Ann HR 2 now Ann HD 16 now Bart RD 12 now Example (Which Table contains Current-Duplicate Rows?) Name Dept vts vte Ann HR 2 8 Ann RD 8 15 Ann AD 15 now Name Dept vts vte Ann HR 2 12 Bart HR 2 12 Curt HR 2 12 Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 27 / 50
  • 39. Non-Sequenced Duplicate Definition (Non-Sequenced Duplicate) Two rows r1 and r2 are non-sequenced duplicates if all their columns (explicit and implicit) are identical. Example VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 (Ann, HR) (Ann, HR) (Bart, RD) (Bart, RD) (Curt, RD) (Curt, RD) The Ann rows are not non-sequenced-duplicates The Bart rows are not non-sequenced-duplicates The Curt rows are non-sequenced-duplicates Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 28 / 50
  • 40. Quiz: Non-Sequenced Duplicate Example (Which Table contains Non-Sequenced Duplicate Rows?) Name Dept vts vte Ann HR 2 8 Ann RD 2 now Ann HR 2 now Name Dept vts vte Ann HR 2 10 Ann RD 2 now Ann HR 2 10 Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 29 / 50
  • 41. Quiz: Non-Sequenced Duplicate Example (Which Table contains Non-Sequenced Duplicate Rows?) Name Dept vts vte Ann HR 2 8 Ann RD 2 now Ann HR 2 now Name Dept vts vte Ann HR 2 10 Ann RD 2 now Ann HR 2 10 Example (Which Table contains Non-Sequenced Duplicate Rows?) Name Dept vts vte Ann HR 2 8 Ann RD 2 8 Ann AD 2 8 Name Dept vts vte Ann HR 2 12 Ann HR 2 10 Ann HR 10 12 Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 29 / 50
  • 42. Summary: Uniqueness Example VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 (Ann, HR) (Ann, HR) (Bart, RD) (Bart, RD) (Curt, RD) (Curt, RD) Value Equi. Seq. Duplicate Non-Seq. Duplicate Ann rows Bart rows Curt rows Note If non-sequenced duplicates then also sequenced duplicates It sequenced duplicates then also value equivalent Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 30 / 50
  • 43. Outline 1 State and Event Tables 2 State Tables Valid Time 3 Uniqueness 4 Temporal Keys Primary Keys Foreign Keys 5 Summary Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 31 / 50
  • 44. Outline 1 State and Event Tables 2 State Tables Valid Time 3 Uniqueness 4 Temporal Keys Primary Keys Foreign Keys 5 Summary Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 32 / 50
  • 45. Uniqueness over Time Cases Your DNA profile remains constant over time Your cell-phone number varies slowly over time, but always one Your checking balances varies almost daily, but always one The IBM stock value changes every second but always exactly one value Note The notaion of a primary key caries over to temporal databases The notaion of a foreign key caries over to temporal databases Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 33 / 50
  • 46. Primary Keys Informally Cases You have been working for a company for eight years. In this time interval you salary has changed several times. However, at any point in time you have always had exactly one salary. You have been married three times. However at any point in time you have had either zero or one spouse. Your car has driven 56,000 kilometers but for all millimeters driven there has been exactly one driver. You have a house that is 34 years old. Since the house was build there has at any time only been one owner of the house. Note There is a general concept of time-varying uniqueness Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 34 / 50
  • 47. Temporal Primary Key Example Example (trainer at time 19) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2, Bo, 302, Bo, 20 1, Ann, 251, Ann, 201, Ann, 10 Example (As Valid-Time Table) tid tname salary vts vte 1 Ann 10 1 7 1 Ann 20 9 15 1 Ann 25 15 now 2 Bo 20 2 13 2 Bo 30 13 18 Note At any point in time is tid a unique value! Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 35 / 50
  • 48. Not Temporal Primary Key Example (tid not a Temporal Primary Key) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2, Bo, 20 2, Bo, 302, Bo, 20 1, Ann, 25 2, Ann, 20 1, Ann, 10 Example (tid a Temporal Primary Key?) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 5, Dan, 20 4, Dan, 20 3, Cho, 40 2, Bo, 402, Bo, 302, Bo, 20 1, Ann, 251, Ann, 10 Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 36 / 50
  • 49. Summary: Primary Key Main Points A temporal primary-key is a straight-forward extension of snapshot primary keys A temporal primary-key much more computation intesive Note Limited or no support for temporal primary keys in DBMSs Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 37 / 50
  • 50. Outline 1 State and Event Tables 2 State Tables Valid Time 3 Uniqueness 4 Temporal Keys Primary Keys Foreign Keys 5 Summary Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 38 / 50
  • 51. Foreign Keys Informally Cases You cannot have a contract to rent a house in the period April to October if the house is first built in September You cannot call your friend after the subscription of her/his cell-phone has expired You expect that the cinema has a copy of the movie Blade Runner II available during the entire period where you have bought a ticket to see this movie in the cinema Note There is a constraint between the time interval associated with the phenomenon stored in the database. Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 39 / 50
  • 52. Temporal Foreign Key Example Example (emp and dept at time 19) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2, Bo, 102, Bo, 10 1, Ann, 101, Ann, 201, Ann, 10 VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 20, RD20, RD20, RD 10, HR10, HR Example (As Tables) tid tname did vts vte 1 Ann 10 1 9 1 Ann 20 10 13 1 Ann 10 16 now 2 Bo 10 2 6 2 Bo 10 13 18 did dname vts vte 10 HR 1 9 10 HR 11 now 20 RD 1 6 20 RD 8 13 20 RD 16 now Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 40 / 50
  • 53. Idea in Foreign-Key Solution Requirements The emp vts value must be covered by an interval in dept The emp vte value must be covered by an interval in dept There cannot be any ”holes” in the coverage of the interval for emp Example (emp and dept at time 19) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Emp Dept Dept “Hole” Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 41 / 50
  • 54. Part 1 as a Figure Example (Overlap of vts) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Emp Case 1 Case 2 Case 3 Case 4 Case 5 Case 6 Case 7 Case 8 Case 9 Case 10 Case 11 Case 12 Case 13 Note Allen’s operators 13 cases because interval to interval comparison Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 42 / 50
  • 55. Part 1 in SQL Example where not exists ( select ∗ −− vts i s not covered from dept as s where s . did = emp. did and s . vts <= emp. vts and emp. vts < s . vte ) Note ≤ when comparing vts values < when comparing a vts value to a vte value Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 43 / 50
  • 56. Part 2 as a Figure and SQL Example (Overlap of vte) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Emp Case 1 Case 2 Case 3 Case 4 Case 5 Example (Overlap vte in SQL) or not exists ( select ∗ −− vte i s not covered from dept as e where e . did = emp. did and e . vts < emp. vte and emp. vte <= e . vte ) Note < when comparing a vts value to a vte value ≤ when comparing vte values Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 44 / 50
  • 57. Part 3 Example as a Figure Example (Overlap of vts) VT 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Emp s e b1 b2 Conditions s overlaps emp.vts e overlaps emp.vte Exist A b1 that fills the “holes” towards emp.vte A b2 that exists the filling of the “hold” towards emp.vte Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 45 / 50
  • 58. Part 3 in SQL Example or exists ( −− there i s a hole select ∗ from dept as b1 where b1 . did = emp. did and emp. vts < b1 . vte and b1 . vte < emp. vte and not exists ( select ∗ from dept as b2 where b2 . did = emp. did and b2 . vts <= b1 . vte and b1 . vte < b2 . vte ) ) Note There exists a row in dept where the vte is in the interval [emp.vts, emp.vte), and there is no row in dept that has an interval that extends towards emp.vte Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 46 / 50
  • 59. Entire Solution Example select ∗ from emp where exists ( select ∗ from dept as s where s . did = emp. did and s . vts <= emp. vts and emp. vts < s . vte ) and exists ( select ∗ from dept as e where e . did = emp. did and e . vts < emp. vte and emp. vte <= e . vte ) and not exists ( select ∗ from dept as b1 where b1 . did = emp. did and emp. vts < b1 . vte and b1 . vte < emp. vte and not exists ( select ∗ from dept as b2 where b2 . did = emp. did and b2 . vts <= b1 . vte and b1 . vte < b2 . vte ) ) Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 47 / 50
  • 60. Summary: Foreign Key Main Points A temporal foreign-key is a straight-forward extension of non-temporal foreign-keys A temporal foreign-key is very expensive to enforce Note Limited or no support for temporal foreign-keys in DBMSs Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 48 / 50
  • 61. Outline 1 State and Event Tables 2 State Tables Valid Time 3 Uniqueness 4 Temporal Keys Primary Keys Foreign Keys 5 Summary Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 49 / 50
  • 62. Summary: Temporal Data Model Main Points Event single timestamp State two timestamps (from and to) What is supported by IBM, Microsoft, and Teradata now = nobind-now (in column vte) Implemented by large timestamp, e.g., 9999-12-31 UC = until-changed (in column tte) Implemented by large timestamp, e.g., 9999-12-31 Temporal primary-key and foreign-key Can be hard to understand Note UC is sometimes all so called now or nobind now Kristian Torp (Aalborg University) Temporal Databases: Data Models November 2, 2015 50 / 50