mirror of
https://github.com/pgvector/pgvector.git
synced 2026-12-05 16:58:38 +00:00
Fixed broken HOT chain handling in parallel index builds
Co-authored-by: Lukas Fittl <lukas@fittl.com>
This commit is contained in:
1 parent
a036566985
commit
9f973cd95f
4 files changed
+14
-4
No files matched your search
@@ -266,6 +266,7 @@ typedef struct HnswShared
|
||||
/* Mutable state */
|
||||
int nparticipantsdone;
|
||||
double reltuples;
|
||||
bool brokenhotchain;
|
||||
HnswGraph graphData;
|
||||
} HnswShared;
|
||||
|
||||
|
||||
+6
-2
@@ -754,7 +754,7 @@ FreeBuildState(HnswBuildState * buildstate)
|
||||
* Within leader, wait for end of heap scan
|
||||
*/
|
||||
static double
|
||||
ParallelHeapScan(HnswBuildState * buildstate)
|
||||
ParallelHeapScan(HnswBuildState * buildstate, bool *brokenhotchain)
|
||||
{
|
||||
HnswShared *hnswshared = buildstate->hnswleader->hnswshared;
|
||||
int nparticipanttuplesorts;
|
||||
@@ -769,6 +769,7 @@ ParallelHeapScan(HnswBuildState * buildstate)
|
||||
buildstate->graph = &hnswshared->graphData;
|
||||
buildstate->hnswarea = buildstate->hnswleader->hnswarea;
|
||||
reltuples = hnswshared->reltuples;
|
||||
*brokenhotchain = hnswshared->brokenhotchain;
|
||||
SpinLockRelease(&hnswshared->mutex);
|
||||
break;
|
||||
}
|
||||
@@ -815,6 +816,8 @@ HnswParallelScanAndInsert(Relation heapRel, Relation indexRel, HnswShared * hnsw
|
||||
SpinLockAcquire(&hnswshared->mutex);
|
||||
hnswshared->nparticipantsdone++;
|
||||
hnswshared->reltuples += reltuples;
|
||||
if (indexInfo->ii_BrokenHotChain)
|
||||
hnswshared->brokenhotchain = true;
|
||||
SpinLockRelease(&hnswshared->mutex);
|
||||
|
||||
/* Log statistics */
|
||||
@@ -1025,6 +1028,7 @@ HnswBeginParallel(HnswBuildState * buildstate, bool isconcurrent, int request)
|
||||
/* Initialize mutable state */
|
||||
hnswshared->nparticipantsdone = 0;
|
||||
hnswshared->reltuples = 0;
|
||||
hnswshared->brokenhotchain = false;
|
||||
table_parallelscan_initialize(buildstate->heap,
|
||||
ParallelTableScanFromHnswShared(hnswshared),
|
||||
snapshot);
|
||||
@@ -1127,7 +1131,7 @@ BuildGraph(HnswBuildState * buildstate)
|
||||
if (buildstate->heap != NULL)
|
||||
{
|
||||
if (buildstate->hnswleader)
|
||||
buildstate->reltuples = ParallelHeapScan(buildstate);
|
||||
buildstate->reltuples = ParallelHeapScan(buildstate, &buildstate->indexInfo->ii_BrokenHotChain);
|
||||
else
|
||||
buildstate->reltuples = table_index_build_scan(buildstate->heap, buildstate->index, buildstate->indexInfo,
|
||||
true, true, BuildCallback, (void *) buildstate, NULL);
|
||||
|
||||
+6
-2
@@ -612,7 +612,7 @@ InitBuildSortState(TupleDesc tupdesc, int memory, SortCoordinate coordinate)
|
||||
* Within leader, wait for end of heap scan
|
||||
*/
|
||||
static double
|
||||
ParallelHeapScan(IvfflatBuildState * buildstate)
|
||||
ParallelHeapScan(IvfflatBuildState * buildstate, bool *brokenhotchain)
|
||||
{
|
||||
IvfflatShared *ivfshared = buildstate->ivfleader->ivfshared;
|
||||
int nparticipanttuplesorts;
|
||||
@@ -626,6 +626,7 @@ ParallelHeapScan(IvfflatBuildState * buildstate)
|
||||
{
|
||||
buildstate->indtuples = ivfshared->indtuples;
|
||||
reltuples = ivfshared->reltuples;
|
||||
*brokenhotchain = ivfshared->brokenhotchain;
|
||||
#ifdef IVFFLAT_KMEANS_DEBUG
|
||||
buildstate->inertia = ivfshared->inertia;
|
||||
#endif
|
||||
@@ -687,6 +688,8 @@ IvfflatParallelScanAndSort(IvfflatSpool * ivfspool, IvfflatShared * ivfshared, S
|
||||
ivfshared->nparticipantsdone++;
|
||||
ivfshared->reltuples += reltuples;
|
||||
ivfshared->indtuples += buildstate.indtuples;
|
||||
if (indexInfo->ii_BrokenHotChain)
|
||||
ivfshared->brokenhotchain = true;
|
||||
#ifdef IVFFLAT_KMEANS_DEBUG
|
||||
ivfshared->inertia += buildstate.inertia;
|
||||
#endif
|
||||
@@ -924,6 +927,7 @@ IvfflatBeginParallel(IvfflatBuildState * buildstate, bool isconcurrent, int requ
|
||||
ivfshared->nparticipantsdone = 0;
|
||||
ivfshared->reltuples = 0;
|
||||
ivfshared->indtuples = 0;
|
||||
ivfshared->brokenhotchain = false;
|
||||
#ifdef IVFFLAT_KMEANS_DEBUG
|
||||
ivfshared->inertia = 0;
|
||||
#endif
|
||||
@@ -1028,7 +1032,7 @@ AssignTuples(IvfflatBuildState * buildstate)
|
||||
if (buildstate->heap != NULL)
|
||||
{
|
||||
if (buildstate->ivfleader)
|
||||
buildstate->reltuples = ParallelHeapScan(buildstate);
|
||||
buildstate->reltuples = ParallelHeapScan(buildstate, &buildstate->indexInfo->ii_BrokenHotChain);
|
||||
else
|
||||
buildstate->reltuples = table_index_build_scan(buildstate->heap, buildstate->index, buildstate->indexInfo,
|
||||
true, true, BuildCallback, (void *) buildstate, NULL);
|
||||
|
||||
@@ -161,6 +161,7 @@ typedef struct IvfflatShared
|
||||
int nparticipantsdone;
|
||||
double reltuples;
|
||||
double indtuples;
|
||||
bool brokenhotchain;
|
||||
|
||||
#ifdef IVFFLAT_KMEANS_DEBUG
|
||||
double inertia;
|
||||
|
||||
Reference in new issue
Block a user