pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Doug Fields <dfields-pg-general@pexicom.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Efficiency question: VARCHAR with empty string vs NULL
Date: Fri, 24 May 2002 14:54:14 -0400
Message-ID: <13510.1022266454@sss.pgh.pa.us> (raw)
In-Reply-To: <5.1.0.14.2.20020524131720.02c09fa0@mail.pexicom.com>
References: <Pine.LNX.4.21.0205231506380.12663-100000@ponder.fairway2k.co.uk>
	<Pine.LNX.4.21.0205231506380.12663-100000@ponder.fairway2k.co.uk>
	<5.1.0.14.2.20020524131720.02c09fa0@mail.pexicom.com>

Doug Fields <dfields-pg-general@pexicom.com> writes:
> Is there a performance difference with VARCHAR elements of value NULL and 
> zero-length string?

These are not semantically equivalent (if you think they are, you've
been using Oracle too long).  You will almost certainly regret it
if you try recoding your app to make them equivalent.  An example:

regression=# select 'foo'::varchar || ''::varchar;
 ?column?
----------
 foo
(1 row)

regression=# select 'foo'::varchar || null::varchar;
 ?column?
----------

(1 row)


But to answer your question, NULLs might save a couple bytes if there
are multiple NULLs per row.  I think that replacing a single empty
varchar with a NULL would net out to no change (you lose the 4-byte
varchar length word, but have to store a null-values bitmap instead),
depending on alignment issues and how many columns there are in the
table.

			regards, tom lane



view thread (3+ messages)  latest in thread

Message-ID: <13510.1022266454@sss.pgh.pa.us>
Permalink:  ../13510.1022266454@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/13510.1022266454@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, dfields-pg-general@pexicom.com, pgsql-general@postgresql.org
  Subject: Re: Efficiency question: VARCHAR with empty string vs NULL
  In-Reply-To: <13510.1022266454@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox