From: | Peter Geoghegan <pg(at)bowt(dot)ie> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: Add hash_mem_multiplier GUC. |
Date: | 2020-07-29 21:15:18 |
Message-ID: | E1k0tPy-0005ZS-0g@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
Add hash_mem_multiplier GUC.
Add a GUC that acts as a multiplier on work_mem. It gets applied when
sizing executor node hash tables that were previously size constrained
using work_mem alone.
The new GUC can be used to preferentially give hash-based nodes more
memory than the generic work_mem limit. It is intended to enable admin
tuning of the executor's memory usage. Overall system throughput and
system responsiveness can be improved by giving hash-based executor
nodes more memory (especially over sort-based alternatives, which are
often much less sensitive to being memory constrained).
The default value for hash_mem_multiplier is 1.0, which is also the
minimum valid value. This means that hash-based nodes continue to apply
work_mem in the traditional way by default.
hash_mem_multiplier is generally useful. However, it is being added now
due to concerns about hash aggregate performance stability for users
that upgrade to Postgres 13 (which added disk-based hash aggregation in
commit 1f39bce0). While the old hash aggregate behavior risked
out-of-memory errors, it is nevertheless likely that many users actually
benefited. Hash agg's previous indifference to work_mem during query
execution was not just faster; it also accidentally made aggregation
resilient to grouping estimate problems (at least in cases where this
didn't create destabilizing memory pressure).
hash_mem_multiplier can provide a certain kind of continuity with the
behavior of Postgres 12 hash aggregates in cases where the planner
incorrectly estimates that all groups (plus related allocations) will
fit in work_mem/hash_mem. This seems necessary because hash-based
aggregation is usually much slower when only a small fraction of all
groups can fit. Even when it isn't possible to totally avoid hash
aggregates that spill, giving hash aggregation more memory will reliably
improve performance (the same cannot be said for external sort
operations, which appear to be almost unaffected by memory availability
provided it's at least possible to get a single merge pass).
The PostgreSQL 13 release notes should advise users that increasing
hash_mem_multiplier can help with performance regressions associated
with hash aggregation. That can be taken care of by a later commit.
Author: Peter Geoghegan
Reviewed-By: Álvaro Herrera, Jeff Davis
Discussion: https://postgr.es/m/20200625203629.7m6yvut7eqblgmfo@alap3.anarazel.de
Discussion: https://postgr.es/m/CAH2-WzmD%2Bi1pG6rc1%2BCjc4V6EaFJ_qSuKCCHVnH%3DoruqD-zqow%40mail.gmail.com
Backpatch: 13-, where disk-based hash aggregation was introduced.
Branch
------
REL_13_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/78530c8e7a5abe0b646b0b46527f8799f831e1e1
Modified Files
--------------
doc/src/sgml/config.sgml | 60 +++++++++++++++++---
doc/src/sgml/ref/postgres-ref.sgml | 8 +--
doc/src/sgml/runtime.sgml | 10 ++--
src/backend/executor/execGrouping.c | 5 +-
src/backend/executor/nodeAgg.c | 30 +++++-----
src/backend/executor/nodeHash.c | 80 ++++++++++++++++++++-------
src/backend/executor/nodeHashjoin.c | 4 +-
src/backend/optimizer/path/costsize.c | 12 ++--
src/backend/optimizer/plan/planner.c | 15 ++---
src/backend/optimizer/plan/subselect.c | 9 +--
src/backend/optimizer/prep/prepunion.c | 9 ++-
src/backend/optimizer/util/pathnode.c | 3 +-
src/backend/utils/adt/ri_triggers.c | 18 ++++--
src/backend/utils/init/globals.c | 1 +
src/backend/utils/misc/guc.c | 11 ++++
src/backend/utils/misc/postgresql.conf.sample | 1 +
src/include/executor/hashjoin.h | 4 +-
src/include/executor/nodeHash.h | 2 +-
src/include/miscadmin.h | 4 ++
19 files changed, 205 insertions(+), 81 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Geoghegan | 2020-07-29 23:01:20 | pgsql: Backpatch tuplesort.c assertion. |
Previous Message | Peter Geoghegan | 2020-07-29 21:15:17 | pgsql: Add hash_mem_multiplier GUC. |