Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 4DCD34762AF for ; Fri, 24 May 2002 15:20:47 -0400 (EDT) Received: from a.mail.pexicom.com (a.mail.pexicom.com [64.125.181.59]) by postgresql.org (Postfix) with ESMTP id DD72A476536 for ; Fri, 24 May 2002 15:10:58 -0400 (EDT) Received: from vaio.dpf.cc ([209.10.243.34] helo=vaio.pexicom.com) by a.mail.pexicom.com with esmtp (SSLv3:DES-CBC3-SHA:168) (Exim 3.35 #1) id 17BKSj-0005XB-00; Fri, 24 May 2002 15:10:53 -0400 Message-Id: <5.1.0.14.2.20020524150418.01ecdeb8@mail.pexicom.com> X-Sender: fields@mail.pexicom.com X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Fri, 24 May 2002 15:10:45 -0400 To: Tom Lane From: Doug Fields Subject: Re: Efficiency question: VARCHAR with empty string Cc: pgsql-general@postgresql.org In-Reply-To: <13510.1022266454@sss.pgh.pa.us> References: <5.1.0.14.2.20020524131720.02c09fa0@mail.pexicom.com> <5.1.0.14.2.20020524131720.02c09fa0@mail.pexicom.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Archive-Number: 200205/904 X-Sequence-Number: 24884 At 02:54 PM 5/24/2002, you wrote: >Doug Fields 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