pgvector.git / summary / log / commit / refs
commit a98534e5ab4735c4a33adb8ea63aef5b832ae5c0
Author: Andrew Kane <andrew@ankane.org>
Date: Thu Oct 10 04:03:18 2024 +0000
DRY HNSW procinfo
src/hnsw.h | 1 +
src/hnswbuild.c | 4 +---
src/hnswinsert.c | 6 ++++--
src/hnswscan.c | 4 +---
src/hnswutils.c | 13 +++++++++++++
src/hnswvacuum.c | 4 ++--
6 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/src/hnsw.h b/src/hnsw.h
index f9e56211..10cc04a4 100644
--- a/src/hnsw.h
+++ b/src/hnsw.h
@@ -370,6 +370,7 @@ typedef struct HnswVacuumState
int HnswGetM(Relation index);
int HnswGetEfConstruction(Relation index);
FmgrInfo *HnswOptionalProcInfo(Relation index, uint16 procnum);
+void HnswSetProcinfo(Relation index, FmgrInfo **procinfo, FmgrInfo **normprocinfo, Oid *collation);
Datum HnswNormValue(const HnswTypeInfo * typeInfo, Oid collation, Datum value);
bool HnswCheckNorm(FmgrInfo *procinfo, Oid collation, Datum value);
Buffer HnswNewBuffer(Relation index, ForkNumber forkNum);
diff --git a/src/hnswbuild.c b/src/hnswbuild.c
index 02e1749f..12a2169d 100644
--- a/src/hnswbuild.c
+++ b/src/hnswbuild.c
@@ -692,9 +692,7 @@ InitBuildState(HnswBuildState * buildstate, Relation heap, Relation index, Index
buildstate->indtuples = 0;
/* Get support functions */
- buildstate->procinfo = index_getprocinfo(index, 1, HNSW_DISTANCE_PROC);
- buildstate->normprocinfo = HnswOptionalProcInfo(index, HNSW_NORM_PROC);
- buildstate->collation = index->rd_indcollation[0];
+ HnswSetProcinfo(index, &buildstate->procinfo, &buildstate->normprocinfo, &buildstate->collation);
InitGraph(&buildstate->graphData, NULL, (Size) maintenance_work_mem * 1024L);
buildstate->graph = &buildstate->graphData;
diff --git a/src/hnswinsert.c b/src/hnswinsert.c
index 9c5b1907..b916521e 100644
--- a/src/hnswinsert.c
+++ b/src/hnswinsert.c
@@ -685,11 +685,13 @@ HnswInsertTupleOnDisk(Relation index, Datum value, ItemPointer heaptid, bool bui
HnswElement element;
int m;
int efConstruction = HnswGetEfConstruction(index);
- FmgrInfo *procinfo = index_getprocinfo(index, 1, HNSW_DISTANCE_PROC);
- Oid collation = index->rd_indcollation[0];
+ 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
diff --git a/src/hnswscan.c b/src/hnswscan.c
index 30815afd..88ecf68f 100644
--- a/src/hnswscan.c
+++ b/src/hnswscan.c
@@ -86,9 +86,7 @@ hnswbeginscan(Relation index, int nkeys, int norderbys)
ALLOCSET_DEFAULT_SIZES);
/* Set support functions */
- so->procinfo = index_getprocinfo(index, 1, HNSW_DISTANCE_PROC);
- so->normprocinfo = HnswOptionalProcInfo(index, HNSW_NORM_PROC);
- so->collation = index->rd_indcollation[0];
+ HnswSetProcinfo(index, &so->procinfo, &so->normprocinfo, &so->collation);
scan->opaque = so;
diff --git a/src/hnswutils.c b/src/hnswutils.c
index 743fa87e..198e4380 100644
--- a/src/hnswutils.c
+++ b/src/hnswutils.c
@@ -153,6 +153,19 @@ HnswOptionalProcInfo(Relation index, uint16 procnum)
return index_getprocinfo(index, 1, procnum);
}
+/*
+ * Set procinfo
+ */
+void
+HnswSetProcinfo(Relation index, FmgrInfo **procinfo, FmgrInfo **normprocinfo, Oid *collation)
+{
+ *procinfo = index_getprocinfo(index, 1, HNSW_DISTANCE_PROC);
+ *collation = index->rd_indcollation[0];
+
+ if (normprocinfo != NULL)
+ *normprocinfo = HnswOptionalProcInfo(index, HNSW_NORM_PROC);
+}
+
/*
* Normalize value
*/
diff --git a/src/hnswvacuum.c b/src/hnswvacuum.c
index 67cc645c..7931f851 100644
--- a/src/hnswvacuum.c
+++ b/src/hnswvacuum.c
@@ -573,13 +573,13 @@ InitVacuumState(HnswVacuumState * vacuumstate, IndexVacuumInfo *info, IndexBulkD
vacuumstate->callback_state = callback_state;
vacuumstate->efConstruction = HnswGetEfConstruction(index);
vacuumstate->bas = GetAccessStrategy(BAS_BULKREAD);
- vacuumstate->procinfo = index_getprocinfo(index, 1, HNSW_DISTANCE_PROC);
- vacuumstate->collation = index->rd_indcollation[0];
vacuumstate->ntup = palloc0(HNSW_TUPLE_ALLOC_SIZE);
vacuumstate->tmpCtx = AllocSetContextCreate(CurrentMemoryContext,
"Hnsw vacuum temporary context",
ALLOCSET_DEFAULT_SIZES);
+ HnswSetProcinfo(index, &vacuumstate->procinfo, NULL, &vacuumstate->collation);
+
/* Get m from metapage */
HnswGetMetaPageInfo(index, &vacuumstate->m, NULL);
[parent: 57c05c59a2c5]