Received: from sss.pgh.pa.us (sss.pgh.pa.us [209.114.132.154]) by mail.postgresql.org (8.11.3/8.11.1) with ESMTP id f2NGU5w98249 for ; Fri, 23 Mar 2001 11:30:06 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.1/8.11.1) with ESMTP id f2NGTu618218; Fri, 23 Mar 2001 11:29:56 -0500 (EST) To: Alexaki Sofia cc: pgsql-sql@postgresql.org Subject: Re: Btree index on varchar In-reply-to: References: Comments: In-reply-to Alexaki Sofia message dated "Fri, 23 Mar 2001 12:59:14 +0200" Date: Fri, 23 Mar 2001 11:29:56 -0500 Message-ID: <18214.985364996@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200103/464 X-Sequence-Number: 2132 Alexaki Sofia writes: > I have a question for Btree indexes on a varchar field. > Does postgres (7.0.2) uses a special encoding when creating > Btree indexes on varchar?? "Special encoding"? No ... a varchar is a varchar. > Is it much more efficient to create indexes on integer than > on strings with average length 30 chars?? It'd save some space and thereby save I/O time. But I dunno about "much" more efficient. Figuring that there's a dozen or so bytes of index-entry overhead in addition to the value itself, you might be looking at a factor of 3 or so difference in index tuple size, hence about a 3x savings in I/O for index scans; but that wouldn't translate to anything like a factor of 3 for the total operation, since the number of main-table tuples visited wouldn't change. Try it and see, but I'd guess that the net effect would be relatively small. Really what you want to be asking yourself is which columns do you need an index on for your query logic. What datatype they are is a minor consideration. regards, tom lane