From 934f5cd5a0e7e67489bc50dad8facf0cb628286a Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Thu, 3 Dec 2026 22:55:40 -0800 Subject: [PATCH] Enabled iterative index scans by default for HNSW [skip ci] --- CHANGELOG.md | 3 ++- src/hnsw.c | 2 +- test/expected/hnsw_vector.out | 2 +- test/t/015_hnsw_vector_duplicates.pl | 1 + test/t/023_hnsw_bit_duplicates.pl | 1 + test/t/027_hnsw_halfvec_duplicates.pl | 1 + test/t/031_hnsw_sparsevec_duplicates.pl | 1 + test/t/046_hnsw_vacuum_scan.pl | 2 +- 8 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86fe1b04..801fb64f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ -## 0.9.0 (unreleased) +## 1.0.0 (unreleased) +- 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` diff --git a/src/hnsw.c b/src/hnsw.c index 819c6c33..23d6a921 100644 --- a/src/hnsw.c +++ b/src/hnsw.c @@ -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", diff --git a/test/expected/hnsw_vector.out b/test/expected/hnsw_vector.out index 1641f040..7a1b37e6 100644 --- a/test/expected/hnsw_vector.out +++ b/test/expected/hnsw_vector.out @@ -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; diff --git a/test/t/015_hnsw_vector_duplicates.pl b/test/t/015_hnsw_vector_duplicates.pl index c68eb030..7b474bec 100644 --- a/test/t/015_hnsw_vector_duplicates.pl +++ b/test/t/015_hnsw_vector_duplicates.pl @@ -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); diff --git a/test/t/023_hnsw_bit_duplicates.pl b/test/t/023_hnsw_bit_duplicates.pl index f6d928c4..a4e8acde 100644 --- a/test/t/023_hnsw_bit_duplicates.pl +++ b/test/t/023_hnsw_bit_duplicates.pl @@ -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); diff --git a/test/t/027_hnsw_halfvec_duplicates.pl b/test/t/027_hnsw_halfvec_duplicates.pl index 80f88530..3e4374a5 100644 --- a/test/t/027_hnsw_halfvec_duplicates.pl +++ b/test/t/027_hnsw_halfvec_duplicates.pl @@ -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); diff --git a/test/t/031_hnsw_sparsevec_duplicates.pl b/test/t/031_hnsw_sparsevec_duplicates.pl index 09b8380b..c76d944d 100644 --- a/test/t/031_hnsw_sparsevec_duplicates.pl +++ b/test/t/031_hnsw_sparsevec_duplicates.pl @@ -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); diff --git a/test/t/046_hnsw_vacuum_scan.pl b/test/t/046_hnsw_vacuum_scan.pl index 909b8209..cfdfa74d 100644 --- a/test/t/046_hnsw_vacuum_scan.pl +++ b/test/t/046_hnsw_vacuum_scan.pl @@ -30,7 +30,7 @@ $node->pgbench( [qr{^$}], "concurrent SELECTs and VACUUM", { - "046_hnsw_vacuum_scan_select\@1000" => "SET hnsw.iterative_scan = strict_order; SELECT i FROM tst ORDER BY v <-> '[0,0,0]' LIMIT 10;", + "046_hnsw_vacuum_scan_select\@1000" => "SELECT i FROM tst ORDER BY v <-> '[0,0,0]' LIMIT 10;", "046_hnsw_vacuum_scan_vacuum\@1" => "VACUUM tst;" } );