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 1jiqHW-0004xm-BP for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jun 2020 02:15:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jiqHV-0005Pr-2P for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jun 2020 02:15:57 +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 1jiqHU-0005Pk-Mg for pgsql-hackers@lists.postgresql.org; Wed, 10 Jun 2020 02:15:56 +0000 Received: from mail-io1-xd43.google.com ([2607:f8b0:4864:20::d43]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jiqHM-0002E5-Bh for pgsql-hackers@postgresql.org; Wed, 10 Jun 2020 02:15:55 +0000 Received: by mail-io1-xd43.google.com with SMTP id q8so445876iow.7 for ; Tue, 09 Jun 2020 19:15:48 -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=L6VSFPVe+3Pu1ZnRIoQsylKi8MM58WWLyD91WTrC7PU=; b=Tv5APcw67ndMR/Xei3uW3T/pMXf4iCSRjA1A7vLRiTmrpPJNC7R0xW57TvnPanLbo4 TO+vO3zChTmjFwfm+t3BaiahA0OIWEbVAXyNLNqPHKYgNS7TB0JhryBQ5Nx1M45UfeLZ YAPsCX9HGiEWwFWv6SkBqI2QHYIHrDKOJJ+N8DHq/bBMGffueOln7mHXHhdZ8dtTrihr qt2zD6mW9uWv62U+wPW4VtLSLQlw2OAGK7hFsdY1wnHbS4Arhzr/m8y54AdDyZeOGXUO XAxu8/tSqPvZO/B2FzglqcT6R9G6ZAF6fg6cbZPd+kMjgCjPMRJvVHIipd4a5C6bADxA sA6g== 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=L6VSFPVe+3Pu1ZnRIoQsylKi8MM58WWLyD91WTrC7PU=; b=mzgUFNhLBfNvDxiHCZ52pBmnFxVx0pAXWK49IIPweG85TOgj1QTajg2Qf5tx/arVsi UnOAHXu4STUeBeD/bMRfnyFBbxKgHzAtaRT1Q/mwvgkwPh8ZR8KsH2gqL9NLkvkwoowq tpHIhkp6bWSP4VAeTgJARTZrNSGx/ScufqSDqv6H620tvARHq2XaQeN/y6oIa8gKG0Zo PGNh/i3LXb9p6eKD/1hru9jt2pZAUw89FniGatKNR8BLp8klc9MiRpE9li9cdiyTJxlM RDi5LpH/QAxHkmcvhJNl0M2KwiVQPLclXYZAHhu0jv4IeNz8435Z7xXtH+vMuEL2l9PL ZMVg== X-Gm-Message-State: AOAM533nk2Zb4xS+CIEViFgCBOQDz3S41u0zGkUXx/Ba2FLeP2QbquLJ HKhFIbowk2pLEw/U+oAvIagKdQ== X-Google-Smtp-Source: ABdhPJzmUGPEz/I1kIo5kTARa3YeEZa1x24EoSFLL5puwdGNJFKQB1Y1c73rMRWWV1bY5HT/T47HXg== X-Received: by 2002:a05:6638:38a:: with SMTP id y10mr1098891jap.131.1591755346567; Tue, 09 Jun 2020 19:15:46 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id x8sm9963792ilo.81.2020.06.09.19.15.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jun 2020 19:15:45 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 95AD680010D; Tue, 9 Jun 2020 21:15:44 -0500 (CDT) Date: Tue, 9 Jun 2020 21:15:44 -0500 From: Justin Pryzby To: Melanie Plageman Cc: Jeff Davis , Robert Haas , Tomas Vondra , pgsql-hackers@postgresql.org Subject: Re: Default setting for enable_hashagg_disk Message-ID: <20200610021544.GA14879@telsasoft.com> References: <9d9d1e1252a52ea1bad84ea40dbebfd54e672a0f.camel@j-davis.com> <20200407223900.GT2228@telsasoft.com> <20200409114855.h4hh7e2wt77p56sv@development> <6292f5a766198d5745eb8cc17ac736366056671d.camel@j-davis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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, Jun 09, 2020 at 06:20:13PM -0700, Melanie Plageman wrote: > On Thu, Apr 9, 2020 at 1:02 PM Jeff Davis wrote: > > > 2. enable_groupingsets_hash_disk (default false): > > > > This is about how we choose which grouping sets to hash and which to > > sort when generating mixed mode paths. > > > > Even before this patch, there are quite a few paths that could be > > generated. It tries to estimate the size of each grouping set's hash > > table, and then see how many it can fit in work_mem (knapsack), while > > also taking advantage of any path keys, etc. > > > > With Disk-based Hash Aggregation, in principle we can generate paths > > representing any combination of hashing and sorting for the grouping > > sets. But that would be overkill (and grow to a huge number of paths if > > we have more than a handful of grouping sets). So I think the existing > > planner logic for grouping sets is fine for now. We might come up with > > a better approach later. > > > > But that created a testing problem, because if the planner estimates > > correctly, no hashed grouping sets will spill, and the spilling code > > won't be exercised. This GUC makes the planner disregard which grouping > > sets' hash tables will fit, making it much easier to exercise the > > spilling code. Is there a better way I should be testing this code > > path? > > So, I was catching up on email and noticed the last email in this > thread. > > I think I am not fully understanding what enable_groupingsets_hash_disk > does. Is it only for testing? If so, it should be in category: "Developer Options". > Using the tests you added to src/test/regress/sql/groupingsets.sql, I > did get a plan that looks like hashagg is spilling to disk (goes through > hashagg_spill_tuple() code path and has number of batches reported in > Explain) in a MixedAgg plan for a grouping sets query even with > enable_groupingsets_hash_disk set to false. > I'm not sure if this is more what you were looking for--or maybe I am > misunderstanding the guc. The behavior of the GUC is inconsistent with the other GUCs, which is confusing. See also Robert's comments in this thread. https://www.postgresql.org/message-id/20200407223900.GT2228%40telsasoft.com The old (pre-13) behavior was: - work_mem is the amount of RAM to which each query node tries to constrain itself, and the planner will reject a plan if it's expected to exceed that. ...But a chosen plan might exceed work_mem anyway. The new behavior in v13 seems to be: - HashAgg now respects work_mem, but instead enable*hash_disk are opportunisitic. A node which is *expected* to spill to disk will be rejected. ...But at execution time, a node which exceeds work_mem will be spilled. If someone sees a plan which spills to disk and wants to improve performance by avoid spilling, they might SET enable_hashagg_disk=off, which might do what they want (if the plan is rejected at plan time), or it might not, which I think will be a surprise every time. If someone agrees, I suggest to add this as an Opened Item. Maybe some combination of these would be an improvement: - change documentation to emphasize behavior; - change EXPLAIN ouput to make it obvious this isn't misbehaving; - rename the GUC to not start with enable_* (work_mem_exceed?) - rename the GUC *values* to something other than on/off. On/Planner? - change the GUC to behave like it sounds like it should, which means "off" would allow the pre-13 behavior of exceeding work_mem. - Maybe make it ternary, like: exceed_work_mem: {spill_disk, planner_reject, allow} -- Justin