mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-14 16:46:54 +08:00
Simplified HNSW vacuum logic
This commit is contained in:
@@ -227,10 +227,13 @@ HnswGetMetaPageInfo(Relation index, int *m, HnswElement * entryPoint)
|
|||||||
if (m != NULL)
|
if (m != NULL)
|
||||||
*m = metap->m;
|
*m = metap->m;
|
||||||
|
|
||||||
if (BlockNumberIsValid(metap->entryBlkno))
|
if (entryPoint != NULL)
|
||||||
*entryPoint = HnswInitElementFromBlock(metap->entryBlkno, metap->entryOffno);
|
{
|
||||||
else
|
if (BlockNumberIsValid(metap->entryBlkno))
|
||||||
*entryPoint = NULL;
|
*entryPoint = HnswInitElementFromBlock(metap->entryBlkno, metap->entryOffno);
|
||||||
|
else
|
||||||
|
*entryPoint = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
UnlockReleaseBuffer(buf);
|
UnlockReleaseBuffer(buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -265,12 +265,7 @@ RepairGraphEntryPoint(HnswVacuumState * vacuumstate)
|
|||||||
|
|
||||||
/* Repair if needed */
|
/* Repair if needed */
|
||||||
if (NeedsUpdated(vacuumstate, highestPoint))
|
if (NeedsUpdated(vacuumstate, highestPoint))
|
||||||
{
|
RepairGraphElement(vacuumstate, highestPoint, HnswGetEntryPoint(index));
|
||||||
/* Get m and entry point */
|
|
||||||
HnswGetMetaPageInfo(index, &vacuumstate->m, &entryPoint);
|
|
||||||
|
|
||||||
RepairGraphElement(vacuumstate, highestPoint, entryPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Release lock */
|
/* Release lock */
|
||||||
UnlockPage(index, HNSW_UPDATE_LOCK, ShareLock);
|
UnlockPage(index, HNSW_UPDATE_LOCK, ShareLock);
|
||||||
@@ -279,8 +274,8 @@ RepairGraphEntryPoint(HnswVacuumState * vacuumstate)
|
|||||||
/* Prevent concurrent inserts when possibly updating entry point */
|
/* Prevent concurrent inserts when possibly updating entry point */
|
||||||
LockPage(index, HNSW_UPDATE_LOCK, ExclusiveLock);
|
LockPage(index, HNSW_UPDATE_LOCK, ExclusiveLock);
|
||||||
|
|
||||||
/* Get m and latest entry point */
|
/* Get latest entry point */
|
||||||
HnswGetMetaPageInfo(index, &vacuumstate->m, &entryPoint);
|
entryPoint = HnswGetEntryPoint(index);
|
||||||
|
|
||||||
if (entryPoint != NULL)
|
if (entryPoint != NULL)
|
||||||
{
|
{
|
||||||
@@ -587,7 +582,6 @@ InitVacuumState(HnswVacuumState * vacuumstate, IndexVacuumInfo *info, IndexBulkD
|
|||||||
vacuumstate->stats = stats;
|
vacuumstate->stats = stats;
|
||||||
vacuumstate->callback = callback;
|
vacuumstate->callback = callback;
|
||||||
vacuumstate->callback_state = callback_state;
|
vacuumstate->callback_state = callback_state;
|
||||||
vacuumstate->m = 0; /* Get m from metapage later */
|
|
||||||
vacuumstate->efConstruction = HnswGetEfConstruction(index);
|
vacuumstate->efConstruction = HnswGetEfConstruction(index);
|
||||||
vacuumstate->bas = GetAccessStrategy(BAS_BULKREAD);
|
vacuumstate->bas = GetAccessStrategy(BAS_BULKREAD);
|
||||||
vacuumstate->procinfo = index_getprocinfo(index, 1, HNSW_DISTANCE_PROC);
|
vacuumstate->procinfo = index_getprocinfo(index, 1, HNSW_DISTANCE_PROC);
|
||||||
@@ -597,6 +591,9 @@ InitVacuumState(HnswVacuumState * vacuumstate, IndexVacuumInfo *info, IndexBulkD
|
|||||||
"Hnsw vacuum temporary context",
|
"Hnsw vacuum temporary context",
|
||||||
ALLOCSET_DEFAULT_SIZES);
|
ALLOCSET_DEFAULT_SIZES);
|
||||||
|
|
||||||
|
/* Get m from metapage */
|
||||||
|
HnswGetMetaPageInfo(index, &vacuumstate->m, NULL);
|
||||||
|
|
||||||
/* Create hash table */
|
/* Create hash table */
|
||||||
hash_ctl.keysize = sizeof(ItemPointerData);
|
hash_ctl.keysize = sizeof(ItemPointerData);
|
||||||
hash_ctl.entrysize = sizeof(ItemPointerData);
|
hash_ctl.entrysize = sizeof(ItemPointerData);
|
||||||
|
|||||||
Reference in New Issue
Block a user