From a651fcfdc689059b466b6a7658422f96dd14fc78 Mon Sep 17 00:00:00 2001 From: Tomas Vondra Date: Sun, 21 Apr 2019 13:31:53 +0200 Subject: [PATCH 2/2] allocate BufFile eagerly --- src/backend/executor/nodeHash.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/backend/executor/nodeHash.c b/src/backend/executor/nodeHash.c index f7c92e78e9..4a1f70771d 100644 --- a/src/backend/executor/nodeHash.c +++ b/src/backend/executor/nodeHash.c @@ -564,6 +564,7 @@ ExecHashTableCreate(HashState *state, List *hashOperators, bool keepNulls) if (nbatch > 1 && hashtable->parallel_state == NULL) { + int i; MemoryContext oldctx; /* @@ -580,6 +581,15 @@ ExecHashTableCreate(HashState *state, List *hashOperators, bool keepNulls) /* ... but make sure we have temp tablespaces established for them */ PrepareTempTablespaces(); + for (i = 1; i < nbatch; i++) + { + if (!hashtable->innerBatchFile[i]) + hashtable->innerBatchFile[i] = BufFileCreateTemp(false); + + if (!hashtable->outerBatchFile[i]) + hashtable->outerBatchFile[i] = BufFileCreateTemp(false); + } + MemoryContextSwitchTo(oldctx); } @@ -925,6 +935,7 @@ ExecHashIncreaseNumBatches(HashJoinTable hashtable) if (hashtable->innerBatchFile == NULL) { + int i; MemoryContext oldctx; oldctx = MemoryContextSwitchTo(hashtable->fileCtx); @@ -937,10 +948,20 @@ ExecHashIncreaseNumBatches(HashJoinTable hashtable) /* time to establish the temp tablespaces, too */ PrepareTempTablespaces(); + for (i = 1; i < nbatch; i++) + { + if (!hashtable->innerBatchFile[i]) + hashtable->innerBatchFile[i] = BufFileCreateTemp(false); + + if (!hashtable->outerBatchFile[i]) + hashtable->outerBatchFile[i] = BufFileCreateTemp(false); + } + MemoryContextSwitchTo(oldctx); } else { + int i; MemoryContext oldctx; oldctx = MemoryContextSwitchTo(hashtable->fileCtx); @@ -955,6 +976,15 @@ ExecHashIncreaseNumBatches(HashJoinTable hashtable) MemSet(hashtable->outerBatchFile + oldnbatch, 0, (nbatch - oldnbatch) * sizeof(BufFile *)); + for (i = 1; i < nbatch; i++) + { + if (!hashtable->innerBatchFile[i]) + hashtable->innerBatchFile[i] = BufFileCreateTemp(false); + + if (!hashtable->outerBatchFile[i]) + hashtable->outerBatchFile[i] = BufFileCreateTemp(false); + } + MemoryContextSwitchTo(oldctx); } -- 2.20.1