80
Temporal Databases: Modification Kristian Torp Department of Computer Science Aalborg University people.cs.aau.dk/˜torp [email protected] November 2, 2015 daisy.aau.dk Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 1 / 57

Temporal Databases: Modifications

  • Upload
    torp42

  • View
    207

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Temporal Databases: Modifications

Temporal Databases: Modification

Kristian Torp

Department of Computer ScienceAalborg University

people.cs.aau.dk/˜[email protected]

November 2, 2015

daisy.aau.dk

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 1 / 57

Page 2: Temporal Databases: Modifications

Outline

1 Transaction-Time State Tables

2 Valid-Time State TablesImplicit TimestampingExplicit Timestamping

3 Bitemporal State TablesImplicit TimestampingExplicit Timestaming

4 Summary

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 2 / 57

Page 3: Temporal Databases: Modifications

Learning Goals

Learning GoalsUnderstand modifications on transaction-time tablesUnderstand modifications on valid-time tables

Implicit timestamping, system suppliedExplicit timestamping, user supplied

Understand modifications on bitemporal tablesImplicit timestamping, system suppliedExplicit timestamping, user supplied

now and UC in modifications

NoteWe will use integers for timestamps

simply because it takes up less space on slides

Will focus on state tablesMost expressiveHardest to understand (compared to event)

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 3 / 57

Page 4: Temporal Databases: Modifications

Outline

1 Transaction-Time State Tables

2 Valid-Time State TablesImplicit TimestampingExplicit Timestamping

3 Bitemporal State TablesImplicit TimestampingExplicit Timestaming

4 Summary

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 4 / 57

Page 5: Temporal Databases: Modifications

Transaction-Time Example, Implicit Timestamping

NoteImplicit means timestamps values are always system supplied

Logical OperationsTime 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Time 12: Hire Bart to work in the HR department

Time 16: Fire Bart

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 5 / 57

Page 6: Temporal Databases: Modifications

Transaction-Time Example, Implicit Timestamping

NoteImplicit means timestamps values are always system supplied

Logical OperationsTime 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Time 12: Hire Bart to work in the HR department

Time 16: Fire Bart

Example (At Time 4: Transaction-Time Insert)

Name Dept tts tte

Ann HR 4 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 5 / 57

Page 7: Temporal Databases: Modifications

Transaction-Time Example, Implicit Timestamping

NoteImplicit means timestamps values are always system supplied

Logical OperationsTime 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Time 12: Hire Bart to work in the HR department

Time 16: Fire Bart

Example (At Time 8: Transaction-Time Update)

Name Dept tts tte

Ann HR 4 8Ann RD 8 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 5 / 57

Page 8: Temporal Databases: Modifications

Transaction-Time Example, Implicit Timestamping

NoteImplicit means timestamps values are always system supplied

Logical OperationsTime 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Time 12: Hire Bart to work in the HR department

Time 16: Fire Bart

Example (At Time 12: Transaction-Time Insert)

Name Dept tts tte

Ann HR 4 8Ann RD 8 UC

Bart HR 12 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 5 / 57

Page 9: Temporal Databases: Modifications

Transaction-Time Example, Implicit Timestamping

NoteImplicit means timestamps values are always system supplied

Logical OperationsTime 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Time 12: Hire Bart to work in the HR department

Time 16: Fire Bart

Example (At Time 16: Transaction-Time Delete)

Name Dept tts tte

Ann HR 4 8Ann RD 8 UC

Bart HR 12 16

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 5 / 57

Page 10: Temporal Databases: Modifications

Transaction-Time Insert

Logical OperationsTime 4: Hire Ann to work in the HR department

Example (Emps as of Time 6)

VT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Ann, HR

Example (Table)

Name Dept tts tte

Ann HR 4 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 6 / 57

Page 11: Temporal Databases: Modifications

Transaction-Time Update

Logical OperationsTime 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Example (Emps as of Time 10)

VT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Ann, RDAnn, HR

Example (Table)

Name Dept tts tte

Ann HR 4 8Ann RD 8 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 7 / 57

