mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-14 08:36:54 +08:00
Improved performance of parallel HNSW index builds
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
## 0.6.2 (unreleased)
|
||||||
|
|
||||||
|
- Improved performance of parallel HNSW index builds
|
||||||
|
|
||||||
## 0.6.1 (2024-03-04)
|
## 0.6.1 (2024-03-04)
|
||||||
|
|
||||||
- Fixed error with `ANALYZE` and vectors with different dimensions
|
- Fixed error with `ANALYZE` and vectors with different dimensions
|
||||||
|
|||||||
@@ -434,24 +434,20 @@ InsertTupleInMemory(HnswBuildState * buildstate, HnswElement element)
|
|||||||
int efConstruction = buildstate->efConstruction;
|
int efConstruction = buildstate->efConstruction;
|
||||||
int m = buildstate->m;
|
int m = buildstate->m;
|
||||||
char *base = buildstate->hnswarea;
|
char *base = buildstate->hnswarea;
|
||||||
|
bool updateEntryPoint;
|
||||||
|
|
||||||
/* Get entry point */
|
/* Get entry point */
|
||||||
LWLockAcquire(entryLock, LW_SHARED);
|
LWLockAcquire(entryLock, LW_EXCLUSIVE);
|
||||||
entryPoint = HnswPtrAccess(base, graph->entryPoint);
|
entryPoint = HnswPtrAccess(base, graph->entryPoint);
|
||||||
|
|
||||||
/* Prevent concurrent inserts when likely updating entry point */
|
/* Pause new inserts when updating entry point */
|
||||||
if (entryPoint == NULL || element->level > entryPoint->level)
|
/* May still be in-flight inserts */
|
||||||
{
|
updateEntryPoint = entryPoint == NULL || element->level > entryPoint->level;
|
||||||
/* Release shared lock */
|
|
||||||
|
/* Release entry lock */
|
||||||
|
if (!updateEntryPoint)
|
||||||
LWLockRelease(entryLock);
|
LWLockRelease(entryLock);
|
||||||
|
|
||||||
/* Get exclusive lock */
|
|
||||||
LWLockAcquire(entryLock, LW_EXCLUSIVE);
|
|
||||||
|
|
||||||
/* Get latest entry point after lock is acquired */
|
|
||||||
entryPoint = HnswPtrAccess(base, graph->entryPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find neighbors for element */
|
/* Find neighbors for element */
|
||||||
HnswFindElementNeighbors(base, element, entryPoint, NULL, procinfo, collation, m, efConstruction, false);
|
HnswFindElementNeighbors(base, element, entryPoint, NULL, procinfo, collation, m, efConstruction, false);
|
||||||
|
|
||||||
@@ -459,7 +455,8 @@ InsertTupleInMemory(HnswBuildState * buildstate, HnswElement element)
|
|||||||
UpdateGraphInMemory(procinfo, collation, element, m, efConstruction, entryPoint, buildstate);
|
UpdateGraphInMemory(procinfo, collation, element, m, efConstruction, entryPoint, buildstate);
|
||||||
|
|
||||||
/* Release entry lock */
|
/* Release entry lock */
|
||||||
LWLockRelease(entryLock);
|
if (updateEntryPoint)
|
||||||
|
LWLockRelease(entryLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user