pgvector.git / summary / log / commit / refs
commit 59962f91ddd285ce8e5ead3dc8411dfaa6a97f35
Author: Andrew Kane <andrew@ankane.org>
Date: Sun Nov 08 22:53:58 2026 +0000
Added vacuuming progress for HNSW
CHANGELOG.md | 1 +
src/hnsw.h | 1 +
src/hnswvacuum.c | 39 ++++++++++++++++++++++++++++++++-------
3 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a724b193..5dc72127 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
## 0.9.0 (unreleased)
- Added asynchronous I/O for HNSW indexes
+- Added vacuuming progress for HNSW
- Added `vector_dims` function for `sparsevec`
- Improved performance of HNSW inserts with `sparsevec`
- Improved `amvalidate` for indexes
diff --git a/src/hnsw.h b/src/hnsw.h
index 95da734c..9ccb2bbf 100644
--- a/src/hnsw.h
+++ b/src/hnsw.h
@@ -452,6 +452,7 @@ typedef struct HnswVacuumState
{
/* Info */
Relation index;
+ IndexVacuumInfo *info;
IndexBulkDeleteResult *stats;
IndexBulkDeleteCallback callback;
void *callback_state;
diff --git a/src/hnswvacuum.c b/src/hnswvacuum.c
index c537438c..3c21fdee 100644
--- a/src/hnswvacuum.c
+++ b/src/hnswvacuum.c
@@ -15,6 +15,11 @@
#include "varatt.h"
#endif
+#if PG_VERSION_NUM >= 200000
+#include "commands/progress.h"
+#include "utils/backend_progress.h"
+#endif
+
#if PG_VERSION_NUM >= 180000
#define vacuum_delay_point() vacuum_delay_point(false)
#endif
@@ -382,6 +387,12 @@ RepairGraph(HnswVacuumState * vacuumstate)
Relation index = vacuumstate->index;
BufferAccessStrategy bas = vacuumstate->bas;
BlockNumber blkno = HNSW_HEAD_BLKNO;
+ BlockNumber totalBlocks;
+#if PG_VERSION_NUM >= 200000
+ bool reportProgress = vacuumstate->info->report_progress;
+#else
+ bool reportProgress = message_level_is_interesting(DEBUG1);
+#endif
/*
* Wait for inserts to complete. Inserts before this point may have
@@ -393,6 +404,14 @@ RepairGraph(HnswVacuumState * vacuumstate)
/* Repair entry point first */
RepairGraphEntryPoint(vacuumstate);
+ if (reportProgress)
+ {
+ totalBlocks = RelationGetNumberOfBlocks(index);
+#if PG_VERSION_NUM >= 200000
+ pgstat_progress_update_param(PROGRESS_SCAN_BLOCKS_TOTAL, totalBlocks);
+#endif
+ }
+
while (BlockNumberIsValid(blkno))
{
Buffer buf;
@@ -490,15 +509,20 @@ RepairGraph(HnswVacuumState * vacuumstate)
MemoryContextSwitchTo(oldCtx);
MemoryContextReset(vacuumstate->tmpCtx);
-#ifdef HNSW_VACUUM_PROGRESS
- if (!BlockNumberIsValid(blkno) || (blkno - HNSW_HEAD_BLKNO) % 1000 == 0)
+ /* Update progress */
+ /* No need to update total blocks since new blocks are quick */
+ if (reportProgress)
{
- BlockNumber totalBlocks = RelationGetNumberOfBlocks(index);
- BlockNumber currentBlocks = BlockNumberIsValid(blkno) ? blkno : totalBlocks;
-
- elog(INFO, "hnsw vacuum progress: %.1f%%", 100.0 * currentBlocks / totalBlocks);
- }
+ BlockNumber currentBlocks = BlockNumberIsValid(blkno) && blkno < totalBlocks ? blkno : totalBlocks;
+
+#if PG_VERSION_NUM >= 200000
+ pgstat_progress_update_param(PROGRESS_SCAN_BLOCKS_DONE, currentBlocks);
+#else
+ /* Check blkno instead of currentBlocks to avoid extra logging */
+ if (!BlockNumberIsValid(blkno) || (blkno % 1000 == 0 && blkno < totalBlocks))
+ elog(DEBUG1, "hnsw vacuum progress: %.1f%%", 100.0 * currentBlocks / totalBlocks);
#endif
+ }
}
}
@@ -851,6 +875,7 @@ InitVacuumState(HnswVacuumState * vacuumstate, IndexVacuumInfo *info, IndexBulkD
stats = palloc0_object(IndexBulkDeleteResult);
vacuumstate->index = index;
+ vacuumstate->info = info;
vacuumstate->stats = stats;
vacuumstate->callback = callback;
vacuumstate->callback_state = callback_state;
[parent: 724588a5504b]