Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id DDD3A6329B5 for ; Thu, 17 Jun 2010 11:59:28 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 78827-07 for ; Thu, 17 Jun 2010 14:59:21 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 7734F63225A for ; Thu, 17 Jun 2010 11:59:21 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o5HEwaY8003776; Thu, 17 Jun 2010 10:58:37 -0400 (EDT) To: "Kaufhold, Christian (LFD)" cc: pgsql-performance@postgresql.org Subject: Re: Query slow after analyse on postgresql 8.2 In-reply-to: <0694BCCA1B37BE4B8FEB01807799BD540142B47F@BLFD_2.lfd.bayern.de> References: <0694BCCA1B37BE4B8FEB01807799BD540142B47F@BLFD_2.lfd.bayern.de> Comments: In-reply-to "Kaufhold, Christian (LFD)" message dated "Thu, 17 Jun 2010 09:52:33 +0200" Date: Thu, 17 Jun 2010 10:58:36 -0400 Message-ID: <3775.1276786716@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/310 X-Sequence-Number: 39166 "Kaufhold, Christian (LFD)" writes: > I have the following query that I run agains postgresql 8.2: > ... > But when I run analyse the same query runs for hours. Seems like the core of the problem is here: > -> Seq > Scan on massnahmeobjekt m (cost=0.00..3271.88 rows=1 width=94) (actual > time=0.387..577.771 rows=3694 loops=1) > Filter: ((aktennummer)::text ~* 'M\\-2009\\-1'::text) If that rowcount estimate weren't off by three orders of magnitude you probably would be getting a more appropriate plan. The first thing you could try is increasing the statistics target for aktennummer. Also, if you're running in a non-C locale and this is 8.2.5 or older, try a more recent 8.2.x. Updating to 8.3 or 8.4 might help even more. regards, tom lane