diff --git a/src/hnsw.h b/src/hnsw.h index e439476..5ccf683 100644 --- a/src/hnsw.h +++ b/src/hnsw.h @@ -200,12 +200,6 @@ typedef struct HnswGraph bool flushed; } HnswGraph; -typedef struct HnswSpool -{ - Relation heap; - Relation index; -} HnswSpool; - typedef struct HnswShared { /* Immutable state */ diff --git a/src/hnswbuild.c b/src/hnswbuild.c index bdcc27e..c8816da 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -722,7 +722,7 @@ ParallelHeapScan(HnswBuildState * buildstate) * Perform a worker's portion of a parallel insert */ static void -HnswParallelScanAndInsert(HnswSpool * hnswspool, HnswShared * hnswshared, char *hnswarea, bool progress) +HnswParallelScanAndInsert(Relation heapRel, Relation indexRel, HnswShared * hnswshared, char *hnswarea, bool progress) { HnswBuildState buildstate; #if PG_VERSION_NUM >= 120000 @@ -734,21 +734,21 @@ HnswParallelScanAndInsert(HnswSpool * hnswspool, HnswShared * hnswshared, char * IndexInfo *indexInfo; /* Join parallel scan */ - indexInfo = BuildIndexInfo(hnswspool->index); + indexInfo = BuildIndexInfo(indexRel); indexInfo->ii_Concurrent = hnswshared->isconcurrent; - InitBuildState(&buildstate, hnswspool->heap, hnswspool->index, indexInfo, MAIN_FORKNUM); + InitBuildState(&buildstate, heapRel, indexRel, indexInfo, MAIN_FORKNUM); buildstate.graph = &hnswshared->graphData; buildstate.hnswarea = hnswarea; InitAllocator(&buildstate.allocator, &HnswSharedMemoryAlloc, &buildstate); #if PG_VERSION_NUM >= 120000 - scan = table_beginscan_parallel(hnswspool->heap, + scan = table_beginscan_parallel(heapRel, ParallelTableScanFromHnswShared(hnswshared)); - reltuples = table_index_build_scan(hnswspool->heap, hnswspool->index, indexInfo, + reltuples = table_index_build_scan(heapRel, indexRel, indexInfo, true, progress, BuildCallback, (void *) &buildstate, scan); #else - scan = heap_beginscan_parallel(hnswspool->heap, &hnswshared->heapdesc); - reltuples = IndexBuildHeapScan(hnswspool->heap, hnswspool->index, indexInfo, + scan = heap_beginscan_parallel(heapRel, &hnswshared->heapdesc); + reltuples = IndexBuildHeapScan(heapRel, indexRel, indexInfo, true, BuildCallback, (void *) &buildstate, scan); #endif @@ -778,7 +778,6 @@ void HnswParallelBuildMain(dsm_segment *seg, shm_toc *toc) { char *sharedquery; - HnswSpool *hnswspool; HnswShared *hnswshared; char *hnswarea; Relation heapRel; @@ -816,15 +815,10 @@ HnswParallelBuildMain(dsm_segment *seg, shm_toc *toc) #endif indexRel = index_open(hnswshared->indexrelid, indexLockmode); - /* Initialize worker's own spool */ - hnswspool = (HnswSpool *) palloc0(sizeof(HnswSpool)); - hnswspool->heap = heapRel; - hnswspool->index = indexRel; - hnswarea = shm_toc_lookup(toc, PARALLEL_KEY_HNSW_AREA, false); /* Perform inserts */ - HnswParallelScanAndInsert(hnswspool, hnswshared, hnswarea, false); + HnswParallelScanAndInsert(heapRel, indexRel, hnswshared, hnswarea, false); /* Close relations within worker */ index_close(indexRel, indexLockmode); @@ -879,15 +873,9 @@ static void HnswLeaderParticipateAsWorker(HnswBuildState * buildstate) { HnswLeader *hnswleader = buildstate->hnswleader; - HnswSpool *leaderworker; - - /* Allocate memory and initialize private spool */ - leaderworker = (HnswSpool *) palloc0(sizeof(HnswSpool)); - leaderworker->heap = buildstate->heap; - leaderworker->index = buildstate->index; /* Perform work common to all participants */ - HnswParallelScanAndInsert(leaderworker, hnswleader->hnswshared, hnswleader->hnswarea, true); + HnswParallelScanAndInsert(buildstate->heap, buildstate->index, hnswleader->hnswshared, hnswleader->hnswarea, true); } /*