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 1jpvij-0006rT-4A for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jun 2020 15:29:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jpvih-0003wJ-TN for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jun 2020 15:29:19 +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 1jpvih-0003wC-MO for pgsql-hackers@lists.postgresql.org; Mon, 29 Jun 2020 15:29:19 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jpvie-0005r6-Ud for pgsql-hackers@postgresql.org; Mon, 29 Jun 2020 15:29:19 +0000 Received: from bruce by momjian.us with local (Exim 4.92) (envelope-from ) id 1jpviX-0002Ys-IJ; Mon, 29 Jun 2020 11:29:09 -0400 Date: Mon, 29 Jun 2020 11:29:09 -0400 From: Bruce Momjian To: Peter Geoghegan Cc: Amit Kapila , Robert Haas , Andres Freund , David Rowley , Jeff Davis , Justin Pryzby , Melanie Plageman , Tomas Vondra , "pgsql-hackers@postgresql.org" Subject: Re: Default setting for enable_hashagg_disk Message-ID: <20200629152909.GC17529@momjian.us> References: <8bff2e4e8020c3caa16b61a46918d21b573eaf78.camel@j-davis.com> <129c8f1739957589584d9525e1d8782eae3f412f.camel@j-davis.com> <20200624191433.5gnqgrxfmucexldm@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sun, Jun 28, 2020 at 05:40:16PM -0700, Peter Geoghegan wrote: > I think any problem that might come up with the costing is best > thought of as a distinct problem. This thread is mostly about the > problem of users getting fewer in-memory hash aggregates compared to a > previous release running the same application (though there has been > some discussion of the other problem, too [1], but it's thought to be > less serious). > > The problem is that affected users were theoretically never entitled > to the performance they came to rely on, and yet there is good reason > to think that hash aggregate really should be entitled to more memory. > They won't care that they were theoretically never entitled to that > performance, though -- they *liked* the fact that hash agg could > cheat. And they'll dislike the fact that this cannot be corrected by > tuning work_mem, since that affects all node types that consume > work_mem, not just hash aggregate -- that could cause OOMs for them. > > There are two or three similar ideas under discussion that might fix > the problem. They all seem to involve admitting that hash aggregate's > "cheating" might actually have been a good thing all along (even > though giving hash aggregate much much more memory than other nodes is > terrible), and giving hash aggregate license to "cheat openly". Note > that the problem isn't exactly a problem with the hash aggregate > spilling patch. You could think of the problem as a pre-existing issue > -- a failure to give more memory to hash aggregate, which really > should be entitled to more memory. Jeff's patch just made the issue > more obvious. In thinking some more about this, I came out with two ideas. First, in pre-PG 13, we didn't choose hash_agg if we thought it would spill, but if we misestimated and it used more work_mem, we allowed it. The effect of this is that if we were close, but it went over, we allowed it just for hash_agg. Is this something we want to codify for all node types, i.e., choose a non-spill node type if we need a lot more than work_mem, but then let work_mem be a soft limit if we do choose it, e.g., allow 50% over work_mem in the executor for misestimation before spill? My point is, do we want to use a lower work_mem for planning and a higher one in the executor before spilling. My second thought is from an earlier report that spilling is very expensive, but smaller work_mem doesn't seem to hurt much. Would we achieve better overall performance by giving a few nodes a lot of memory (and not spill those), and other nodes very little, rather than having them all be the same size, and all spill? -- Bruce Momjian https://momjian.us EnterpriseDB https://enterprisedb.com The usefulness of a cup is in its emptiness, Bruce Lee