Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 297F7476476 for ; Mon, 13 Jan 2003 16:44:37 -0500 (EST) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by postgresql.org (Postfix) with ESMTP id 84F6947626A for ; Mon, 13 Jan 2003 16:44:36 -0500 (EST) Received: from [66.219.92.2] (HELO chocolate-mousse) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 2312560; Mon, 13 Jan 2003 13:44:42 -0800 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Christopher Smith , pgsql-sql@postgresql.org Subject: Re: query speed joining tables Date: Mon, 13 Jan 2003 13:47:49 -0800 X-Mailer: KMail [version 1.4] References: <20030113212052.60493.qmail@web14107.mail.yahoo.com> In-Reply-To: <20030113212052.60493.qmail@web14107.mail.yahoo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200301131347.49013.josh@agliodbs.com> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/188 X-Sequence-Number: 11053 Chris, Here are probably your two main query problems: > strpos(user_match_details.ethnicity,'Asian') !=3D0 AND It is impossible for Postgres to use an index for the above as it is writte= n.=20=20 I would suggest one of two improvements; 1) Modify the schema so that multiple ethnicity details are kept in a=20 sub-table rather than a free-form text field you have to search, or: 2) Create a cachable function for "contains_asian" and index on that. > user_details_p.zipcode in (select zips_max.destination from zips_max wher= e=20 zips_max.origin=3D'90210' ) > order by user_login.last_login desc; Use a "WHERE EXISTS" clause instead of "IN".=20=20 --=20 -Josh Berkus Aglio Database Solutions San Francisco