diff --git a/src/hnsw.h b/src/hnsw.h index ccfe463..b6f0e63 100644 --- a/src/hnsw.h +++ b/src/hnsw.h @@ -258,7 +258,8 @@ List *HnswSearchLayer(Datum q, List *ep, int ef, int lc, Relation index, Fmgr HnswElement HnswGetEntryPoint(Relation index); HnswElement HnswInitElement(ItemPointer tid, int m, double ml, int maxLevel); void HnswFreeElement(HnswElement element); -HnswElement HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, FmgrInfo *procinfo, Oid collation, int m, int efConstruction, bool vacuuming); +void HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, FmgrInfo *procinfo, Oid collation, int m, int efConstruction, bool vacuuming); +HnswElement HnswFindDuplicate(HnswElement e); HnswCandidate *HnswEntryCandidate(HnswElement em, Datum q, Relation rel, FmgrInfo *procinfo, Oid collation, bool loadVec); void HnswUpdateMetaPage(Relation index, bool updateEntry, HnswElement entryPoint, BlockNumber insertPage, ForkNumber forkNum); void HnswSetNeighborTuple(HnswNeighborTuple ntup, HnswElement e, int m); diff --git a/src/hnswbuild.c b/src/hnswbuild.c index 5b45273..eefc642 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -288,7 +288,10 @@ InsertTuple(Relation index, Datum *values, HnswElement element, HnswBuildState * memcpy(element->vec, DatumGetVector(value), VECTOR_SIZE(buildstate->dimensions)); /* Insert element in graph */ - *dup = HnswInsertElement(element, entryPoint, NULL, procinfo, collation, m, efConstruction, false); + HnswInsertElement(element, entryPoint, NULL, procinfo, collation, m, efConstruction, false); + + /* Look for duplicate */ + *dup = HnswFindDuplicate(element); /* Update neighbors if needed */ if (*dup == NULL) diff --git a/src/hnswinsert.c b/src/hnswinsert.c index 4e8af35..bfd2b5f 100644 --- a/src/hnswinsert.c +++ b/src/hnswinsert.c @@ -446,7 +446,10 @@ HnswInsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heap_ti entryPoint = HnswGetEntryPoint(index); /* Insert element in graph */ - dup = HnswInsertElement(element, entryPoint, index, procinfo, collation, m, efConstruction, false); + HnswInsertElement(element, entryPoint, index, procinfo, collation, m, efConstruction, false); + + /* Look for duplicate */ + dup = HnswFindDuplicate(element); /* Write to disk */ WriteElement(index, procinfo, collation, element, m, dup, entryPoint); diff --git a/src/hnswutils.c b/src/hnswutils.c index 685e876..b763647 100644 --- a/src/hnswutils.c +++ b/src/hnswutils.c @@ -743,7 +743,7 @@ SelectNeighbors(List *c, int m, int lc, FmgrInfo *procinfo, Oid collation, HnswC /* * Find duplicate element */ -static HnswElement +HnswElement HnswFindDuplicate(HnswElement e) { HnswNeighborArray *neighbors = &e->neighbors[0]; @@ -884,7 +884,7 @@ HnswUpdateConnection(HnswElement element, HnswCandidate * hc, int m, int lc, int /* * Algorithm 1 from paper */ -HnswElement +void HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, FmgrInfo *procinfo, Oid collation, int m, int efConstruction, bool vacuuming) { List *ep = NIL; @@ -939,10 +939,4 @@ HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, F ep = w; } - - /* Look for duplicates */ - if (!vacuuming) - return HnswFindDuplicate(element); - - return NULL; }