From e1d6654063b617996479faea9028fdb911c4297c Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sun, 13 Aug 2023 17:19:22 -0700 Subject: [PATCH] Revert "Improved HNSW vacuum performance" This reverts commit c5b2f3ac8bd404017ab6dcd18b01b3396a386882. --- src/hnsw.h | 3 +-- src/hnswinsert.c | 33 +++------------------------------ src/hnswvacuum.c | 10 +++++----- 3 files changed, 9 insertions(+), 37 deletions(-) diff --git a/src/hnsw.h b/src/hnsw.h index b6e680d..c9aabf6 100644 --- a/src/hnsw.h +++ b/src/hnsw.h @@ -268,12 +268,11 @@ void HnswSetNeighborTuple(HnswNeighborTuple ntup, HnswElement e, int m); void HnswAddHeapTid(HnswElement element, ItemPointer heaptid); void HnswInitNeighbors(HnswElement element, int m); bool HnswInsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heap_tid, Relation heapRel); -void UpdateNeighborPages(Relation index, FmgrInfo *procinfo, Oid collation, HnswElement e, int m, HTAB *deleted); +void UpdateNeighborPages(Relation index, FmgrInfo *procinfo, Oid collation, HnswElement e, int m); void HnswLoadElement(HnswElement element, float *distance, Datum *q, Relation index, FmgrInfo *procinfo, Oid collation, bool loadVec); void HnswSetElementTuple(HnswElementTuple etup, HnswElement element); void HnswUpdateConnection(HnswElement element, HnswCandidate * hc, int m, int lc, int *updateIdx, Relation index, FmgrInfo *procinfo, Oid collation); void HnswLoadNeighbors(HnswElement element, Relation index); -bool HnswDeletedContains(HTAB *deleted, ItemPointer indextid); /* Index access methods */ IndexBuildResult *hnswbuild(Relation heap, Relation index, IndexInfo *indexInfo); diff --git a/src/hnswinsert.c b/src/hnswinsert.c index fea75aa..b397941 100644 --- a/src/hnswinsert.c +++ b/src/hnswinsert.c @@ -283,33 +283,11 @@ WriteNewElementPages(Relation index, HnswElement e, int m, BlockNumber insertPag *updatedInsertPage = newInsertPage; } -/* - * Get index of deleted neighbor - */ -static int -GetDeletedIndex(HnswElement element, HTAB *deleted, int lc) -{ - HnswNeighborArray *neighbors = &element->neighbors[lc]; - - for (int i = 0; i < neighbors->length; i++) - { - HnswCandidate *hc = &neighbors->items[i]; - ItemPointerData ipData; - - ItemPointerSet(&ipData, hc->element->blkno, hc->element->offno); - - if (HnswDeletedContains(deleted, &ipData)) - return i; - } - - return -1; -} - /* * Update neighbors */ void -UpdateNeighborPages(Relation index, FmgrInfo *procinfo, Oid collation, HnswElement e, int m, HTAB *deleted) +UpdateNeighborPages(Relation index, FmgrInfo *procinfo, Oid collation, HnswElement e, int m) { for (int lc = e->level; lc >= 0; lc--) { @@ -333,13 +311,8 @@ UpdateNeighborPages(Relation index, FmgrInfo *procinfo, Oid collation, HnswEleme /* Do not lock yet since selecting neighbors can take time */ HnswLoadNeighbors(hc->element, index); - /* Find deleted index without loading elements if possible */ - if (deleted != NULL) - idx = GetDeletedIndex(hc->element, deleted, lc); - /* Select neighbors */ - if (idx == -1) - HnswUpdateConnection(e, hc, lm, lc, &idx, index, procinfo, collation); + HnswUpdateConnection(e, hc, lm, lc, &idx, index, procinfo, collation); /* New element was not selected as a neighbor */ if (idx == -1) @@ -511,7 +484,7 @@ WriteElement(Relation index, FmgrInfo *procinfo, Oid collation, HnswElement elem HnswUpdateMetaPage(index, false, NULL, newInsertPage, MAIN_FORKNUM); /* Update neighbors */ - UpdateNeighborPages(index, procinfo, collation, element, m, NULL); + UpdateNeighborPages(index, procinfo, collation, element, m); /* Update metapage if needed */ if (element->level > entryPoint->level) diff --git a/src/hnswvacuum.c b/src/hnswvacuum.c index a476b1b..e2f412d 100644 --- a/src/hnswvacuum.c +++ b/src/hnswvacuum.c @@ -10,8 +10,8 @@ /* * Check if deleted list contains an index tid */ -bool -HnswDeletedContains(HTAB *deleted, ItemPointer indextid) +static bool +DeletedContains(HTAB *deleted, ItemPointer indextid) { bool found; @@ -167,7 +167,7 @@ NeedsUpdated(HnswVacuumState * vacuumstate, HnswElement element) continue; /* Check if in deleted list */ - if (HnswDeletedContains(vacuumstate->deleted, indextid)) + if (DeletedContains(vacuumstate->deleted, indextid)) { needsUpdated = true; break; @@ -255,7 +255,7 @@ RepairGraphElement(HnswVacuumState * vacuumstate, HnswElement element) UnlockReleaseBuffer(buf); /* Update neighbors */ - UpdateNeighborPages(index, procinfo, collation, element, m, vacuumstate->deleted); + UpdateNeighborPages(index, procinfo, collation, element, m); } /* @@ -293,7 +293,7 @@ RepairGraphEntryPoint(HnswVacuumState * vacuumstate) ItemPointerSet(&epData, entryPoint->blkno, entryPoint->offno); - if (HnswDeletedContains(vacuumstate->deleted, &epData)) + if (DeletedContains(vacuumstate->deleted, &epData)) HnswUpdateMetaPage(index, true, highestPoint, InvalidBlockNumber, MAIN_FORKNUM); else {