X-Original-To: pgsql-performance@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id F20004763CE for ; Wed, 7 May 2003 12:39:11 -0400 (EDT) Received: from t-9.net (unknown [64.246.36.43]) by postgresql.org (Postfix) with SMTP id F154C476501 for ; Wed, 7 May 2003 12:38:59 -0400 (EDT) Received: (qmail 16334 invoked by uid 0); 7 May 2003 14:43:28 -0000 Received: from localhost (HELO seahat.com) (127.0.0.1) by localhost with SMTP; 7 May 2003 14:43:28 -0000 Received: from 65.102.128.233 (SquirrelMail authenticated user snubber@seahat.com) by fordparts.com with HTTP; Wed, 7 May 2003 09:43:28 -0500 (CDT) Message-ID: <10192.65.102.128.233.1052318608.squirrel@fordparts.com> Date: Wed, 7 May 2003 09:43:28 -0500 (CDT) Subject: Re: Yet another 'why does it not use my index' question. From: "Ryan" To: In-Reply-To: <20030507162815.GA27158@wolff.to> References: <11207.65.102.128.233.1052316709.squirrel@fordparts.com> <20030507162815.GA27158@wolff.to> X-Priority: 3 Importance: Normal Cc: X-Mailer: SquirrelMail (version 1.2.8) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, hits=-25.1 required=5.0 tests=BAYES_01,IN_REP_TO,MSG_ID_ADDED_BY_MTA_3,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200305/85 X-Sequence-Number: 1864 > On Wed, May 07, 2003 at 09:11:49 -0500, > Ryan wrote: >> I wanted to do the following: >> >> midas=3D# explain analyze select * from zip where zip in >> (select option_value from client_options where option_name =3D >> 'ZIP_CODE' ); > > Until 7.4 comes out IN will be slow and you should use a join to do > this. > >> midas=3D# explain analyze select * from zip z, client_options c where >> c.option_name =3D 'ZIP_CODE' and c.option_value =3D z.zip; > > I think the problem here might be related to option_value being text and > zip being char varying. This might prevent an index from being used to > do the join. HMMMM. I'll have to re-insert that table (it was a dbf2pg job) and change that. Any reason why postgres is so picky about varchar/text conversion, considering they are practally the same thing? Something intresting however. If I do this: select * from zip where zip =3D 98404; I get a seq scan, as postgres types it to text. but if I do this: select * from zip where zip =3D '98404'; Postgres types it as character varying and uses the index. Not that it would happen any time soon, but it would be nice if explain analyze would tell you why it chose an seq scan on an indexed field. (e.g. You should know better than to try an index with a different type!) Ryan