Hacker News new | ask | show | jobs
by jng 1431 days ago
I'm a bit surprised that Posgres doesn't optimize the COUNT(column) expression to not actually read the value of the column, which is not necessary. Am I missing something?
3 comments

Pg has to read the xmin and xmax anyway to determine if the row is visible to your transaction (for rows without hint bits set, in pages without hint bits set).
It does have to read it because NULLs aren't counted
If the column is NOT NULL, does it still read it?
Shouldn’t do. Postgres is usually pretty good at making these types of optimisations.
Same - the row format itself starts with a bitmask listing all null columns. You don’t need to read the column data itself to determine if a column is null.

https://www.postgresql.org/docs/current/storage-page-layout....