Enabled iterative index scans by default for HNSW [skip ci]

This commit is contained in:
Andrew Kane committed 2026-12-03 15:50:36 -08:00
1 parent 8877adc5a7
commit a48dfdfc49
8 files changed
+28 -3

No files matched your search

+4 -1
View File
@@ -1,5 +1,8 @@
## 0.9.0 (unreleased)
## 1.0.0 (unreleased)
See the [upgrade notes](README.md#1-0) to avoid a performance regression with certain queries
- Enabled iterative index scans by default for HNSW
- Added asynchronous I/O for indexes
- Added vacuuming progress for indexes
- Added `vector_dims` function for `sparsevec`
+18
View File
@@ -1287,6 +1287,24 @@ You can check the version in the current database with:
SELECT extversion FROM pg_extension WHERE extname = 'vector';
```
## Upgrade Notes
### 1.0
pgvector 1.0 enables iterative index scans by default for HNSW. Unfortunately, this can cause a performance regression for queries with a distance filter due to the [current behavior](https://www.postgresql.org/message-id/flat/CAOdR5yGUoMQ6j7M5hNUXrySzaqZVGf_Ne%2B8fwZMRKTFxU1nbJg%40mail.gmail.com) of the Postgres executor.
```sql
SELECT id FROM items WHERE embedding <-> '[1,2,3]' < 5 ORDER BY embedding <-> '[1,2,3]' LIMIT 5;
```
Before upgrading, update these queries to use a materialized CTE and place the distance filter outside of it.
```sql
WITH nearest_results AS MATERIALIZED (
SELECT id, embedding <-> '[1,2,3]' AS distance FROM items ORDER BY distance LIMIT 5
) SELECT id FROM nearest_results WHERE distance < 5 ORDER BY distance;
```
## Thanks
Thanks to:
+1 -1
View File
@@ -106,7 +106,7 @@ HnswInit(void)
DefineCustomEnumVariable("hnsw.iterative_scan", "Sets the mode for iterative scans",
NULL, &hnsw_iterative_scan,
HNSW_ITERATIVE_SCAN_OFF, hnsw_iterative_scan_options, PGC_USERSET, GUC_EXPLAIN, NULL, NULL, NULL);
HNSW_ITERATIVE_SCAN_STRICT, hnsw_iterative_scan_options, PGC_USERSET, GUC_EXPLAIN, NULL, NULL, NULL);
/* This is approximate and does not affect the initial scan */
DefineCustomIntVariable("hnsw.max_scan_tuples", "Sets the max number of tuples to visit for iterative scans",
+1 -1
View File
@@ -184,7 +184,7 @@ ERROR: 1001 is outside the valid range for parameter "hnsw.ef_search" (1 .. 100
SHOW hnsw.iterative_scan;
hnsw.iterative_scan
---------------------
off
strict_order
(1 row)
SET hnsw.iterative_scan = on;
+1
View File
@@ -26,6 +26,7 @@ sub test_duplicates
my $res = $node->safe_psql("postgres", qq(
SET enable_seqscan = off;
SET hnsw.ef_search = 1;
SET hnsw.iterative_scan = off;
SELECT COUNT(*) FROM (SELECT * FROM tst ORDER BY v <-> '[1,1,1]') t;
));
is($res, 10);
+1
View File
@@ -26,6 +26,7 @@ sub test_duplicates
my $res = $node->safe_psql("postgres", qq(
SET enable_seqscan = off;
SET hnsw.ef_search = 1;
SET hnsw.iterative_scan = off;
SELECT COUNT(*) FROM (SELECT * FROM tst ORDER BY v <~> '111') t;
));
is($res, 10);
+1
View File
@@ -26,6 +26,7 @@ sub test_duplicates
my $res = $node->safe_psql("postgres", qq(
SET enable_seqscan = off;
SET hnsw.ef_search = 1;
SET hnsw.iterative_scan = off;
SELECT COUNT(*) FROM (SELECT * FROM tst ORDER BY v <-> '[1,1,1]') t;
));
is($res, 10);
+1
View File
@@ -26,6 +26,7 @@ sub test_duplicates
my $res = $node->safe_psql("postgres", qq(
SET enable_seqscan = off;
SET hnsw.ef_search = 1;
SET hnsw.iterative_scan = off;
SELECT COUNT(*) FROM (SELECT * FROM tst ORDER BY v <-> '{1:1,2:1,3:1}/3') t;
));
is($res, 10);