Page 12: Temporal Databases: Modifications

Transaction-Time Insert (Again)Logical Operations

Time 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Time 12: Hire Bart to work in the HR department

Example (Emps as of Time 14)

VT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Bart, RDAnn, RD

Ann, HR

Example (Table)

Name Dept tts tte

Ann HR 4 8Ann RD 8 UC

Bart HR 12 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 8 / 57

Page 13: Temporal Databases: Modifications

Transaction-Time DeleteLogical Operations

Time 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Time 12: Hire Bart to work in the HR department

Time 16: Fire BartExample (Emps as of Time 18)

VT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Bart, RDAnn, RD

Ann, HR

Example (Table)

Name Dept tts tte

Ann HR 4 8Ann RD 8 UC

Bart HR 12 16Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 9 / 57

Page 14: Temporal Databases: Modifications

Quiz: Transaction-Time State Table

Logical OperationsTime 4 Hire Curt to work in the HR department

Time 8 Move Curt to the RD department

Time 12 Fire Curt from the company

Name Dept tts tte

Curt HR 4 UC

Curt RD 8 UC

Name Dept tts tte

Curt HR 4 8Curt RD 8 UC

A B

Name Dept tts tte

Curt HR 4 8Curt RD 8 12

Name Dept tts tte

Curt HR 4 8Curt RD 8 12Curt RD 12 UC

C D

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 10 / 57

Page 15: Temporal Databases: Modifications

Summary: Transaction-Time Modifications

Main PointsTransaction time always system supplied values

Insert: Explicit attributes + [current time, UC)

Delete: Set column tte to current time

Update: A delete followed by an insert

NoteSystem always supplies the timestamps!!!UC = Until Changed

Also called now or nobind-now

Queries on current state of table work as beforeBackwards compatibility⇒ no rewrite of existing code

Logical deletes (newer physical deletes)

More than one insert/update/delete per time unit

Physical database design split current from history

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 11 / 57

Page 16: Temporal Databases: Modifications

Outline

1 Transaction-Time State Tables

2 Valid-Time State TablesImplicit TimestampingExplicit Timestamping

3 Bitemporal State TablesImplicit TimestampingExplicit Timestaming

4 Summary

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 12 / 57

Page 17: Temporal Databases: Modifications

Outline

1 Transaction-Time State Tables

2 Valid-Time State TablesImplicit TimestampingExplicit Timestamping

3 Bitemporal State TablesImplicit TimestampingExplicit Timestaming

4 Summary

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 13 / 57

Page 18: Temporal Databases: Modifications

Valid-Time Implicit Timestamping

NoteRecall, implicit means timestamps values are always system supplied

Logical Operationstime: 4 Hire Ann to work in the HR department

time: 8 Move Ann to the RD department

time: 12 Hire Bart to work in the HR department

time: 16 Fire Bart

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 14 / 57

Page 19: Temporal Databases: Modifications

Valid-Time Implicit Timestamping

NoteRecall, implicit means timestamps values are always system supplied

Logical Operationstime: 4 Hire Ann to work in the HR department

time: 8 Move Ann to the RD department

time: 12 Hire Bart to work in the HR department

time: 16 Fire Bart

Example (At Time 4: Valid-Time Insert)

Name Dept vts vte

Ann HR 4 now

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 14 / 57

Page 20: Temporal Databases: Modifications

Valid-Time Implicit Timestamping

NoteRecall, implicit means timestamps values are always system supplied

Logical Operationstime: 4 Hire Ann to work in the HR department

time: 8 Move Ann to the RD department

time: 12 Hire Bart to work in the HR department

time: 16 Fire Bart

Example (At Time 8: Valid-Time Update)

Name Dept vts vte

Ann HR 4 8Ann RD 8 now

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 14 / 57

Page 21: Temporal Databases: Modifications

Valid-Time Implicit Timestamping

NoteRecall, implicit means timestamps values are always system supplied

Logical Operationstime: 4 Hire Ann to work in the HR department

time: 8 Move Ann to the RD department

time: 12 Hire Bart to work in the HR department

