News for hackers. Stuff that matters.
Re:Database Performance Optimization and Scaling in Rails by jemmyw on Friday December 09, 2022 @12:35PM (#33924071)
> It also wraps every query in an explicit transaction unnecessarily causing locks to be held while waiting for the commit from the server

no it doesn't. It only wraps updates in transactions, and a single line update would have an implicit transaction at the database anyway.

Re:Database Performance Optimization and Scaling in Rails by Rapzid on Friday December 09, 2022 @09:35PM (#33929229)
It would have an implicit transaction, wouldn't it?

Think about what we both wrote here (sans the weak man argument, of course I'm talking about updates).

Re:Database Performance Optimization and Scaling in Rails by jemmyw on Sunday December 11, 2022 @11:58PM (#33951045)
I see. Well you could have been more explicit in your original message, I don't think it was obvious at all that you were talking about updates.

Rails does the right thing here in my opinion. Anything that happens between calling `.save` and it returning should be in the safe envelop of a transaction. It can't know that you're only going to emit a single UPDATE query in that transaction, plus the framework user expects any exception between calling save and it returning to roll back. There are outs if you need them. I've worked on a few reasonably high traffic and complex rails applications and I don't recall a time when the time between the last query and the commit caused an issue. Yes times when the transaction itself had got too large and that commit was taking awhile. That said, there were more of these types of locking issues in the project I worked on 10 years ago with MySQL and repeatable read isolation level than with PG since then which defaults to read committed.