5 ms·
Pet peeve: why is the common term "n+1 query problem" when it's the 1 that happens first and the n that is the problem? As a pedant, I've been referring to it
by crabmusket 2y ago
Pet peeve: why is the common term "n+1 query problem" when it's the 1 that happens first and the n that is the problem?
As a pedant, I've been referring to it as a "1+n" problem, but haven't managed to make it catch on yet!
- Izkata 2y agoI swear "n+1" only popped up in the past 5 or so years with this meaning. I learned it over a decade ago as "1+n". Also "n+1" looks more like a reference to concurrency/synchronization throughput - like, n concurrent threads or requests where the results are collected and used together. I was really confused the first few times I saw "n+1" because of that.
- crabmusket 2y agoIt reminds me of mathematical induction, where the k=n and k=n+1 cases are compared. The emphasis is on the +1, the next case to be proved. It looks like this page in the SQLite docs has had the "n+1" terminology for as long as it's been on the internet archive (2016): https://web.archive.org/web/20161112021608/https://www.sqlite.org/np1queryprob.html https://web.archive.org/web/20161112021608/https://www.sqlit...
- dullcrisp 2y agoCommutativity of addition
- crabmusket 2y ago-is irrelevant when we're not dealing with algebra, but a sequence of dependent RPC calls!
- nodoodles 2y agoI have thought of that as ‘n’ being the manageable threshold and the (uncontrolled) ‘+1’ the overflow creates the problems. Typically in terms of additional layers or iterations.. but i like your point and perhaps’n+1’ and ‘1+n’ mean different problem shapes
- crabmusket 2y agoI could see that making sense in some contexts, like the "straw that breaks the camel's back". However that's not what's usually being referred to in this database query problem. Usually it's doing one query that returns n results, then doing one more query for each result. Therefore, you end up having done 1+n queries. If you'd used a join you could potentially have done only 1 query.
- jjtheblunt 2y agomy guess is then you express recursion as "1+n" -> "1+n-1" or "n" it's less traditional, and somehow the "n+1" -> "n" is traditional.