6 ms·
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 missin
by jng 4y 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?
- nattaylor 4y agoIt does have to read it because NULLs aren't counted
- teddyh 4y agoIf the column is NOT NULL, does it still read it?
- avianlyric 4y agoShouldn’t do. Postgres is usually pretty good at making these types of optimisations.
- zeroimpl 4y agoSame - 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.html https://www.postgresql.org/docs/current/storage-page-layout....
- nicwolff 4y agoPg 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).