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 88A279FA605; Mon, 3 Jul 2006 20:06:02 -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 87415-04; Mon, 3 Jul 2006 20:05:56 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- X-Greylist: from auto-whitelisted by SQLgrey- Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.171]) by postgresql.org (Postfix) with ESMTP id 77DB89FA60B; Mon, 3 Jul 2006 20:05:56 -0300 (ADT) Received: from [84.12.170.54] (helo=[192.168.0.2]) by mrelayeu.kundenserver.de (node=mrelayeu1) with ESMTP (Nemesis), id 0MKwpI-1FxXUG16Ni-0002OL; Tue, 04 Jul 2006 01:05:52 +0200 Subject: Re: query very slow when enable_seqscan=on From: Simon Riggs To: Tomasz Ostrowski Cc: pgsql-bugs@postgresql.org, pgsql-performance@postgresql.org In-Reply-To: <20060703203105.GA2801@batory.org.pl> References: <20060703203105.GA2801@batory.org.pl> Content-Type: text/plain Date: Tue, 04 Jul 2006 00:05:42 +0100 Message-Id: <1151967943.2479.330.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 (2.6.1-1.fc5.2) Content-Transfer-Encoding: 7bit X-Provags-ID: kundenserver.de abuse@kundenserver.de login:726643fe08f41a451f0fe7fa43bce239 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/14 X-Sequence-Number: 15359 On Mon, 2006-07-03 at 22:31 +0200, Tomasz Ostrowski wrote: > I have a very slow query when enable_seqscan=on and very fast when > enable_seqscan=off. My schema looks like this (relevant columns > only): > PS. Actual table and column names are different (they're in Polish) > but I've translated them for better readability for english-speaking. Thanks > PS. I wonder if it makes sense to "enable_seqscan=off" for every client > if a database is small enough to fit in OS cache. You can set this for individual statements if you choose to. > -> 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) The issue is caused by the under-estimation of the number of rows in the table as a result of the regular expression comparison. As a result the planner thinks it can choose a nested loops scan, though ends up doing 1892 seq scans of persons, when it thought it would do only one. The under estimation is a known issue. Posting to -perform for the record. -- Simon Riggs EnterpriseDB http://www.enterprisedb.com