Temporal

2,424 views

Published on

this is just a test slide

Published in: Technology, Economy & Finance
1 Comment
0 Likes
Statistics
Notes
  • nice presentation
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Views
Total views
2,424
On SlideShare
0
From Embeds
0
Number of Embeds
31
Actions
Shares
0
Downloads
164
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Temporal

  1. 1. Temporal Databases (Managing time varying data) Rob Squire - UK Consulting
  2. 2. Temporal Databases Am I a good guy or a bad guy?
  3. 3. Temporal Databases <ul><li>Interval Data Type ( Timestamps ) </li></ul><ul><li>6NF (horizontal and vertical decomposition aka TNF ) </li></ul><ul><li>Pack/UnPack (Collapsed form) </li></ul><ul><li>No ‘special’ attributes </li></ul><ul><li>SQL with no extensions </li></ul>
  4. 4. Temporal Databases <ul><li>What are temporal databases? </li></ul><ul><li>What is time varying data ? </li></ul><ul><li>Implementation Approaches </li></ul><ul><li>Why now? </li></ul><ul><li>Demonstration </li></ul><ul><li>Questions and Answers </li></ul>
  5. 5. Temporal Databases <ul><li>What are temporal databases? </li></ul><ul><li>What is time varying data ? </li></ul><ul><li>Implementation Approaches </li></ul><ul><li>Why now? </li></ul><ul><li>Demonstration </li></ul><ul><li>Questions and Answers </li></ul>
  6. 6. What are temporal databases? <ul><li>Non Temporal </li></ul><ul><ul><li>store only a single state of the real world, usually the most recent state </li></ul></ul><ul><ul><li>classified as snapshot databases </li></ul></ul><ul><ul><li>application developers and database designers need to code for time varying data requirements eg history tables, forecast reports etc </li></ul></ul>
  7. 7. What are temporal databases? <ul><li>Temporal </li></ul><ul><ul><li>stores upto two dimensions of time i.e VALID (stated) time and TRANSACTION (logged) time </li></ul></ul><ul><ul><li>Classified as historical , rollback or bi-temporal </li></ul></ul><ul><ul><li>No need for application developers or database designers to code for time varying data requirements i.e time is inherently supported </li></ul></ul>
  8. 8. What are temporal databases? Valid (stated) Time Transaction (logged) Time The 2 dimensions of time
  9. 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. 10. What are temporal databases? The moving point ‘now’ Valid (stated) Time Transaction (logged) Time
  11. 11. What are temporal databases? <ul><li>We can use these two dimensions to distinguish between different forms of temporal database </li></ul><ul><li>A rollback database stores data with respect to transaction time e.g. Oracle 10g has flashback query </li></ul><ul><li>A historical database stores data with respect to valid time </li></ul><ul><li>A bi-temporal database stores data with respect to both valid time and transaction time. </li></ul>
  12. 12. Temporal Databases <ul><li>What are temporal databases? </li></ul><ul><li>What is time varying data ? </li></ul><ul><li>Implementation Approaches </li></ul><ul><li>Why now? </li></ul><ul><li>Demonstration </li></ul><ul><li>Questions and Answers </li></ul>
  13. 13. What is time varying data? <ul><li>You want a reprint of a customer's invoice of August 12, 1999. </li></ul><ul><li>What was the stock value of the Oracle shares on June 15th, last year? </li></ul><ul><li>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? </li></ul><ul><li>Where do you enter the new address of this customer as from the first of next month? </li></ul><ul><li>What will your profits be next month, given the price list and cost prices by then? </li></ul>
  14. 14. What is time varying data? <ul><li>And combinations of the situations can be very complex </li></ul><ul><li>  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? </li></ul><ul><li>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? </li></ul>
  15. 15. What is time varying data? <ul><li>Examples of application domains dealing with time varying data: </li></ul><ul><li>Financial Apps (e.g. history of stock market data) </li></ul><ul><li>Insurance Apps (e.g. when were the policies in effect) </li></ul><ul><li>Reservation Systems (e.g. when is which room in a hotel booked) </li></ul><ul><li>Medical Information Management Systems (e.g. patient records) </li></ul><ul><li>Decision Support Systems (e.g. planning future contigencies) </li></ul><ul><li>CRM applications (eg customer history / future) </li></ul><ul><li>HR applications (e.g Date tracked positions in hierarchies) </li></ul>
  16. 16. What is time varying data? <ul><li>In fact, time varying data has ALWAYS been in business requirements – but existing technology does not deal with it elegantly! </li></ul>
  17. 17. What is time varying data? <ul><li>Ask yourself two questions </li></ul><ul><li>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)? </li></ul><ul><li>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)? </li></ul>
  18. 18. What is time varying data? <ul><li>If you answer &quot; Yes &quot; on one or both of these questions then your data varies over time and you could consider adopting a temporal approach </li></ul>
  19. 19. Temporal Databases <ul><li>What are temporal databases? </li></ul><ul><li>What is time varying data ? </li></ul><ul><li>Implementation Approaches </li></ul><ul><li>Why now? </li></ul><ul><li>Demonstration </li></ul><ul><li>Questions and Answers </li></ul>
  20. 20. Implementation Approaches <ul><li>Several implementation strategies are available </li></ul><ul><li>Use a date type supplied in a non-temporal DBMS and build temporal support into applications ( traditional ) </li></ul><ul><li>Implement an abstract data type for time ( object oriented ) </li></ul><ul><li>Provide a program layer (api) above a non-temporal data model ( stratum ) </li></ul>
  21. 21. Implementation Approaches <ul><li>Generalise a non-temporal data model into a temporal data model ( Temporal Normal Form ) </li></ul><ul><li>Re-design core database kernel ( Temporal Database ) </li></ul>
  22. 22. Implementation Approaches <ul><li>Q: Why don’t temporal databases already exist? </li></ul><ul><li>A: Dealing with time-varying data is complex </li></ul>
  23. 23. Implementation Approaches <ul><li>For example: </li></ul><ul><li>Avoiding duplicates requires complex logic. </li></ul><ul><li>Avoiding gaps in a time-varying data requires complex logic. </li></ul><ul><li>A simple join when applied to time-varying data turns into many lines of code consisting of multiple FROM and WHERE clauses. </li></ul><ul><li>A simple update translates into several modification statements requiring many lines of code. </li></ul>
  24. 24. Temporal Databases <ul><li>What are temporal databases? </li></ul><ul><li>What is time varying data ? </li></ul><ul><li>Implementation Approaches </li></ul><ul><li>Why now? </li></ul><ul><li>Demonstration </li></ul><ul><li>Questions and Answers </li></ul>
  25. 25. Why now? <ul><li>Plummeting cost of storage </li></ul><ul><li>Widespread adoption of warehouse technology has led to an i ncreasing interest in temporal databases </li></ul><ul><li>The idea of maintaining and processing historical data has become not just a goal but a reality for many organisations </li></ul>
  26. 26. Why now? <ul><li>DW vendors are themselves faced with temporal problems (slowly changing time dimension) and have begun to feel the need for a new solution </li></ul><ul><li>DB Vendors considering adding temporal support to existing product ( Oracle flashback query ) and applications ( Oracle HR date tracking/payroll ) </li></ul><ul><li>SQL bodies are beginning to think about adding syntax to the standard to support temporal features ( SQL3 , TSQL ) </li></ul>
  27. 27. Temporal Databases <ul><li>What are temporal databases? </li></ul><ul><li>What is time varying data ? </li></ul><ul><li>Implementation Approaches </li></ul><ul><li>Why now? </li></ul><ul><li>Demonstration </li></ul><ul><li>Questions and Answers </li></ul>
  28. 28. Demonstration <ul><li>Temporal Normal Form (approach 4) </li></ul><ul><li>Generate TNF for supplier, supplier part schema </li></ul><ul><li>Show select, insert, update and delete operations </li></ul><ul><li>Show Referential Integrity </li></ul><ul><li>With a Temporal Data Dictionary </li></ul><ul><li>Using simple standard SQL with no extensions </li></ul>
  29. 29. Demonstration Fix Valid Time Now SUPPLIER
  30. 30. Demonstration Fix Valid Time Timestamp or Now + 2 days SUPPLIER
  31. 31. Demonstration SUPPLIER Fix Transaction Time Now
  32. 32. Demonstration SUPPLIER Fix Transaction Time Timestamp or Now - 2 days
  33. 33. Demonstration Fix Transaction and Valid Time SUPPLIER
  34. 34. Demonstration Demo 01 Generating, populating and querying TNF
  35. 35. Demonstration SUPPLIER 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. 36. Demonstration SUPPLIER SUPPLIER PART Non Temporal Schema (SP) TNF Temporal Schema (TSP) SUPPLIER SUPPLIER PART Generate
  37. 37. Demonstration Record Timestamp 1 03-NOV-05 15.45.23.125990000
  38. 38. Demonstration SUPPLIER SUPPLIER PART Non Temporal Schema (SP) TNF Temporal Schema (TSP) SUPPLIER SUPPLIER PART Populate Insert as Select * from
  39. 39. DEMO 1 t0(now) Transaction time = now
  40. 40. DEMO 1 t1(now) S1 S2 S4 S3 S5 Transaction time = now
  41. 41. Demonstration Fix Valid Time timestamp1 SUPPLIER
  42. 42. DEMO 1 t2(timestamp1) S1 S2 S4 S3 S5 Transaction time = now
  43. 43. Demonstration Un Fix Valid Time SUPPLIER Now
  44. 44. DEMO 1 t3 (now) S1 S2 S4 S3 S5 Transaction time = now
  45. 45. Demonstration Fix Valid Time Now + 2 days SUPPLIER
  46. 46. DEMO 1 t4 (now+2days) S1 S2 S4 S3 S5 Transaction time = now
  47. 47. DEMO 1 delete S1 S2 S4 S3 S5 Transaction time = now
  48. 48. Demonstration Un Fix Valid Time SUPPLIER Now
  49. 49. DEMO 1 t5 (now) S1 S2 S4 S3 S5 Transaction time = now
  50. 50. DEMO 1 S1 S2 S4 S3 S5 eovt Transaction time = now
  51. 51. DEMO 1 t6 (now) S1 S2 S4 S3 S5 Transaction time = now
  52. 52. Demonstration Record Timestamp 2 03-NOV-05 15.57.04.334588000
  53. 53. Demonstration Fix Valid Time Now + 30 seconds SUPPLIER
  54. 54. DEMO 1 t7(now+30 seconds) S2 S4 S3 S5 S1 Transaction time = now
  55. 55. DEMO 1 delete S1 S2 S4 S3 S5 Transaction time = now
  56. 56. Demonstration Un Fix Valid Time SUPPLIER Now
  57. 57. DEMO 1 t8(now) S1 S2 S4 S3 S5 Transaction time = now
  58. 58. DEMO 1 t9(now) S1 S2 S4 S3 S5 Transaction time = now
  59. 59. Demonstration Demo 02 Fixing transaction time
  60. 60. DEMO 2 t10(now) S1 S2 S4 S3 S5 33 Transaction time = now
  61. 61. DEMO 2 t11(now) S1 S2 S4 S3 S5 45 Transaction time = now
  62. 62. DEMO 2 t12(now) S1 S2 S4 S3 S5 65 Transaction time = now
  63. 63. Demonstration SUPPLIER Fix Transaction Time Timestamp 2
  64. 64. DEMO 2 S2 S4 S3 S5 S1 171000 t13(now) Transaction time < t7
  65. 65. DEMO 2 S2 S4 S3 S5 S1 170900 t14(now) Transaction time < t7
  66. 66. DEMO 2 S2 S4 S3 S5 S1 170800 t15(now) Transaction time < t7
  67. 67. DEMO 2 S2 S4 S3 S5 S1 Lifetime >2 days Transaction time < t7
  68. 68. Demonstration SUPPLIER UnFix Transaction Time Now
  69. 69. DEMO 2 S2 S4 S3 S5 S1 Lifetime 1 hour Transaction time = now t16(now)
  70. 70. Demonstration Demo 03 (part1) DML not allowed when transaction time is fixed
  71. 71. Demonstration Fix Transaction Time Current Timestamp SUPPLIER
  72. 72. DEMO 3 t17(now) Transaction time <> now ORA-20001: S: Cannot insert while system Y time is set.
  73. 73. Demonstration SUPPLIER UnFix Transaction Time Now
  74. 74. Demonstration Demo 03 (part 2) Updating in TNF
  75. 75. Demonstration Fix Valid Time Now – 10 days SUPPLIER
  76. 76. DEMO 3 t18(now-10days) London Paris London Paris Athens Transaction time = now
  77. 77. Demonstration Fix Valid Time Now – 8 days SUPPLIER
  78. 78. DEMO 3 t19(now-8days) London Lyons London Athens Transaction time = now Paris Paris Lyons
  79. 79. Demonstration Fix Valid Time Now – 6 days SUPPLIER
  80. 80. DEMO 3 t20(now-6days) London Lyons London Corinth Transaction time = now Paris Paris Lyons Athens
  81. 81. Demonstration Fix Valid Time Now – 4 days SUPPLIER
  82. 82. DEMO 3 t21(now-4days) Lyons Manchester Corinth Transaction time = now Paris Paris Lyons Athens London London Manchester
  83. 83. Demonstration Un Fix Valid Time SUPPLIER Now
  84. 84. DEMO 3 t22(now) Lyons Manchester Corinth Transaction time = now Paris Paris Lyons Athens London London Manchester
  85. 85. DEMO 3 Lyons Manchester Corinth Transaction time = now Paris Paris Lyons Athens London London Manchester t18 t19 t20 t21
  86. 86. Demonstration Demo 04 (part1) Maintaining Referential Integrity
  87. 87. Demonstration Un Fix Valid Time SUPPLIER Now
  88. 88. DEMO 4 S Transaction time = now SP ORA-20001: :Integrity Constraint violated – parent key not found (showing one S relvar) t23(now)
  89. 89. DEMO 4 S Transaction time = now SP (showing one S relvar) t23(now)
  90. 90. DEMO 4 S Transaction time = now SP (showing one S relvar) t23(now)
  91. 91. Demonstration Demo 04 (part2) Foreign Key Rules for TNF
  92. 92. Demonstration Fix Valid Time Now – 10 days SUPPLIER
  93. 93. DEMO 4 S1 Transaction time = now (showing one S relvar) t24(now-10days)
  94. 94. Demonstration Un Fix Valid Time SUPPLIER Now
  95. 95. DEMO 4 S1 Transaction time = now (showing one S relvar) t25(now)
  96. 96. Demonstration Fix Valid Time Now – 5 days SUPPLIER
  97. 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. 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. 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. 100. Demonstration Un Fix Valid Time SUPPLIER Now
  101. 101. DEMO 4 S1 Transaction time = now (showing one S relvar) t27(now) S1,P1
  102. 102. Demonstration Demo 05 A more complex example
  103. 103. Demonstration SUPPLIER UnFix Transaction Time Now
  104. 104. Demonstration Fix Valid Time Now – 100 days SUPPLIER
  105. 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. 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 S1 S3 S2
  107. 107. DEMO 5 Transaction 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 S1 S1 S2 S2 S3 S3
  108. 108. Demonstration Demo 06 (part1) The classic Employee Department schema example
  109. 109. Demonstration Un Fix Valid Time SUPPLIER Now
  110. 110. Demonstration SUPPLIER UnFix Transaction Time Now
  111. 111. DEMO 6 Dept 10, Sales, New York Transaction time = now (showing Dept relvar) t28(now)
  112. 112. DEMO 6 Dept 10, Sales, New York Transaction time = now (showing Dept relvars) Dept 20, Finance, New York t29(now)
  113. 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. 114. Demonstration Fix Valid Time Now + 20 days SUPPLIER
  115. 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. 116. Demonstration Un Fix Valid Time SUPPLIER Now
  117. 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. 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. 119. Demonstration Demo 06 (part2) Non Transferable foreign keys
  120. 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. 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. 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. 123. Demonstration <ul><li>You have just seen </li></ul><ul><li>A practical implementation of TNF </li></ul><ul><li>Using Standard SQL </li></ul><ul><li>Where existing data modelling techniques for current view apply </li></ul><ul><li>Providing bi temporal support </li></ul><ul><li>Can underpin any application development platform (forms, java, html etc) </li></ul>
  124. 124. Demonstration <ul><li>Next Steps </li></ul><ul><li>Gather feedback and responses on TNF from Oracle user organisations </li></ul><ul><li>Contact Oracle Expert Services </li></ul><ul><ul><li>0870 550 3060 </li></ul></ul><ul><ul><li>expertservices _ uk @oracle.com </li></ul></ul><ul><ul><li>www.oracle.com/uk/expert_services </li></ul></ul>
  125. 125. A Q & Q U E S T I O N S A N S W E R S Rob Squire UK Consulting [email_address]

×