Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TXD33-0003So-Na for pgsql-performance@postgresql.org; Sat, 10 Nov 2012 15:32:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TXD31-00015X-Fx for pgsql-performance@postgresql.org; Sat, 10 Nov 2012 15:32:41 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id qAAFWPMD009131; Sat, 10 Nov 2012 10:32:26 -0500 (EST) From: Tom Lane To: postgresql@os10000.net cc: pgsql-performance@postgresql.org Subject: Re: parallel query evaluation In-reply-to: <214a89820818a3da44bcadb4ab829c14@os10000.net> References: <214a89820818a3da44bcadb4ab829c14@os10000.net> Comments: In-reply-to Oliver Seidel message dated "Thu, 08 Nov 2012 12:55:12 +0100" Date: Sat, 10 Nov 2012 10:32:25 -0500 Message-ID: <9130.1352561545@sss.pgh.pa.us> X-Pg-Spam-Score: -2.3 (--) X-Archive-Number: 201211/127 X-Sequence-Number: 48493 Oliver Seidel writes: > I have > create table x ( att bigint, val bigint, hash varchar(30) > ); > with 693million rows. The query > create table y as select att, val, count(*) as cnt from x > group by att, val; > ran for more than 2000 minutes and used 14g memory on an 8g physical > RAM machine What was the plan for that query? What did you have work_mem set to? I can believe such a thing overrunning memory if the planner chose to use a hash-aggregation plan instead of sort-and-unique, but it would only do that if it had made a drastic underestimate of the number of groups implied by the GROUP BY clause. Do you have up-to-date statistics for the source table? regards, tom lane