diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 23f081389b..6650e543a0 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -58,6 +58,7 @@ typedef struct BrinSpool
 	Tuplesortstate *sortstate;	/* state data for tuplesort.c */
 	Relation	heap;
 	Relation	index;
+	uint32		sortmem;
 } BrinSpool;
 
 /*
@@ -236,11 +237,9 @@ static Size _brin_parallel_estimate_shared(Relation heap, Snapshot snapshot);
 static void _brin_leader_participate_as_worker(BrinBuildState *buildstate,
 											   Relation heap, Relation index);
 static void _brin_parallel_scan_and_build(BrinBuildState *buildstate,
-										  BrinSpool *brinspool,
 										  BrinShared *brinshared,
 										  Sharedsort *sharedsort,
-										  Relation heap, Relation index,
-										  int sortmem, bool progress);
+										  bool progress);
 
 /*
  * BRIN handler function: return IndexAmRoutine with access method parameters
@@ -1200,8 +1199,7 @@ brinbuild(Relation heap, Relation index, IndexInfo *indexInfo)
 		 * factor.
 		 */
 		state->bs_spool->sortstate =
-			tuplesort_begin_index_brin(heap, index,
-									   maintenance_work_mem, coordinate,
+			tuplesort_begin_index_brin(maintenance_work_mem, coordinate,
 									   TUPLESORT_NONE);
 
 		/*
@@ -2702,23 +2700,22 @@ static void
 _brin_leader_participate_as_worker(BrinBuildState *buildstate, Relation heap, Relation index)
 {
 	BrinLeader *brinleader = buildstate->bs_leader;
-	int			sortmem;
 
 	/* Allocate memory and initialize private spool */
 	buildstate->bs_spool = (BrinSpool *) palloc0(sizeof(BrinSpool));
-	buildstate->bs_spool->heap = buildstate->bs_spool->heap;
-	buildstate->bs_spool->index = buildstate->bs_spool->index;
+	buildstate->bs_spool->heap = heap;
+	buildstate->bs_spool->index = index;
 
 	/*
 	 * Might as well use reliable figure when doling out maintenance_work_mem
 	 * (when requested number of workers were not launched, this will be
 	 * somewhat higher than it is for other workers).
 	 */
-	sortmem = maintenance_work_mem / brinleader->nparticipanttuplesorts;
+	buildstate->bs_spool->sortmem = maintenance_work_mem / brinleader->nparticipanttuplesorts;
 
 	/* Perform work common to all participants */
-	_brin_parallel_scan_and_build(buildstate, buildstate->bs_spool, brinleader->brinshared,
-								  brinleader->sharedsort, heap, index, sortmem, true);
+	_brin_parallel_scan_and_build(buildstate, brinleader->brinshared,
+								  brinleader->sharedsort, true);
 }
 
 /*
@@ -2734,15 +2731,15 @@ _brin_leader_participate_as_worker(BrinBuildState *buildstate, Relation heap, Re
  * When this returns, workers are done, and need only release resources.
  */
 static void
