Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Temporal Databases: Data Models

920 views

Published on

An overview of the event and state temporal database support. Clear focus on the (from, to) timestamping used for the state temporal support.

Published in: Education
  • Be the first to comment

Temporal Databases: Data Models

  1. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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

×