Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 77D579FA6BA for ; Wed, 29 Aug 2007 14:52:14 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 79336-03 for ; Wed, 29 Aug 2007 14:52:04 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id C97399F96B2 for ; Wed, 29 Aug 2007 14:52:05 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l7THpfJh007015; Wed, 29 Aug 2007 13:51:41 -0400 (EDT) To: Mark Lewis cc: Karthikeyan Mahadevan , pgsql-performance@postgresql.org Subject: Re: LIKE query verses = In-reply-to: <1188407551.22730.113.camel@archimedes> References: <1188407551.22730.113.camel@archimedes> Comments: In-reply-to Mark Lewis message dated "Wed, 29 Aug 2007 10:12:31 -0700" Date: Wed, 29 Aug 2007 13:51:41 -0400 Message-ID: <7014.1188409901@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/381 X-Sequence-Number: 26511 Mark Lewis writes: > What you probably want to do is tell PG that you're looking for a > literal underscore and not for any matching character by escaping the > underscore, that will allow it to do a much quicker index scan. The other half of the problem is that the planner is drastically misestimating the number of matching rows --- it thinks only one when there are really about a thousand, and this leads it to use a nestloop that will be very inefficient with so many rows. Try increasing the statistics target for that column. Also, if this is a pre-8.2 PG release, consider upgrading; I believe we improved the LIKE estimator in 8.2. regards, tom lane