Is there ever a case where `SELECT COUNT(*)` would return a different result in `SELECT COUNT(something)` assuming no group by clause? I'm curious why they generate different query plans on virtually every backend.
I suspect the answer is "because fuck you don't do that", but it's a performance detail that I specifically had to work around in Diesel (like 2 years ago) so I'm quite curious if there's an actual technical reason. (I'm updating the docs for count is why I was thinking abt this)
-
-
I experimented with select count(*) vs count(id) on a 4 million row table in Postgres 9.6. count(id) took 316.15 ms, count(*) took 186.27 ms. Both queries did a sequential scan. One difference I noticed in the query plan was "width=8" in the plan for select count(id).
-
What I think is going on is that the select(id) needs to examine data inside each row, where as count(*) only needs to know the rows existence
- 7 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.