Live data from Hacker News

MariaDB Temporal Data Tables

mariadb.com

21–30 of 44 posts

Re: MariaDB Temporal Data Tables

#21
post #19

> mysqldump does not read historical rows from versioned tables, and so historical data will not be backed up. Also, a restore of the timestamps would not be possible as they cannot be defined by an insert/a user. Given this caveat, this seems unusable for production systems.

Well, conceptually this makes sense for what mysqldump is.

I'm guessing that "backups" would actually have to be live replicas set up from the start, and if the master fails, you convert a replica to master.

In addition, you could perform actual static backups by pausing a replica, backing up the actual table files themselves, then resuming the replica (and it will catch up). In case of total failure, you just dump the table files into a fresh install of MariaDB. (Copying database files is a common technique for migrating data, not just SQL command import/export.)

Is there any reason why these wouldn't work?

Re: MariaDB Temporal Data Tables

#22
This is fascinating. I've got two basic questions, however:

1) Is this always going to be performant with indices? It seems like "time" is kind of like another index here, and when designing queries which indices are used and in which order can be the difference between taking milliseconds and taking an hour. It's not obvious to me whether this will have hidden gotchas or query execution complexities, or if it's designed in a way that's so restricted and integrated into indices themselves that query performance will always remain within the same order of magnitude

2) What is the advantage of building this into the database, instead of adding your own timestamp columns e.g. 'created_timestamp' and 'expunged_timestamp'? Not only does that seem relatively simple, but it gives you the flexibility of creating indices across multiple columns (including them) for desired performance, the ability to work with tools like mysqldump, and it's just conceptually simpler to understand the database. And if the question is data security, is there a real difference between a "security layer" that is built around the database, versus one built into it? It would be fairly simple to write a command-line tool to change the MariaDB data files directly, no?

Re: MariaDB Temporal Data Tables

#23
post #19

> mysqldump does not read historical rows from versioned tables, and so historical data will not be backed up. Also, a restore of the timestamps would not be possible as they cannot be defined by an insert/a user. Given this caveat, this seems unusable for production systems.

Well, conceptually this makes sense for what mysqldump is. I'm guessing that "backups" would actually have to be live replicas set up from the start, and if the master fails, you convert a replica to master. In addition, you could perform actual static backups by pausing a replica, backing up the actual table files themselves, then resuming the replica (and it will catch up). In case of total failure, you just dump t…

Or ZFS snapshots, for example.

From the description it looks like it would be easy to do backups, it's just that mysqldump is not currently aware of temporal tables.

Just use

SELECT * FROM t FOR SYSTEM_TIME ALL;

And export it in an appropriate format.

Re: MariaDB Temporal Data Tables

#24

Earlier quoted context omitted.

Well, conceptually this makes sense for what mysqldump is. I'm guessing that "backups" would actually have to be live replicas set up from the start, and if the master fails, you convert a replica to master. In addition, you could perform actual static backups by pausing a replica, backing up the actual table files themselves, then resuming the replica (and it will catch up). In case of total failure, you just dump t…

Or ZFS snapshots, for example. From the description it looks like it would be easy to do backups, it's just that mysqldump is not currently aware of temporal tables. Just use SELECT * FROM t FOR SYSTEM_TIME ALL; And export it in an appropriate format.

That does, of course, export complete data, but the problem is you can't then import it, because that breaks the entire guarantee about not being able to edit past data.

Re: MariaDB Temporal Data Tables

#25

This is fascinating. I've got two basic questions, however: 1) Is this always going to be performant with indices? It seems like "time" is kind of like another index here, and when designing queries which indices are used and in which order can be the difference between taking milliseconds and taking an hour. It's not obvious to me whether this will have hidden gotchas or query execution complexities, or if it's desi…

re 2) - it is a complex topic but in short, the queries get really complex really fast for anything other than a simple select. see http://www2.cs.arizona.edu/~rts/tdbbook.pdf.

also, DDL migrations become a nightmare.

