Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id BF8B1632EE5 for ; Tue, 27 Jul 2010 15:25:35 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 84272-10 for ; Tue, 27 Jul 2010 18:25:27 +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 56172632F28 for ; Tue, 27 Jul 2010 15:25:28 -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 o6RIPPMb010771; Tue, 27 Jul 2010 14:25:25 -0400 (EDT) To: "Kneringer, Armin" cc: "pgsql-performance@postgresql.org" Subject: Re: potential performance gain by query planner optimization In-reply-to: <12F45C8182386842930DCE2051B2AA601AD60AC1@fabamailserver.fabagl.fabasoft.com> References: <12F45C8182386842930DCE2051B2AA601AD60AC1@fabamailserver.fabagl.fabasoft.com> Comments: In-reply-to "Kneringer, Armin" message dated "Tue, 20 Jul 2010 16:25:55 -0000" Date: Tue, 27 Jul 2010 14:25:25 -0400 Message-ID: <10770.1280255125@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: 201007/403 X-Sequence-Number: 39792 "Kneringer, Armin" writes: > I think I found a potential performance gain if the query planner would be optimized. All Tests has been performed with 8.4.1 (and earlier versions) on CentOS 5.3 (x64) > The following query will run on my database (~250 GB) for ca. 1600 seconds and the sort will result in a disk merge deploying ca. 200 GB of data to the local disk (ca. 180.000 tmp-files) What have you got work_mem set to? It looks like you must be using an unreasonably large value, else the planner wouldn't have tried to use a hash join here: > -> Hash (cost=11917516.57..11917516.57 rows=55006045159 width=16) > -> Nested Loop (cost=0.00..11917516.57 rows=55006045159 width=16) > -> Seq Scan on atdateval t5 (cost=0.00...294152.40 rows=1859934 width=12) > Filter: (attrid = 281479288456447::bigint) > -> Index Scan using ind_ataggval on ataggval q1_1 (cost=0.00..6.20 rows=4 width=12) > Index Cond: ((q1_1.attrid = 281479288456451::bigint) AND (q1_1.aggval = t5.aggrid)) > Filter: (q1_1.aggrid = 0) Also, please try something newer than 8.4.1 --- this might be some already-fixed bug. regards, tom lane