Re: Default setting for enable_hashagg_disk
Bruce Momjian <bruce@momjian.us>
From: Bruce Momjian <bruce@momjian.us>
To: Peter Geoghegan <pg@bowt.ie>
Cc: Amit Kapila <amit.kapila16@gmail.com>, Robert Haas <robertmhaas@gmail.com>, Andres Freund <andres@anarazel.de>, David Rowley <dgrowleyml@gmail.com>, Jeff Davis <pgsql@j-davis.com>, Justin Pryzby <pryzby@telsasoft.com>, Melanie Plageman <melanieplageman@gmail.com>, Tomas Vondra <tomas.vondra@2ndquadrant.com>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2020-06-29T15:29:09Z
Lists: pgsql-hackers, pgsql-docs
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 <bruce@momjian.us> https://momjian.us EnterpriseDB https://enterprisedb.com The usefulness of a cup is in its emptiness, Bruce Lee
Commits
-
Add hash_mem_multiplier GUC.
- d6c08e29e7bc 14.0 landed
- 78530c8e7a5a 13.0 landed
-
HashAgg: use better cardinality estimate for recursive spilling.
- 3a232a3183d5 13.0 landed
- 9878b643f37b 14.0 landed
-
Remove hashagg_avoid_disk_plan GUC.
- bcbf9446a298 14.0 landed
- 5a6cc6ffa914 13.0 landed
-
Doc fixup for hashagg_avoid_disk_plan GUC.
- d33f33539d7f 13.0 landed
- 7ce461560159 14.0 landed
-
Rework HashAgg GUCs.
- 13e0fa7ae50c 13.0 landed
- 92c58fd94801 14.0 landed
-
Disk-based Hash Aggregation.
- 1f39bce02154 13.0 cited
-
Implement partition-wise grouping/aggregation.
- e2f1eb0ee30d 11.0 cited
-
Defer creation of partially-grouped relation until it's needed.
- 4f15e5d09de2 11.0 cited