Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id CAE5E475FEB for ; Wed, 2 Oct 2002 13:53:20 -0400 (EDT) Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 270C6475E2E for ; Wed, 2 Oct 2002 13:53:20 -0400 (EDT) Received: from [66.219.92.2] (HELO chocolate-mousse) by davinci.ethosmedia.com (CommuniGate Pro SMTP 3.5.9) with ESMTP id 1737643; Wed, 02 Oct 2002 10:53:54 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: "Beth Gatewood" , "'Bruce Momjian'" Subject: Re: indexing on char vs varchar Date: Wed, 2 Oct 2002 10:55:22 -0700 X-Mailer: KMail [version 1.4] Cc: References: <000001c26a36$c1a48c80$0c00000a@bethvizx> In-Reply-To: <000001c26a36$c1a48c80$0c00000a@bethvizx> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200210021055.22641.josh@agliodbs.com> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/23 X-Sequence-Number: 9741 Beth, > Sorry....I don't understand. The length is at the front of what? In some RDBMSs, the VARCHAR data type has a 2 or 4-byte indicator of the=20 length of the stored string before the data itself, while CHAR does not=20 require this information because it is fixed-length. This makes the CHAR= =20 datatype marginally smaller, and thus faster, than the VARCHAR data type on= =20 those databases. This difference goes back to much older databases and=20 computers, where every byte of a row counted in terms of performance. In my experience, even though MS SQL Server still functions this way, the= =20 performance difference between CHAR and VARCHAR is not measurable unless yo= u=20 are getting close to the 8K data page limit that MSSQL imposes. YMMV. Postgres does not materially differentiate between CHAR, VARCHAR, and TEXT,= =20 except that CHAR is padded by spaces and VARCHAR often has a length limit.= =20=20=20 However, in terms of storage efficiency (and indexing efficiency), they are= =20 identical. In Postgres, the character count is included in all string data= =20 types. Thus, you should use the data type most appropriate to the data you are=20 storing, ignoring performance issues. If the data is a fixed-length string= =20 (such as a required zip code) use CHAR; if it's variable but limited, use= =20 varchar; if it's a long description, use TEXT. --=20 -Josh Berkus Aglio Database Solutions San Francisco