Presentation is loading. Please wait.

Presentation is loading. Please wait.

Temporal Databases (Managing time varying data) Rob Squire - UK Consulting.

Similar presentations


Presentation on theme: "Temporal Databases (Managing time varying data) Rob Squire - UK Consulting."— Presentation transcript:

1 Temporal Databases (Managing time varying data) Rob Squire - UK Consulting

2 Temporal Databases Am I a good guy or a bad guy?

3 Temporal Databases Interval Data Type (Timestamps) 6NF (horizontal and vertical decomposition aka TNF) Pack/UnPack (Collapsed form) No special attributes SQL with no extensions

4 Temporal Databases What are temporal databases? What is time varying data? Implementation Approaches Why now? Demonstration Questions and Answers

5 Temporal Databases What are temporal databases? What is time varying data? Implementation Approaches Why now? Demonstration Questions and Answers

6 What are temporal databases? Non Temporal – store only a single state of the real world, usually the most recent state – classified as snapshot databases – application developers and database designers need to code for time varying data requirements eg history tables, forecast reports etc

7 What are temporal databases? Temporal – stores upto two dimensions of time i.e VALID (stated) time and TRANSACTION (logged) time – Classified as historical, rollback or bi-temporal – No need for application developers or database designers to code for time varying data requirements i.e time is inherently supported

8 What are temporal databases? Valid (stated) Time Transaction (logged) Time The 2 dimensions of time

9 What are temporal databases? Valid (stated) Time Transaction (logged) Time Granularity of the time axis Chronons can be days, Seconds, milliseconds depending on the application domain

10 What are temporal databases? The moving point now Valid (stated) Time Transaction (logged) Time

11 What are temporal databases? We can use these two dimensions to distinguish between different forms of temporal database A rollback database stores data with respect to transaction time e.g. Oracle 10g has flashback query A historical database stores data with respect to valid time A bi-temporal database stores data with respect to both valid time and transaction time.

12 Temporal Databases What are temporal databases? What is time varying data? Implementation Approaches Why now? Demonstration Questions and Answers

13 What is time varying data? You want a reprint of a customer's invoice of August 12, What was the stock value of the Oracle shares on June 15th, last year? What was the lowest stock quantity for every product last year? How much money will you save, if you keep the stocks at those levels? Where do you enter the new address of this customer as from the first of next month? What will your profits be next month, given the price list and cost prices by then?

14 What is time varying data? And combinations of the situations can be very complex You offered these goods to the customer on January 10 this year. What were the billing prices and what was his discount level when you sent him this offer? He has not accepted yet. Is it smart to offer him an actualized discount now? Given the final settlements for all the insurance claims of the last three years, what will be the minimum insurance premium your customers have to pay next year?

15 What is time varying data? Examples of application domains dealing with time varying data: Financial Apps (e.g. history of stock market data) Insurance Apps (e.g. when were the policies in effect) Reservation Systems (e.g. when is which room in a hotel booked) Medical Information Management Systems (e.g. patient records) Decision Support Systems (e.g. planning future contigencies) CRM applications (eg customer history / future) HR applications (e.g Date tracked positions in hierarchies)

16 What is time varying data? In fact, time varying data has ALWAYS been in business requirements – but existing technology does not deal with it elegantly!

