pgvector.git / summary / log / commit / refs
commit 8cd9bd16e6cd4ba0ca460176af886bd2729d6b63
Author: Andrew Kane <andrew@ankane.org>
Date: Wed Oct 28 22:41:54 2026 +0000
Improved property testing for indexes
CHANGELOG.md | 1 +
src/hnsw.c | 18 ++++++++++++++++--
src/ivfflat.c | 18 ++++++++++++++++--
test/expected/hnsw_vector.out | 34 ++++++++++++++++++++++++++++++++++
test/expected/ivfflat_vector.out | 37 +++++++++++++++++++++++++++++++++++++
test/sql/hnsw_vector.sql | 14 ++++++++++++++
test/sql/ivfflat_vector.sql | 14 ++++++++++++++
7 files changed, 132 insertions(+), 4 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a1615bc2..b82e658d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
- Added `vector_dims` function for `sparsevec`
- Improved performance of HNSW inserts with `sparsevec`
- Improved `amvalidate` for indexes
+- Improved property testing for indexes
- Dropped support for Postgres 13 and 14
## 0.8.7 (2026-10-01)
diff --git a/src/hnsw.c b/src/hnsw.c
index bd196eba..32f43122 100644
--- a/src/hnsw.c
+++ b/src/hnsw.c
@@ -265,6 +265,20 @@ hnswoptions(Datum reloptions, bool validate)
tab, lengthof(tab));
}
+/*
+ * Check whether access method, index, or column has property
+ */
+static bool
+hnswproperty(Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
+{
+ if (attno == 0 || prop != AMPROP_DISTANCE_ORDERABLE)
+ return false;
+
+ *res = true;
+ *isnull = false;
+ return true;
+}
+
/*
* Validate catalog entries for the specified operator class
*/
@@ -491,7 +505,7 @@ hnswhandler(PG_FUNCTION_ARGS)
.amcostestimate = hnswcostestimate,
.amgettreeheight = NULL,
.amoptions = hnswoptions,
- .amproperty = NULL,
+ .amproperty = hnswproperty,
.ambuildphasename = hnswbuildphasename,
.amvalidate = hnswvalidate,
.amadjustmembers = NULL,
@@ -559,7 +573,7 @@ hnswhandler(PG_FUNCTION_ARGS)
amroutine->amgettreeheight = NULL;
#endif
amroutine->amoptions = hnswoptions;
- amroutine->amproperty = NULL; /* TODO AMPROP_DISTANCE_ORDERABLE */
+ amroutine->amproperty = hnswproperty;
amroutine->ambuildphasename = hnswbuildphasename;
amroutine->amvalidate = hnswvalidate;
amroutine->amadjustmembers = NULL;
diff --git a/src/ivfflat.c b/src/ivfflat.c
index 95cf80f2..0c982016 100644
--- a/src/ivfflat.c
+++ b/src/ivfflat.c
@@ -165,6 +165,20 @@ ivfflatcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
*indexPages = costs.numIndexPages;
}
+/*
+ * Check whether access method, index, or column has property
+ */
+static bool
+ivfflatproperty(Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
+{
+ if (attno == 0 || prop != AMPROP_DISTANCE_ORDERABLE)
+ return false;
+
+ *res = true;
+ *isnull = false;
+ return true;
+}
+
/*
* Parse and validate the reloptions
*/
@@ -413,7 +427,7 @@ ivfflathandler(PG_FUNCTION_ARGS)
.amcostestimate = ivfflatcostestimate,
.amgettreeheight = NULL,
.amoptions = ivfflatoptions,
- .amproperty = NULL,
+ .amproperty = ivfflatproperty,
.ambuildphasename = ivfflatbuildphasename,
.amvalidate = ivfflatvalidate,
.amadjustmembers = NULL,
@@ -481,7 +495,7 @@ ivfflathandler(PG_FUNCTION_ARGS)
amroutine->amgettreeheight = NULL;
#endif
amroutine->amoptions = ivfflatoptions;
- amroutine->amproperty = NULL; /* TODO AMPROP_DISTANCE_ORDERABLE */
+ amroutine->amproperty = ivfflatproperty;
amroutine->ambuildphasename = ivfflatbuildphasename;
amroutine->amvalidate = ivfflatvalidate;
amroutine->amadjustmembers = NULL;
diff --git a/test/expected/hnsw_vector.out b/test/expected/hnsw_vector.out
index 02376819..11af1eec 100644
--- a/test/expected/hnsw_vector.out
+++ b/test/expected/hnsw_vector.out
@@ -215,6 +215,40 @@ DROP TABLE t;
CREATE TABLE t (val vector(2001));
CREATE INDEX ON t USING hnsw (val vector_l2_ops);
ERROR: column cannot have more than 2000 dimensions for hnsw index
+DROP TABLE t;
+-- properties
+SELECT pg_indexam_has_property(oid, 'distance_orderable') FROM pg_am WHERE amname = 'hnsw';
+ pg_indexam_has_property
+-------------------------
+
+(1 row)
+
+CREATE TABLE t (val vector(3));
+CREATE INDEX idx ON t USING hnsw (val vector_l2_ops);
+SELECT pg_index_has_property('idx'::regclass, 'distance_orderable');
+ pg_index_has_property
+-----------------------
+
+(1 row)
+
+SELECT pg_index_column_has_property('idx'::regclass, 1, 'distance_orderable');
+ pg_index_column_has_property
+------------------------------
+ t
+(1 row)
+
+SELECT pg_index_column_has_property('idx'::regclass, 2, 'distance_orderable');
+ pg_index_column_has_property
+------------------------------
+
+(1 row)
+
+SELECT pg_index_column_has_property('idx'::regclass, 1, 'search_nulls');
+ pg_index_column_has_property
+------------------------------
+ f
+(1 row)
+
DROP TABLE t;
-- opclass validation
SELECT opcname FROM pg_opclass WHERE NOT amvalidate(oid);
diff --git a/test/expected/ivfflat_vector.out b/test/expected/ivfflat_vector.out
index d4ba5f11..ec3f778b 100644
--- a/test/expected/ivfflat_vector.out
+++ b/test/expected/ivfflat_vector.out
@@ -210,3 +210,40 @@ DETAIL: This will cause low recall.
HINT: Drop the index until the table has more data.
DROP TABLE t;
RESET maintenance_work_mem;
+-- properties
+SELECT pg_indexam_has_property(oid, 'distance_orderable') FROM pg_am WHERE amname = 'ivfflat';
+ pg_indexam_has_property
+-------------------------
+
+(1 row)
+
+CREATE TABLE t (val vector(3));
+CREATE INDEX idx ON t USING ivfflat (val vector_l2_ops);
+NOTICE: ivfflat index created with little data
+DETAIL: This will cause low recall.
+HINT: Drop the index until the table has more data.
+SELECT pg_index_has_property('idx'::regclass, 'distance_orderable');
+ pg_index_has_property
+-----------------------
+
+(1 row)
+
+SELECT pg_index_column_has_property('idx'::regclass, 1, 'distance_orderable');
+ pg_index_column_has_property
+------------------------------
+ t
+(1 row)
+
+SELECT pg_index_column_has_property('idx'::regclass, 2, 'distance_orderable');
+ pg_index_column_has_property
+------------------------------
+
+(1 row)
+
+SELECT pg_index_column_has_property('idx'::regclass, 1, 'search_nulls');
+ pg_index_column_has_property
+------------------------------
+ f
+(1 row)
+
+DROP TABLE t;
diff --git a/test/sql/hnsw_vector.sql b/test/sql/hnsw_vector.sql
index 7ccfb34e..eb2d192e 100644
--- a/test/sql/hnsw_vector.sql
+++ b/test/sql/hnsw_vector.sql
@@ -123,6 +123,20 @@ CREATE TABLE t (val vector(2001));
CREATE INDEX ON t USING hnsw (val vector_l2_ops);
DROP TABLE t;
+-- properties
+
+SELECT pg_indexam_has_property(oid, 'distance_orderable') FROM pg_am WHERE amname = 'hnsw';
+
+CREATE TABLE t (val vector(3));
+CREATE INDEX idx ON t USING hnsw (val vector_l2_ops);
+
+SELECT pg_index_has_property('idx'::regclass, 'distance_orderable');
+SELECT pg_index_column_has_property('idx'::regclass, 1, 'distance_orderable');
+SELECT pg_index_column_has_property('idx'::regclass, 2, 'distance_orderable');
+SELECT pg_index_column_has_property('idx'::regclass, 1, 'search_nulls');
+
+DROP TABLE t;
+
-- opclass validation
SELECT opcname FROM pg_opclass WHERE NOT amvalidate(oid);
diff --git a/test/sql/ivfflat_vector.sql b/test/sql/ivfflat_vector.sql
index 3338f639..7c8537cf 100644
--- a/test/sql/ivfflat_vector.sql
+++ b/test/sql/ivfflat_vector.sql
@@ -119,3 +119,17 @@ INSERT INTO t (val) VALUES (array_fill(0, ARRAY[2000]));
CREATE INDEX ON t USING ivfflat (val vector_l2_ops);
DROP TABLE t;
RESET maintenance_work_mem;
+
+-- properties
+
+SELECT pg_indexam_has_property(oid, 'distance_orderable') FROM pg_am WHERE amname = 'ivfflat';
+
+CREATE TABLE t (val vector(3));
+CREATE INDEX idx ON t USING ivfflat (val vector_l2_ops);
+
+SELECT pg_index_has_property('idx'::regclass, 'distance_orderable');
+SELECT pg_index_column_has_property('idx'::regclass, 1, 'distance_orderable');
+SELECT pg_index_column_has_property('idx'::regclass, 2, 'distance_orderable');
+SELECT pg_index_column_has_property('idx'::regclass, 1, 'search_nulls');
+
+DROP TABLE t;
[parent: 3fc275dab278]