views:

268

answers:

10

I was just wondering if a storage engine type existed that allowed you to do version control on row level contents. For instance, if I have a simple table with ID, name, value, and ID is the PK, I could see that row 354 started as (354, "zak", "test")v1 then was updated to be (354, "zak", "this is version 2 of the value")v2 , and could see a change history on the row with something like select history (value) where ID = 354.

It's kind of an esoteric thing, but it would beat having to keep writing these separate history tables and functions every time a change is made...

+3  A: 

It seems you are looking more for auditing features. Oracle and several other DBMS have full auditing features. But many DBAs still end up implementing trigger based row auditing. It all depends on your needs.

Oracle supports several granularities of auditing that are easy to configure from the command line.

I see you tagged as MySQL, but asked about any storage engine. Anyway, other answers are saying the same thing, so I'm going delete this post as originally it was about the flashback features.

mrjoltcola
Flashback query and flashback table are not permanent data stores; they just enable the recovery of data from the UNDO tablespace. I say "just", obviously these are powerful features but they are not a true "version control for data" solution.
APC
Yes. If you read my edit, I added that prior to your comment.
mrjoltcola
I probably should edit it out altogether, as possibly misleading. Quick scanning a question is getting me in trouble. :)
mrjoltcola
+1  A: 

You can achieve similar behavior with triggers (search for "triggers to catch all database changes") - particularly if they implement SQL92 INFORMATION_SCHEMA.

Otherwise I'd agree with mrjoltcola

Edit: The only gotcha I'd mention with MySQL and triggers is that (as of the latest community version I downloaded) it requires the user account have the SUPER privilege, which can make things a little ugly

AJ
Yes, I read the first part of the question regarding "versioning" and thought flashback, but then realized he seems to be looking for long-term auditing. I have edited my answer as such. Thanks.
mrjoltcola
Agreed - I read it the same way as you first, but then figured it was more common to want auditing
AJ
+3  A: 

Obviously you are really after a MySQL solution, so this probably won't help you much, but Oracle has a feature called Total Recall (more formally Flashback Archive) which automates the process you are currently hand-rolling. The Archive is a set of compressed tables which are populated with changes automatically, and queryable with a simple AS OF syntax.

Naturally being Oracle they charge for it: it needs an additional license on top of the Enterprise Edition, alas. Find out more (PDF).

APC
A: 

One approximation to this is a temporal database - which allows you to see the status of the whole database at different times in the past. I'm not sure that wholly answers your question though; it would not allow you to see the contents of Row 1 at time t1 while simultaneously letting you look at the contents of Row 2 at a separate time t2.

Jonathan Leffler
+1  A: 

Oracle and Sql Server both call this feature Change Data Capture. There is no equivalent for MySql at this time.

Joel Coehoorn
+1  A: 

I think Big table, the Google DB engine, does something like that : it associate a timestamp with every update of a row.

Maybe you can try Google App Engine.

There is a Google paper explaining how Big Table works.

e-satis
+1  A: 

CouchDB has full versioning for every change made, but it is part of the NOSQL world, so would probably be a pretty crazy shift from what you are currently doing.

Mike McKay
+1  A: 

The wikipedia article on google's bigtable mentions that it allows versioning by adding a time dimension to the tables:

Each table has multiple dimensions (one of which is a field for time, allowing versioning).

There are also links there to several non-google implementations of a bigtable-type dbms.

Johrn
+1  A: 

The book Refactoring Databases has some insights on the matter.

But it also points out there is no real solution currently, other then carefully making changes and managing them manually.

Am
A: 

"It's kind of an esoteric thing, but it would beat having to keep writing these separate history tables and functions every time a change is made..."

I wouldn't call audit trails (which is obviously what you're talking of) an "esoteric thing" ...

And : there is still a difference between the history of database updates, and the history of reality. Historical database tables should really be used to reflect the history of reality, NOT the history of database updates.

The history of database updates is already kept by the DBMS in its logs and journals. If someone needs to inquire the history of database upates, then he/she should really resort to the logs and journals, not to any kind of application-level construct that can NEVER provide sufficient guarantee that it reflects ALL updates.

Erwin Smout