diff --git a/src/hnsw.h b/src/hnsw.h index 5853fc9..ab75a0c 100644 --- a/src/hnsw.h +++ b/src/hnsw.h @@ -316,7 +316,7 @@ typedef struct HnswVacuumState int HnswGetM(Relation index); int HnswGetEfConstruction(Relation index); FmgrInfo *HnswOptionalProcInfo(Relation index, uint16 procnum); -bool HnswNormValue(FmgrInfo *procinfo, Oid collation, Datum *value, Vector * result); +void HnswNormValue(FmgrInfo *procinfo, Oid collation, Datum *value, Vector * result); void HnswCommitBuffer(Buffer buf, GenericXLogState *state); Buffer HnswNewBuffer(Relation index, ForkNumber forkNum); void HnswInitPage(Buffer buf, Page page); diff --git a/src/hnswbuild.c b/src/hnswbuild.c index ea7b889..3588fee 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -307,10 +307,7 @@ InsertTuple(Relation index, Datum *values, HnswElement element, HnswBuildState * /* Normalize if needed */ if (buildstate->normprocinfo != NULL) - { - if (!HnswNormValue(buildstate->normprocinfo, collation, &value, buildstate->normvec)) - return false; - } + HnswNormValue(buildstate->normprocinfo, collation, &value, buildstate->normvec); /* Copy value to element so accessible outside of memory context */ oldCtx = MemoryContextSwitchTo(outerCtx); diff --git a/src/hnswinsert.c b/src/hnswinsert.c index 873be3a..7971409 100644 --- a/src/hnswinsert.c +++ b/src/hnswinsert.c @@ -500,10 +500,7 @@ HnswInsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heap_ti /* Normalize if needed */ normprocinfo = HnswOptionalProcInfo(index, HNSW_NORM_PROC); if (normprocinfo != NULL) - { - if (!HnswNormValue(normprocinfo, collation, &value, NULL)) - return false; - } + HnswNormValue(normprocinfo, collation, &value, NULL); /* * Get a shared lock. This allows vacuum to ensure no in-flight inserts diff --git a/src/hnswutils.c b/src/hnswutils.c index 0eee24e..95676e9 100644 --- a/src/hnswutils.c +++ b/src/hnswutils.c @@ -55,7 +55,7 @@ HnswOptionalProcInfo(Relation index, uint16 procnum) * The caller needs to free the pointer stored in value * if it's different than the original value */ -bool +void HnswNormValue(FmgrInfo *procinfo, Oid collation, Datum *value, Vector * result) { double norm = DatumGetFloat8(FunctionCall1Coll(procinfo, collation, *value)); @@ -71,11 +71,7 @@ HnswNormValue(FmgrInfo *procinfo, Oid collation, Datum *value, Vector * result) result->x[i] = v->x[i] / norm; *value = PointerGetDatum(result); - - return true; } - - return false; } /* diff --git a/src/ivfbuild.c b/src/ivfbuild.c index 15ba9aa..a2b094d 100644 --- a/src/ivfbuild.c +++ b/src/ivfbuild.c @@ -177,10 +177,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)) - return; - } + IvfflatNormValue(buildstate->normprocinfo, buildstate->collation, &value, buildstate->normvec); /* Find the list that minimizes the distance */ for (int i = 0; i < centers->length; i++) diff --git a/src/ivfinsert.c b/src/ivfinsert.c index 103fe49..a8e67bd 100644 --- a/src/ivfinsert.c +++ b/src/ivfinsert.c @@ -83,10 +83,7 @@ InsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heap_tid, R /* Normalize if needed */ normprocinfo = IvfflatOptionalProcInfo(index, IVFFLAT_NORM_PROC); if (normprocinfo != NULL) - { - if (!IvfflatNormValue(normprocinfo, index->rd_indcollation[0], &value, NULL)) - return; - } + IvfflatNormValue(normprocinfo, index->rd_indcollation[0], &value, NULL); /* Find the insert page - sets the page and list info */ FindInsertPage(index, values, &insertPage, &listInfo); diff --git a/test/expected/hnsw_cosine.out b/test/expected/hnsw_cosine.out index df9eb81..01542bc 100644 --- a/test/expected/hnsw_cosine.out +++ b/test/expected/hnsw_cosine.out @@ -9,18 +9,19 @@ SELECT * FROM t ORDER BY val <=> '[3,3,3]'; [1,1,1] [1,2,3] [1,2,4] -(3 rows) + [0,0,0] +(4 rows) SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <=> '[0,0,0]') t2; count ------- - 3 + 4 (1 row) SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <=> (SELECT NULL::vector)) t2; count ------- - 3 + 4 (1 row) DROP TABLE t; diff --git a/test/expected/ivfflat_cosine.out b/test/expected/ivfflat_cosine.out index 8584d95..d647057 100644 --- a/test/expected/ivfflat_cosine.out +++ b/test/expected/ivfflat_cosine.out @@ -9,18 +9,19 @@ SELECT * FROM t ORDER BY val <=> '[3,3,3]'; [1,1,1] [1,2,3] [1,2,4] -(3 rows) + [0,0,0] +(4 rows) SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <=> '[0,0,0]') t2; count ------- - 3 + 4 (1 row) SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <=> (SELECT NULL::vector)) t2; count ------- - 3 + 4 (1 row) DROP TABLE t;