Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1joUWp-0000ut-2q for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2020 16:15:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1joUWo-00049i-1a for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2020 16:15:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1joUWn-00049b-Lz for pgsql-hackers@lists.postgresql.org; Thu, 25 Jun 2020 16:15:05 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1joUWk-0004S0-C7 for pgsql-hackers@postgresql.org; Thu, 25 Jun 2020 16:15:04 +0000 Received: by mail-pj1-x1029.google.com with SMTP id d6so3448471pjs.3 for ; Thu, 25 Jun 2020 09:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :mime-version:content-transfer-encoding; bh=2smGwvoJzTJekiljQLOi0H13LNHPucCqIDsyBC6tw+c=; b=OXyfnUjCaeHXyQlG2KVYBfNNZ3RGYKRkCUYez+hTBI5LgqaxtIVQMMO2aJZcNXqNxV t4baDqOZzRUcdonyNv+pvwNQpIvHcODzgFU7SYV0aCRuepWbgbcxW7MrXttTCjvvsee2 3Tl8/LkJ6x+X1nEguVl+yfOUVmUfLqY/Jw5F08B9le8dybOoVcsdc1D7P9ZZ1UAimbXd fyIZYJAYQZ6E39/gBp9sVg4ieuSnpJy8E3gUWwLhp3WmySLlZNua+QZnd8+OS2SKKlYx MM7vVXUjZHJ/L5+I7RukD1T7iIw2o8zwQqEmRy9dKZXj9hR0vp1wyT9/liAwL+O2UFG0 KPpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=2smGwvoJzTJekiljQLOi0H13LNHPucCqIDsyBC6tw+c=; b=k04vlC0zERY55QllFDnrQtXtvSyORg8Nrrcm8Ga71glfOJM+2w3vc8YVK5ethKg8Ad 22VsYQWxlhht4y9lqHbmpHlIADjMuSzn1SOL8v8fasyLqSGOtCGOLeLX7WBLwBhI6YvD MhnomyGkxQtd8pwJ/Lt0enOZuT9TmfRfJLT+BvJe4eJkNrsxcjHx/1qrdLXssqJOTm9R OzUjRH98BlmkSjDR2TWdB+PJbwmaWZnL3Ytopx5bkAtyoNvKaEfHXunqV0Csl5llUEdh TmFNOepddKunxR9t8AT+IClMD/s2eb7Og5yX2e1ZK2/Gk5Akq/E9VYNBkLVHdvifULni hmSA== X-Gm-Message-State: AOAM533aIL5ZRPJWwOqccllaPKhfn2pD0ipXdaiT2ICZXHxN6GuPf21W 9YW9n0G9+obNcc+BE5hdQYtetQ== X-Google-Smtp-Source: ABdhPJxKYF+suVitEnClwQnbmRqxGzY4mjNKoP1VDPOp1iQBHXDBY4Vf2g+otfp1+mYkN7vWqFYZvg== X-Received: by 2002:a17:90b:1282:: with SMTP id fw2mr4144922pjb.144.1593101700189; Thu, 25 Jun 2020 09:15:00 -0700 (PDT) Received: from jdavis.lan (c-73-231-146-4.hsd1.ca.comcast.net. [73.231.146.4]) by smtp.gmail.com with ESMTPSA id g3sm1908230pfq.19.2020.06.25.09.14.58 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Jun 2020 09:14:58 -0700 (PDT) Message-ID: <1e75737369e1b6182ebaef7d6bbe098ad620bbb6.camel@j-davis.com> Subject: Re: Default setting for enable_hashagg_disk From: Jeff Davis To: Robert Haas , Andres Freund Cc: David Rowley , Justin Pryzby , Melanie Plageman , Tomas Vondra , "pgsql-hackers@postgresql.org" Date: Thu, 25 Jun 2020 09:14:56 -0700 In-Reply-To: References: <6292f5a766198d5745eb8cc17ac736366056671d.camel@j-davis.com> <20200610021544.GA14879@telsasoft.com> <8bff2e4e8020c3caa16b61a46918d21b573eaf78.camel@j-davis.com> <129c8f1739957589584d9525e1d8782eae3f412f.camel@j-davis.com> <20200624191433.5gnqgrxfmucexldm@alap3.anarazel.de> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, 2020-06-24 at 15:28 -0400, Robert Haas wrote: > On Wed, Jun 24, 2020 at 3:14 PM Andres Freund > wrote: > > FWIW, my gut feeling is that we'll end up have to separate the > > "execution time" spilling from using plain work mem, because it'll > > trigger spilling too often. E.g. if the plan isn't expected to > > spill, > > only spill at 10 x work_mem or something like that. Or we'll need > > better management of temp file data when there's plenty memory > > available. ... > I think that's actually pretty appealing. Separating the memory we > plan to use from the memory we're willing to use before spilling > seems > like a good idea in general, and I think we should probably also do > it > in other places - like sorts. I'm trying to make sense of this. Let's say there are two GUCs: planner_work_mem=16MB and executor_work_mem=32MB. And let's say a query comes along and generates a HashAgg path, and the planner (correctly) thinks if you put all the groups in memory at once, it would be 24MB. Then the planner, using planner_work_mem, would think spilling was necessary, and generate a cost that involves spilling. Then it's going to generate a Sort+Group path, as well. And perhaps it estimates that sorting all of the tuples in memory would also take 24MB, so it generates a cost that involves spilling to disk. But it has to choose one of them. We've penalized plans at risk of spilling to disk, but what's the point? The planner needs to choose one of them, and both are at risk of spilling to disk. Regards, Jeff Davis