Webinar - MariaDB Temporal Tables: a demonstration

Federico Razzoli
Federico RazzoliVettabase Founder at Vettabase
MariaDB Temporal Tables:
A Demonstration
● Why track data changes?
● System-versioned tables
● Application-period tables
● Bitemporal tables
● A word on MindsDB
Agenda
Tracking data
changes
● Auditing
● Travel back in time
● Compare today situation with 6 months ago
● Statistics on data changes
● Find correlations
● History of an entity
● Debug
Tracking Data Changes: WHY?
● There are many ways to track data changes.
● Most commonly, they involve having a consumer that reads the
binary log and send changes to other technologies, like Kafka.
● Great for analytics, message queues, auditing.
● But the changes are:
○ Replicated asynchronously
○ Not available to the application
Tracking Data Changes
In-Database data changes tracking methods:
● Logging row versions into a table
● Logging each value change into a table
● Temporal tables
Tracking Data Changes
Advantages of Temporal Tables:
● The versioning logic is transparent
● Rotation can be automated
● Faster and more scalable
Tracking Data Changes
Temporal Tables
Overview
Existing implementations (I know about):
● Oracle 11g (2007)
● IBM Db2 (2012)
● SQL Server (2016)
● Snowflake
Temporal Tables Overview
Existing implementations (I know about):
● PostgreSQL has a temporal tables extension
● CockroachDB
● CruxDB
● HBase (kind of)
Temporal Tables Overview
● MariaDB 10.3: system-versioned tables
● MariaDB 10.4: application period tables
A table can implement both. It's called a bitemporal table.
Temporal Tables Overview
● Rows are versioned
● Every row has 2 timestamps, the start & end of that version
validity
● INSERT, UPDATE, DELETE modify those timestamps in a
transparent way
● Plain SQL SELECTs only return current data
● Using temporal syntax, we can query past data
System-Versioned
● Works best to describe events with a start and an end
● Especially when some events cannot overlap
● Timestamps are written explicitly by the application
● But UPDATE and DELETE can automagically shrink or split
periods
● Apart from this, they are regular tables that you use with normal
SQL syntax
Application-Period Tables
● Not understanding this damages projects.
● If you work for a vendor, whether you want to say it or not, feel
free to correct any mistake I might make
Temporal Tables Overview
System-Versioned
Tables
● Create a sysver table:
CREATE TABLE tbl_name (
…
valid_since TIMESTAMP(6) GENERATED ALWAYS AS ROW START
INVISIBLE,
valid_until TIMESTAMP(6) GENERATED ALWAYS AS ROW END
INVISIBLE,
PERIOD FOR SYSTEM_TIME(valid_since, valid_until)
)
WITH SYSTEM VERSIONING
;
System-Versioned Tables
Best practices:
● You could omit the column names, but then you won't be able to
use them in queries
● You can use different names, but I recommend you always use
the same names
● You could use visible columns, but most of the times you don't
want to see them
System-Versioned Tables
● An existing table can be made sysver:
ALTER TABLE tbl_name
ADD COLUMN valid_since TIMESTAMP(6) GENERATED
ALWAYS AS ROW START INVISIBLE,
ADD COLUMN valid_until TIMESTAMP(6) GENERATED
ALWAYS AS ROW END INVISIBLE,
ADD PERIOD FOR SYSTEM_TIME(valid_since,
valid_until),
ADD SYSTEM VERSIONING
;
System-Versioned Tables
Best practices:
● Making one, multiple, or even all tables sysver is not a risky
operation - but you never know
● You can do this on a new replica that is used by analysts or
programs that read historical data
● For such replicas it's usually ok not to use an LTS version
● Once you're confident enough, you can make the change on the
master
System-Versioned Tables
● In both cases (new or existing table), it's practical to create one
or more separate partitions for historical data:
ALTER TABLE tbl_name
PARTITION BY SYSTEM_TIME (
PARTITION p_history1 HISTORY,
… ,
PARTITION p_current CURRENT
)
;
System-Versioned Tables
How to delete history:
● Remove history before a point in time:
DELETE HISTORY FROM tbl_name
BEFORE SYSTEM_TIME '2020-01-01 00:00:00';
● Remove whole history:
DELETE HISTORY FROM tbl_name;
● Remove history and make the table non-sysver:
ALTER TABLE t DROP SYSTEM VERSIONING;
● Remove history and current data:
TRUNCATE TABLE tbl_name;
System-Versioned Tables
● GDPR and possibly some other regulations guarantee the
Right To Be Forgotten (RTBF)
● This means that we can't keep the whole history of columns that
contain Personal Identifiable Information (PII)
● To exclude these columns from a table history:
CREATE TABLE user (
…
email VARCHAR(100) NOT NULL WITHOUT SYSTEM VERSIONING,
…
)
WITH SYSTEM VERSIONING
;
Right To Be Forgotten
Application-Period
Tables
● Creating an Application-Period table:
CREATE OR REPLACE TABLE reservation (
uuid UUID DEFAULT UUID(),
bungalow_name VARCHAR(100) NOT NULL,
client_name VARCHAR(100) NOT NULL,
start_date DATE,
end_date DATE,
PRIMARY KEY (uuid, start_date),
PERIOD FOR reservation (start_date, end_date)
);
System-Versioned Tables
● If you don't use periods explicitly, it will be a regular table
● But you can manipulate periods with this syntax:
○ DELETE FROM <table_name>
FOR PORTION OF <period_name>
FROM <date1> TO <date2>
○ UPDATE <table_name>
FOR PORTION OF <period_name>
FROM <date1> TO <date2>
System-Versioned Tables
Bitemporal Tables
● Combine the syntaxes of sysver and application-period tables to
obtain a bitemporal table
● This table will store two separate pairs of timestamps:
○ When the row was physically inserted/deleted/updated
○ The boundaries of the represented period
System-Versioned Tables
Example:
● 2018/01/10 - Customer registers, she lives in Glasgow
● 2022/05/01 - Customer relocates to Inverness
● 2022/06/01 - Customer orders a product
● 2022/06/02 - Customer changes her address in her profile, and
correctly dates the change to 2022/05/01
Customer never received the parcel. Our temporal table allows us
to track this chronology and point out that
the customer communicated her address change too late.
System-Versioned Tables
A note of MindsDB
● If you built Temporal Tables, you have something similar to
(but slightly more complex than) a time series
● Do you know that you can query future data?
System-Versioned Tables
● MindsDB is an AI-based virtual database
● It connects to a huge range of external data sources,
including MariaDB
● It accepts SQL queries
● The results are calculated using Machine Learning algorithms
System-Versioned Tables
So, for example, if you have data about your sales in the last 2
years, you can obtain a forecast about the next 6 months
Vettabase is MindsDB partner.
We maintain their MySQL integration.
System-Versioned Tables
1 of 32

