From: jitokim (@jitokim) <noreply+jitokim@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] PR #1026: HNSW: don't rewind insertPage to deleted slots that cannot fit the element
Date: Fri, 16 Oct 2026 16:37:41 +0000
Message-ID: <gh-pgvector-pgvector-1026-c6220157113@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-1026@github.com>
References: <gh-pgvector-pgvector-1026@github.com>
Sure. The setup:
```sql
CREATE TABLE tst (i serial, v sparsevec(10000));
-- 20k rows, nnz=100 each
CREATE INDEX idx ON tst USING hnsw (v sparsevec_l2_ops);
-- delete only the rows whose element is at level >= 1 (about 1,270 rows), then
VACUUM tst;
-- then insert one row with nnz=155
```
The level >= 1 delete is what makes it contrived: every freed slot ends up too small for the new row.
Results on 78647a3 (PG 16.10, 5 runs each from a fresh copy of the same database, buffers from EXPLAIN (ANALYZE, BUFFERS)):
- Index built with 78647a3: insertPage is already the last page (2858 of 2,859) before and after. Level 0 inserts still touch ~4,300 buffers (read 2,871), level 1 inserts ~1,450. Same as 9b91f2d. 8 inserts in a row: level 0 stays at ~4,280 hits each.
- Index built and vacuumed with master (insertPage 3), then 78647a3 installed: the first insert reads 2,868 and moves insertPage to 2858, like you described. After that, 8 inserts in a row are ~2,100 hits each, and insertPage moves to 2859 once the index extends. On master the same index stays at insertPage 3 and ~5,070 buffers per insert.
So the previous-index case looks fixed. The new-index case doesn't seem to be about insertPage, since it's already at the end.