Time in Databases CSCI 6442 With thanks to Richard Snodgrass, 1985 ACM 0-89791-160-1/85/005/0236.

Slides:



Advertisements
Similar presentations
TSQL 2 : QUERY LANGUAGE FOR TEMPORAL DATA CS 224 : Advanced Topics in Data Management.
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Manipulating Data Schedule: Timing Topic 60 minutes Lecture
Advanced Databases Temporal Databases Dr Theodoros Manavis
CIT 613: Relational Database Development using SQL Introduction to SQL.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Introduction to Structured Query Language (SQL)
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
Dimensional Modeling CS 543 – Data Warehousing. CS Data Warehousing (Sp ) - Asim LUMS2 From Requirements to Data Models.
A Guide to SQL, Seventh Edition. Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT.
Database table design Single table vs. multiple tables Sen Zhang.
Introduction to Structured Query Language (SQL)
Database Management: Getting Data Together Chapter 14.
Temporal Databases. Outline Spatial Databases Indexing, Query processing Temporal Databases Spatio-temporal ….
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Database Systems More SQL Database Design -- More SQL1.
Introduction to Structured Query Language (SQL)
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Adapted from Afyouni, Database Security and Auditing Database Application Auditing – Ch. 8.
SQL's Data Definition Language (DDL) – View, Sequence, Index.
Introduction –All information systems create, read, update and delete data. This data is stored in files and databases. Files are collections of similar.
Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 13 Database Management Systems: Getting Data Together.
Security, Transactions, and Views. Security Achieved through GRANT & REVOKE Assumes the database can recognize its users and verify their identity can.
Database Technical Session By: Prof. Adarsh Patel.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Natural vs. Generated Keys. Definitions Natural key—a key that occurs in the data, that uniquely identifies rows. AKA candidate key. Generated key—a key.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Introduction to Relational Databases &
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
USE OF TEMPORAL CONCEPTS IN TRANSACTIONAL DATABASES.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Triggers. Why Triggers ? Suppose a warehouse wishes to maintain a minimum inventory of each item. Number of items kept in items table Items(name, number,...)
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Distributed Database. Introduction A major motivation behind the development of database systems is the desire to integrate the operational data of an.
O FFICE M ANAGEMENT T OOL - II B BA -V I TH. Abdus Salam2 Week-7 Introduction to Query Introduction to Query Querying from Multiple Tables Querying from.
Fall 2001Database Systems1 Triggers Assertions –Assertions describe rules that should hold for a given database. –An assertion is checked anytime a table.
Advanced SQL: Triggers & Assertions
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
06 | Modifying Data in SQL Server Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
Topics Related to Attribute Values Objectives of the Lecture : To consider sorting relations by attribute values. To consider Triggers and their use for.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
Session 1 Module 1: Introduction to Data Integrity
CIT 613: Relational Database Development using SQL Introduction to SQL DeSiaMorePowered by DeSiaMore 1.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L12_JDBC_MySQL 1 Transations.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
Temporal Data Modeling
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
Databases Flat Files & Relational Databases. Learning Objectives Describe flat files and databases. Explain the advantages that using a relational database.
Oracle 10g Database Administrator: Implementation and Administration Chapter 10 Basic Data Management.
A Guide to MySQL 6. 2 Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT command.
CSCI N311: Oracle Database Programming 5-1 Chapter 15: Changing Data: insert, update, delete Insert Rollback Commit Update Delete Insert Statement –Allows.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
NormalisationNormalisation Normalization is the technique of organizing data elements into records. Normalization is the technique of organizing data elements.
CPT-S Advanced Databases 11 Yinghui Wu EME 49.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
SPECIAL PURPOSE DATABASES 13/09/ Temporal Database Concepts  Time is considered ordered sequence of points in some granularity Use the term choronon.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Katowice,
Tables and Triggers.
Chapter 6 - Database Implementation and Use
Introduction to Database Systems, CS420
SQL 101.
Traveling in time with SQL Server 2017
Temporal Databases.
Advanced SQL: Views & Triggers
Adding history to crud (Really) DINO ESPOSITO
Author: Miran Miklič Comparison and advantages of the Bitemporal and Temporal databases over Tuple-versioning (point-in-time) database.
Triggers 7/11/2019 See scm-intranet.
CS240A: Databases and Knowledge Bases A Taxonomy of Temporal DBs
Presentation transcript:

Time in Databases CSCI 6442 With thanks to Richard Snodgrass, 1985 ACM /85/005/0236

Agenda Taxonomy of time in databases Point-in-time databases 2

The Problem Suppose you are away from your company for 6 months assigned to work at an outpost in Australia, in the opal mines in Coober Pedy, underground, out of communication. You are eligible for a raise in the midst of this. When you return they notice this. Now it is approved and entered into the database within a few days, but you get the extra money from 3 months ago Which times get recorded in the database? 3

Types of Time Transaction time—time when the information was stored in the database Valid time—the time that the stored information models reality User-defined time—a time that is important to and is defined by the application 4