17 What is time varying data? Ask yourself two questions Does your business need to know the situation as it was known at a particular date (e.g. the reprint of the customer's invoice)? Does your business use information that was effective in the past or will become effective in the future (e.g. the new address of the customer)?

18 What is time varying data? If you answer "Yes" on one or both of these questions then your data varies over time and you could consider adopting a temporal approach

19 Temporal Databases What are temporal databases? What is time varying data? Implementation Approaches Why now? Demonstration Questions and Answers

20 Implementation Approaches Several implementation strategies are available Use a date type supplied in a non-temporal DBMS and build temporal support into applications (traditional) Implement an abstract data type for time (object oriented) Provide a program layer (api) above a non- temporal data model (stratum)

21 Implementation Approaches Generalise a non-temporal data model into a temporal data model (Temporal Normal Form) Re-design core database kernel (Temporal Database)

22 Implementation Approaches Q: Why dont temporal databases already exist? A: Dealing with time-varying data is complex

23 Implementation Approaches For example: Avoiding duplicates requires complex logic. Avoiding gaps in a time-varying data requires complex logic. A simple join when applied to time-varying data turns into many lines of code consisting of multiple FROM and WHERE clauses. A simple update translates into several modification statements requiring many lines of code.

24 Temporal Databases What are temporal databases? What is time varying data? Implementation Approaches Why now? Demonstration Questions and Answers

25 Why now? Plummeting cost of storage Widespread adoption of warehouse technology has led to an increasing interest in temporal databases The idea of maintaining and processing historical data has become not just a goal but a reality for many organisations

26 Why now? DW vendors are themselves faced with temporal problems (slowly changing time dimension) and have begun to feel the need for a new solution DB Vendors considering adding temporal support to existing product (Oracle flashback query) and applications (Oracle HR date tracking/payroll) SQL bodies are beginning to think about adding syntax to the standard to support temporal features (SQL3, TSQL)

27 Temporal Databases What are temporal databases? What is time varying data? Implementation Approaches Why now? Demonstration Questions and Answers

28 Demonstration Temporal Normal Form (approach 4) Generate TNF for supplier, supplier part schema Show select, insert, update and delete operations Show Referential Integrity With a Temporal Data Dictionary Using simple standard SQL with no extensions

29 Demonstration SUPPLIER Fix Valid Time Now

30 Demonstration SUPPLIER Fix Valid Time Timestamp or Now + 2 days

31 Demonstration SUPPLIER Fix Transaction Time Now

32 Demonstration SUPPLIER Fix Transaction Time Timestamp or Now - 2 days

33 Demonstration Fix Transaction and Valid Time SUPPLIER

34 Demonstration Demo 01 Generating, populating and querying TNF

35 Demonstration SUPPLIER PART Non Temporal Schema (SP)TNF Temporal Schema (TSP) Example schema taken from Temporal Data and the Relational Model by CJ Date, H Darwin, NA Lorentzos (2003)

36 Demonstration SUPPLIER PART Non Temporal Schema (SP)TNF Temporal Schema (TSP) SUPPLIER PART Generate

37 Demonstration Record Timestamp 1 03-NOV

38 Demonstration SUPPLIER PART Non Temporal Schema (SP)TNF Temporal Schema (TSP) SUPPLIER PART Populate Insert as Select * from

39 DEMO 1 t0(now) Transaction time = now

40 DEMO 1 t1(now) S1 S2 S4 S3 S5 Transaction time = now

41 Demonstration SUPPLIER Fix Valid Time timestamp1

42 DEMO 1 t2(timestamp1) S1 S2 S4 S3 S5 Transaction time = now

43 Demonstration Un Fix Valid Time SUPPLIER Now

44 DEMO 1 t3 (now) S1 S2 S4 S3 S5 Transaction time = now

45 Demonstration SUPPLIER Fix Valid Time Now + 2 days

46 DEMO 1 t4 (now+2days) S1 S2 S4 S3 S5 Transaction time = now

47 DEMO 1 delete S1 S2 S4 S3 S5 Transaction time = now

48 Demonstration Un Fix Valid Time SUPPLIER Now

49 DEMO 1 t5 (now) S1 S2 S4 S3 S5 Transaction time = now

50 DEMO 1 S1 S2 S4 S3 S5 eovt Transaction time = now

51 DEMO 1 t6 (now) S1 S2 S4 S3 S5 Transaction time = now

52 Demonstration Record Timestamp 2 03-NOV

53 Demonstration SUPPLIER Fix Valid Time Now + 30 seconds

54 DEMO 1 t7(now+30 seconds) S2 S4 S3 S5 S1 Transaction time = now

55 DEMO 1 delete S1 S2 S4 S3 S5 Transaction time = now

56 Demonstration Un Fix Valid Time SUPPLIER Now

57 DEMO 1 t8(now) S1 S2 S4 S3 S5 Transaction time = now

58 DEMO 1 t9(now) S1 S2 S4 S3 S5 Transaction time = now

59 Demonstration Demo 02 Fixing transaction time

60 DEMO 2 t10(now) S1 S2 S4 S3 S5 33 Transaction time = now

61 DEMO 2 t11(now) S1 S2 S4 S3 S5 45 Transaction time = now

62 DEMO 2 t12(now) S1 S2 S4 S3 S5 65 Transaction time = now

63 Demonstration SUPPLIER Fix Transaction Time Timestamp 2

64 DEMO 2 S2 S4 S3 S5 S t13(now) Transaction time < t7

65 DEMO 2 S2 S4 S3 S5 S t14(now) Transaction time < t7

66 DEMO 2 S2 S4 S3 S5 S t15(now) Transaction time < t7

67 DEMO 2 S2 S4 S3 S5 S1 Lifetime >2 days Transaction time < t7

68 Demonstration SUPPLIER UnFix Transaction Time Now

69 DEMO 2 S2 S4 S3 S5 S1 Lifetime 1 hour Transaction time = now t16(now)

70 Demonstration Demo 03 (part1) DML not allowed when transaction time is fixed

71 Demonstration SUPPLIER Fix Transaction Time Current Timestamp

72 DEMO 3 t17(now) Transaction time <> now ORA-20001: S: Cannot insert while system Y time is set.

73 Demonstration SUPPLIER UnFix Transaction Time Now

74 Demonstration Demo 03 (part 2) Updating in TNF

75 Demonstration SUPPLIER Fix Valid Time Now – 10 days

76 DEMO 3 t18(now-10days) London Paris London Paris Athens Transaction time = now

77 Demonstration SUPPLIER Fix Valid Time Now – 8 days

78 DEMO 3 t19(now-8days) London Lyons London Athens Transaction time = now Paris Lyons

79 Demonstration SUPPLIER Fix Valid Time Now – 6 days

80 DEMO 3 t20(now-6days) London Lyons London Corinth Transaction time = now Paris Lyons Athens

81 Demonstration SUPPLIER Fix Valid Time Now – 4 days

82 DEMO 3 t21(now-4days) Lyons Manchester Corinth Transaction time = now Paris Lyons Athens London Manchester

83 Demonstration Un Fix Valid Time SUPPLIER Now

84 DEMO 3 t22(now) Lyons Manchester Corinth Transaction time = now Paris Lyons Athens London Manchester

85 DEMO 3 Lyons Manchester Corinth Transaction time = now Paris Lyons Athens London Manchester t18t19t20t21

86 Demonstration Demo 04 (part1) Maintaining Referential Integrity

87 Demonstration Un Fix Valid Time SUPPLIER Now

88 DEMO 4 S Transaction time = now SP ORA-20001: :Integrity Constraint violated – parent key not found (showing one S relvar) t23(now)

89 DEMO 4 S Transaction time = now SP (showing one S relvar) t23(now)

90 DEMO 4 S Transaction time = now SP (showing one S relvar) t23(now)

91 Demonstration Demo 04 (part2) Foreign Key Rules for TNF

92 Demonstration SUPPLIER Fix Valid Time Now – 10 days

93 DEMO 4 S1 Transaction time = now(showing one S relvar) t24(now-10days)

94 Demonstration Un Fix Valid Time SUPPLIER Now

95 DEMO 4 S1 Transaction time = now(showing one S relvar) t25(now)

96 Demonstration SUPPLIER Fix Valid Time Now – 5 days

97 DEMO 4 S1 Transaction time = now(showing one S relvar) t26(now-5days) ORA-20001: :Integrity Constraint violated – parent key not found S1,P1

98 DEMO 4 S1 Transaction time = now(showing one S relvar) t26(now-5days) Delete rule on foreign key constraint SP_S_FK is RESTRICT S1,P1 delete restrict

99 DEMO 4 S1 Transaction time = now(showing one S relvar) t26(now-5days) Delete rule on foreign key constraint SP_S_FK is CASCADE S1,P1 delete cascade

100 Demonstration Un Fix Valid Time SUPPLIER Now

101 DEMO 4 S1 Transaction time = now(showing one S relvar) t27(now) S1,P1

102 Demonstration Demo 05 A more complex example

103 Demonstration SUPPLIER UnFix Transaction Time Now

104 Demonstration SUPPLIER Fix Valid Time Now – 100 days

105 DEMO 5 S1,P2 Transaction time = now(showing all SP relvars) S1,P3 S2,P4 S2,P5 S2,P6 S3,P1 S3,P3 S3,P6 S1,P4 S1,P5 S1,P1

106 DEMO 5 S1,P2 Transaction time = now(showing all SP relvars) S1,P3 S2,P4 S2,P5 S2,P6 S3,P1 S3,P3 S3,P6 S1,P4 S1,P5 S1,P1 QUERY A – Page 74 List of dates each supplier was able to supply at least one part S1 S3 S2

107 DEMO 5Transaction time = now(showing all SP relvars) S2,P4 S2,P5 S2,P6 S3,P1 S3,P3 S3,P6 S1,P4 S1,P5 QUERY B – Page 75 List of dates each supplier was unable to supply at least one part S1,P2 S1,P3 S1,P1 S1 S2 S3

108 Demonstration Demo 06 (part1) The classic Employee Department schema example

109 Demonstration Un Fix Valid Time SUPPLIER Now

110 Demonstration SUPPLIER UnFix Transaction Time Now

111 DEMO 6 Dept 10, Sales, New York Transaction time = now(showing Dept relvar) t28(now)

112 DEMO 6 Dept 10, Sales, New York Transaction time = now(showing Dept relvars) Dept 20, Finance, New York t29(now)

113 DEMO 6 Dept 10, Sales, New York Transaction time = now(showing Dept/Emp relvars) Dept 20, Finance, New York t30(now) Emp 1, John, Clerk,…,Dept 10

114 Demonstration SUPPLIER Fix Valid Time Now + 20 days

115 DEMO 6 Dept 10, Sales, New York Transaction time = now Dept 20, Finance, New York t31(now+20) Emp 1, John, Clerk,…,Dept 10 (showing Dept/Emp relvars)

116 Demonstration Un Fix Valid Time SUPPLIER Now

117 DEMO 6 Dept 10, Sales, New York Transaction time = now Dept 20, Finance, New York t32(now) Emp 1, John, Clerk,…,Dept 10 ORA-20001: :Integrity Constraint violated – parent key not found delete restrict (showing Dept/Emp relvars)

118 DEMO 6 Dept 10, Sales, New York Transaction time = now Dept 20, Finance, New York t33(now) Emp 1, John, Clerk,…,Dept 20 delete cascade (showing Dept/Emp relvars)

119 Demonstration Demo 06 (part2) Non Transferable foreign keys

120 DEMO 6 Dept 10, Sales, New York Transaction time = now Dept 20, Finance, New York t33(now) Emp 1, John, Clerk,…,Dept 20 transferable (showing Dept/Emp relvars)

121 DEMO 6 Dept 10, Sales, New York Transaction time = now Dept 20, Finance, New York t34(now) Emp 1, John, Clerk,…,Dept 20 Non transferable ORA-20001: :Illegal attempt to modify non- transferable foreign key. (showing Dept/Emp relvars)

122 DEMO 6 Dept 10, Sales, New York Transaction time = now Dept 20, Finance, New York t34(now) Emp 1, John, Clerk,…,Dept 20 Non transferable (showing Dept/Emp relvars)

123 Demonstration You have just seen A practical implementation of TNF Using Standard SQL Where existing data modelling techniques for current view apply Providing bi temporal support Can underpin any application development platform (forms, java, html etc)

124 Demonstration Next Steps Gather feedback and responses on TNF from Oracle user organisations Contact Oracle Expert Services

125 A Q & Q U E S T I O N S A N S W E R S Rob Squire UK Consulting


Download ppt "Temporal Databases (Managing time varying data) Rob Squire - UK Consulting."

Similar presentations


Ads by Google