From 02d74361c28a930135549ad679b7baa061d6a90b Mon Sep 17 00:00:00 2001 From: "Andrey V. Lepikhov" Date: Tue, 12 Mar 2024 13:39:29 +0700 Subject: [PATCH] Strictly limit max size of batches in Parallel Hash Join by DSA limits. Because batch descriptors allocates in the DSA area we must limit their number by the limitations of maximum size of DSA area that can be allocated. --- src/backend/executor/nodeHash.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/backend/executor/nodeHash.c b/src/backend/executor/nodeHash.c index 61480733a1..d95700a4f7 100644 --- a/src/backend/executor/nodeHash.c +++ b/src/backend/executor/nodeHash.c @@ -1145,6 +1145,7 @@ ExecParallelHashIncreaseNumBatches(HashJoinTable hashtable) /* Allocate new larger generation of batches. */ Assert(hashtable->nbatch == pstate->nbatch); + ExecParallelHashJoinSetUpBatches(hashtable, new_nbatch); Assert(hashtable->nbatch == pstate->nbatch); @@ -1246,6 +1247,8 @@ ExecParallelHashIncreaseNumBatches(HashJoinTable hashtable) { bool space_exhausted = false; bool extreme_skew_detected = false; + int max_batches = (int) pg_prevpower2_32((uint32) + (MaxAllocSize / EstimateParallelHashJoinBatch(hashtable))); /* Make sure that we have the current dimensions and buckets. */ ExecParallelHashEnsureBatchAccessors(hashtable); @@ -1276,7 +1279,7 @@ ExecParallelHashIncreaseNumBatches(HashJoinTable hashtable) } /* Don't keep growing if it's not helping or we'd overflow. */ - if (extreme_skew_detected || hashtable->nbatch >= INT_MAX / 2) + if (extreme_skew_detected || hashtable->nbatch >= max_batches) pstate->growth = PHJ_GROWTH_DISABLED; else if (space_exhausted) pstate->growth = PHJ_GROWTH_NEED_MORE_BATCHES; -- 2.44.0