From 3fcf38603ebbd07e36dccadf84ab84409964fe7a Mon Sep 17 00:00:00 2001 From: Tomas Vondra Date: Sat, 20 Apr 2019 21:59:37 +0200 Subject: [PATCH 2/2] allocate BufFile eagerly --- src/backend/executor/nodeHash.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/backend/executor/nodeHash.c b/src/backend/executor/nodeHash.c index 7d36c22d61..7f125d8dba 100644 --- a/src/backend/executor/nodeHash.c +++ b/src/backend/executor/nodeHash.c @@ -915,6 +915,7 @@ ExecHashIncreaseNumBatches(HashJoinTable hashtable) if (hashtable->innerBatchFile == NULL) { + int i; MemoryContext oldctx; hashtable->fileCtx = AllocSetContextCreate(CurrentMemoryContext, @@ -931,10 +932,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); @@ -949,6 +960,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