Basically, NULL values occupy 1 bit in a NULL raster file. But it is not so simple.
a zero bitmap (for each row) exists only if at least one column in this row contains a NULL value. This can lead to a paradox effect in tables with 9 or more columns: assigning the first NULL value to a column can take up more disk space than writing a value to it. Conversely, with the last non-zero column, the zero bitmap is discarded for the row.
Physically, the original null bitmap takes 1 byte between the HeapTupleHeader (23 bytes) and the actual column data or OID string (if you still have to use this), which always starts with a multiple of MAXALIGN (usually 8 bytes ). This leaves 1 fill byte, which is used by the original zero bitmap.
In fact, NULL storage is completely free for tables of 8 columns or less .
After that, for the next columns of MAXALIGN * 8 , MAXALIGN bytes are allocated (usually 8) (usually 64). Etc.
More details in the manual and on these related issues:
- How much disk space is needed to store a NULL value using postgresql DB?
- Doesn’t NULL in PostgreSQL still use a NULL bitmap in the header?
- How many records can I store in 5 MB PostgreSQL on Heroku?
After you understand the alignment of data elements, you can further optimize storage:
- Calculating and saving space in PostgreSQL
But cases are rare when you can save a significant amount of space. This is usually not worth the effort.
@Daniel already covers effects on index size.
Erwin Brandstetter Aug 27 '12 at 18:04 2012-08-27 18:04
source share