Repository navigation
Conversation
Retain the first page with deleted elements when using the free space map, and use the tail page only as a fallback. This preserves reusable space for insertions whose element and neighbors need separate pages. Cover repeated delete, vacuum, and insert cycles with large sparsevecs. Audit finding: F007
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repeatedly deleting, vacuuming, and reinserting a single large
sparseveccan cause an HNSW index to grow on every cycle, even without concurrent activity or an increase in the number of live rows.When the free space map is enabled, VACUUM currently sets the insertion hint to the last page. Large elements whose element and neighbor tuples require separate pages cannot satisfy the combined-size free-space request. Starting from the last page then misses reusable space on earlier pages and causes unnecessary index extension.
Preserve the first page containing a deleted element as the insertion fallback, while continuing to maintain the free space map. Use the last page only when no deleted element was found.
Example
The regression test maintains one live row containing a sparse vector with 1,000 nonzero elements. Each
cycle deletes the row, runs
VACUUM (INDEX_CLEANUP ON), and reinserts the same vector.With 8 KiB pages and default HNSW index parameters, the observed index sizes are:
After every cycle, the table still contains only one live row. The fix allows the index to reuse the pages holding deleted elements.
The complete reproducer is included in
test/t/049_f007_regression.pl.Validation