From 451e36cee7b87d178c02282c7d6a2a934e8642b3 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Thu, 10 Aug 2023 21:09:38 -0700 Subject: [PATCH] Added check for ef_construction [skip ci] --- src/hnswbuild.c | 3 +++ test/expected/hnsw_options.out | 2 ++ test/sql/hnsw_options.sql | 1 + 3 files changed, 6 insertions(+) diff --git a/src/hnswbuild.c b/src/hnswbuild.c index eefc642..6a7e7f3 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -423,6 +423,9 @@ InitBuildState(HnswBuildState * buildstate, Relation heap, Relation index, Index if (buildstate->dimensions > HNSW_MAX_DIM) elog(ERROR, "column cannot have more than %d dimensions for hnsw index", HNSW_MAX_DIM); + if (buildstate->efConstruction < 2 * buildstate->m) + elog(ERROR, "ef_construction must be greater than or equal to 2 * m"); + buildstate->reltuples = 0; buildstate->indtuples = 0; diff --git a/test/expected/hnsw_options.out b/test/expected/hnsw_options.out index 5935110..1a07fef 100644 --- a/test/expected/hnsw_options.out +++ b/test/expected/hnsw_options.out @@ -12,6 +12,8 @@ DETAIL: Valid values are between "10" and "1000". CREATE INDEX ON t USING hnsw (val vector_l2_ops) WITH (ef_construction = 1001); ERROR: value 1001 out of bounds for option "ef_construction" DETAIL: Valid values are between "10" and "1000". +CREATE INDEX ON t USING hnsw (val vector_l2_ops) WITH (m = 16, ef_construction = 31); +ERROR: ef_construction must be greater than or equal to 2 * m SHOW hnsw.ef_search; hnsw.ef_search ---------------- diff --git a/test/sql/hnsw_options.sql b/test/sql/hnsw_options.sql index 1e4ca54..845921d 100644 --- a/test/sql/hnsw_options.sql +++ b/test/sql/hnsw_options.sql @@ -5,6 +5,7 @@ CREATE INDEX ON t USING hnsw (val vector_l2_ops) WITH (m = 1); CREATE INDEX ON t USING hnsw (val vector_l2_ops) WITH (m = 101); CREATE INDEX ON t USING hnsw (val vector_l2_ops) WITH (ef_construction = 9); CREATE INDEX ON t USING hnsw (val vector_l2_ops) WITH (ef_construction = 1001); +CREATE INDEX ON t USING hnsw (val vector_l2_ops) WITH (m = 16, ef_construction = 31); SHOW hnsw.ef_search;