PostgreSQL Subtransactions Considered Harmful
1–10 of 43 posts
Re: PostgreSQL Subtransactions Considered Harmful
#2Re: PostgreSQL Subtransactions Considered Harmful
#3Re: PostgreSQL Subtransactions Considered Harmful
#4Maybe too much 30,000 feet perspective, but in general everything that is "state" in a session is a potential limit to performance and scalability.
In this blog post, it is the "state" associated with subtransactions. In another area, it may be Prepared Statements. Often regarded as better performing than non prepared (and they strictly are, generally), they impose hard limits into connection scalability. Connection poolers cannot hold this state and thus you cannot use transaction pooling, which boosts performance and resource usage much more than prepared vs non-prepared.
Anyway, that's another topic. But session state --is something I'm becoming more and more against. YMMV.
Re: PostgreSQL Subtransactions Considered Harmful
#5Really dislike these "considered harmful" type titles.
[1] https://www.enterprisedb.com/blog/schema-later-considered-ha...
Re: PostgreSQL Subtransactions Considered Harmful
#6Re: PostgreSQL Subtransactions Considered Harmful
#7Really dislike these "considered harmful" type titles.
I'm the co-author of one of such ones: "Schema Later Considered Harmful" [1]. I don't see what's wrong with this "type titles", may you elaborate? :) [1] https://www.enterprisedb.com/blog/schema-later-considered-ha...
Re: PostgreSQL Subtransactions Considered Harmful
#8We then mindlessly copy that to our database code -- each mutation function takes a "database object", which could be a direct database connection, or it could be an in-progress transaction. It's generic so that you don't have to care. Functions that think their stuff needs to be a transaction just start one, and if it errors out, hey, it's rolled back.
(Whenever you have a "don't care" type, it means half the functions will be documented "// must be run in a transaction" and the other half will pessimistically create a transaction "just in case" it was invoked with a raw database connection instead of a transaction object.)
Thinking about it more critically, 100% of the times I've wanted to write this, I've wanted to abort the parent transaction as soon as the first child fails. I tend to retry transactions, and doing that twice doesn't make a lot of sense (parent transaction starts, calls a helper function, that starts a transaction, it has a conflict and has to be rolled back, helper function is re-run, that ends up committing, parent transaction fails because of a conflict... and the update gets rolled back anyway).
I basically structure my database APIs to take transaction objects, and make each public API member a transactional unit. Then, the very top level creates and commits the transaction, and can add whatever retry logic it deems necessary.
(Using the classic example, TransferFunds() would be public, and addMoney() and withdrawMoney() would be private. That way, the runner of a transaction can't do "doTx(addMoney); doTx(withdrawMoney)", it would be forced to do "doTx(TransferFunds)". And, all three would take a Transaction object instead of a TransactionOrDatabase object, so the type system enforces the transactional expectations of a money transfer operation.)
Re: PostgreSQL Subtransactions Considered Harmful
#9Earlier quoted context omitted.
I'm the co-author of one of such ones: "Schema Later Considered Harmful" [1]. I don't see what's wrong with this "type titles", may you elaborate? :) [1] https://www.enterprisedb.com/blog/schema-later-considered-ha...
They're hyperbolic and don't actually give you any useful information on why they're "harmful" or what's wrong with the subject being discussed.
(edit, typo)
Re: PostgreSQL Subtransactions Considered Harmful
#10Really dislike these "considered harmful" type titles.
I'm the co-author of one of such ones: "Schema Later Considered Harmful" [1]. I don't see what's wrong with this "type titles", may you elaborate? :) [1] https://www.enterprisedb.com/blog/schema-later-considered-ha...
Drinking bleach is harmful.