Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] space usage of NULL fields

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: honza(at)ied(dot)com (Jan Vicherek)
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] space usage of NULL fields
Date: 1998-12-27 16:00:54
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
>   Hello,
>     a quick question (I couldn't contact, so I didn't check
> the FAQ, but I doubt it would be there.)
>    When I create a table with field "nnn float8" and total row size, say
> 140 bytes, and then I insert a row with NULL in this field, will my record
> take up those 8 bytes in physical page (say 140 bytes) or will it take up
> less (like 140-8=132), i.e. will it be shortened by those 8 bytes, since
> the value is NULL and no information is stored in that field ? ( I *hate*
> run-on sentences :)

Shorter.  Nulls are not stored in the row.  There is a bitmask on every
row that shows the number of NULL fields.

>    In general, what are the savings/overheads associated in PG with
> NULL/not NULL fields ? I.e. if will I save the space if I define the field
> as varchar(8) instead of float8  ?

no. float8 is shorter because varchar has 4-byte overhead.  The faq is
in docs/FAQ too.

  Bruce Momjian                        |
  maillist(at)candle(dot)pha(dot)pa(dot)us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

In response to

pgsql-hackers by date

Next:From: Terry MackintoshDate: 1998-12-27 17:35:02
Subject: regression test: triggers fial:
Previous:From: Angelos KarageorgiouDate: 1998-12-27 10:49:02
Subject: pg_hba.conf

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group