Re: - Mailing list pgsql-general

From Tom Lane
Subject Re:
Date
Msg-id 4773.1025808353@sss.pgh.pa.us
Whole thread Raw
In response to ...  (Francisco Reyes <lists@natserv.com>)
Responses Re:  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-general
Francisco Reyes <lists@natserv.com> writes:
> How much space does "NULL" takes on a varchar.

This is getting to be a FAQ itself --- Bruce, would you like to
add something along the following lines to the FAQ?

Q.  How much space does a NULL take?

A.  None; it's not stored.  However, if a table row contains any NULLs
then it must include a "nulls bitmap" that shows which columns are NULL.
The bitmap has one bit per table column.  The bitmap is omitted if the
row contains no NULLs at all.  So, in practice the first NULL you put in
a row costs number-of-columns bits.  Any additional NULLs in the same
row are completely free as far as storage space is concerned.

Also, the space effectively occupied by the bitmap depends on alignment
considerations, because the total size of the row header and bitmap
will be rounded up to a MAXALIGN boundary (either 4 or 8 bytes on
most hardware).  In 7.3 it's likely that a bitmap for a row of up to
8 columns will be completely free, because the rounded-up header size
will be the same with or without it.

            regards, tom lane



pgsql-general by date:

Previous
From: nconway@klamath.dyndns.org (Neil Conway)
Date:
Subject: Re: repeatable crash generating two column index
Next
From: Tom Lane
Date:
Subject: Re: repeatable crash generating two column index