time: 16 Fire Bart

Example (At Time 12: Valid-Time Insert)

Name Dept vts vte

Ann HR 4 8Ann RD 8 now

Bart HR 12 now

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 14 / 57

Page 22: Temporal Databases: Modifications

Valid-Time Implicit Timestamping

NoteRecall, implicit means timestamps values are always system supplied

Logical Operationstime: 4 Hire Ann to work in the HR department

time: 8 Move Ann to the RD department

time: 12 Hire Bart to work in the HR department

time: 16 Fire Bart

Example (At Time 16: Valid-Time Delete)

Name Dept vts vte

Ann HR 4 8Ann RD 8 now

Bart HR 12 16

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 14 / 57

Page 23: Temporal Databases: Modifications

Valid-Time Insert

Logical OperationsTime 4: Hire Ann to work in the HR department

Example (Emps as of Time 6)

VT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Ann, HR

Example (Table)

Name Dept vts vte

Ann HR 4 now

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 15 / 57

Page 24: Temporal Databases: Modifications

Valid-Time Update

Logical OperationsTime 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Example (Emps as of Time 10)

VT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Ann, RDAnn, HR

Example (Table)

Name Dept vts vte

Ann HR 4 8Ann RD 4 now

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 16 / 57

Page 25: Temporal Databases: Modifications

Valid-Time Insert (Again)Logical Operations

Time 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Time 12: Hire Bart to work in the HR department

Example (Emps as of Time 14)

VT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Bart, RDAnn, RD

Ann, HR

Example (Table)

Name Dept vts vte

Ann HR 4 8Ann RD 6 now

Bart HR 12 now

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 17 / 57

Page 26: Temporal Databases: Modifications

Valid-Time DeleteLogical Operations

Time 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Time 12: Hire Bart to work in the HR department

Time 16: Fire BartExample (Emps as of Time 18)

VT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Bart, RDAnn, RD

Ann, HR

Example (Table)

Name Dept vts vte

Ann HR 4 8Ann RD 6 now

Bart HR 12 16Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 18 / 57

Page 27: Temporal Databases: Modifications

Summary: Implicit Timestamping

Temporal ModificationsInsert: explicit attributes + [current time, now)

Delete: Set column vte to current time

Update: A delete followed by an insert

NoteImplicit valid-time and transaction-time is handled similarly

System can supplies the timestamps!!!

Operations on current state of table as before

Logical deletes (no physical deletes in these cases!!!)

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 19 / 57

Page 28: Temporal Databases: Modifications

Quiz: Modifications to Table

Logical Operationstime:1 Hire Curt to work in the HR department

time:12 Fire Curt

time:20 Hire Dan to work in the HR department

Name Dept vts vte

Curt HR 1 12Dan HR 20 now

Name Dept vts vte

Curt HR 1 12Curt HR 12 now

Dan HR 20 now

A BName Dept vts vte

Curt HR 1 now

Curt HR 12 now

Dan HR 20 now

Name Dept vts vte

Curt HR 1 12Curt HR 12 20Dan HR 20 now

C D

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 20 / 57

Page 29: Temporal Databases: Modifications

Quiz: Table to Modifications

Name Dept vts vte

Dan HR 1 now

Eli RD 10 20

ATime 1 Hire Dan, HR

Time 10 Hire Eli, RD

BTime 1 Hire Dan, HR

Time 10 Hire Eli, RD

Time 20 Fire Eli

CTime 1 Hire Dan, HR

Time 10 Hire Eli, RD

Time 10 Fire Dan

Time 20 Fire Eli

DTime 1 Hire Dan, HR

Time 10 Hire Eli, RD

Time 10 Eli to RD

Time 20 Fire EliKristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 21 / 57

Page 30: Temporal Databases: Modifications

Quiz: Conceptual Difference?

Example (Departments)

Name Dept vts vte

Ann HR 1 10Ann RD 10 20Ann HR 20 40

Name Dept vts vte

Ann HR 1 15Ann RD 10 20Ann HR 20 40

Example (Salaries)

Name Salary vts vte