-_brin_parallel_scan_and_build(BrinBuildState *state, BrinSpool *brinspool,
+_brin_parallel_scan_and_build(BrinBuildState *state, 
 							  BrinShared *brinshared, Sharedsort *sharedsort,
-							  Relation heap, Relation index, int sortmem,
 							  bool progress)
 {
 	SortCoordinate coordinate;
 	TableScanDesc scan;
 	double		reltuples;
 	IndexInfo  *indexInfo;
+	BrinSpool	 *bs_spool;
 
 	/* Initialize local tuplesort coordination state */
 	coordinate = palloc0(sizeof(SortCoordinateData));
@@ -2751,26 +2748,25 @@ _brin_parallel_scan_and_build(BrinBuildState *state, BrinSpool *brinspool,
 	coordinate->sharedsort = sharedsort;
 
 	/* Begin "partial" tuplesort */
-	brinspool->sortstate = tuplesort_begin_index_brin(brinspool->heap,
-													  brinspool->index,
-													  sortmem, coordinate,
+	bs_spool = state->bs_spool;
+	bs_spool->sortstate = tuplesort_begin_index_brin(bs_spool->sortmem, coordinate,
 													  TUPLESORT_NONE);
 
 	/* Join parallel scan */
-	indexInfo = BuildIndexInfo(index);
+	indexInfo = BuildIndexInfo(bs_spool->index);
 	indexInfo->ii_Concurrent = brinshared->isconcurrent;
 
-	scan = table_beginscan_parallel(heap,
+	scan = table_beginscan_parallel(bs_spool->heap,
 									ParallelTableScanFromBrinShared(brinshared));
 
-	reltuples = table_index_build_scan(heap, index, indexInfo, true, true,
-									   brinbuildCallbackParallel, state, scan);
+	reltuples = table_index_build_scan(bs_spool->heap, bs_spool->index, indexInfo,
+									   true, true, brinbuildCallbackParallel, state, scan);
 
 	/* insert the last item */
 	form_and_spill_tuple(state);
 
 	/* sort the BRIN ranges built by this worker */
-	tuplesort_performsort(brinspool->sortstate);
+	tuplesort_performsort(bs_spool->sortstate);
 
 	state->bs_reltuples += reltuples;
 
@@ -2786,7 +2782,7 @@ _brin_parallel_scan_and_build(BrinBuildState *state, BrinSpool *brinspool,
 	/* Notify leader */
 	ConditionVariableSignal(&brinshared->workersdonecv);
 
-	tuplesort_end(brinspool->sortstate);
+	tuplesort_end(bs_spool->sortstate);
 }
 
 /*
@@ -2805,7 +2801,6 @@ _brin_parallel_build_main(dsm_segment *seg, shm_toc *toc)
 	LOCKMODE	indexLockmode;
 	WalUsage   *walusage;
 	BufferUsage *bufferusage;
-	int			sortmem;
 
 	/*
 	 * The only possible status flag that can be set to the parallel worker is
@@ -2849,6 +2844,13 @@ _brin_parallel_build_main(dsm_segment *seg, shm_toc *toc)
 	buildstate->bs_spool->heap = heapRel;
 	buildstate->bs_spool->index = indexRel;
 
+	/*
+	 * Might as well use reliable figure when doling out maintenance_work_mem
+	 * (when requested number of workers were not launched, this will be
+	 * somewhat higher than it is for other workers).
+	 */
+	buildstate->bs_spool->sortmem = maintenance_work_mem / brinshared->scantuplesortstates;
+
 	/* Look up shared state private to tuplesort.c */
 	sharedsort = shm_toc_lookup(toc, PARALLEL_KEY_TUPLESORT, false);
 	tuplesort_attach_shared(sharedsort, seg);
@@ -2856,16 +2858,9 @@ _brin_parallel_build_main(dsm_segment *seg, shm_toc *toc)
 	/* Prepare to track buffer usage during parallel execution */
 	InstrStartParallelQuery();
 
-	/*
-	 * Might as well use reliable figure when doling out maintenance_work_mem
-	 * (when requested number of workers were not launched, this will be
-	 * somewhat higher than it is for other workers).
-	 */
-	sortmem = maintenance_work_mem / brinshared->scantuplesortstates;
-
-	_brin_parallel_scan_and_build(buildstate, buildstate->bs_spool,
+	_brin_parallel_scan_and_build(buildstate,
 								  brinshared, sharedsort,
-								  heapRel, indexRel, sortmem, false);
+								  false);
 
 	/* Report WAL/buffer usage during parallel execution */
 	bufferusage = shm_toc_lookup(toc, PARALLEL_KEY_BUFFER_USAGE, false);
diff --git a/src/backend/utils/sort/tuplesortvariants.c b/src/backend/utils/sort/tuplesortvariants.c
index 90fc605f1c..27425880a5 100644
--- a/src/backend/utils/sort/tuplesortvariants.c
+++ b/src/backend/utils/sort/tuplesortvariants.c
@@ -137,16 +137,6 @@ typedef struct
 	uint32		max_buckets;
 } TuplesortIndexHashArg;
 
-/*
- * Data struture pointed by "TuplesortPublic.arg" for the index_brin subcase.
- */
-typedef struct
-{
-	TuplesortIndexArg index;
-
-	/* XXX do we need something here? */
-} TuplesortIndexBrinArg;
-
 /*
  * Data struture pointed by "TuplesortPublic.arg" for the Datum case.
  * Set by tuplesort_begin_datum and used only by the DatumTuple routines.
@@ -562,20 +552,13 @@ tuplesort_begin_index_gist(Relation heapRel,
 }
 
 Tuplesortstate *
-tuplesort_begin_index_brin(Relation heapRel,
-						   Relation indexRel,
-						   int workMem,
+tuplesort_begin_index_brin(int workMem,
 						   SortCoordinate coordinate,
 						   int sortopt)
 {
 	Tuplesortstate *state = tuplesort_begin_common(workMem, coordinate,
 												   sortopt);
 	TuplesortPublic *base = TuplesortstateGetPublic(state);
-	MemoryContext oldcontext;
-	TuplesortIndexBrinArg *arg;
-
-	oldcontext = MemoryContextSwitchTo(base->maincontext);
-	arg = (TuplesortIndexBrinArg *) palloc(sizeof(TuplesortIndexBrinArg));
 
 #ifdef TRACE_SORT
 	if (trace_sort)
@@ -592,12 +575,7 @@ tuplesort_begin_index_brin(Relation heapRel,
 	base->writetup = writetup_index_brin;
 	base->readtup = readtup_index_brin;
 	base->haveDatum1 = true;
-	base->arg = arg;
-
-	arg->index.heapRel = heapRel;
-	arg->index.indexRel = indexRel;
-
-	MemoryContextSwitchTo(oldcontext);
+	base->arg = NULL;
 
 	return state;
 }
diff --git a/src/include/utils/tuplesort.h b/src/include/utils/tuplesort.h
index 357eb35311..103ced4005 100644
--- a/src/include/utils/tuplesort.h
+++ b/src/include/utils/tuplesort.h
@@ -430,9 +430,7 @@ extern Tuplesortstate *tuplesort_begin_index_gist(Relation heapRel,
 												  Relation indexRel,
 												  int workMem, SortCoordinate coordinate,
 												  int sortopt);
-extern Tuplesortstate *tuplesort_begin_index_brin(Relation heapRel,
-												  Relation indexRel,
-												  int workMem, SortCoordinate coordinate,
+extern Tuplesortstate *tuplesort_begin_index_brin(int workMem, SortCoordinate coordinate,
 												  int sortopt);
 extern Tuplesortstate *tuplesort_begin_datum(Oid datumType,
 											 Oid sortOperator, Oid sortCollation,
