Webinar - MariaDB Temporal Tables: a demonstration

Federico Razzoli
Federico RazzoliVettabase Founder em 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 de 32

Recomendados

MariaDB Temporal Tables por
MariaDB Temporal TablesMariaDB Temporal Tables
MariaDB Temporal TablesFederico Razzoli
408 visualizações39 slides
Perfect trio : temporal tables, transparent archiving in db2 for z_os and idaa por
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 visualizações29 slides
sql_server_2016_history_tables por
sql_server_2016_history_tablessql_server_2016_history_tables
sql_server_2016_history_tablesarthurjosemberg
266 visualizações28 slides
Time Travelling With DB2 10 For zOS por
Time Travelling With DB2 10 For zOSTime Travelling With DB2 10 For zOS
Time Travelling With DB2 10 For zOSLaura Hood
499 visualizações34 slides
Temporal Tables, Transparent Archiving in DB2 for z/OS and IDAA por
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 visualizações39 slides
CDC patterns in Apache Kafka® por
CDC patterns in Apache Kafka®CDC patterns in Apache Kafka®
CDC patterns in Apache Kafka®confluent
715 visualizações21 slides

Mais conteúdo relacionado

Similar a Webinar - MariaDB Temporal Tables: a demonstration

A time Travel with temporal tables por
A time Travel with temporal tablesA time Travel with temporal tables
A time Travel with temporal tablesLeonel Abreu
187 visualizações17 slides
Sql server 2016 new features por
Sql server 2016 new featuresSql server 2016 new features
Sql server 2016 new featuresAjeet Singh
4.2K visualizações14 slides
Sql server 2016 new features por
Sql server 2016 new featuresSql server 2016 new features
Sql server 2016 new featuresAjeet pratap Singh
223 visualizações14 slides
SQL Server 2016 novelties por
SQL Server 2016 noveltiesSQL Server 2016 novelties
SQL Server 2016 noveltiesMSDEVMTL
2.9K visualizações85 slides
Time is of the essence - The Fourth Dimension in Oracle Database 12c (on Flas... por
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 visualizações50 slides
Redefining tables online without surprises por
Redefining tables online without surprisesRedefining tables online without surprises
Redefining tables online without surprisesNelson Calero
4.7K visualizações40 slides

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

A time Travel with temporal tables por Leonel Abreu
A time Travel with temporal tablesA time Travel with temporal tables
A time Travel with temporal tables
Leonel Abreu187 visualizações
Sql server 2016 new features por Ajeet Singh
Sql server 2016 new featuresSql server 2016 new features
Sql server 2016 new features
Ajeet Singh4.2K visualizações
Sql server 2016 new features por Ajeet pratap Singh
Sql server 2016 new featuresSql server 2016 new features
Sql server 2016 new features
Ajeet pratap Singh223 visualizações
SQL Server 2016 novelties por MSDEVMTL
SQL Server 2016 noveltiesSQL Server 2016 novelties
SQL Server 2016 novelties
MSDEVMTL2.9K visualizações
Time is of the essence - The Fourth Dimension in Oracle Database 12c (on Flas... por 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 visualizações
Redefining tables online without surprises por Nelson Calero
Redefining tables online without surprisesRedefining tables online without surprises
Redefining tables online without surprises
Nelson Calero4.7K visualizações
SQL Extensions to Support Streaming Data With Fabian Hueske | Current 2022 por 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
HostedbyConfluent368 visualizações
MariaDB Temporal Tables por Federico Razzoli
MariaDB Temporal TablesMariaDB Temporal Tables
MariaDB Temporal Tables
Federico Razzoli167 visualizações
Sql 2016 - What's New por dpcobb
Sql 2016 - What's NewSql 2016 - What's New
Sql 2016 - What's New
dpcobb822 visualizações
Back to the future - Temporal Table in SQL Server 2016 por 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
Stéphane Fréchette4.8K visualizações
Liquibase case study por Vivek Dhayalan
Liquibase case studyLiquibase case study
Liquibase case study
Vivek Dhayalan830 visualizações
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität por 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 plc257 visualizações
Teradata Tutorial for Beginners por rajkamaltibacademy
Teradata Tutorial for BeginnersTeradata Tutorial for Beginners
Teradata Tutorial for Beginners
rajkamaltibacademy442 visualizações
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres Open por 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 visualizações
Oracle data capture c dc por Amit Sharma
Oracle data capture c dcOracle data capture c dc
Oracle data capture c dc
Amit Sharma803 visualizações
PHP Detroit -- MySQL 8 A New Beginning (updated presentation) por 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 visualizações
MODULE 5.pptx por lathass5
MODULE 5.pptxMODULE 5.pptx
MODULE 5.pptx
lathass54 visualizações
Why PostgreSQL for Analytics Infrastructure (DW)? por Huy Nguyen
Why PostgreSQL for Analytics Infrastructure (DW)?Why PostgreSQL for Analytics Infrastructure (DW)?
Why PostgreSQL for Analytics Infrastructure (DW)?
Huy Nguyen2.7K visualizações
Technical Presentation - TimeWIzard por Praveen Kumar Peddi
Technical Presentation - TimeWIzardTechnical Presentation - TimeWIzard
Technical Presentation - TimeWIzard
Praveen Kumar Peddi243 visualizações
SQL Server Temporal Tables por Greg McMurray
SQL Server Temporal TablesSQL Server Temporal Tables
SQL Server Temporal Tables
Greg McMurray181 visualizações

Mais de Federico Razzoli

A first look at MariaDB 11.x features and ideas on how to use them por
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
47 visualizações36 slides
MariaDB stored procedures and why they should be improved por
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 visualizações32 slides
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11 por
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
63 visualizações36 slides
MariaDB 10.11 key features overview for DBAs por
MariaDB 10.11 key features overview for DBAsMariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsFederico Razzoli
145 visualizações38 slides
Recent MariaDB features to learn for a happy life por
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 visualizações38 slides
Advanced MariaDB features that developers love.pdf por
Advanced MariaDB features that developers love.pdfAdvanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdfFederico Razzoli
102 visualizações38 slides

Mais de Federico Razzoli(18)

A first look at MariaDB 11.x features and ideas on how to use them por 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 Razzoli47 visualizações
MariaDB stored procedures and why they should be improved por 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
Federico Razzoli8 visualizações
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11 por 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 Razzoli63 visualizações
MariaDB 10.11 key features overview for DBAs por 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 Razzoli145 visualizações
Recent MariaDB features to learn for a happy life por 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 visualizações
Advanced MariaDB features that developers love.pdf por Federico Razzoli
Advanced MariaDB features that developers love.pdfAdvanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdf
Federico Razzoli102 visualizações
Automate MariaDB Galera clusters deployments with Ansible por Federico Razzoli
Automate MariaDB Galera clusters deployments with AnsibleAutomate MariaDB Galera clusters deployments with Ansible
Automate MariaDB Galera clusters deployments with Ansible
Federico Razzoli489 visualizações
Creating Vagrant development machines with MariaDB por Federico Razzoli
Creating Vagrant development machines with MariaDBCreating Vagrant development machines with MariaDB
Creating Vagrant development machines with MariaDB
Federico Razzoli62 visualizações
MariaDB, MySQL and Ansible: automating database infrastructures por Federico Razzoli
MariaDB, MySQL and Ansible: automating database infrastructuresMariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructures
Federico Razzoli175 visualizações
Playing with the CONNECT storage engine por Federico Razzoli
Playing with the CONNECT storage enginePlaying with the CONNECT storage engine
Playing with the CONNECT storage engine
Federico Razzoli126 visualizações
Database Design most common pitfalls por Federico Razzoli
Database Design most common pitfallsDatabase Design most common pitfalls
Database Design most common pitfalls
Federico Razzoli553 visualizações
MySQL and MariaDB Backups por Federico Razzoli
MySQL and MariaDB BackupsMySQL and MariaDB Backups
MySQL and MariaDB Backups
Federico Razzoli775 visualizações
JSON in MySQL and MariaDB Databases por Federico Razzoli
JSON in MySQL and MariaDB DatabasesJSON in MySQL and MariaDB Databases
JSON in MySQL and MariaDB Databases
Federico Razzoli900 visualizações
How MySQL can boost (or kill) your application v2 por 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 visualizações
MySQL Transaction Isolation Levels (lightning talk) por Federico Razzoli
MySQL Transaction Isolation Levels (lightning talk)MySQL Transaction Isolation Levels (lightning talk)
MySQL Transaction Isolation Levels (lightning talk)
Federico Razzoli119 visualizações
Cassandra sharding and consistency (lightning talk) por Federico Razzoli
Cassandra sharding and consistency (lightning talk)Cassandra sharding and consistency (lightning talk)
Cassandra sharding and consistency (lightning talk)
Federico Razzoli2.3K visualizações
MySQL Query Optimisation 101 por Federico Razzoli
MySQL Query Optimisation 101MySQL Query Optimisation 101
MySQL Query Optimisation 101
Federico Razzoli852 visualizações
How MySQL can boost (or kill) your application por 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 visualizações

Último

Using Qt under LGPL-3.0 por
Using Qt under LGPL-3.0Using Qt under LGPL-3.0
Using Qt under LGPL-3.0Burkhard Stubert
14 visualizações11 slides
The Path to DevOps por
The Path to DevOpsThe Path to DevOps
The Path to DevOpsJohn Valentino
6 visualizações6 slides
FOSSLight Community Day 2023-11-30 por
FOSSLight Community Day 2023-11-30FOSSLight Community Day 2023-11-30
FOSSLight Community Day 2023-11-30Shane Coughlan
8 visualizações18 slides
Top-5-production-devconMunich-2023-v2.pptx por
Top-5-production-devconMunich-2023-v2.pptxTop-5-production-devconMunich-2023-v2.pptx
Top-5-production-devconMunich-2023-v2.pptxTier1 app
9 visualizações42 slides
How Workforce Management Software Empowers SMEs | TraQSuite por
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteTraQSuite
7 visualizações3 slides
aATP - New Correlation Confirmation Feature.pptx por
aATP - New Correlation Confirmation Feature.pptxaATP - New Correlation Confirmation Feature.pptx
aATP - New Correlation Confirmation Feature.pptxEsatEsenek1
222 visualizações6 slides

Último(20)

Using Qt under LGPL-3.0 por Burkhard Stubert
Using Qt under LGPL-3.0Using Qt under LGPL-3.0
Using Qt under LGPL-3.0
Burkhard Stubert14 visualizações
The Path to DevOps por John Valentino
The Path to DevOpsThe Path to DevOps
The Path to DevOps
John Valentino6 visualizações
FOSSLight Community Day 2023-11-30 por Shane Coughlan
FOSSLight Community Day 2023-11-30FOSSLight Community Day 2023-11-30
FOSSLight Community Day 2023-11-30
Shane Coughlan8 visualizações
Top-5-production-devconMunich-2023-v2.pptx por Tier1 app
Top-5-production-devconMunich-2023-v2.pptxTop-5-production-devconMunich-2023-v2.pptx
Top-5-production-devconMunich-2023-v2.pptx
Tier1 app9 visualizações
How Workforce Management Software Empowers SMEs | TraQSuite por TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuite
TraQSuite7 visualizações
aATP - New Correlation Confirmation Feature.pptx por EsatEsenek1
aATP - New Correlation Confirmation Feature.pptxaATP - New Correlation Confirmation Feature.pptx
aATP - New Correlation Confirmation Feature.pptx
EsatEsenek1222 visualizações
Streamlining Your Business Operations with Enterprise Application Integration... por Flexsin
Streamlining Your Business Operations with Enterprise Application Integration...Streamlining Your Business Operations with Enterprise Application Integration...
Streamlining Your Business Operations with Enterprise Application Integration...
Flexsin 5 visualizações
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile... por Stefan Wolpers
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...
Stefan Wolpers44 visualizações
Automated Testing of Microsoft Power BI Reports por RTTS
Automated Testing of Microsoft Power BI ReportsAutomated Testing of Microsoft Power BI Reports
Automated Testing of Microsoft Power BI Reports
RTTS11 visualizações
Top-5-production-devconMunich-2023.pptx por Tier1 app
Top-5-production-devconMunich-2023.pptxTop-5-production-devconMunich-2023.pptx
Top-5-production-devconMunich-2023.pptx
Tier1 app10 visualizações
Introduction to Git Source Control por John Valentino
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source Control
John Valentino8 visualizações
Benefits in Software Development por John Valentino
Benefits in Software DevelopmentBenefits in Software Development
Benefits in Software Development
John Valentino6 visualizações
Introduction to Maven por John Valentino
Introduction to MavenIntroduction to Maven
Introduction to Maven
John Valentino7 visualizações
Agile 101 por John Valentino
Agile 101Agile 101
Agile 101
John Valentino13 visualizações
Quality Engineer: A Day in the Life por John Valentino
Quality Engineer: A Day in the LifeQuality Engineer: A Day in the Life
Quality Engineer: A Day in the Life
John Valentino10 visualizações
EV Charging App Case por iCoderz Solutions
EV Charging App Case EV Charging App Case
EV Charging App Case
iCoderz Solutions10 visualizações
Dapr Unleashed: Accelerating Microservice Development por Miroslav Janeski
Dapr Unleashed: Accelerating Microservice DevelopmentDapr Unleashed: Accelerating Microservice Development
Dapr Unleashed: Accelerating Microservice Development
Miroslav Janeski16 visualizações
Understanding HTML terminology por artembondar5
Understanding HTML terminologyUnderstanding HTML terminology
Understanding HTML terminology
artembondar58 visualizações
Bootstrapping vs Venture Capital.pptx por Zeljko Svedic
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptx
Zeljko Svedic16 visualizações
Winter Projects GDSC IITK por SahilSingh368445
Winter Projects GDSC IITKWinter Projects GDSC IITK
Winter Projects GDSC IITK
SahilSingh368445416 visualizações

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