pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas@2ndquadrant.com>
Subject: [PATCH 2/2] allocate BufFile eagerly
Date: Sun, 21 Apr 2019 13:31:53 +0200

---
 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


--te4f7ouzjnzpgo6v--





Message-ID: <no-message-id-5655@localhost>
Permalink:  ../no-message-id-5655@localhost/
Also on:    postgresql.org/message-id/no-message-id-5655@localhost

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tomas@2ndquadrant.com
  Subject: Re: [PATCH 2/2] allocate BufFile eagerly
  In-Reply-To: <no-message-id-5655@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox