Do NULLs take place in postgresql indexes?

While it is easily documented that NULLs only occupy 1 bit in the postgresql tuple header for a row, how many spaces does NULL occupy in an index with a null column (not a tuple, but an index)? Is it the same 1 bit in the index as in the tuple, or is it the total size of the column type data (EG: integer = 4 bytes)?

The context of the question is that I have a postgresql table in which there are 3 columns of links (EG: foo_id, bar_id and baz_id), and for any row only one of these columns will matter (the other 2 columns will be ZERO). However, I need all 3 columns to be indexed. Assuming each column is an integer (4 bytes in postgresql), each row should occupy 4 bytes (for a non-empty column) plus 2 bits (for 2 zero columns). However, if I were to add indexes for all three columns, then the storage for 3 indexes would be 12 bytes (if the index takes 4 bytes for a null value) or the same 4 bytes + 2 bits as in the tuple itself.

+5
source share
1 answer

The btree access routines use PageGetItem () to get the actual key from the index. Therefore, I believe that btree index pages use the same storage scheme as regular heap pages (including a zero-probability mask), they simply have additional navigation information in the "special" area of ​​the page to store all btree pointers.

+1
source

All Articles