From: Doug Fields <dfields-pg-general@pexicom.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-general@postgresql.org
Subject: Re: Efficiency question: VARCHAR with empty string
Date: Fri, 24 May 2002 15:10:45 -0400
Message-ID: <5.1.0.14.2.20020524150418.01ecdeb8@mail.pexicom.com> (raw)
In-Reply-To: <13510.1022266454@sss.pgh.pa.us>
References: <5.1.0.14.2.20020524131720.02c09fa0@mail.pexicom.com>
<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>
At 02:54 PM 5/24/2002, you wrote:
>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:
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
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: dfields-pg-general@pexicom.com, tgl@sss.pgh.pa.us, pgsql-general@postgresql.org
Subject: Re: Efficiency question: VARCHAR with empty string
In-Reply-To: <5.1.0.14.2.20020524150418.01ecdeb8@mail.pexicom.com>
* 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