14
USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

Embed Size (px)

Citation preview

Page 1: USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

Page 2: USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

Co-Authors

• Vesić Slavimir, Ph.D student – Faculty of Organizational Sciences

• Babarogić Slađan, Ph.D, Assistant professor – Faculty of Organizational Sciences

• Aničić Nenad, Ph.D, Assistant professor – Faculty of Organizational Sciences

Page 3: USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

Basic Concepts (1)

• conventional databases – memorize only current state (snapshot database)

• 2 periods of temporal concepts:1.SQL/Temporal (1986 – 2001)2.SQL:2011 (2008-2011)

• Temporal concept - links time of event, or fact with time point in database

Page 4: USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

Basic Concepts (2)

• Valid time – link between time in database and time of event in real world (fact is valid or true)

• Transaction time – indicate that information is valid in database

• Bitemporal – supports both time dimensions

Page 5: USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

Basic Concepts (3)

SQL/Temporal SQL:2011 IBM DB2 10.5

valid time application time business time

transaction time system time system time

valid time table application time period table

table with business time

transaction time table system-versioned table table with system time

bitemporal table system-versioned application time period

table

bitemporal table

Differences in terminology:

Page 6: USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

IBM DB2 – Table with Business time(1)

CreateCREATE TABLE Product(id INT NOT NULL, name VARCHAR(20),price DECIMAL, discount INT,bus_start DATE NOT NULL,bus_end DATE NOT NULL,PERIOD BUSINESS_TIME(bus_start, bus_end),PRIMARY KEY(id, BUSINESS_TIME WITHOUT OVERLAPS))

Insert into:INSERT INTO Product VALUES(1, 'Black Shoes', 150, 10, '2012-12-25', '2013-01-10'), (1, 'Black Shoes', 150, 5, '2013-01-10', '2013-01-31'), (1, 'Black Shoes', 150, 0, '2013-01-31', '9999-12-30'), (2, 'Moccasin', 100, 5, '2012-09-01', '2013-04-01')

Id name price discount bus_start bus_end

1 Black Shoes 150 10 2012-12-25 2013-01-10

1 Black Shoes 150 5 2013-01-10 2013-01-31

1 Black Shoes 150 0 2013-01-31 9999-12-30

2 Moccasin 100 5 2013-09-01 2013-03-01

INSERT INTO Product VALUES (1, 'Black Shoes', 150, 10, '2013-06-06', '2013-07-07')

Page 7: USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

IBM DB2 – Table with Business time(2)

UPDATE Product FOR PORTION OF BUSINESS_TIME FROM '2013-06-01' TO '2013-09-01'SET discount = 20WHERE id = 1; Id name price discount bus_start bus_end

1 Black Shoes 150 10 2012-12-25 2013-01-10

1 Black Shoes 150 5 2013-01-10 2013-01-31

1 Black Shoes 150 0 2013-01-31 2013-06-01

1 Black Shoes 150 20 2013-06-01 2013-09-01

1 Black Shoes 150 0 2013-09-01 9999-12-30

2 Moccasin 100 5 2013-09-01 2013-03-01

• Update for portion

rowspliting

SELECT discount FROM Product FOR BUSINESS_TIME AS OF '2013-03-20'WHERE id = 1

• Temporal query

Result: 0

Page 8: USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

IBM DB2 – Table with system time (1)

• old rows are kept in history table – table that is separated from table with current data, with the same structure

• Table creation - 3 steps:1.Create the base table for current data CREATE TABLE Product(id INT PRIMARY KEY NOT NULL, name VARCHAR(20),price DECIMAL, discount INT,sys_start TIMESTAMP(12) GENERATED ALWAYS AS ROW BEGIN NOT NULL, sys_end TIMESTAMP(12) GENERATED ALWAYS AS ROW END NOT NULL, trans_start TIMESTAMP(12) GENERATED ALWAYS AS TRANSACTION START ID IMPLICITLY HIDDEN, PERIOD SYSTEM_TIME (sys_start, sys_end) );

Page 9: USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

IBM DB2 – Table with system time (2)

2. Create the history table - this table has structure identical to the table that contains current data

CREATE TABLE Product_history LIKE Product

3. Alter the current table to enable versioning and identify the history table

ALTER TABLE Product ADD VERSIONING USE HISTORY TABLE Product_history;

- Command was executed on April 13, 2014:INSERT INTO Product(id, name, price, discount)VALUES (1, 'Black Shoes', 150.00, 10), VALUES (2, 'Moccasin', 100.00, 5);

Page 10: USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

IBM DB2 – Table with system time (3)

id name price discount sys_start sys_end

1 Black Shoes 150 10 2014-04-13 17:53:25 9999-12-30 00:00:00

2 Moccasin 100 5 2014-04-13 17:53:25 9999-12-30 00:00:00

Product table

Product_history table - empty

- Command was executed on April 15, 2014UPDATE ProductSET discount = 30 where id = 1;

id name price discount sys_start sys_end1 Black Shoes 150 30 2014-04-15 12:53:25 9999-12-30 00:00:00

2 Moccasin 100 5 2014-04-13 17:53:25 9999-12-30 00:00:00

id name price discount sys_start sys_end1 Black Shoes 150 10 2014-04-13 17:53:25 2014-04-15 12:53:25

Product table

Product_history table

Page 11: USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

System time & Business time

Characteristics of system time Characteristics of business time

Captures the time when changes happen to data inside DB2 database.

Captures the time when changes happen to business objects in the real world

Maintains a history of updated and deleted rows, generated by DB2

Maintains application-driven changes to the time dimensions of business objects

History based on DB2 system timestamps Dates or timestamps are provided by application

DB2’s physical view of time Your application’s logical view of time

Spans from the past to the present time Spans past, present, and future timeSystem validity (transaction time) Business validity (valid time)Supports queries such as:“Which policies were stored in the database on June 30?”

Support queries such as:“Which policies were valid on June 30?”

Page 12: USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

Bitemporal table

Table with business time + Table with system time = Bitemporal table•can be used to solve the following business requirements:

A client inquiry reveals a data entry error involving the three-month introductory interest rate on a credit card. The bank needs to retroactively correct the error (and compute a new balance, if necessary).

Page 13: USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

Conclusion• tracking the state in real system • tracking the state in database itself• combination of both concepts as bitemporal• simplify the logic of applications, stored procedures

and triggers, which would be used if we want to implement tracking the state of tables

• IBM DB2 - fully supports temporal concepts

• Future directions: temporal joins + performance optimization

Page 14: USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

THANK YOU FOR YOUR ATTENTION! ANY QUESTIONS?