Static Databases A conventional database models the current state of a dynamically changing world When an update is made, the past values are forgotten completely This sort of database is called a static database It can’t tell you what Jones’s salary was two years ago or how many raises Jones has had in the past four years 5

Static Rollback Databases We can provide the capability to roll back a database to a previous state, such as by using a log The effect of recent transactions is removed, until the desired state is reached Then the intended query can be posed Past values cannot be changed; only operations on current values are permitted, because this preserves the series of past operations Transaction time must be recorded for every change, to support rollback Current operations must be suspended while rollback operations are under way 6

Historical Databases Historical databases record the history of the values of data as it is best known As errors are discovered, they are corrected by changing the database Previous states are not retained; at any time, the database reflects the best-known history of the data Time represented in historical database is valid time, the time that the stored information models 7

Temporal Databases A temporal database allows one to view tuples valid at one moment as seen from another moment Such a database completely captures the history of current and retroactive changes 8

Snodgrass Wrote “A Taxonomy of Time in Databases” (1985) Regarded as the authoritative work Defines three types of time 9

Types of Time There are three times: Transaction time—when the change is made to the database Valid time—when the change was approved User-defined time—when the raise is effective (application- specific) 10

Static Database Database that reflects changing values with a snapshot at any particular time Does not necessarily reflect the state of the real world We discard past states of the database Can’t answer questions about what past values were Can’t show trends in change over time 11

Static Rollback Database Adds some time sequence Ability to back out transactions is provided Can back out one at a time to previous states of the database Such a database shows the history of transactions rather than the history of the actual data 12

Snodgrass’s Taxonomy Is a useful way to talk about time in databases His levels of databases are theoretical, a basis for research What if we want to model current and past states of a single table in a SQL database system? 13

Point in Time Databases We can model current and former values of data in a single relational table We need to add time to the data model so that changes are captured It is possible to use a single table to capture current and former values of data in a single relation As performance limitations of databases disappear because of increasing machine power, this becomes practical In fact, this approach is used in some advanced applications However, it is not widely known 14

Point In Time Databases A single database models the present and all past states of the data as it matters to the organization Enough information about past states is stored so that the past state can be obtained using a SQL query Instead of deleting rows they are marked as no longer valid When values are updated, the old values are kept as well This was impractical in 1970 because of cost and efficiency issues Is it practical today? 15

What We Store With each change to a row, we insert a new row, instead of changing the previous row Consider EMP(EMPNO, ENAME, SAL) We add the attributes START and END EMP(EMPNO, ENAME, SAL, START, END) New attributes are start and end times for validity When we change a row, that time is the END time for validity of the previous row, START time of validity for the new row These times are usually what Snodgrass calls “user-defined” time because that’s the time that matters to the organization His “valid time” is just a date of transaction approval Transaction time is when entered into the database Let’s call this time “effective time” because it’s the time when the row’s values are effective 16

Point In Time Operations Insert: New row is added Start time is set Stop time is left null Delete: Stop time is set Update: New row added with new values, start time Old row is kept and stop time is set Read: Current values: STOP ISNULL As of values: ASOF >= START AND (ASOF < STOP OR STOP ISNULL) 17

Example: Retroactive Pay Increase Chen is given a salary increase The salary increase is approved at date t 1 The increase is effective at date t 2. However, the increase does not get entered into the database until some other time, t 3 >t 2 (called a retroactive salary increase). In this case, t 1 is an attribute of the approval process, t 2 is the start of effective time and t 3 is the transaction time. Most important to the organization is the time when Chen is getting the higher pay 18

An Example: EMP Schema Definition: EMP(EMPNO,ENAME,JOB,SAL,DEPTNO) Now we add START and STOP for validity dates: EMP(EMPNO,ENAME,JOB,SAL,DEPTNO,START,STOP) START gives the first time of validity for the values in the row STOP gives the last time of validity for the values in the row A row with no value for STOP is the current value 19

Example To find the status of EMP on 1/1/2008 SELECT * FROM EMP WHERE START = to_date( '01-JAN-2008','dd-mmm-yyyy') OR STOP ISNULL); DELETE statements will now be UPDATEs instead 20

Complexities Not every column value needs to be tracked Can simplify by not tracking some column values This is a semantic issue Change in primary key If primary key changes, hard to relate changed row to original row Potential case for use of generated key Cascading changes Other tables may change because of one change Use trigger instead of automatic foreign key update Cascading deletes Other tables may have rows deleted because of one change Use trigger instead of automatic foreign key delete 21

Capabilities These techniques allow you to implement a database that can show its state as of any time in the past This can be done while the database is actively being used and even updated by multiple processes One process can be looking at the database as of two years ago while another is doing current processing You can record retroactive changes You can implement applications to process retroactive changes 22

Bottom Line This is a practical approach that potentially simplifies data models and processing One table replaces duplication of data and completely different functions One somewhat more complex function replaces two (or more) separate functions Use can be presented a unifying interface that simplifies use of the application It’s a tradeoff—sometimes use a separate history table 23

Homework You have the opportunity to explore this You get to build a point-in-time EMP table Then you use it to give a retroactive raise And then compute how much we owe to the person with the retroactive raise 24