Re: MariaDB Temporal Data Tables

#26
post #11

Earlier quoted context omitted.

> I've always been bewildered why this wasn't a core part of SQL from the very beginning. It's a long and messy history (no pun intended), but essentially it was rarely practical to consider retaining database history for the first few decades of SQL, due to physical storage costs & limitations. Snodgrass and Jensen proposed initial bitemporal extensions in the 90s and lot of research was done subsequently, but most…

> it was rarely practical to consider retaining database history for the first few decades of SQL That does make sense from a historical perspective and I don't doubt that's why. But still I find it unsatisfying because any competent database schema will always retain the history that needs to be retained. If you don't have the storage capacity, you choose to not store so much history. If you don't have native concep…

> temporal concepts should have been deeply native to SQL right to its core

Oh absolutely. I think the original intuition by Snodgrass et al. in TSQL2 to model temporality outside of the actual relational structure was a more promising direction, otherwise the complexity of composing joins across many tables, each with independent temporal versioning, seems rather overwhelming (note that the article doesn't discuss joins at all). Schema migration is another hairy topic that the 2011 standard barely addresses.

Modelling temporality outside of the database is what we've been pushing ahead with on Crux, which provides Datalog as the native query language but will imminently also support a simple bitemporal flavour of SQL for point-in-time querying (using Apache Calcite), where application & system time are defined by a single "as-of" prefix at the beginning of the statement that applies across the entire query: https://github.com/juxt/crux/tree/master/crux-sql#bitemporal... (queries over ranges and periods are currently out-of-scope)

Re: MariaDB Temporal Data Tables

#27
post #14

Earlier quoted context omitted.

That sounds neat. What does the performance of querying past versions look like? For instance, is lookup time linear with the amount of history or do you maintain special temporal indexes?

It varies depending on how the user chooses to structure storage (we're flexible with that) and what mode of querying they use. We have a more in-depth explanation and some benchmarks in an IPython notebook at [1]. We store Splitgraph "image" (schema snapshot) metadata in PostgreSQL itself and each image has a timestamp, so you could create a PG index on that to quickly get to an image valid at a certain time. Each i…

Thanks for the explanations. That is a very intriguing use-case for foreign data wrappers!

Re: MariaDB Temporal Data Tables

#28

Earlier quoted context omitted.

Or ZFS snapshots, for example. From the description it looks like it would be easy to do backups, it's just that mysqldump is not currently aware of temporal tables. Just use SELECT * FROM t FOR SYSTEM_TIME ALL; And export it in an appropriate format.

That does, of course, export complete data, but the problem is you can't then import it, because that breaks the entire guarantee about not being able to edit past data.

Ah. There is that.

They really need to create a workaround for that, because sooner or later you will need to migrate your data and right now it's simply impossible.

Edit: Particularly as, reading further, you cannot ALTER a temporal table. Which does make sense, but the problem remains.

Re: MariaDB Temporal Data Tables

#29
post #6

I understand the benefits of this feature for audits, but how does one deal with GDPR requirements? Is there some way to alter historic data to remove PII, or should the affected columns be excluded?

You can't alter historic data, but you can include or exclude just selected columns from versioning. You can also purge all history by date range, but not apparently just the history for a given record.

Re: MariaDB Temporal Data Tables

#30

I really hope Postgres can support temporal table out of the box. Temporal table can simplify development for the feature that need audits.

I work at a company where (many years ago) we built an extension to Postgres (and some helper libs in SQLAlchemy, Go) for implementing decently-performant bitemporal tables (biggest history tables have hundreds of millions of rows). Pretty much our entire company runs on it today.

We implemented the “minimum viable” features (i.e. automatic expiring, non-destructive updates, generated indexes and generated table declarations), but left some of the “harder” ideas up to the application designer (adding semantic versioning on top of temporal versioning, schema migrations).

It’s worked really well for us. I can’t think of anything we’ve done that’s had a higher ROI than this. I’ll really miss it when I leave!

Post reply on HN