Implementing Temporal Features in PostgreSQL: SQL Standard and Beyond#

Temporal DB Basics#

Why Time Travel is Needed?#

Point in Time (Snapshot) queries: How my report looked on last day of previous month? Change Log: When and how the state of my request was changed? Fully Temporal: When these objects co-exist? Before/after/meets etc. Temporal joins, aggregations etc.

Storing Temporal Data#

Snapshots: any theoretical paper starts with it Event Logs: Often produced by applications with a hope that they will be used for analysis in the future Perionds: Used by everyone who actually implements temporal features in a dabase All are equivalent but query performance may differ

Time Semantics#

Discrete Periods with closed-open semantics (I’m not are semantics is the right word on this slide)

Dimensions of Time#

Theis is something beyond common sense in th real life, however, we need them Transactional (system) Valid = Effective Asserted ~ transactional Much more were defined but are not widely known

Temporal Features in the SQL Standard#

Data Types and Predicates#

Actually no new data types, periods are represented as pairs of timestamp columns Closed-open periods Predicates: OVERLAPS …

Transactional Time#

Past but not future Data can never be changed Dose NOT require separate table for historical data, although some implementations do that

Other Time Dimensions#

The standard does not specify any semantics for other time dimensions Currently at most one additional time dimension can be specified

Queries and Manipulation#

Syntax extensions for INSERT, UPDATE, DELETE to specify period(s) Syntax extensions for SELECT

PostgreSQL Support for Temporal Data#

Data Types, Operators, and Predicates#

Period data types are provided although are not required by the Standard Rich set of operators and functions for timestamps, intervals, and periods Predicates are implemented as required by the Standard (including closed-open semantics)

Storage and Performance#

Spatial indexes With exclusion

Bitemporal Implementation#

Overview of Bitemporal#

Suports assered and effective time dimensions Transactional dimension can be queries but is not explicitly supported Heavily relies on PostgreSQL features Does not provide any syntax extensions Data manipulation is implemented with user-defined functions Detailed refinement of data manipulation semantics Integrity cnstraints

Data Manipulation#

The refinements of manipulation semantics are here INSERT UPDATE CORRECTION DEACTIVATE DELETE

StoragStorage and Indexes#

Queries#

Time-related conditions must be explicitly specified Built-in predicates are helpful Fully temporal queries are still trichy

Bi-Temporal vs. SQL Standard#

Probably a table is needed here

What is Still Missing?#

What is missing in th e Standard#

What is missing in PostgreSQL#

Of course, bi-temporal

What is Missing in Bitemporal#

Syntax extensions Design methodologies (also missing in the Standard) Explicit support for transactional time dimension, although transactional dimension is not really needed

Conclusions#

Past, Present, and Future#

Of Temporal Databases The SQL Standard provides very reasonable conservative support PostgreSQL contains everything that is needed for efficient implementation but not an implementation Bitemporal is not too far from the Standard