Live data from Hacker News

What is a database transaction?

planetscale.com

61–70 of 70 posts

Re: What is a database transaction?

#61

For all interested in this topic, I highly recommend the book Designing Data Intensive Applications https://www.goodreads.com/book/show/23463279-designing-data-... . It goes into not only different isolation levels, but also some ambiguity in the traditional ACID definition. I believe a 2nd edition is imminent.

Second edition is available now: https://www.oreilly.com/library/view/designing-data-intensiv...

Re: What is a database transaction?

#62
post #59
post #56

I like to think of transactions, in an MVCC system like Postgres, as being like snapshots in copy-on-write filesystems like btrfs or zfs. When you BEGIN a transaction, the DB takes a snapshot of your data, so now there are two versions of the data, the snapshot (visible to everyone else) and the "private" version visible only to your transaction. Then as you run UPDATEs, the new data is written to the private copy, b…

Not quite. Databases use both branching and locking. Two transactions that conflict can cause one thread to block, rather than rolling back. SELECT followed by an update is the most usual case for a block. (I have to code one today, and I want to see if I can rewrite it as one MySQL statement.)

Yes, the analogy isn't perfect. I didn't want to get into all the subtleties in an introductory analogy, but I should probably have mentioned blocking. Too late for me to edit my post with your correction, though.

Re: What is a database transaction?

#63
post #57

One way to think about transactions, as I wrote in an earlier comment, would be to think of them as being like snapshots in a copy-on-write filesystem like btrfs or zfs. But another way to think of them is being like Git branches. When you BEGIN a transaction, you're creating a branch in Git. Everyone else continues to work on the master branch, perhaps making their own branches (transactions) off of it while you're…

concurr

Re: What is a database transaction?

#64
post #10

I think this is a great post to have but I'm going to make a critical usability suggestion: * the videos should have "pause" and a "step at a time" control * Even at the "half speed", without a deep knowledge of the context, the videos move way too fast for me to read the syntax that's invoking and line it up with the data on the left side. I (and im definitely not the only one) need to be able to sit on one step and…

I appreciate this feedback, and then you read through it with enough rigor to notice.

I second it. At the very least a pause button is needed.

Re: What is a database transaction?

#65

Seems like a frequent surprise is that Postgres and MySQL don't default to serializable (so not fully I in ACID). They do read-committed. I didn't see this article mention that, but maybe I missed it. The article says read-committed provides "slightly" better performance, but it's been way faster in my experience. Forget where, but I think they said they chose this default for that reason. Using read-committed ofc me…

> Postgres and MySQL don't default to serializable Oracle and SQL Server also default to read committed, not serializable. Serializable looks good in text books but is rarely used in practice.

One reason Oracle uses it is because this mode scales horizontally whilst allowing very large transactions. You can just keep adding write masters.

The best implementation of serializable transactions I've seen is in FoundationDB but it comes with serious costs. Transactions are limited in size and duration to a point where many normal database operations are disallowed by the system and require app-layer workarounds (at which point, of course, you lose serializability). And in many cases you do need cluster locks for other purposes anyway.

Re: What is a database transaction?

#66
post #26

We built an entire project for a client-side project with millions of SQL rows and thousands of users without adding a single transaction. :/

But are you sure it was correct? Typical web apps are riddled with race conditions due to incorrect use of database locking and transactions, in my experience.

Re: What is a database transaction?

#67

Earlier quoted context omitted.

> Postgres and MySQL don't default to serializable Oracle and SQL Server also default to read committed, not serializable. Serializable looks good in text books but is rarely used in practice.

One reason Oracle uses it is because this mode scales horizontally whilst allowing very large transactions. You can just keep adding write masters. The best implementation of serializable transactions I've seen is in FoundationDB but it comes with serious costs. Transactions are limited in size and duration to a point where many normal database operations are disallowed by the system and require app-layer workarounds…

Spanner has similar limitations on xact size, maybe for this reason?

Re: What is a database transaction?

#68

Earlier quoted context omitted.

One reason Oracle uses it is because this mode scales horizontally whilst allowing very large transactions. You can just keep adding write masters. The best implementation of serializable transactions I've seen is in FoundationDB but it comes with serious costs. Transactions are limited in size and duration to a point where many normal database operations are disallowed by the system and require app-layer workarounds…

Spanner has similar limitations on xact size, maybe for this reason?

Probably. I've seen it argued that TX size limits are a good practice anyway, and not having them is a design fault of SQL, but it's an argument on thin ice. Transaction size and scope is usually defined by the nature of the business logic, it's not something you can just define to be whatever you want without consequence. An RDBMS can do atomic and correct changes to an entire very large table without any developer effort. That might hang writes for a few minutes so depending on the nature of your application that might not be a feature you can get away with using, but if the table in question is updated by background workers and not on a latency sensitive path it can be a perfectly viable thing to do (on a good database engine, so not postgres mvcc).

Re: What is a database transaction?

#69

Earlier quoted context omitted.

Spanner has similar limitations on xact size, maybe for this reason?

Probably. I've seen it argued that TX size limits are a good practice anyway, and not having them is a design fault of SQL, but it's an argument on thin ice. Transaction size and scope is usually defined by the nature of the business logic, it's not something you can just define to be whatever you want without consequence. An RDBMS can do atomic and correct changes to an entire very large table without any developer…

I'll keep my xacts small until that one time we have to do some big manual fix or migration. But you don't even have to do anything that wild to hit the Spanner 100MB limit.

Re: What is a database transaction?

#70

Earlier quoted context omitted.

Probably. I've seen it argued that TX size limits are a good practice anyway, and not having them is a design fault of SQL, but it's an argument on thin ice. Transaction size and scope is usually defined by the nature of the business logic, it's not something you can just define to be whatever you want without consequence. An RDBMS can do atomic and correct changes to an entire very large table without any developer…

I'll keep my xacts small until that one time we have to do some big manual fix or migration. But you don't even have to do anything that wild to hit the Spanner 100MB limit.

And 100MB is huge! FoundationDB limits transactions to 10MB.
Post reply on HN