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 1jLwsD-0000bH-Vd for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2020 22:39:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jLwsC-0003uF-9q for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2020 22:39:12 +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 1jLwsB-0003u8-Vv for pgsql-hackers@lists.postgresql.org; Tue, 07 Apr 2020 22:39:12 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jLws5-0001tT-2r for pgsql-hackers@postgresql.org; Tue, 07 Apr 2020 22:39:11 +0000 Received: by mail-qt1-x841.google.com with SMTP id f20so4115548qtq.6 for ; Tue, 07 Apr 2020 15:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=q7lgf7nq2BSEyCmRJl9+AwCWAAHgcauq12ChoFHvjSE=; b=otKGgv1fHTb+E2FtKuhm6EX0FAaPTN7L318oj/tPQOog6Q32bJ0LwiontdOIqvkADo UsVRVZFPupy6KFWX0E2dVRVJHtyii8+ThJFBjFOdthvlZIWVwtKxjkJPWgi+TCYQIzs3 6nDdzSVwlsKu1W8ZVoL7R+5u2viDSZAWKjmGKfemlZCYemrBJyyEyOAl0S0wWqSPI+5R znCuFWpuQ28p8lzUeOUihQbuujkvftnIdxG1Hs04/cEUdz/qzk7VMVcfsOJb7okJxrG1 WAvBIQgkNtyQPbhkU0bVKKkroocZhIK5bXbfsAcv3+8yuJtT24jCUMHspf2fmVXkzMwq RkvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=q7lgf7nq2BSEyCmRJl9+AwCWAAHgcauq12ChoFHvjSE=; b=oy/zNrjauV8p/GdEvCN5SuOuVWZdfR6tTANYrCRJoQwVTW6He4B1CAcDYYJcnI2cAK 1s/72hIb8mV1LBHxKduDv9IFfEcYDp2tbjnGZEySiHxw8UV5mZoQX0B9PDgt9tR5wUkd 4mRXPrcKE7BAm/MDiELUP+46Z2ruQbvJ08mZSp5qJA4xsvh4yamEMhb+VK2Uv40YfjHN IDwgPez9LKiAr/6Du54k/QZQaypKYNjiNV/QdytRbPLh7ohwoXR+yUAw1kNGUWugt7Vr BUMTWIqdvBXN4nKBgowR1Y0dZNCY6X0GLztFuoERUym30jgq1eWGPQC1GqdWrJtHcZqO +21Q== X-Gm-Message-State: AGi0PuY1crXOb1TLSoSjGKS2lD24w06UeCuUe5PHjtmK5T4iUrizjt9v x8d2yhGDtWtHrl7b4VLrGF2g6tDZfUg= X-Google-Smtp-Source: APiQypJseRK6ly69wa+E9S38J32pcCyDJYwv/4/JzWY5ofQ7Mcy+ZY8NUV5+Oh3Wu/2tJmyJTReXFA== X-Received: by 2002:ac8:6f6c:: with SMTP id u12mr2775086qtv.103.1586299143386; Tue, 07 Apr 2020 15:39:03 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id k2sm17692535qte.16.2020.04.07.15.39.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Apr 2020 15:39:02 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 2A3CC800897; Tue, 7 Apr 2020 17:39:01 -0500 (CDT) Date: Tue, 7 Apr 2020 17:39:01 -0500 From: Justin Pryzby To: Jeff Davis Cc: pgsql-hackers@postgresql.org Subject: Re: Default setting for enable_hashagg_disk Message-ID: <20200407223900.GT2228@telsasoft.com> References: <9d9d1e1252a52ea1bad84ea40dbebfd54e672a0f.camel@j-davis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9d9d1e1252a52ea1bad84ea40dbebfd54e672a0f.camel@j-davis.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Apr 07, 2020 at 11:20:46AM -0700, Jeff Davis wrote: > The enable_hashagg_disk GUC, if set to true, chooses HashAgg based on > costing. If false, it only generates a HashAgg path if it thinks it will fit > in work_mem, similar to the old behavior (though it wlil now spill to disk if > the planner was wrong about it fitting in work_mem). The current default is > true. Are there any other GUCs that behave like that ? It's confusing to me when I see "Disk Usage: ... kB", despite setting it to "disable", and without the usual disable_cost. I realize that postgres chose the plan on the hypothesis that it would *not* exceed work_mem, and that spilling to disk is considered preferable to ignoring the setting, and that "going back" to planning phase isn't a possibility. template1=# explain (analyze, costs off, summary off) SELECT a, COUNT(1) FROM generate_series(1,999999) a GROUP BY 1 ; HashAggregate (actual time=1370.945..2877.250 rows=999999 loops=1) Group Key: a Peak Memory Usage: 5017 kB Disk Usage: 22992 kB HashAgg Batches: 84 -> Function Scan on generate_series a (actual time=314.507..741.517 rows=999999 loops=1) A previous version of the docs said this, which I thought was confusing, and you removed it. But I guess this is the behavior it was trying to .. explain. + enable_hashagg_disk (boolean) + ... This only affects the planner choice; + execution time may still require using disk-based hash + aggregation. The default is on. I suggest that should be reworded and then re-introduced, unless there's some further behavior change allowing the previous behavior of might-exceed-work-mem. "This setting determines whether the planner will elect to use a hash plan which it expects will exceed work_mem and spill to disk. During execution, hash nodes which exceed work_mem will spill to disk even if this setting is disabled. To avoid spilling to disk, either increase work_mem (or set enable_hashagg=off)." For sure the release notes should recommend re-calibrating work_mem. -- Justin