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
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Kristian Torp (Aalborg University) Temporal Databases: Modification November 2, 2015 34 / 57
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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