Recommended

MariaDB Temporal Tables by
MariaDB Temporal TablesMariaDB Temporal Tables
MariaDB Temporal TablesFederico Razzoli
407 views39 slides
Perfect trio : temporal tables, transparent archiving in db2 for z_os and idaa by
Perfect trio : temporal tables, transparent archiving in db2 for z_os and idaaPerfect trio : temporal tables, transparent archiving in db2 for z_os and idaa
Perfect trio : temporal tables, transparent archiving in db2 for z_os and idaaCuneyt Goksu
298 views29 slides
sql_server_2016_history_tables by
sql_server_2016_history_tablessql_server_2016_history_tables
sql_server_2016_history_tablesarthurjosemberg
266 views28 slides
Time Travelling With DB2 10 For zOS by
Time Travelling With DB2 10 For zOSTime Travelling With DB2 10 For zOS
Time Travelling With DB2 10 For zOSLaura Hood
499 views34 slides
Temporal Tables, Transparent Archiving in DB2 for z/OS and IDAA by
Temporal Tables, Transparent Archiving in DB2 for z/OS and IDAATemporal Tables, Transparent Archiving in DB2 for z/OS and IDAA
Temporal Tables, Transparent Archiving in DB2 for z/OS and IDAACuneyt Goksu
3K views39 slides
CDC patterns in Apache Kafka® by
CDC patterns in Apache Kafka®CDC patterns in Apache Kafka®
CDC patterns in Apache Kafka®confluent
715 views21 slides

More Related Content

Similar to Webinar - MariaDB Temporal Tables: a demonstration