Ann 40 1 10Ann 50 10 20Ann 70 20 40

Name Salary vts vte

Ann 40 1 15Ann 50 10 20Ann 70 20 40

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 22 / 57

Page 31: Temporal Databases: Modifications

Quiz: Conceptual Difference?

Example (Departments)

Name Dept vts vte

Ann HR 1 10Ann RD 10 20Ann HR 20 40

Name Dept vts vte

Ann HR 1 15Ann RD 10 20Ann HR 20 40

Example (Salaries)

Name Salary vts vte

Ann 40 1 10Ann 50 10 20Ann 70 20 40

Name Salary vts vte

Ann 40 1 15Ann 50 10 20Ann 70 20 40

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 22 / 57

Page 32: Temporal Databases: Modifications

Outline

1 Transaction-Time State Tables

2 Valid-Time State TablesImplicit TimestampingExplicit Timestamping

3 Bitemporal State TablesImplicit TimestampingExplicit Timestaming

4 Summary

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 23 / 57

Page 33: Temporal Databases: Modifications

Valid-Time Example: Case One

NoteExlicit means timestamps values are user supplied

Logical OperationsTime 4: Hire Ann HR department [2, 14)

Time 8: Hire Bart RD department [14, now)

Time 12: Fire Ann

Time 16: Move Bart to HR department

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 24 / 57

Page 34: Temporal Databases: Modifications

Valid-Time Example: Case One

NoteExlicit means timestamps values are user supplied

Logical OperationsTime 4: Hire Ann HR department [2, 14)

Time 8: Hire Bart RD department [14, now)

Time 12: Fire Ann

Time 16: Move Bart to HR department

Example (At Time 4: Valid-Time Insert)

Name Dept vts vte

Ann HR 2 14

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 24 / 57

Page 35: Temporal Databases: Modifications

Valid-Time Example: Case One

NoteExlicit means timestamps values are user supplied

Logical OperationsTime 4: Hire Ann HR department [2, 14)

Time 8: Hire Bart RD department [14, now)

Time 12: Fire Ann

Time 16: Move Bart to HR department

Example (At Time 8: Valid-Time Insert)

Name Dept vts vte

Ann HR 2 14Bart RD 14 now

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 24 / 57

Page 36: Temporal Databases: Modifications

Valid-Time Example: Case One

NoteExlicit means timestamps values are user supplied

Logical OperationsTime 4: Hire Ann HR department [2, 14)

Time 8: Hire Bart RD department [14, now)

Time 12: Fire Ann

Time 16: Move Bart to HR department

Example (At Time 12: Valid-Time Delete)

Name Dept vts vte

Ann HR 2 12Bart RD 14 now

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 24 / 57

Page 37: Temporal Databases: Modifications

Valid-Time Example: Case One

NoteExlicit means timestamps values are user supplied

Logical OperationsTime 4: Hire Ann HR department [2, 14)

Time 8: Hire Bart RD department [14, now)

Time 12: Fire Ann

Time 16: Move Bart to HR department

Example (At Time 16: Valid-Time Update)

Name Dept vts vte

Ann HR 2 12Bart RD 14 16Bart HR 16 now

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 24 / 57

Page 38: Temporal Databases: Modifications

Valid-Time Insert

Logical OperationsTime:4 Hire Ann HR department [2, 14)

Example (Emps at Time 6)

VT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Ann, HR

Example (Table)

Name Dept vts vte

Ann HR 2 14

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 25 / 57

Page 39: Temporal Databases: Modifications

Valid-Time Insert with now

Logical OperationsTime 4: Hire Ann HR department [2, 14)

Time 8: Hire Bart RD department [14, now)

Example (Emps as of Time 10)

VT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Bart, RDAnn, HR

Example (Table)

Name Dept vts vte

Ann HR 2 14Bart RD 14 now

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 26 / 57

Page 40: Temporal Databases: Modifications

Valid-Time Delete

Logical OperationsTime 4: Hire Ann HR department [2, 14)

Time 8: Hire Bart RD department [14, now)

Time 12: Fire Ann

