Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 6371AB5DBD3 for ; Mon, 20 Jun 2011 13:08:37 -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 36821-03 for ; Mon, 20 Jun 2011 16:08:31 +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 67727B5D90E for ; Mon, 20 Jun 2011 13:08:23 -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 p5KG8JwF006962; Mon, 20 Jun 2011 12:08:19 -0400 (EDT) To: Jon Nelson cc: pgsql-performance@postgresql.org Subject: Re: bad plan: 8.4.8, hashagg, work_mem=1MB. In-reply-to: References: Comments: In-reply-to Jon Nelson message dated "Mon, 20 Jun 2011 10:53:52 -0500" Date: Mon, 20 Jun 2011 12:08:19 -0400 Message-ID: <6961.1308586099@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: 201106/183 X-Sequence-Number: 44116 Jon Nelson writes: > I ran a query recently where the result was very large. The outer-most > part of the query looked like this: > HashAggregate (cost=56886512.96..56886514.96 rows=200 width=30) > -> Result (cost=0.00..50842760.97 rows=2417500797 width=30) > The row count for 'Result' is in the right ballpark, but why does > HashAggregate think that it can turn 2 *billion* rows of strings (an > average of 30 bytes long) into only 200? 200 is the default assumption about number of groups when it's unable to make any statistics-based estimate. You haven't shown us any details so it's hard to say more than that. regards, tom lane