From f27ac1e3388329b811c5a82362b739af5e8ded7f Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Fri, 4 Aug 2023 15:59:11 -0700 Subject: [PATCH] Fixed repairing graph entry point --- src/hnswutils.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/hnswutils.c b/src/hnswutils.c index 6603289..4261130 100644 --- a/src/hnswutils.c +++ b/src/hnswutils.c @@ -846,15 +846,22 @@ HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, F HnswElement dup; BlockNumber *skipPage = vacuuming ? &element->neighborPage : NULL; OffsetNumber *skipOffno = vacuuming ? &element->neighborOffno : NULL; + bool removeEntryPoint; + HnswCandidate *entryCandidate; /* Get entry point and level */ if (entryPoint != NULL) { - ep = lappend(ep, EntryCandidate(entryPoint, q, index, procinfo, collation, true)); + entryCandidate = EntryCandidate(entryPoint, q, index, procinfo, collation, true); + ep = lappend(ep, entryCandidate); entryLevel = entryPoint->level; + removeEntryPoint = vacuuming && list_length(entryPoint->heaptids) == 0; } else + { entryLevel = -1; + removeEntryPoint = false; + } for (int lc = entryLevel; lc >= level + 1; lc--) { @@ -870,6 +877,8 @@ HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, F int lm = GetLayerM(m, lc); w = SearchLayer(q, ep, efConstruction, lc, index, procinfo, collation, true, skipPage, skipOffno); + if (removeEntryPoint) + w = list_delete_ptr(w, entryCandidate); newNeighbors[lc] = SelectNeighbors(w, lm, lc, procinfo, collation, NULL); ep = w; }