Example (Emps as of Time 15)

VT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Bart, RDAnn, HR

Example (Table)

Name Dept vts vte

Ann HR 2 12Bart RD 14 now

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 27 / 57

Page 41: Temporal Databases: Modifications

Valid-Time UpdateLogical Operations

Time 4: Hire Ann HR department [2, 14)

Time 8: Hire Bart RD department [14, now)

Time 12: Fire Ann

Time 16: Move Bart to HR department

Example (Emps as of Time 18)

VT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Bart, HRBart, RD

Ann, HR

Example (Table)

Name Dept vts vte

Ann HR 2 12Bart RD 14 16Bart HR 16 now

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 28 / 57

Page 42: Temporal Databases: Modifications

Valid-Time Example: Case Two

Logical OperationsTime 4: Hire Ann HR department [2, 18)

Time 8: Hire Bart RD Department [14, 24)

Time 12: Ann on leave [6, 14)

Time 16: Remove Bart from HR for the period [8, 20)

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 29 / 57

Page 43: Temporal Databases: Modifications

Valid-Time Example: Case Two

Logical OperationsTime 4: Hire Ann HR department [2, 18)

Time 8: Hire Bart RD Department [14, 24)

Time 12: Ann on leave [6, 14)

Time 16: Remove Bart from HR for the period [8, 20)

Example (At Time 4: Valid-Time Insert)

Name Dept vts vte

Ann HR 2 18

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 29 / 57

Page 44: Temporal Databases: Modifications

Valid-Time Example: Case Two

Logical OperationsTime 4: Hire Ann HR department [2, 18)

Time 8: Hire Bart RD Department [14, 24)

Time 12: Ann on leave [6, 14)

Time 16: Remove Bart from HR for the period [8, 20)

Example (At Time 8: Valid-Time Insert)

Name Dept vts vte

Ann HR 2 18Bart RD 14 24

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 29 / 57

Page 45: Temporal Databases: Modifications

Valid-Time Example: Case Two

Logical OperationsTime 4: Hire Ann HR department [2, 18)

Time 8: Hire Bart RD Department [14, 24)

Time 12: Ann on leave [6, 14)

Time 16: Remove Bart from HR for the period [8, 20)

Example (At Time 12: Valid-Time Update)

Name Dept vts vte

Ann HR 2 6Ann HR 14 18Bart RD 14 24

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 29 / 57

Page 46: Temporal Databases: Modifications

Valid-Time Example: Case Two

Logical OperationsTime 4: Hire Ann HR department [2, 18)

Time 8: Hire Bart RD Department [14, 24)

Time 12: Ann on leave [6, 14)

Time 16: Remove Bart from HR for the period [8, 20)

Example (At Time 16: Valid-Time Delete)

Name Dept vts vte

Ann HR 2 6Ann HR 14 18Bart RD 20 24

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 29 / 57

Page 47: Temporal Databases: Modifications

Valid-Time Insert

Logical OperationsTime 4: Hire Ann HR department [2, 18)

Example (Emps as of Time 6)

VT0 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

Ann, HR

Example (Table)

Name Dept vts vte

Ann HR 2 18

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 30 / 57

Page 48: Temporal Databases: Modifications

Valid-Time Insert (Again)

Logical OperationsTime 4: Hire Ann HR department [2, 18)

Time 8: Hire Bart RD Department [14, 24)

Example (Emps as of Time 10)

VT0 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

Bart, RDAnn, HR

Example (Table)

Name Dept vts vte

Ann HR 2 18Bart RD 14 24

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 31 / 57

Page 49: Temporal Databases: Modifications

Valid-Time Update

Logical OperationsTime 4: Hire Ann HR department [2, 18)

Time 8: Hire Bart RD Department [14, 24)

Time 12: Ann on leave [6, 14)

Example (Emps as of Time 15)

VT0 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

Ann, HRBart, RD

Ann, HR

Example (Table)

Name Dept vts vte

Ann HR 2 6Ann HR 14 16Bart RD 14 24

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 32 / 57

Page 50: Temporal Databases: Modifications

