From 064db12de7d0ca1625a77152d2ad13304f003639 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Wed, 9 Oct 2024 21:59:21 -0700 Subject: [PATCH] Moved procinfo initialization for inserts [skip ci] --- src/hnsw.h | 2 +- src/hnswbuild.c | 8 +++++--- src/hnswinsert.c | 15 +++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/hnsw.h b/src/hnsw.h index 10cc04a..364e03e 100644 --- a/src/hnsw.h +++ b/src/hnsw.h @@ -389,7 +389,7 @@ void HnswSetNeighborTuple(char *base, HnswNeighborTuple ntup, HnswElement e, in void HnswAddHeapTid(HnswElement element, ItemPointer heaptid); HnswNeighborArray *HnswInitNeighborArray(int lm, HnswAllocator * allocator); void HnswInitNeighbors(char *base, HnswElement element, int m, HnswAllocator * alloc); -bool HnswInsertTupleOnDisk(Relation index, Datum value, ItemPointer heaptid, bool building); +bool HnswInsertTupleOnDisk(Relation index, FmgrInfo *procinfo, Oid collation, Datum value, ItemPointer heaptid, bool building); void HnswUpdateNeighborsOnDisk(Relation index, FmgrInfo *procinfo, Oid collation, HnswElement e, int m, bool checkExisting, bool building); void HnswLoadElementFromTuple(HnswElement element, HnswElementTuple etup, bool loadHeaptids, bool loadVec); void HnswLoadElement(HnswElement element, double *distance, Datum *q, Relation index, FmgrInfo *procinfo, Oid collation, bool loadVec, double *maxDistance); diff --git a/src/hnswbuild.c b/src/hnswbuild.c index 12a2169..6fab132 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -476,6 +476,8 @@ InsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heaptid, Hn HnswGraph *graph = buildstate->graph; HnswElement element; HnswAllocator *allocator = &buildstate->allocator; + FmgrInfo *procinfo = buildstate->procinfo; + Oid collation = buildstate->collation; Size valueSize; Pointer valuePtr; LWLock *flushLock = &graph->flushLock; @@ -483,7 +485,7 @@ InsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heaptid, Hn Datum value; /* Form index value */ - if (!HnswFormIndexValue(&value, values, isnull, buildstate->typeInfo, buildstate->normprocinfo, buildstate->collation)) + if (!HnswFormIndexValue(&value, values, isnull, buildstate->typeInfo, buildstate->normprocinfo, collation)) return false; /* Get datum size */ @@ -497,7 +499,7 @@ InsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heaptid, Hn { LWLockRelease(flushLock); - return HnswInsertTupleOnDisk(index, value, heaptid, true); + return HnswInsertTupleOnDisk(index, procinfo, collation, value, heaptid, true); } /* @@ -529,7 +531,7 @@ InsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heaptid, Hn LWLockRelease(flushLock); - return HnswInsertTupleOnDisk(index, value, heaptid, true); + return HnswInsertTupleOnDisk(index, procinfo, collation, value, heaptid, true); } /* Ok, we can proceed to allocate the element */ diff --git a/src/hnswinsert.c b/src/hnswinsert.c index b916521..45530b9 100644 --- a/src/hnswinsert.c +++ b/src/hnswinsert.c @@ -679,19 +679,15 @@ UpdateGraphOnDisk(Relation index, FmgrInfo *procinfo, Oid collation, HnswElement * Insert a tuple into the index */ bool -HnswInsertTupleOnDisk(Relation index, Datum value, ItemPointer heaptid, bool building) +HnswInsertTupleOnDisk(Relation index, FmgrInfo *procinfo, Oid collation, Datum value, ItemPointer heaptid, bool building) { HnswElement entryPoint; HnswElement element; int m; int efConstruction = HnswGetEfConstruction(index); - FmgrInfo *procinfo; - Oid collation; LOCKMODE lockmode = ShareLock; char *base = NULL; - HnswSetProcinfo(index, &procinfo, NULL, &collation); - /* * Get a shared lock. This allows vacuum to ensure no in-flight inserts * before repairing graph. Use a page lock so it does not interfere with @@ -740,14 +736,17 @@ HnswInsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heaptid { Datum value; const HnswTypeInfo *typeInfo = HnswGetTypeInfo(index); - FmgrInfo *normprocinfo = HnswOptionalProcInfo(index, HNSW_NORM_PROC); - Oid collation = index->rd_indcollation[0]; + FmgrInfo *procinfo; + FmgrInfo *normprocinfo; + Oid collation; + + HnswSetProcinfo(index, &procinfo, &normprocinfo, &collation); /* Form index value */ if (!HnswFormIndexValue(&value, values, isnull, typeInfo, normprocinfo, collation)) return; - HnswInsertTupleOnDisk(index, value, heaptid, false); + HnswInsertTupleOnDisk(index, procinfo, collation, value, heaptid, false); } /*