3 ms·
I'm not sure I understand your statement. On databases without an intrinsic row count property the only way to find the row count is to go to every page and cou
by sitharus 8y ago
I'm not sure I understand your statement. On databases without an intrinsic row count property the only way to find the row count is to go to every page and count the rows there. The query planner will use the same plan for both `count(*)` and `count(1)`.
- znep 8y agoAn interesting postgres oddity I ran into a few years ago that isn't about counting but is in a similar arena is how under very specific circumstances, "SELECT *" is significantly faster than "SELECT one_column" despite the conventional and normally well advised advice that you should only select the columns you need. See https://www.postgresql.org/message-id/CAN1FPGN1ynBj3m1DMszc9MEYVj41S96OMy8-Q1cgKMGxv482SA%40mail.gmail.com https://www.postgresql.org/message-id/CAN1FPGN1ynBj3m1DMszc9... and Tom Lane's followup for details.
- hinkley 8y agoNot according to that blurb. There have been other databases where count(1) was much faster. Here they are saying that in Postgres, count(1) is slower because star is treated as no arguments, and count(1) is more complex.
- laurenz_albe 8y agoThat is not what "they" are saying. count(1) and count(*) are equally fast because they are doing the same thing.