Valid-Time DeleteLogical Operations

Time 4: Hire Ann HR department [2, 18)

Time 8: Hire Bart RD Department [14, 24)

Time 12: Ann on leave [6, 14)

Time 16: Remove Bart from HR for the period [8, 20)

Example (Emps as of Time 18)

VT0 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

Ann, HRBart, RD

Ann, HR

Example (Table)

Name Dept vts vte

Ann HR 2 6Ann HR 14 16Bart RD 20 24

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 33 / 57

Page 51: Temporal Databases: Modifications

Visualizations of DeleteExample (Result: Zero Rows)

VT0 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

DataDeleteResult

Example (Result: One Row)

VT0 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

DataDelete

Result

Example (Result: Two Rows)

VT0 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

DataDelete

Result Result

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 34 / 57

Page 52: Temporal Databases: Modifications

Visualizations of DeleteExample (Result: Zero Rows)

VT0 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

DataDeleteResult

Example (Result: One Row)

VT0 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

DataDelete

Result

Example (Result: Two Rows)

VT0 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

DataDelete

Result Result

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 34 / 57

Page 53: Temporal Databases: Modifications

Visualizations of DeleteExample (Result: Zero Rows)

VT0 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

DataDeleteResult

Example (Result: One Row)

VT0 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

DataDelete

Result

Example (Result: Two Rows)

VT0 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

DataDelete

Result Result

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 34 / 57

Page 54: Temporal Databases: Modifications

Valid-Time State Modifications, Explicit Timestamping

OperationsInsert: Explicit attributes + interval suppliedDelete: Remove where delete interval overlaps (for each original row)

0 rows if delete interval totally overlaps1 row if delete interval left/right overlaps2 rows if delete interval contained in row interval

Update: Delete followed by insert

NoteUser supplies the timestamps

Physical deletes may occur

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 35 / 57

Page 55: Temporal Databases: Modifications

Outline

1 Transaction-Time State Tables

2 Valid-Time State TablesImplicit TimestampingExplicit Timestamping

3 Bitemporal State TablesImplicit TimestampingExplicit Timestaming

4 Summary

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 36 / 57

Page 56: Temporal Databases: Modifications

Outline

1 Transaction-Time State Tables

2 Valid-Time State TablesImplicit TimestampingExplicit Timestamping

3 Bitemporal State TablesImplicit TimestampingExplicit Timestaming

4 Summary

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 37 / 57

Page 57: Temporal Databases: Modifications

Bitemporal Example, Implicit Timestamping

Logical OperationsTime 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Time 12: Hire Bart to work in the HR department

Time 16: Fire Bart

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 38 / 57

Page 58: Temporal Databases: Modifications

Bitemporal Example, Implicit Timestamping

Logical OperationsTime 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Time 12: Hire Bart to work in the HR department

Time 16: Fire Bart

Example (At Time 4: Bitemporal Insert)

Name Dept vts vte tts tte

Ann HR 4 now 4 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 38 / 57

Page 59: Temporal Databases: Modifications

Bitemporal Example, Implicit Timestamping

Logical OperationsTime 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Time 12: Hire Bart to work in the HR department

Time 16: Fire Bart

Example (At Time 8: Bitemporal Update)

Name Dept vts vte tts tte

Ann HR 4 now 4 8Ann HR 4 8 8 UC

Ann RD 8 now 8 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 38 / 57

Page 60: Temporal Databases: Modifications

Bitemporal Example, Implicit Timestamping

Logical OperationsTime 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Time 12: Hire Bart to work in the HR department

Time 16: Fire Bart

Example (At Time 12: : Bitemporal Insert)

Name Dept vts vte tts tte

Ann HR 4 now 4 8Ann HR 4 8 8 UC

Ann RD 8 now 8 UC

Bart HR 12 now 12 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 38 / 57

Page 61: Temporal Databases: Modifications

Bitemporal Example, Implicit Timestamping

Logical OperationsTime 4: Hire Ann to work in the HR department

Time 8: Move Ann to the RD department

Time 12: Hire Bart to work in the HR department

