Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 3AC981337B6E for ; Thu, 13 Jan 2011 13:13:31 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 89662-04 for ; Thu, 13 Jan 2011 17:13:24 +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 C77DF1337B68 for ; Thu, 13 Jan 2011 13:13:23 -0400 (AST) 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 p0DHDMDl019303; Thu, 13 Jan 2011 12:13:22 -0500 (EST) To: Jon Nelson cc: pgsql-performance@postgresql.org Subject: Re: queries with lots of UNIONed relations In-reply-to: References: Comments: In-reply-to Jon Nelson message dated "Thu, 13 Jan 2011 09:55:31 -0600" Date: Thu, 13 Jan 2011 12:13:22 -0500 Message-ID: <19302.1294938802@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: 201101/77 X-Sequence-Number: 41864 Jon Nelson writes: > In the former case, the query plan was a bitmap heap scan for each > table. Then those results were Appended, Sorted, Uniqued, Sorted > again, and then returned. > In the latter, before Appending, each table's results were run through > HashAggregate. Probably the reason it did that is that each individual de-duplication looked like it would fit in work_mem, but a single de-duplication didn't. Consider raising work_mem, at least for this one query. regards, tom lane