pgvector.git / summary / log / commit / refs
commit 86b31fdf96cb09fc7c90ae0dafcd4f6e09c8690b
Author: Andrew Kane <andrew@ankane.org>
Date: Mon Jan 29 06:18:22 2024 +0000
Revert "Update neighbor tuples in-place for HNSW index build"
This reverts commit 270dd8189aa8b21b69fc8041f4ad9269e78bbabe.
src/hnswbuild.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/hnswbuild.c b/src/hnswbuild.c
index 42cb4dcc..18a82587 100644
--- a/src/hnswbuild.c
+++ b/src/hnswbuild.c
@@ -254,14 +254,17 @@ WriteNeighborTuples(HnswBuildState * buildstate)
int m = buildstate->m;
HnswElementPtr iter = buildstate->graph->head;
char *base = buildstate->hnswarea;
+ HnswNeighborTuple ntup;
+
+ /* Allocate once */
+ ntup = palloc0(BLCKSZ);
while (!HnswPtrIsNull(base, iter))
{
HnswElement e = HnswPtrAccess(base, iter);
Buffer buf;
Page page;
- ItemId itemid;
- HnswNeighborTuple ntup;
+ Size ntupSize = HNSW_NEIGHBOR_TUPLE_SIZE(e->level, m);
/* Update iterator */
iter = e->next;
@@ -273,19 +276,18 @@ WriteNeighborTuples(HnswBuildState * buildstate)
buf = ReadBufferExtended(index, forkNum, e->neighborPage, RBM_NORMAL, NULL);
LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE);
page = BufferGetPage(buf);
- itemid = PageGetItemId(page, e->neighborOffno);
- ntup = (HnswNeighborTuple) PageGetItem(page, itemid);
-
- /* Check expected size */
- Assert(ItemIdGetLength(itemid) == HNSW_NEIGHBOR_TUPLE_SIZE(e->level, m));
- /* Update page in-place */
HnswSetNeighborTuple(base, ntup, e, m);
+ if (!PageIndexTupleOverwrite(page, e->neighborOffno, (Item) ntup, ntupSize))
+ elog(ERROR, "failed to add index item to \"%s\"", RelationGetRelationName(index));
+
/* Commit */
MarkBufferDirty(buf);
UnlockReleaseBuffer(buf);
}
+
+ pfree(ntup);
}
/*
[parent: 5023269f0d8d]