Compare commits

...

2 Commits

Author SHA1 Message Date
Andrew Kane
abbc1c3379 Improved code 2024-03-11 17:30:27 -07:00
Andrew Kane
72c20fc14f Improved performance of parallel HNSW index builds 2024-03-11 17:24:42 -07:00
2 changed files with 17 additions and 16 deletions

View File

@@ -1,3 +1,7 @@
## 0.6.2 (unreleased)
- Improved performance of parallel HNSW index builds
## 0.6.1 (2024-03-04)
- Fixed error with `ANALYZE` and vectors with different dimensions

View File

@@ -400,7 +400,7 @@ UpdateNeighborsInMemory(char *base, FmgrInfo *procinfo, Oid collation, HnswEleme
* Update graph in memory
*/
static void
UpdateGraphInMemory(FmgrInfo *procinfo, Oid collation, HnswElement element, int m, int efConstruction, HnswElement entryPoint, HnswBuildState * buildstate)
UpdateGraphInMemory(FmgrInfo *procinfo, Oid collation, HnswElement element, int m, int efConstruction, bool updateEntryPoint, HnswBuildState * buildstate)
{
HnswGraph *graph = buildstate->graph;
char *base = buildstate->hnswarea;
@@ -416,7 +416,7 @@ UpdateGraphInMemory(FmgrInfo *procinfo, Oid collation, HnswElement element, int
UpdateNeighborsInMemory(base, procinfo, collation, element, m);
/* Update entry point if needed (already have lock) */
if (entryPoint == NULL || element->level > entryPoint->level)
if (updateEntryPoint)
HnswPtrStore(base, graph->entryPoint, element);
}
@@ -434,32 +434,29 @@ InsertTupleInMemory(HnswBuildState * buildstate, HnswElement element)
int efConstruction = buildstate->efConstruction;
int m = buildstate->m;
char *base = buildstate->hnswarea;
bool updateEntryPoint;
/* Get entry point */
LWLockAcquire(entryLock, LW_SHARED);
LWLockAcquire(entryLock, LW_EXCLUSIVE);
entryPoint = HnswPtrAccess(base, graph->entryPoint);
/* Prevent concurrent inserts when likely updating entry point */
if (entryPoint == NULL || element->level > entryPoint->level)
{
/* Release shared lock */
/* Pause new inserts when updating entry point */
/* May still be in-flight inserts */
updateEntryPoint = entryPoint == NULL || element->level > entryPoint->level;
/* Release entry lock */
if (!updateEntryPoint)
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 */
HnswFindElementNeighbors(base, element, entryPoint, NULL, procinfo, collation, m, efConstruction, false);
/* Update graph in memory */
UpdateGraphInMemory(procinfo, collation, element, m, efConstruction, entryPoint, buildstate);
UpdateGraphInMemory(procinfo, collation, element, m, efConstruction, updateEntryPoint, buildstate);
/* Release entry lock */
LWLockRelease(entryLock);
if (updateEntryPoint)
LWLockRelease(entryLock);
}
/*