X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id CFA6D475C26 for ; Mon, 3 Mar 2003 20:27:04 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 60854-08 for ; Mon, 3 Mar 2003 20:27:03 -0500 (EST) Received: from sabre.velocet.net (sabre.velocet.net [216.138.209.205]) by postgresql.org (Postfix) with ESMTP id 4D741475B84 for ; Mon, 3 Mar 2003 20:27:03 -0500 (EST) Received: from stark.dyndns.tv (H162.C233.tor.velocet.net [216.138.233.162]) by sabre.velocet.net (Postfix) with ESMTP id 01F391382A8; Mon, 3 Mar 2003 20:27:06 -0500 (EST) Received: from localhost ([127.0.0.1] helo=stark.dyndns.tv ident=foobar) by stark.dyndns.tv with smtp (Exim 3.36 #1 (Debian)) id 18q1Cz-0005hG-00; Mon, 03 Mar 2003 20:27:05 -0500 To: Stephan Szabo Cc: Michael Nachbaur , Subject: Re: Forcing query to use an index References: <20030303140649.H42776-100000@megazone23.bigpanda.com> In-Reply-To: <20030303140649.H42776-100000@megazone23.bigpanda.com> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 03 Mar 2003 20:26:59 -0500 Message-ID: <877kbfj50c.fsf@stark.dyndns.tv> Lines: 28 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new X-Archive-Number: 200303/104 X-Sequence-Number: 12144 > -> Merge Join (cost=6106.42..6335.30 rows=2679 width=265) (actual time=859.77..948.06 rows=1 loops=1) Actually another problem, notice the big discrepancy between the estimated row and the actual rows. That's because you have the big OR clause so postgres figures there's a good chance one of the clauses will be true so it estimates a lot of rows will match. In fact of course they're all very selective and you'll usually probably only get a few records. If you're stuck with the unanchored text search it will always do a full table scan so it will never be lightening fast. But it would probably be a bit faster if you put a limit clause (on a subquery) on the table that's doing the full table scan. That will convince postgres that there won't be thousands of resulting records, which might convince it to do a nested loop. Also, as a beneficial side effect will also limit the damage if one your users does a search for "e"... This only really helps if you can get rid of the OR CMS.package clause... otherwise it actually needs all the records in case they match a summary record with a kate package. -- greg