Presentation is loading. Please wait.

Presentation is loading. Please wait.

USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES.

Similar presentations


Presentation on theme: "USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES."— Presentation transcript:

1 USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES

2 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

3 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

4 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

5 Basic Concepts (3) SQL/TemporalSQL:2011IBM DB2 10.5 valid timeapplication timebusiness time transaction timesystem time valid time tableapplication time period table table with business time transaction time tablesystem-versioned tabletable with system time bitemporal tablesystem-versioned application time period table bitemporal table Differences in terminology:

6 IBM DB2 – Table with Business time(1) Create CREATE 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') Idnamepricediscountbus_startbus_end 1Black Shoes150102012-12-252013-01-10 1Black Shoes15052013-01-102013-01-31 1Black Shoes15002013-01-319999-12-30 2Moccasin10052013-09-012013-03-01 INSERT INTO Product VALUES (1, 'Black Shoes', 150, 10, '2013-06-06', '2013-07-07')

7 IBM DB2 – Table with Business time(2) UPDATE Product FOR PORTION OF BUSINESS_TIME FROM '2013-06-01' TO '2013-09-01' SET discount = 20 WHERE id = 1; Idnamepricediscountbus_startbus_end 1Black Shoes150102012-12-252013-01-10 1Black Shoes15052013-01-102013-01-31 1Black Shoes15002013-01-312013-06-01 1Black Shoes150202013-06-012013-09-01 1Black Shoes15002013-09-019999-12-30 2Moccasin10052013-09-012013-03-01 Update for portion row spliting SELECT discount FROM Product FOR BUSINESS_TIME AS OF '2013-03-20' WHERE id = 1 Temporal query Result: 0

8 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) );

9 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);

10 IBM DB2 – Table with system time (3) idnamepricediscountsys_startsys_end 1Black Shoes150102014-04-13 17:53:259999-12-30 00:00:00 2Moccasin1005 2014-04-13 17:53:25 9999-12-30 00:00:00 Product table Product_history table - empty - Command was executed on April 15, 2014 UPDATE Product SET discount = 30 where id = 1; idnamepricediscountsys_startsys_end 1Black Shoes150302014-04-15 12:53:259999-12-30 00:00:00 2Moccasin10052014-04-13 17:53:259999-12-30 00:00:00 idnamepricediscountsys_startsys_end 1Black Shoes150102014-04-13 17:53:252014-04-15 12:53:25 Product table Product_history table

11 System time & Business time Characteristics of system timeCharacteristics 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 timeYour application’s logical view of time Spans from the past to the present timeSpans past, present, and future time System 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?”

12 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).

13 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

14 THANK YOU FOR YOUR ATTENTION! ANY QUESTIONS?


Download ppt "USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES."

Similar presentations


Ads by Google