Temporal database
A temporal database stores data relating to time instances. It offers temporal data types and stores information relating to past, present and future time.
Temporal databases could be uni-temporal, bi-temporal or tri-temporal.
More specifically the temporal aspects usually include valid time, transaction time or decision time.
- Valid time is the time period during which a fact is true in the real world.
- Transaction time is the time at which a fact was recorded in the database.
- Decision time is the time at which the decision was made about the fact.
Uni-Temporal
Bi-Temporal
A bi-temporal database has two axis of time:- valid time
- transaction time or decision time
Tri-Temporal
- valid time
- transaction time
- decision time
Temporal databases are in contrast to current databases, which store only facts which are believed to be true at the current time.
Features
Temporal databases support managing and accessing temporal data by providing one or more of the following features:- A time period datatype, including the ability to represent time periods with no end
- The ability to define valid and transaction time period attributes and bitemporal relations
- System-maintained transaction time
- Temporal primary keys, including non-overlapping period constraints
- Temporal constraints, including non-overlapping uniqueness and referential integrity
- Update and deletion of temporal records with automatic splitting and coalescing of time periods
- Temporal queries at current time, time points in the past or future, or over durations
- Predicates for querying time periods, often based on Allen’s interval relations
History
Richard Snodgrass proposed in 1992 that temporal extensions to SQL be developed by the temporal database community. In response to this proposal, a committee was formed to design extensions to the 1992 edition of the SQL standard ; those extensions, known as TSQL2, were developed during 1993 by this committee. In late 1993, Snodgrass presented this work to the group responsible for the American National Standard for Database Language SQL, ANSI Technical Committee X3H2. The preliminary language specification appeared in the March 1994 ACM SIGMOD Record. Based on responses to that specification, changes were made to the language, and the definitive version of the TSQL2 Language Specification was published in September, 1994
An attempt was made to incorporate parts of TSQL2 into the new SQL standard, called SQL3. Parts of TSQL2 were included in a new substandard of SQL3, ISO/IEC 9075-7, called SQL/Temporal. The TSQL2 approach was heavily criticized by Chris Date and Hugh Darwen. The ISO project responsible for temporal support was canceled near the end of 2001.
As of December 2011, ISO/IEC 9075, Database Language Part 2: SQL/Foundation included clauses in table definitions to define "application-time period tables", "system-versioned tables" and "system-versioned application-time period tables". A substantive difference between the TSQL2 proposal and what was adopted in SQL:2011 is that there are no hidden columns in the SQL:2011 treatment, nor does it have a new data type for intervals; instead two date or timestamp columns can be bound together using a
PERIOD FOR
declaration. Another difference is replacement of the controversial statement modifiers from TSQL2 with a set of temporal predicates.Other features of standard related to temporal databases are automatic time period splitting, temporal primary keys, temporal referential integrity, temporal predicates with Allen's interval algebra and time-sliced and sequenced queries.
Example
For illustration, consider the following short biography of a fictional man, John Doe:Using a non-temporal database
To store the life of John Doe in a current database we use a table Person .John's father officially reported his birth on April 4, 1975. On this date a Smallville official inserted the following entry in the database:
Person
.Note that the date itself is not stored in the database.
After graduation, John moves out, but forgets to register his new address. John's entry in the database is not changed until December 27, 1994, when he finally reports it. A Bigtown official updates his address in the database. The Person table now contains
Person
.Note that the information of John living in Smallville has been overwritten, so it is no longer possible to retrieve that information from the database. An official accessing the database on December 28, 1994 would be told that John lives in Bigtown.
More technically: if a database administrator ran the query
SELECT ADDRESS FROM PERSON WHERE NAME='John Doe'
on December 26, 1994, the result would be Smallville
. Running the same query 2 days later would result in Bigtown
.Until his death, the database would state that he lived in Bigtown. On April 1, 2001, the coroner deletes the John Doe entry from the database. After this, running the above query would return no result at all.
Date | Real world event | Database Action | What the database shows |
April 3, 1975 | John is born | Nothing | There is no person called John Doe |
April 4, 1975 | John's father officially reports John's birth | Inserted:Person | John Doe lives in Smallville |
August 26, 1994 | After graduation, John moves to Bigtown, but forgets to register his new address | Nothing | John Doe lives in Smallville |
December 26, 1994 | Nothing | Nothing | John Doe lives in Smallville |
December 27, 1994 | John registers his new address | Updated:Person | John Doe lives in Bigtown |
April 1, 2001 | John dies | Deleted:Person | There is no person called John Doe |
Using a single axis: valid time or transaction time
is the time for which a fact is true in the real world. A valid time period may be in the past, span the current time, or occur in the future.For the example above, to record valid time, the Person table has two fields added, Valid-From and Valid-To. These specify the period when a person's address is valid in the real world.
On April 4, 1975 John's father registered his son's birth. An official then inserts a new entry into the database stating that John lives in Smallville from April 3. Note that although the data was inserted on the 4th, the database states that the information is valid since the 3rd. The official does not yet know if or when John will move to another place, so the Valid-To field is set to infinity. The entry in the database is:
Person.
On December 27, 1994 John reports his new address in Bigtown where he has been living since August 26, 1994. A new database entry is made to record this fact:
Person.
The original entry
Person
is not deleted, but has the Valid-To attribute updated to reflect that it is now known that John stopped living in Smallville on August 26, 1994.The database now contains two entries for John Doe
Person.
Person.
When John dies his current entry in the database is updated stating that John does not live in Bigtown any longer. The database now looks like this
Person.
Person.
Using two axes: valid time and transaction time
records the time period during which a database entry is accepted as correct. This enables queries that show the state of the database at a given time. Transaction time periods can only occur in the past or up to the current time. In a transaction time table, records are never deleted. Only new records can be inserted, and existing ones updated by setting their transaction end time to show that they are no longer current.To enable transaction time in the example above, two more fields are added to the Person table: Transaction-From and Transaction-To. Transaction-From is the time a transaction was made, and Transaction-To is the time that the transaction was superseded. This makes the table into a [|bitemporal table].
What happens if the person's address as stored in the database is incorrect? Suppose an official accidentally entered the wrong address or date? Or, suppose the person lied about their address for some reason. Upon discovery of the error, the officials update the database to correct the information recorded.
For example, from 1-Jun-1995 to 3-Sep-2000, John Doe moved to Beachy. But to avoid paying Beachy's exorbitant residence tax, he never reported it to the authorities. Later during a tax investigation, it is discovered on 2-Feb-2001 that he was in fact in Beachy during those dates. To record this fact, the existing entry about John living in Bigtown must be split into two separate records, and a new record inserted recording his residence in Beachy. The database would then appear as follows:
Person.
Person.
Person.
Person.
However, this leaves no record that the database ever claimed that he lived in Bigtown during 1-Jun-1995 to 3-Sep-2000. This might be important to know for auditing reasons, or to use as evidence in the official's tax investigation. Transaction time allows capturing this changing knowledge in the database, since entries are never directly modified or deleted. Instead, each entry records when it was entered and when it was superseded. The database contents then look like this:
Name, City, Valid From, Valid Till, Entered, Superseded
Person.
Person.
Person.
Person.
Person.
Person.
Person.
The database records not only what happened in the real world, but also what was officially recorded at different times.
Using three axes: valid time, decision time, and transaction time
is an alternative to the transaction time period for recording the time at which a database entry may be accepted as correct. This enables queries that show the officially recognized facts at a given time, even if there was a delay in committing those facts to the database. Support for decision time preserves the entire history and prevents the loss of information during updates.Decision time periods can only occur in the past or up to the transaction time. As in a transaction time table, records are never deleted. Only new records can be inserted, and existing ones updated by setting their decision end time to show that they are no longer current.
To enable decision time, two more fields are added to a database table: Decision From and Decision To. Decision From is the time a decision was made, and Decision-To is the time that the decision was superseded. When combined with transaction time, this makes the table into a [|tritemporal table].
The following is a list of real-world events that occurred between the United States presidential elections of 1964 and 1976:
Date | Decision Maker | Real world event |
November 3, 1964 | Electoral College | Election of 1964 |
November 5, 1968 | Electoral College | Election of 1968 |
November 7, 1972 | Electoral College | Election of 1972 |
October 10, 1973 | Spiro Agnew | Agnew resigns |
October 12, 1973 | Richard Nixon | Nixon nominates Ford |
December 6, 1973 | Congress | Congress confirms Ford |
August 9, 1974 | Richard Nixon | Nixon resigns |
August 20, 1974 | Gerald Ford | Ford nominates Rockefeller |
December 19, 1974 | Congress | Congress confirms Rockefeller |
November 2, 1976 | Electoral College | Election of 1976 |
Suppose there is a constant 7-day delay between the decision time and the transaction time committed to the database. Then following the election of 1976 the database contents would be:
President, Vice President, Valid From, Valid Till, Decision From, Decision To, Transaction From, Transaction To
----------------------------------------------------------------------------------------------------------------------------------
Administration
Administration
Administration
Administration
Administration
Administration
Administration
Administration
Administration
Administration
Administration
Administration
Administration
Administration
Administration
Administration
Administration
Administration
Administration
Administration
Consider the question of who would be President and Vice President for a valid time of 1-Jan-1977:
- Nixon/Agnew when using a decision time and transaction time of 14-Nov-1972
- Nixon/ when using a decision time and transaction time of 17-Oct-1973
- Nixon/Ford when using a decision time and transaction time of 8-Aug-1974
- Ford/ when using a decision time of 8-Aug-1974 and transaction time of current
- Ford/Rockefeller when using a decision time and transaction time of current
Bitemporal Modelling
The valid time and transaction time do not have to be the same for a single fact. For example, consider a temporal database storing data about the 18th century. The valid time of these facts is somewhere between 1701 and 1800. The transaction time would show when the facts were inserted into the database.
Schema evolution
A challenging issue is the support of temporal queries in a transaction time database under evolving schema. In order to achieve perfect archival quality it is of key importance to store the data under the schema version under which they first appeared. However, even the most simple temporal query rewriting the history of an attribute value would be required to be manually rewritten under each of the schema versions, potentially hundreds as in the case of MediaWiki .This process would be particularly taxing for users. A proposed solution is to provide automatic query rewriting, although this is not part of SQL or similar standards.
Approaches to minimize the complexities of schema evolution are:
- to use a semi-structured database/NoSQL database which reduces the complexities of modeling attribute data but provides no features for handling multiple time axes.
- to use a database capable of storing both semi-structured data for attributes and structured data for time axes
Implementations in notable products
- MariaDB version 10.3.4 added support for standard as "System-Versioned Tables".
- Oracle Database Oracle Workspace Manager is a feature of Oracle Database which enables application developers and DBAs to manage current, proposed and historical versions of data in the same database.
- PostgreSQL version 9.2 added native ranged data types that are capable of implementing all of the features of the pgFoundry temporal contributed extension. The PostgreSQL range types are supported by numerous native operators and functions.
- Teradata provides two products. Teradata version 13.10 and Teradata version 14 have temporal features based on TSQL2 built into the database.
- IBM DB2 version 10 added a feature called "time travel query" which is based on the temporal capabilities of the standard.
- Microsoft SQL Server introduced Temporal Tables as a feature for SQL Server 2016. The feature is described in a video on Microsoft's "Channel 9" web site.
- MarkLogic introduced bitemporal data support in version 8.0. Time stamps for Valid and System time are stored in JSON or XML documents.
- stores snapshots of XML- and JSON-documents very efficiently in a binary format due to a novel versioning algorithm called sliding snapshot, which balances read-/write-performance and never creates write peaks. Time-travel queries are supported natively as well as diffing functions.
- provides point-in-time bitemporal Datalog queries over transactions and documents ingested from semi-immutable Kafka logs. Documents are automatically indexed to create Entity–attribute–value model indexes without any requirement to define a schema. Transaction operations specify the effective Valid times. Transaction times are assigned by Kafka and enable horizontal scalability via consistent reads.
- is a point-in-time, unitemporal graph database, built on top of ArangoDB. It runs on ArangoDB's sub-system. It features VCS-like semantics in many parts of its interface, and is backed by a transactional event tracker. Bitemporality is listed as one of the items in its .
Alternatives