News for hackers. Stuff that matters.
Re:Rewrite it in Rails by randomdata on Monday November 04, 2024 @09:43PM (#42048148)
Because of the high latency between messages? After all, eliminate the latency and the N+1 problem goes away.
Re:Rewrite it in Rails by cpursley on Wednesday November 06, 2024 @06:48AM (#42060593)
Why not just use the database correctly?
Re:Rewrite it in Rails by randomdata on Wednesday November 06, 2024 @12:23PM (#42065711)
What do you mean? The N+1 problem lies on the theoretically correct solution. That is using the database properly.

It is just not tenable where latency poses a practical constraint under an implementation that is not theoretically sound. There are plenty of hacks to work around it, though, so it is not really a problem in practice. To call those hacks to work around a system with shortcomings "using the database properly" is a bit of a stretch, though.

Just so we're clear, the use of JOIN, IN, etc. are not hacks in and of themselves. They serve a purpose even where latency doesn't exist. But when applied to solving the N+1 problem, their use is a hack. Again, one that gets the job done and solves the problem – hacks aren't bad, but is not theoretically sound. If you did not have latency constraints to contend with, you would not prefer it.

The better question is: Why use a database that sucks? Latency periods are small enough in SQLite, for example, that you don't have to worry about the N+1 problem in any real-world situation. It doesn't have to be a problem in need of hacks.