A time Travel with temporal tables by
A time Travel with temporal tablesA time Travel with temporal tables
A time Travel with temporal tablesLeonel Abreu
187 views17 slides
Sql server 2016 new features by
Sql server 2016 new featuresSql server 2016 new features
Sql server 2016 new featuresAjeet Singh
4.2K views14 slides
Sql server 2016 new features by
Sql server 2016 new featuresSql server 2016 new features
Sql server 2016 new featuresAjeet pratap Singh
223 views14 slides
SQL Server 2016 novelties by
SQL Server 2016 noveltiesSQL Server 2016 novelties
SQL Server 2016 noveltiesMSDEVMTL
2.9K views85 slides
Time is of the essence - The Fourth Dimension in Oracle Database 12c (on Flas... by
Time is of the essence - The Fourth Dimension in Oracle Database 12c (on Flas...Time is of the essence - The Fourth Dimension in Oracle Database 12c (on Flas...
Time is of the essence - The Fourth Dimension in Oracle Database 12c (on Flas...Lucas Jellema
1.8K views50 slides
Redefining tables online without surprises by
Redefining tables online without surprisesRedefining tables online without surprises
Redefining tables online without surprisesNelson Calero
4.7K views40 slides

Similar to Webinar - MariaDB Temporal Tables: a demonstration(20)

A time Travel with temporal tables by Leonel Abreu
A time Travel with temporal tablesA time Travel with temporal tables
A time Travel with temporal tables
Leonel Abreu187 views
Sql server 2016 new features by Ajeet Singh
Sql server 2016 new featuresSql server 2016 new features
Sql server 2016 new features
Ajeet Singh4.2K views
SQL Server 2016 novelties by MSDEVMTL
SQL Server 2016 noveltiesSQL Server 2016 novelties
SQL Server 2016 novelties
MSDEVMTL2.9K views
Time is of the essence - The Fourth Dimension in Oracle Database 12c (on Flas... by Lucas Jellema
Time is of the essence - The Fourth Dimension in Oracle Database 12c (on Flas...Time is of the essence - The Fourth Dimension in Oracle Database 12c (on Flas...
Time is of the essence - The Fourth Dimension in Oracle Database 12c (on Flas...
Lucas Jellema1.8K views
Redefining tables online without surprises by Nelson Calero
Redefining tables online without surprisesRedefining tables online without surprises
Redefining tables online without surprises
Nelson Calero4.7K views
SQL Extensions to Support Streaming Data With Fabian Hueske | Current 2022 by HostedbyConfluent
SQL Extensions to Support Streaming Data With Fabian Hueske | Current 2022SQL Extensions to Support Streaming Data With Fabian Hueske | Current 2022
SQL Extensions to Support Streaming Data With Fabian Hueske | Current 2022
HostedbyConfluent361 views
Sql 2016 - What's New by dpcobb
Sql 2016 - What's NewSql 2016 - What's New
Sql 2016 - What's New
dpcobb822 views
Back to the future - Temporal Table in SQL Server 2016 by Stéphane Fréchette
Back to the future - Temporal Table in SQL Server 2016Back to the future - Temporal Table in SQL Server 2016
Back to the future - Temporal Table in SQL Server 2016
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität by MariaDB plc
MariaDB Server 10.3 - Temporale Daten und neues zur DB-KompatibilitätMariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB plc256 views
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres Open by PostgresOpen
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres OpenKeith Fiske - When PostgreSQL Can't, You Can @ Postgres Open
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres Open
PostgresOpen1.9K views
Oracle data capture c dc by Amit Sharma
Oracle data capture c dcOracle data capture c dc
Oracle data capture c dc
Amit Sharma802 views
PHP Detroit -- MySQL 8 A New Beginning (updated presentation) by Dave Stokes
PHP Detroit -- MySQL 8 A New Beginning (updated presentation)PHP Detroit -- MySQL 8 A New Beginning (updated presentation)
PHP Detroit -- MySQL 8 A New Beginning (updated presentation)
Dave Stokes294 views
MODULE 5.pptx by lathass5
MODULE 5.pptxMODULE 5.pptx
MODULE 5.pptx
lathass54 views
Why PostgreSQL for Analytics Infrastructure (DW)? by Huy Nguyen
Why PostgreSQL for Analytics Infrastructure (DW)?Why PostgreSQL for Analytics Infrastructure (DW)?
Why PostgreSQL for Analytics Infrastructure (DW)?
Huy Nguyen2.7K views
SQL Server Temporal Tables by Greg McMurray
SQL Server Temporal TablesSQL Server Temporal Tables
SQL Server Temporal Tables
Greg McMurray181 views

More from Federico Razzoli

A first look at MariaDB 11.x features and ideas on how to use them by
A first look at MariaDB 11.x features and ideas on how to use themA first look at MariaDB 11.x features and ideas on how to use them
A first look at MariaDB 11.x features and ideas on how to use themFederico Razzoli
45 views36 slides
MariaDB stored procedures and why they should be improved by
MariaDB stored procedures and why they should be improvedMariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improvedFederico Razzoli
8 views32 slides
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11 by
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11Federico Razzoli
57 views36 slides
MariaDB 10.11 key features overview for DBAs by
MariaDB 10.11 key features overview for DBAsMariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsFederico Razzoli
143 views38 slides
Recent MariaDB features to learn for a happy life by
Recent MariaDB features to learn for a happy lifeRecent MariaDB features to learn for a happy life
Recent MariaDB features to learn for a happy lifeFederico Razzoli
31 views38 slides
Advanced MariaDB features that developers love.pdf by
Advanced MariaDB features that developers love.pdfAdvanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdfFederico Razzoli
99 views38 slides

More from Federico Razzoli(18)

A first look at MariaDB 11.x features and ideas on how to use them by Federico Razzoli
A first look at MariaDB 11.x features and ideas on how to use themA first look at MariaDB 11.x features and ideas on how to use them
A first look at MariaDB 11.x features and ideas on how to use them
Federico Razzoli45 views
MariaDB stored procedures and why they should be improved by Federico Razzoli
MariaDB stored procedures and why they should be improvedMariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improved
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11 by Federico Razzoli
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11
Federico Razzoli57 views
MariaDB 10.11 key features overview for DBAs by Federico Razzoli
MariaDB 10.11 key features overview for DBAsMariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAs
Federico Razzoli143 views
Recent MariaDB features to learn for a happy life by Federico Razzoli
Recent MariaDB features to learn for a happy lifeRecent MariaDB features to learn for a happy life
Recent MariaDB features to learn for a happy life
Federico Razzoli31 views
Advanced MariaDB features that developers love.pdf by Federico Razzoli
Advanced MariaDB features that developers love.pdfAdvanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdf
Federico Razzoli99 views
Automate MariaDB Galera clusters deployments with Ansible by Federico Razzoli
Automate MariaDB Galera clusters deployments with AnsibleAutomate MariaDB Galera clusters deployments with Ansible
Automate MariaDB Galera clusters deployments with Ansible
Federico Razzoli489 views
Creating Vagrant development machines with MariaDB by Federico Razzoli
Creating Vagrant development machines with MariaDBCreating Vagrant development machines with MariaDB
Creating Vagrant development machines with MariaDB
Federico Razzoli62 views
MariaDB, MySQL and Ansible: automating database infrastructures by Federico Razzoli
MariaDB, MySQL and Ansible: automating database infrastructuresMariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructures
Federico Razzoli173 views
Playing with the CONNECT storage engine by Federico Razzoli
Playing with the CONNECT storage enginePlaying with the CONNECT storage engine
Playing with the CONNECT storage engine
Federico Razzoli126 views
Database Design most common pitfalls by Federico Razzoli
Database Design most common pitfallsDatabase Design most common pitfalls
Database Design most common pitfalls
Federico Razzoli553 views
How MySQL can boost (or kill) your application v2 by Federico Razzoli
How MySQL can boost (or kill) your application v2How MySQL can boost (or kill) your application v2
How MySQL can boost (or kill) your application v2
Federico Razzoli124 views
MySQL Transaction Isolation Levels (lightning talk) by Federico Razzoli
MySQL Transaction Isolation Levels (lightning talk)MySQL Transaction Isolation Levels (lightning talk)
MySQL Transaction Isolation Levels (lightning talk)
Federico Razzoli119 views
Cassandra sharding and consistency (lightning talk) by Federico Razzoli
Cassandra sharding and consistency (lightning talk)Cassandra sharding and consistency (lightning talk)
Cassandra sharding and consistency (lightning talk)
Federico Razzoli2.3K views
How MySQL can boost (or kill) your application by Federico Razzoli
How MySQL can boost (or kill) your applicationHow MySQL can boost (or kill) your application
How MySQL can boost (or kill) your application
Federico Razzoli341 views

Recently uploaded

SAP FOR TYRE INDUSTRY.pdf by
SAP FOR TYRE INDUSTRY.pdfSAP FOR TYRE INDUSTRY.pdf
SAP FOR TYRE INDUSTRY.pdfVirendra Rai, PMP
24 views3 slides
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... by
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Donato Onofri
795 views34 slides
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionMárton Kodok
5 views55 slides
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... by
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Marc Müller
37 views83 slides
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx by
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptxanimuscrm
14 views19 slides
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme... by
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...Deltares
5 views28 slides

Recently uploaded(20)

Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... by Donato Onofri
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Donato Onofri795 views
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok5 views
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... by Marc Müller
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Marc Müller37 views
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx by animuscrm
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
animuscrm14 views
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme... by Deltares
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
Deltares5 views
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the... by Deltares
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
Deltares6 views
Headless JS UG Presentation.pptx by Jack Spektor
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptx
Jack Spektor7 views
AI and Ml presentation .pptx by FayazAli87
AI and Ml presentation .pptxAI and Ml presentation .pptx
AI and Ml presentation .pptx
FayazAli8711 views
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports by Ra'Fat Al-Msie'deen
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsBushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... by Deltares
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
Deltares6 views
Navigating container technology for enhanced security by Niklas Saari by Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy13 views
360 graden fabriek by info33492
360 graden fabriek360 graden fabriek
360 graden fabriek
info3349237 views
SUGCON ANZ Presentation V2.1 Final.pptx by Jack Spektor
SUGCON ANZ Presentation V2.1 Final.pptxSUGCON ANZ Presentation V2.1 Final.pptx
SUGCON ANZ Presentation V2.1 Final.pptx
Jack Spektor22 views
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge... by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
Deltares17 views
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... by Deltares
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
Deltares9 views

Webinar - MariaDB Temporal Tables: a demonstration

  • 2. ● Why track data changes? ● System-versioned tables ● Application-period tables ● Bitemporal tables ● A word on MindsDB Agenda
  • 4. ● Auditing ● Travel back in time ● Compare today situation with 6 months ago ● Statistics on data changes ● Find correlations ● History of an entity ● Debug Tracking Data Changes: WHY?
  • 5. ● There are many ways to track data changes. ● Most commonly, they involve having a consumer that reads the binary log and send changes to other technologies, like Kafka. ● Great for analytics, message queues, auditing. ● But the changes are: ○ Replicated asynchronously ○ Not available to the application Tracking Data Changes
  • 6. In-Database data changes tracking methods: ● Logging row versions into a table ● Logging each value change into a table ● Temporal tables Tracking Data Changes
  • 7. Advantages of Temporal Tables: ● The versioning logic is transparent ● Rotation can be automated ● Faster and more scalable Tracking Data Changes
  • 9. Existing implementations (I know about): ● Oracle 11g (2007) ● IBM Db2 (2012) ● SQL Server (2016) ● Snowflake Temporal Tables Overview
  • 10. Existing implementations (I know about): ● PostgreSQL has a temporal tables extension ● CockroachDB ● CruxDB ● HBase (kind of) Temporal Tables Overview
  • 11. ● MariaDB 10.3: system-versioned tables ● MariaDB 10.4: application period tables A table can implement both. It's called a bitemporal table. Temporal Tables Overview
  • 12. ● Rows are versioned ● Every row has 2 timestamps, the start & end of that version validity ● INSERT, UPDATE, DELETE modify those timestamps in a transparent way ● Plain SQL SELECTs only return current data ● Using temporal syntax, we can query past data System-Versioned
  • 13. ● Works best to describe events with a start and an end ● Especially when some events cannot overlap ● Timestamps are written explicitly by the application ● But UPDATE and DELETE can automagically shrink or split periods ● Apart from this, they are regular tables that you use with normal SQL syntax Application-Period Tables
  • 14. ● Not understanding this damages projects. ● If you work for a vendor, whether you want to say it or not, feel free to correct any mistake I might make Temporal Tables Overview
  • 16. ● Create a sysver table: CREATE TABLE tbl_name ( … valid_since TIMESTAMP(6) GENERATED ALWAYS AS ROW START INVISIBLE, valid_until TIMESTAMP(6) GENERATED ALWAYS AS ROW END INVISIBLE, PERIOD FOR SYSTEM_TIME(valid_since, valid_until) ) WITH SYSTEM VERSIONING ; System-Versioned Tables
  • 17. Best practices: ● You could omit the column names, but then you won't be able to use them in queries ● You can use different names, but I recommend you always use the same names ● You could use visible columns, but most of the times you don't want to see them System-Versioned Tables
  • 18. ● An existing table can be made sysver: ALTER TABLE tbl_name ADD COLUMN valid_since TIMESTAMP(6) GENERATED ALWAYS AS ROW START INVISIBLE, ADD COLUMN valid_until TIMESTAMP(6) GENERATED ALWAYS AS ROW END INVISIBLE, ADD PERIOD FOR SYSTEM_TIME(valid_since, valid_until), ADD SYSTEM VERSIONING ; System-Versioned Tables
  • 19. Best practices: ● Making one, multiple, or even all tables sysver is not a risky operation - but you never know ● You can do this on a new replica that is used by analysts or programs that read historical data ● For such replicas it's usually ok not to use an LTS version ● Once you're confident enough, you can make the change on the master System-Versioned Tables
  • 20. ● In both cases (new or existing table), it's practical to create one or more separate partitions for historical data: ALTER TABLE tbl_name PARTITION BY SYSTEM_TIME ( PARTITION p_history1 HISTORY, … , PARTITION p_current CURRENT ) ; System-Versioned Tables
  • 21. How to delete history: ● Remove history before a point in time: DELETE HISTORY FROM tbl_name BEFORE SYSTEM_TIME '2020-01-01 00:00:00'; ● Remove whole history: DELETE HISTORY FROM tbl_name; ● Remove history and make the table non-sysver: ALTER TABLE t DROP SYSTEM VERSIONING; ● Remove history and current data: TRUNCATE TABLE tbl_name; System-Versioned Tables
  • 22. ● GDPR and possibly some other regulations guarantee the Right To Be Forgotten (RTBF) ● This means that we can't keep the whole history of columns that contain Personal Identifiable Information (PII) ● To exclude these columns from a table history: CREATE TABLE user ( … email VARCHAR(100) NOT NULL WITHOUT SYSTEM VERSIONING, … ) WITH SYSTEM VERSIONING ; Right To Be Forgotten
  • 24. ● Creating an Application-Period table: CREATE OR REPLACE TABLE reservation ( uuid UUID DEFAULT UUID(), bungalow_name VARCHAR(100) NOT NULL, client_name VARCHAR(100) NOT NULL, start_date DATE, end_date DATE, PRIMARY KEY (uuid, start_date), PERIOD FOR reservation (start_date, end_date) ); System-Versioned Tables
  • 25. ● If you don't use periods explicitly, it will be a regular table ● But you can manipulate periods with this syntax: ○ DELETE FROM <table_name> FOR PORTION OF <period_name> FROM <date1> TO <date2> ○ UPDATE <table_name> FOR PORTION OF <period_name> FROM <date1> TO <date2> System-Versioned Tables
  • 27. ● Combine the syntaxes of sysver and application-period tables to obtain a bitemporal table ● This table will store two separate pairs of timestamps: ○ When the row was physically inserted/deleted/updated ○ The boundaries of the represented period System-Versioned Tables
  • 28. Example: ● 2018/01/10 - Customer registers, she lives in Glasgow ● 2022/05/01 - Customer relocates to Inverness ● 2022/06/01 - Customer orders a product ● 2022/06/02 - Customer changes her address in her profile, and correctly dates the change to 2022/05/01 Customer never received the parcel. Our temporal table allows us to track this chronology and point out that the customer communicated her address change too late. System-Versioned Tables
  • 29. A note of MindsDB
  • 30. ● If you built Temporal Tables, you have something similar to (but slightly more complex than) a time series ● Do you know that you can query future data? System-Versioned Tables
  • 31. ● MindsDB is an AI-based virtual database ● It connects to a huge range of external data sources, including MariaDB ● It accepts SQL queries ● The results are calculated using Machine Learning algorithms System-Versioned Tables
  • 32. So, for example, if you have data about your sales in the last 2 years, you can obtain a forecast about the next 6 months Vettabase is MindsDB partner. We maintain their MySQL integration. System-Versioned Tables