mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-13 16:16:56 +08:00
Made entryPoint argument for RepairGraphElement
This commit is contained in:
@@ -188,7 +188,7 @@ NeedsUpdated(HnswVacuumState * vacuumstate, HnswElement element)
|
|||||||
* Repair graph for a single element
|
* Repair graph for a single element
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
RepairGraphElement(HnswVacuumState * vacuumstate, HnswElement element)
|
RepairGraphElement(HnswVacuumState * vacuumstate, HnswElement element, HnswElement entryPoint)
|
||||||
{
|
{
|
||||||
Relation index = vacuumstate->index;
|
Relation index = vacuumstate->index;
|
||||||
Buffer buf;
|
Buffer buf;
|
||||||
@@ -198,35 +198,13 @@ RepairGraphElement(HnswVacuumState * vacuumstate, HnswElement element)
|
|||||||
int efConstruction = vacuumstate->efConstruction;
|
int efConstruction = vacuumstate->efConstruction;
|
||||||
FmgrInfo *procinfo = vacuumstate->procinfo;
|
FmgrInfo *procinfo = vacuumstate->procinfo;
|
||||||
Oid collation = vacuumstate->collation;
|
Oid collation = vacuumstate->collation;
|
||||||
HnswElement entryPoint;
|
|
||||||
BufferAccessStrategy bas = vacuumstate->bas;
|
BufferAccessStrategy bas = vacuumstate->bas;
|
||||||
HnswNeighborTuple ntup = vacuumstate->ntup;
|
HnswNeighborTuple ntup = vacuumstate->ntup;
|
||||||
Size ntupSize = HNSW_NEIGHBOR_TUPLE_SIZE(element->level, m);
|
Size ntupSize = HNSW_NEIGHBOR_TUPLE_SIZE(element->level, m);
|
||||||
|
|
||||||
/* Check if any neighbors point to deleted values */
|
/* Skip if element is entry point */
|
||||||
if (!NeedsUpdated(vacuumstate, element))
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Refresh entry point for each element */
|
|
||||||
entryPoint = HnswGetEntryPoint(index);
|
|
||||||
|
|
||||||
/* Special case for entry point */
|
|
||||||
if (entryPoint != NULL && element->blkno == entryPoint->blkno && element->offno == entryPoint->offno)
|
if (entryPoint != NULL && element->blkno == entryPoint->blkno && element->offno == entryPoint->offno)
|
||||||
{
|
return;
|
||||||
if (BlockNumberIsValid(vacuumstate->highestPoint.blkno))
|
|
||||||
{
|
|
||||||
/* Already updated */
|
|
||||||
if (vacuumstate->highestPoint.blkno == element->blkno && vacuumstate->highestPoint.offno == element->offno)
|
|
||||||
return;
|
|
||||||
|
|
||||||
entryPoint = &vacuumstate->highestPoint;
|
|
||||||
|
|
||||||
/* Reset neighbors from previous update */
|
|
||||||
entryPoint->neighbors = NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
entryPoint = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Init fields */
|
/* Init fields */
|
||||||
HnswInitNeighbors(element, m);
|
HnswInitNeighbors(element, m);
|
||||||
@@ -285,7 +263,9 @@ RepairGraphEntryPoint(HnswVacuumState * vacuumstate)
|
|||||||
if (highestPoint != NULL)
|
if (highestPoint != NULL)
|
||||||
{
|
{
|
||||||
HnswLoadElement(highestPoint, NULL, NULL, index, vacuumstate->procinfo, vacuumstate->collation, true);
|
HnswLoadElement(highestPoint, NULL, NULL, index, vacuumstate->procinfo, vacuumstate->collation, true);
|
||||||
RepairGraphElement(vacuumstate, highestPoint);
|
|
||||||
|
if (NeedsUpdated(vacuumstate, highestPoint))
|
||||||
|
RepairGraphElement(vacuumstate, highestPoint, HnswGetEntryPoint(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See if entry point needs updated */
|
/* See if entry point needs updated */
|
||||||
@@ -305,7 +285,15 @@ RepairGraphEntryPoint(HnswVacuumState * vacuumstate)
|
|||||||
{
|
{
|
||||||
/* Repair the entry point with the highest point */
|
/* Repair the entry point with the highest point */
|
||||||
HnswLoadElement(entryPoint, NULL, NULL, index, vacuumstate->procinfo, vacuumstate->collation, true);
|
HnswLoadElement(entryPoint, NULL, NULL, index, vacuumstate->procinfo, vacuumstate->collation, true);
|
||||||
RepairGraphElement(vacuumstate, entryPoint);
|
|
||||||
|
if (NeedsUpdated(vacuumstate, entryPoint))
|
||||||
|
{
|
||||||
|
/* Reset neighbors from previous update */
|
||||||
|
if (highestPoint != NULL)
|
||||||
|
highestPoint->neighbors = NULL;
|
||||||
|
|
||||||
|
RepairGraphElement(vacuumstate, entryPoint, highestPoint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,7 +366,16 @@ RepairGraph(HnswVacuumState * vacuumstate)
|
|||||||
|
|
||||||
/* Update neighbor pages */
|
/* Update neighbor pages */
|
||||||
foreach(lc2, elements)
|
foreach(lc2, elements)
|
||||||
RepairGraphElement(vacuumstate, (HnswElement) lfirst(lc2));
|
{
|
||||||
|
HnswElement element = (HnswElement) lfirst(lc2);
|
||||||
|
|
||||||
|
/* Check if any neighbors point to deleted values */
|
||||||
|
if (!NeedsUpdated(vacuumstate, element))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Refresh entry point for each element */
|
||||||
|
RepairGraphElement(vacuumstate, element, HnswGetEntryPoint(index));
|
||||||
|
}
|
||||||
|
|
||||||
/* Reset memory context */
|
/* Reset memory context */
|
||||||
MemoryContextSwitchTo(oldCtx);
|
MemoryContextSwitchTo(oldCtx);
|
||||||
|
|||||||
Reference in New Issue
Block a user