Re: Efficiency question: VARCHAR with empty string

From: Doug Fields <dfields-pg-general(at)pexicom(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Efficiency question: VARCHAR with empty string
Date: 2002-05-24 19:10:45
Message-ID: 5.1.0.14.2.20020524150418.01ecdeb8@mail.pexicom.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

At 02:54 PM 5/24/2002, you wrote:
>Doug Fields <dfields-pg-general(at)pexicom(dot)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:

Sorry, I haven't used Oracle in quite some time so I don't have any bad
Oracle-isms. :)

Thanks, Tom. Yes, I am aware of this already and my application largely
doesn't care (i.e. in the places it does it asks = '' as well as OR IS
NULL, but in most places it doesn't bother because it doesn't matter).

I'm merely trying to wring the last ounce of performance from the database,
especially given that most of these columns are rarely searched and
certainly not indexed.

>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.

So, in essence, having a zero-length VARCHAR requires no additional page
loads (from the VARCHAR heap, if such a thing is used) and does not
increase the record size over having NULLs? My intent is to make this query
as fast as possible and require as few disk hits: SELECT * FROM table with
this many VARCHAR'd table.

Thanks,

Doug

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Doug Fields 2002-05-24 19:15:51 Re: Case Insensitive Data Type
Previous Message Doug Fields 2002-05-24 19:04:05 Re: Altering existing table to be WITHOUT OIDs

Browse pgsql-sql by date

  From Date Subject
Next Message Ron Peterson 2002-05-24 19:28:07 Re: Trees in SQL
Previous Message Tom Lane 2002-05-24 18:54:14 Re: Efficiency question: VARCHAR with empty string vs NULL