Time 16: Fire Bart

Example (At Time 16: : Bitemporal Delete)

Name Dept vts vte tts tte

Ann HR 4 now 4 8Ann HR 4 8 8 UC

Ann RD 8 now 8 UC

Bart HR 12 now 12 16Bart HR 12 16 16 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 38 / 57

Page 62: Temporal Databases: Modifications

Bitemporal Graphs

Example (Ann)

TT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

VT

0123456789

101112131415161718

Ann, HR Ann, HR

Ann, RD

Example (Bart)

TT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

VT

0123456789

101112131415161718

Bart, HRBart, HR

NoteVisualized in two graphs, because data ”overlap”

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 39 / 57

Page 63: Temporal Databases: Modifications

Outline

1 Transaction-Time State Tables

2 Valid-Time State TablesImplicit TimestampingExplicit Timestamping

3 Bitemporal State TablesImplicit TimestampingExplicit Timestaming

4 Summary

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 40 / 57

Page 64: Temporal Databases: Modifications

Bitemporal Delete, Explicit Valid Time

Example (Case 1: No changes)time:1 Insert Ann, HR, [2, 8)

Example (Case 2: Delete entire interval)time:1 Insert Ann, HR, [2, 8)

time:5 Delete Ann, HR, [1, 10)

Example (Case 3: Delete first part)time:1 Insert Ann, HR, [2, 8)

time:5 Delete Ann, HR, [1, 5)

Example (Case 4: Delete in the middle)time:1 Insert Ann, HR, [2, 8)

time:5 Delete Ann, HR, [4, 7)

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 41 / 57

Page 65: Temporal Databases: Modifications

Bitemporal Delete, Explicit Valid Time, Case 1, Time 10

Example (Case 1: No changes)time:1 Insert Ann, HR, [2, 8)

Example (Graph)

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HR

Example (Table)

Name Dept vts vte tts tte

Ann HR 2 8 1 now

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 42 / 57

Page 66: Temporal Databases: Modifications

Bitemporal Delete, Explicit Valid Time, Case 2, Time 10

Example (Case 2: Delete entire interval)time:1 Insert Ann, HR, [2, 8)

time:5 Delete Ann, HR, [1, 10)

Example (Graph)

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HR

Example (Table)

Name Dept vts vte tts tte

Ann HR 2 8 1 5

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 43 / 57

Page 67: Temporal Databases: Modifications

Bitemporal Delete, Explicit Valid Time, Case 3, Time 10

Example (Case 3: Delete first part)time:1 Insert Ann, HR, [2, 8)

time:5 Delete Ann, HR, [1, 5)

Example (Graph)

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HRAnn, HR

Example (Table)

Name Dept vts vte tts tte

Ann HR 2 8 1 5Ann HR 5 8 5 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 44 / 57

Page 68: Temporal Databases: Modifications

Bitemporal Delete, Explicit Valid Time, Case 4, Time 10

Example (Case 4: Delete in the middle)time:1 Insert Ann, HR, [2, 8)

time:5 Delete Ann, HR, [4, 7)

Example (Graph)

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HR

Ann, HR

Ann, HR

Example (Table)

Name Dept vts vte tts tte

Ann HR 2 8 1 5Ann HR 2 4 5 UC

Ann HR 7 8 5 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 45 / 57

Page 69: Temporal Databases: Modifications

Bitemporal Delete Explicit Valid-Time, Summary, Time 10

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HR

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HR

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HRAnn, HR

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HR

Ann, HR

Ann, HR

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 46 / 57

Page 70: Temporal Databases: Modifications

Bitemporal Update Explicit Valid-Time

Example (Case 1: No changes)time:1 Insert Ann, HR, [2, 8)

Example (Case 2: Update entire interval)time:1 Insert Ann, HR, [2, 8)

time:5 Update Ann, RD, [1, 10)

Example (Case 3: Update first part)time:1 Insert Ann, HR, [2, 8)

time:5 Update Ann, RD, [1, 5)

Example (Case 4: Update in the middle)time:1 Insert Ann, HR, [2, 8)

