Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHHAZ-0001tf-4w for pgsql-general@arkaria.postgresql.org; Tue, 21 Nov 2017 22:37:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHHAY-0002vK-OE for pgsql-general@arkaria.postgresql.org; Tue, 21 Nov 2017 22:37:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eHHAY-0002v9-IG for pgsql-general@lists.postgresql.org; Tue, 21 Nov 2017 22:37:30 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eHHAU-0001QI-FN for pgsql-general@postgresql.org; Tue, 21 Nov 2017 22:37:30 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id vALMbNVX004347; Tue, 21 Nov 2017 17:37:23 -0500 From: Tom Lane To: Thomas Munro cc: Cory Tucker , "pgsql-general@postgresql.org" Subject: Re: [GENERAL] Query Using Massive Temp Space In-reply-to: References: <16625.1511199408@sss.pgh.pa.us> <12076.1511287447@sss.pgh.pa.us> Comments: In-reply-to Thomas Munro message dated "Wed, 22 Nov 2017 10:18:40 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4345.1511303843.1@sss.pgh.pa.us> Date: Tue, 21 Nov 2017 17:37:23 -0500 Message-ID: <4346.1511303843@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Thomas Munro writes: > On Wed, Nov 22, 2017 at 7:04 AM, Tom Lane wrote: >> Now, there's definitely something busted here; it should not have gone as >> far as 2 million batches before giving up on splitting. > I had been meaning to discuss this. We only give up when we reach the > point when a batch is entirely entirely kept or sent to a new batch > (ie splitting the batch resulted in one batch with the whole contents > and another empty batch). If you have about 2 million evenly > distributed keys and an ideal hash function, and then you also have 42 > billion keys that are the same (and exceed work_mem), we won't detect > extreme skew until the 2 million well behaved keys have been spread so > thin that the 42 billion keys are isolated in a batch on their own, > which we should expect to happen somewhere around 2 million batches. Yeah, I suspected it was something like that, but hadn't dug into the code yet. > I have wondered if our extreme skew detector needs to go off sooner. > I don't have a specific suggestion, but it could just be something > like 'you threw out or kept more than X% of the tuples'. Doing this, with some threshold like 95% or 99%, sounds plausible to me. I'd like to reproduce Cory's disk-space issue before we monkey with related logic, though; fixing the part we understand might obscure the part we still don't. regards, tom lane