From 564a3d45fc20ac66037f661a3fa340a3bcbb19ca Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Wed, 4 Oct 2023 20:14:50 -0700 Subject: [PATCH] Added check for MVCC-compliant snapshot for HNSW index scans - closes #281 --- CHANGELOG.md | 1 + src/hnswscan.c | 14 +++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00c8be1..55f9b85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 0.5.1 (unreleased) +- Added check for MVCC-compliant snapshot for HNSW index scans - Improved performance of index scans for IVFFlat after updates and deletes ## 0.5.0 (2023-08-28) diff --git a/src/hnswscan.c b/src/hnswscan.c index d391a10..7cf2bf0 100644 --- a/src/hnswscan.c +++ b/src/hnswscan.c @@ -160,6 +160,11 @@ hnswgettuple(IndexScanDesc scan, ScanDirection dir) if (scan->orderByData == NULL) elog(ERROR, "cannot scan hnsw index without order"); + /* Requires MVCC-compliant snapshot as not able to maintain a pin */ + /* https://www.postgresql.org/docs/current/index-locking.html */ + if (!IsMVCCSnapshot(scan->xs_snapshot)) + elog(ERROR, "non-MVCC snapshots are not supported with hnsw"); + /* Get scan value */ value = GetScanValue(scan); @@ -201,15 +206,6 @@ hnswgettuple(IndexScanDesc scan, ScanDirection dir) scan->xs_ctup.t_self = *heaptid; #endif - /* - * Typically, an index scan must maintain a pin on the index page - * holding the item last returned by amgettuple. However, this is not - * needed with the current vacuum strategy, which ensures scans do not - * visit tuples in danger of being marked as deleted. - * - * https://www.postgresql.org/docs/current/index-locking.html - */ - scan->xs_recheckorderby = false; return true; }