time:5 Update Ann, RD, [4, 7)

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 47 / 57

Page 71: Temporal Databases: Modifications

Bitemporal Update Explicit Valid-Time, Case 1, Time 10

Example (Case 1: No changes)time:1 Insert Ann, HR, [2, 8)

Example (Graph)

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HR

Example (Table)

Name Dept vts vte tts tte

Ann HR 2 8 1 now

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 48 / 57

Page 72: Temporal Databases: Modifications

Bitemporal Update Explicit Valid-Time, Case 2, Time 10

Example (Case 2: Update entire)time:1 Insert Ann, HR, [2, 8)

time:5 Update Ann, RD, [1, 10)

Example (Graph)

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HRAnn, RD

Example (Table)

Name Dept vts vte tts tte

Ann HR 2 8 1 5Ann RD 1 10 5 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 49 / 57

Page 73: Temporal Databases: Modifications

Bitemporal Update Explicit Valid-Time, Case 3, Time 10

Example (Case 3: Update first part)time:1 Insert Ann, HR, [2, 8)

time:5 Update Ann, RD, [1, 5)

Example (Graph)

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HRAnn, HR

Ann, RD

Example (Table)

Name Dept vts vte tts tte

Ann HR 2 8 1 5Ann HR 5 8 5 UC

Ann RD 1 5 5 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 50 / 57

Page 74: Temporal Databases: Modifications

Bitemporal Update Explicit Valid-Time, Case 4, Time 10

Example (Case 4: Update in the middle)time:1 Insert Ann, HR, [2, 8)

time:5 Update Ann, RD, [4, 7)

Example (Graph)

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HR

Ann, HR

Ann, HR

Ann, RD

Example (Table)

Name Dept vts vte tts tte

Ann HR 2 8 1 5Ann HR 2 4 5 UC

Ann HR 7 8 5 UC

Ann RD 4 7 5 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 51 / 57

Page 75: Temporal Databases: Modifications

Bitemporal Graphs: Explicit Valid-Time at Time 10

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HR

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HRAnn, RD

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HRAnn, HR

Ann, RD

TT0 1 2 3 4 5 6 7 8 9 10

VT

0123456789

10

Ann, HR

Ann, HR

Ann, HR

Ann, RD

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 52 / 57

Page 76: Temporal Databases: Modifications

Assignment: Bitemporal Modification I

Modifications on (Name, Salary)Time:2 insert Joe, 10

Time:4 insert Tom, 22

Time:10 Update Joe’s salary to 15

Time:12 Delete Tom

AssignmentsShow the content of the table emp bt at time 15

Draw the bitemporal graph for the table emp bt

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 53 / 57

Page 77: Temporal Databases: Modifications

Assignment: Bitemporal Modification II

Name Salary vts vte tts tte

Joe 10 2 now 2 10Tom 22 4 now 4 12Joe 10 2 10 10 UC

Joe 15 10 now 10 UC

Tom 22 4 12 4 UC

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 54 / 57

Page 78: Temporal Databases: Modifications

Assignment: Bitemporal Modification III

TT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

VT

0123456789

101112131415

Joe, 10 Joe, 10

Joe, 15

TT0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

VT

0123456789

101112131415

Tom, 22 Tom, 22

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 55 / 57

Page 79: Temporal Databases: Modifications

Outline

1 Transaction-Time State Tables

2 Valid-Time State TablesImplicit TimestampingExplicit Timestamping

3 Bitemporal State TablesImplicit TimestampingExplicit Timestaming

4 Summary

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 56 / 57

Page 80: Temporal Databases: Modifications

Summary

Main PointsImplicit timestamps valid-time ≈ transaction-timeExplicit timestamp for valid-time many details

Insert, fairly straight-forwardDelete, complicated because 0, 1, or 2 intervalsUpdate, is conceptual still a delete followed by an insert!

Many details for bitemporal with explicit timestampingAgain delete the hardest to understandUpdate, is conceptual still a delete followed by an insert!

NoteUse half-open intervals, e.g., [10, 15) makes life simpler!

Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 57 / 57