From 57b5d8484c8a0949c3fa8205a324ac7bf3a377fb Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Fri, 20 Nov 2020 14:41:14 +0200 Subject: [PATCH] Skip allocating hash table in EXPLAIN-only mode. This is a backpatch of commit 2cccb627f1, backpatched due to popular demand. Backpatch to all supported versions. Author: Alexey Bashtanov Discussion: https://www.postgresql.org/message-id/36823f65-050d-ae24-aa4d-a37726998240%40imap.cc --- src/backend/executor/nodeAgg.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c index 6b274751ba..f2bb5502b2 100644 --- a/src/backend/executor/nodeAgg.c +++ b/src/backend/executor/nodeAgg.c @@ -2454,7 +2454,11 @@ ExecInitAgg(Agg *node, EState *estate, int eflags) aggstate->hash_pergroup = pergroups; find_hash_columns(aggstate); - build_hash_table(aggstate); + + /* Skip massive memory allocation if we are just doing EXPLAIN */ + if (!(eflags & EXEC_FLAG_EXPLAIN_ONLY)) + build_hash_table(aggstate); + aggstate->table_filled = false; }