pgvector.git / summary / log / commit / refs
commit ed513e62c16a930643cdc1e21db2816a979e2bad
Author: Andrew Kane <andrew@ankane.org>
Date: Thu Aug 10 22:29:08 2023 +0000
Improved code for skipping element [skip ci]
src/hnsw.h | 2 +-
src/hnswscan.c | 4 ++--
src/hnswutils.c | 11 +++++------
3 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/hnsw.h b/src/hnsw.h
index a5e4cdcf..a0930724 100644
--- a/src/hnsw.h
+++ b/src/hnsw.h
@@ -254,7 +254,7 @@ Buffer HnswNewBuffer(Relation index, ForkNumber forkNum);
void HnswInitPage(Buffer buf, Page page);
void HnswInitRegisterPage(Relation index, Buffer *buf, Page *page, GenericXLogState **state);
void HnswInit(void);
-List *HnswSearchLayer(Datum q, List *ep, int ef, int lc, Relation index, FmgrInfo *procinfo, Oid collation, bool inserting, BlockNumber *skipPage, OffsetNumber *skipOffno);
+List *HnswSearchLayer(Datum q, List *ep, int ef, int lc, Relation index, FmgrInfo *procinfo, Oid collation, bool inserting, HnswElement skipElement);
HnswElement HnswGetEntryPoint(Relation index);
HnswElement HnswInitElement(ItemPointer tid, int m, double ml, int maxLevel);
void HnswFreeElement(HnswElement element);
diff --git a/src/hnswscan.c b/src/hnswscan.c
index 365c6e36..b65f4c48 100644
--- a/src/hnswscan.c
+++ b/src/hnswscan.c
@@ -27,11 +27,11 @@ GetScanItems(IndexScanDesc scan, Datum q)
for (int lc = entryPoint->level; lc >= 1; lc--)
{
- w = HnswSearchLayer(q, ep, 1, lc, index, procinfo, collation, false, NULL, NULL);
+ w = HnswSearchLayer(q, ep, 1, lc, index, procinfo, collation, false, NULL);
ep = w;
}
- so->w = HnswSearchLayer(q, ep, hnsw_ef_search, 0, index, procinfo, collation, false, NULL, NULL);
+ so->w = HnswSearchLayer(q, ep, hnsw_ef_search, 0, index, procinfo, collation, false, NULL);
}
/*
diff --git a/src/hnswutils.c b/src/hnswutils.c
index f0f972bb..ab7d1dec 100644
--- a/src/hnswutils.c
+++ b/src/hnswutils.c
@@ -522,7 +522,7 @@ AddToVisited(HTAB *v, HnswCandidate * hc, Relation index, bool *found)
* Algorithm 2 from paper
*/
List *
-HnswSearchLayer(Datum q, List *ep, int ef, int lc, Relation index, FmgrInfo *procinfo, Oid collation, bool inserting, BlockNumber *skipPage, OffsetNumber *skipOffno)
+HnswSearchLayer(Datum q, List *ep, int ef, int lc, Relation index, FmgrInfo *procinfo, Oid collation, bool inserting, HnswElement skipElement)
{
ListCell *lc2;
@@ -603,7 +603,7 @@ HnswSearchLayer(Datum q, List *ep, int ef, int lc, Relation index, FmgrInfo *pro
continue;
/* Skip self for vacuuming update */
- if (skipPage != NULL && e->element->neighborPage == *skipPage && e->element->neighborOffno == *skipOffno)
+ if (skipElement != NULL && e->element->neighborPage == skipElement->neighborPage && e->element->neighborOffno == skipElement->neighborOffno)
continue;
/* Make robust to issues */
@@ -892,8 +892,7 @@ HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, F
int level = element->level;
int entryLevel;
Datum q = PointerGetDatum(element->vec);
- BlockNumber *skipPage = existing ? &element->neighborPage : NULL;
- OffsetNumber *skipOffno = existing ? &element->neighborOffno : NULL;
+ HnswElement skipElement = existing ? element : NULL;
bool removeEntryPoint;
HnswCandidate *entryCandidate;
@@ -914,7 +913,7 @@ HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, F
/* 1st phase: greedy search to insert level */
for (int lc = entryLevel; lc >= level + 1; lc--)
{
- w = HnswSearchLayer(q, ep, 1, lc, index, procinfo, collation, true, skipPage, skipOffno);
+ w = HnswSearchLayer(q, ep, 1, lc, index, procinfo, collation, true, skipElement);
ep = w;
}
@@ -927,7 +926,7 @@ HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, F
int lm = HnswGetLayerM(m, lc);
List *neighbors;
- w = HnswSearchLayer(q, ep, efConstruction, lc, index, procinfo, collation, true, skipPage, skipOffno);
+ w = HnswSearchLayer(q, ep, efConstruction, lc, index, procinfo, collation, true, skipElement);
/* Remove entry point if it's being deleted */
if (removeEntryPoint)
[parent: 27ccb5fa7a14]