From a62c045c937cd5d23d4649a7b59cde9da4fbf88e Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sat, 19 Aug 2023 12:19:42 -0700 Subject: [PATCH] Update metapage if needed for HNSW vacuum --- src/hnswvacuum.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/hnswvacuum.c b/src/hnswvacuum.c index f493bd2..60e2410 100644 --- a/src/hnswvacuum.c +++ b/src/hnswvacuum.c @@ -368,13 +368,24 @@ RepairGraph(HnswVacuumState * vacuumstate) foreach(lc2, elements) { HnswElement element = (HnswElement) lfirst(lc2); + HnswElement entryPoint; /* Check if any neighbors point to deleted values */ if (!NeedsUpdated(vacuumstate, element)) continue; /* Refresh entry point for each element */ - RepairGraphElement(vacuumstate, element, HnswGetEntryPoint(index)); + entryPoint = HnswGetEntryPoint(index); + + /* Repair connections */ + RepairGraphElement(vacuumstate, element, entryPoint); + + /* + * Update metapage if needed. Should only happen if entry point + * was replaced and highest point was outdated. + */ + if (entryPoint == NULL || element->level > entryPoint->level) + HnswUpdateMetaPage(index, HNSW_UPDATE_ENTRY_GREATER, element, InvalidBlockNumber, MAIN_FORKNUM); } /* Reset memory context */