Live data from Hacker News

Demystifying Database Systems: An Introduction to Transaction Isolation Levels

fauna.com

21–23 of 23 posts

Re: Demystifying Database Systems: An Introduction to Transaction Isolation Levels

#21
post #19

Earlier quoted context omitted.

To implement the serializable isolation level, the database system must track access to every single row you access, even the ones you read or filter out. (The need to track reads, even for rows filtered out of a select statement is surprising but necessary.) Consider a common scenario where you SELECT a set of rows and take a SUM over a column. Suppose your query and another query begin reading from the same committ…

> The only way for the database system to guarantee there is no conflict is to keep track of every single row your query accesses, even if it is a row passed over by a WHERE clause! Why is putting a lock on the table itself not an option?

You're correct that a table-level lock is a useful tool to ensure serializability, but it's also a drastic one since it blocks other transactions requesting a higher access level. The concurrency control system is trying to provide a generic way to both guarantee consistency and maintain a high throughout on a variety of workloads, and locking tables always would diminish throughout for many common workloads. For example, one where inserts and reads tend to occur simultaneously at high volume.

Re: Demystifying Database Systems: An Introduction to Transaction Isolation Levels

#22
post #8

Earlier quoted context omitted.

As mentioned in the post: "There are several ways to achieve [serializability] — such as via locking, validation, or multi-versioning." Deadlock happens under some, but not all implementations of serializability via locking. There have been several database systems developed in my lab that use locking to achieve serializability, but yet never deadlock. Examples include: (1) Calvin: http://www.cs.umd.edu/~abadi/papers…

What I'm talking about here is not academic database technologies in laboratories, but the typical mysql/postgres/oracle/sqlserver production world regular programmers live in. So yes, I know pragmatic strategies for avoiding deadlocks, but in all the databases I've used, you have to proactively employ such a strategy. Many if not most of these programmers have at best a rudimentary knowledge of transactions and/or w…

In my experience, novices generally stick with the default. And when they don't, their code breaks because they assumed serializable was somehow magic and they don't handle the inevitable transaction failures (generally on production, when there is load). This is exactly why PostgreSQL drivers that used serializable as a default had to backtrack and default to read committed. And yes, I agree that the blog is encouraging serializable without adequately pointing out the downsides; th extra burden on application developers would be #1 in the caveats in my book, and using serializable when you don't have to will lead to a net increase in bugs.

Re: Demystifying Database Systems: An Introduction to Transaction Isolation Levels

#23
post #12

In many real world applications using common databases you do not always need “transaction safety”, in particular when reading data for statistical purposes. Performance gains and not blocking the database for many other readers and writers will in many scenarios outweigh the possibly of reading uncommitted/dirty data. Use: SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED (whether you are are querying from within a t…

It can certainly solve performance problems, in much the same way as turning of fsync. Even a contractor contracted specifically to fix a performance problem shouldn't do this without understanding how this will affect the particular application, or they open themselves to professional malfeasance (if noticed; otherwise they will likely get the contract to fix the data corruption problem since they did such a good job last time...)
Post reply on HN