Live data from Hacker News

MariaDB Temporal Data Tables

mariadb.com

11–20 of 44 posts

Re: MariaDB Temporal Data Tables

#11
post #7

I've been begging for exactly this for quite some time. Because of the way I use databases, I've always been bewildered why this wasn't a core part of SQL from the very beginning. From what I'm reading there's still a lot to be fleshed out to be maximally useful to me, but even in its current state I could imagine using this. — I'd like to have a field property that limits stored values to a single version and thus i…

> 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 vendors didn't make their move until the 2011 standard was formed (Oracle Flashback being the most notable exception). Unfortunately the rollout of the 2011 temporal standard has been underwhelming across the board, as each vendor ended up implementing something subtly different, which I think has massively hindered adoption. Since then I would guess that "immutability" has been the largest driving force behind the resurgence of interest.

Re: MariaDB Temporal Data Tables

#12
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?

Possibly the idea of "crypto-shredding" could apply, where the PII values are encrypted and you throw away the key if you get a delete request.

Re: MariaDB Temporal Data Tables

#13
post #7

I've been begging for exactly this for quite some time. Because of the way I use databases, I've always been bewildered why this wasn't a core part of SQL from the very beginning. From what I'm reading there's still a lot to be fleshed out to be maximally useful to me, but even in its current state I could imagine using this. — I'd like to have a field property that limits stored values to a single version and thus i…

Joining on self by a different time range from the current is probably doable?

Re: MariaDB Temporal Data Tables

#14

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

Shameless plug (I'm a co-founder) but this is basically what we've built with Splitgraph[0]: we can add change tracking to tables using PostgreSQL's audit triggers and let the user switch between different versions of the table / query past versions. [0] https://www.splitgraph.com/product/data-lifecycle/research

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?

Re: MariaDB Temporal Data Tables

#15
post #14

Earlier quoted context omitted.

Shameless plug (I'm a co-founder) but this is basically what we've built with Splitgraph[0]: we can add change tracking to tables using PostgreSQL's audit triggers and let the user switch between different versions of the table / query past versions. [0] https://www.splitgraph.com/product/data-lifecycle/research

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 image consists of tables and each table is a set of possibly overlapping objects, or "chunks". If two chunks have a row with the same PK, the row from the latter will take precedence. Within these constraints, you can store table versions however you want -- e.g. as a big "base" chunk and multiple deltas (least storage, slowest querying) or as a multiple big chunks (faster querying, more storage).

You can query tables in two ways. Firstly, you can perform a "checkout". Like Git, this replays changes to a table in the staging area and turns it into a normal PostgreSQL table with audit triggers. You get same read performance (and can create whatever PG indexes you want to speed it up). Write performance is 2x slower than normal PostgreSQL since every change has to be mirrored by the audit trigger. When you "commit" the table (a Splitgraph commit, not the Postgres commit), we grab those changes and package them into a new chunk. In this case, you have to pay the initial checkout cost.

You can also query tables without checking them out (we call this "layered querying" [2]). We implemented this through a read-only foreign data wrapper, so all PG clients still support it. In layered querying, we find the chunks that the query requires (using bloom filters and other metadata), direct the query to those and assemble the result. The cool thing about this is you don't have to have the whole table history local to your machine: you can store some chunks on S3 and Splitgraph will download them behind the scenes as required, without interrupting the client. Especially for large tables, this can be faster than PostgreSQL itself, since we are backed by a columnar store [3].

[1] https://www.splitgraph.com/docs/getting-started/frequently-a...

[2] https://www.splitgraph.com/docs/large-datasets/layered-query...

[3] https://www.splitgraph.com/docs/concepts/objects

Re: MariaDB Temporal Data Tables

#16
post #11
post #7

I've been begging for exactly this for quite some time. Because of the way I use databases, I've always been bewildered why this wasn't a core part of SQL from the very beginning. From what I'm reading there's still a lot to be fleshed out to be maximally useful to me, but even in its current state I could imagine using this. — I'd like to have a field property that limits stored values to a single version and thus i…

> 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 concepts for storing history, you kludge it yourself.

Whether you have native temporal support or have to kludge a DIY solution in the schema, the data you need to store gets stored.

My frustration is that I feel that temporal concepts should have been deeply native to SQL right to its core. History should have been as fundamental to database design as columns and rows. It should be a thing you turn off when you don't want it, not a thing you turn on when you do.

Re: MariaDB Temporal Data Tables

#17
post #9

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

Funny historical and architecture fact about PostgreSQL. It actually can do this, for all tables without special features. Unfortunately the facility to perform a query like this is no longer exposed but it shouldn't be impossible to re-add in a more modern way. Essentially PostgreSQL has copy-on-write semantics, so historical records exist unless a vacuum marks them as no longer needed and subsequent insert/updates…

Really nice background, thanks for sharing! I knew Postgres did CoW internally and always wondered why the SQL standard for time-travel queries was not implemented.

I am using triggers and audit tables which works but my data requirements are relatively small so I won't face any challenges that way. However, re-using the old rows like this would lead to a far more efficient approach if it were supported natively.

Re: MariaDB Temporal Data Tables

#18
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?

There are gdpr exceptions for use cases like audit trails, so if there is a requirement to keep the data, you can.

It’s an excellent point to be aware of.

Re: MariaDB Temporal Data Tables

#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.

Re: MariaDB Temporal Data Tables

#20

How does this feature compare to MS SQL's Temporal Tables https://docs.microsoft.com/en-us/sql/relational-databases/ta... ? This feature seems to be well fitted to support some of the cases where event sourcing is introduced, I wonder if someone successfully applied event sourcing with use of temporal tables to reduce the amount of work that has to be done in the application code (Akka, etc.).

When we looked at temporal tables in SQL Server for event sourcing, I was put off by the fact that you have to read from multiple tables. CDC + some external data source still seems to be the better solution here, imo.
Post reply on HN