X-Original-To: pgsql-bugs-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 34EB89FA66C for ; Mon, 3 Jul 2006 20:06:00 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 85458-09 for ; Mon, 3 Jul 2006 20:05:51 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 9B1309FA605 for ; Mon, 3 Jul 2006 20:05:50 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k63N5kWr007354; Mon, 3 Jul 2006 19:05:46 -0400 (EDT) To: Tomasz Ostrowski cc: pgsql-bugs@postgresql.org Subject: Re: query very slow when enable_seqscan=on In-reply-to: <20060703203105.GA2801@batory.org.pl> References: <20060703203105.GA2801@batory.org.pl> Comments: In-reply-to Tomasz Ostrowski message dated "Mon, 03 Jul 2006 22:31:07 +0200" Date: Mon, 03 Jul 2006 19:05:46 -0400 Message-ID: <7353.1151967946@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/13 X-Sequence-Number: 15358 Tomasz Ostrowski writes: > I have a very slow query when enable_seqscan=on and very fast when > enable_seqscan=off. Here's your problem: > -> Seq Scan on organization (cost=0.00..480.95 rows=1 width=4) (actual time=0.071..69.702 rows=1892 loops=1) > Filter: ((organization_location)::text ~* 'warszawa'::text) If it were estimating something like the actual number of rows matching that filter, it'd never have chosen a nestloop plan like that. How many rows are there in the organization table? This is probably the fault of the pattern-selectivity heuristic: it's far too optimistic about long match strings eliminating a lot of rows. I think there's been some discussion of modifying that logic but no one's really stepped up with a better idea. regards, tom lane