From ba18942fcff8aa846df284b0b10517ec85d0e36b Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Wed, 27 Mar 2024 16:41:17 -0700 Subject: [PATCH] Removed normvec from IVFFlat for simplicity (no difference in performance) --- src/ivfbuild.c | 8 ++------ src/ivfflat.h | 3 +-- src/ivfinsert.c | 2 +- src/ivfscan.c | 2 +- src/ivfutils.c | 6 ++---- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/ivfbuild.c b/src/ivfbuild.c index c4f4d4b..4c52d9f 100644 --- a/src/ivfbuild.c +++ b/src/ivfbuild.c @@ -57,7 +57,7 @@ AddSample(Datum *values, IvfflatBuildState * buildstate) */ if (buildstate->kmeansnormprocinfo != NULL) { - if (!IvfflatNormValue(buildstate->kmeansnormprocinfo, buildstate->collation, &value, buildstate->normvec)) + if (!IvfflatNormValue(buildstate->kmeansnormprocinfo, buildstate->collation, &value)) return; } @@ -153,7 +153,7 @@ AddTupleToSort(Relation index, ItemPointer tid, Datum *values, IvfflatBuildState /* Normalize if needed */ if (buildstate->normprocinfo != NULL) { - if (!IvfflatNormValue(buildstate->normprocinfo, buildstate->collation, &value, buildstate->normvec)) + if (!IvfflatNormValue(buildstate->normprocinfo, buildstate->collation, &value)) return; } @@ -356,9 +356,6 @@ InitBuildState(IvfflatBuildState * buildstate, Relation heap, Relation index, In buildstate->centers = VectorArrayInit(buildstate->lists, buildstate->dimensions); buildstate->listInfo = palloc(sizeof(ListInfo) * buildstate->lists); - /* Reuse for each tuple */ - buildstate->normvec = InitVector(buildstate->dimensions); - buildstate->tmpCtx = AllocSetContextCreate(CurrentMemoryContext, "Ivfflat build temporary context", ALLOCSET_DEFAULT_SIZES); @@ -380,7 +377,6 @@ FreeBuildState(IvfflatBuildState * buildstate) { VectorArrayFree(buildstate->centers); pfree(buildstate->listInfo); - pfree(buildstate->normvec); #ifdef IVFFLAT_KMEANS_DEBUG pfree(buildstate->listSums); diff --git a/src/ivfflat.h b/src/ivfflat.h index e27420b..422967f 100644 --- a/src/ivfflat.h +++ b/src/ivfflat.h @@ -172,7 +172,6 @@ typedef struct IvfflatBuildState VectorArray samples; VectorArray centers; ListInfo *listInfo; - Vector *normvec; #ifdef IVFFLAT_KMEANS_DEBUG double inertia; @@ -267,7 +266,7 @@ void VectorArrayFree(VectorArray arr); void PrintVectorArray(char *msg, VectorArray arr); void IvfflatKmeans(Relation index, VectorArray samples, VectorArray centers); FmgrInfo *IvfflatOptionalProcInfo(Relation index, uint16 procnum); -bool IvfflatNormValue(FmgrInfo *procinfo, Oid collation, Datum *value, Vector * result); +bool IvfflatNormValue(FmgrInfo *procinfo, Oid collation, Datum *value); int IvfflatGetLists(Relation index); void IvfflatGetMetaPageInfo(Relation index, int *lists, int *dimensions); void IvfflatUpdateList(Relation index, ListInfo listInfo, BlockNumber insertPage, BlockNumber originalInsertPage, BlockNumber startPage, ForkNumber forkNum); diff --git a/src/ivfinsert.c b/src/ivfinsert.c index 342cca7..2d8d4c3 100644 --- a/src/ivfinsert.c +++ b/src/ivfinsert.c @@ -85,7 +85,7 @@ InsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heap_tid, R normprocinfo = IvfflatOptionalProcInfo(index, IVFFLAT_NORM_PROC); if (normprocinfo != NULL) { - if (!IvfflatNormValue(normprocinfo, index->rd_indcollation[0], &value, NULL)) + if (!IvfflatNormValue(normprocinfo, index->rd_indcollation[0], &value)) return; } diff --git a/src/ivfscan.c b/src/ivfscan.c index 9b0e03e..66b3ae6 100644 --- a/src/ivfscan.c +++ b/src/ivfscan.c @@ -293,7 +293,7 @@ ivfflatgettuple(IndexScanDesc scan, ScanDirection dir) /* Fine if normalization fails */ if (so->normprocinfo != NULL) - IvfflatNormValue(so->normprocinfo, so->collation, &value, NULL); + IvfflatNormValue(so->normprocinfo, so->collation, &value); } IvfflatBench("GetScanLists", GetScanLists(scan, value)); diff --git a/src/ivfutils.c b/src/ivfutils.c index a8746f7..587a97e 100644 --- a/src/ivfutils.c +++ b/src/ivfutils.c @@ -75,16 +75,14 @@ IvfflatOptionalProcInfo(Relation index, uint16 procnum) * if it's different than the original value */ bool -IvfflatNormValue(FmgrInfo *procinfo, Oid collation, Datum *value, Vector * result) +IvfflatNormValue(FmgrInfo *procinfo, Oid collation, Datum *value) { double norm = DatumGetFloat8(FunctionCall1Coll(procinfo, collation, *value)); if (norm > 0) { Vector *v = DatumGetVector(*value); - - if (result == NULL) - result = InitVector(v->dim); + Vector *result = InitVector(v->dim); for (int i = 0; i < v->dim; i++) result->x[i] = v->x[i] / norm;