X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5EDC79DC834 for ; Sat, 28 Jan 2006 13:37:07 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 11321-08 for ; Sat, 28 Jan 2006 13:37:05 -0400 (AST) 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 86B5C9DC81E for ; Sat, 28 Jan 2006 13:37:03 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k0SHb0Ce018416; Sat, 28 Jan 2006 12:37:00 -0500 (EST) To: "Jeffrey W. Baker" cc: pgsql-performance@postgresql.org Subject: Re: Huge Data sets, simple queries In-reply-to: <1138468133.9336.5.camel@noodles> References: <007101c623a9$82207c10$0200a8c0@videobox> <11814.1138463702@sss.pgh.pa.us> <1138468133.9336.5.camel@noodles> Comments: In-reply-to "Jeffrey W. Baker" message dated "Sat, 28 Jan 2006 09:08:53 -0800" Date: Sat, 28 Jan 2006 12:37:00 -0500 Message-ID: <18415.1138469820@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.1 required=5 tests=[AWL=0.100] X-Spam-Score: 0.1 X-Spam-Level: X-Archive-Number: 200601/461 X-Sequence-Number: 16939 "Jeffrey W. Baker" writes: > On Sat, 2006-01-28 at 10:55 -0500, Tom Lane wrote: >> Assuming that "month" means what it sounds like, the above would result >> in running twelve parallel sort/uniq operations, one for each month >> grouping, to eliminate duplicates before counting. You've got sortmem >> set high enough to blow out RAM in that scenario ... > Hrmm, why is it that with a similar query I get a far simpler plan than > you describe, and relatively snappy runtime? You can't see the sort operations in the plan, because they're invoked implicitly by the GroupAggregate node. But they're there. Also, a plan involving GroupAggregate is going to run the "distinct" sorts sequentially, because it's dealing with only one grouping value at a time. In the original case, the planner probably realizes there are only 12 groups and therefore prefers a HashAggregate, which will try to run all the sorts in parallel. Your "group by date" isn't a good approximation of the original conditions because there will be a lot more groups. (We might need to tweak the planner to discourage selecting HashAggregate in the presence of DISTINCT aggregates --- I don't remember whether it accounts for the sortmem usage in deciding whether the hash will fit in memory or not ...) regards, tom lane