Add test for single-page VACUUM of hash index on INSERT

_hash_vacuum_one_page() in hashinsert.c is a routine related to hash
indexes that can perform a single-page VACUUM when dead tuples are
detected during index insertion.  This routine previously had no test
coverage, and this commit adds a test case for that purpose.

To safely create dead tuples in a way that works with parallel tests,
this uses a technique based on a rollbacked INSERT, following a
suggestion by Heikki Linnakangas.

Author: Alexander Kuzmenkov <akuzmenkov@tigerdata.com>
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://postgr.es/m/CALzhyqxrc1ZHYmf5V8NE+yMboqVg7xZrQM7K2c7VS0p1v8z42w@mail.gmail.com
This commit is contained in:
Michael Paquier 2026-03-22 15:24:33 +09:00
parent 322bab7974
commit 1f7947a48d
2 changed files with 38 additions and 0 deletions

View file

@ -333,6 +333,27 @@ ROLLBACK;
INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 50) as i;
CHECKPOINT;
VACUUM hash_cleanup_heap;
-- Test cleanup of dead index tuples on single page with INSERT.
TRUNCATE hash_cleanup_heap;
INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 1000) as i;
-- This relies on a rollbacked INSERT instead of a DELETE to make the creation
-- of the dead tuples concurrent-safe.
BEGIN;
INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 500) as i;
ROLLBACK;
SET enable_seqscan = off;
SET enable_bitmapscan = off;
SELECT count(*) FROM hash_cleanup_heap WHERE keycol = 1;
count
-------
1000
(1 row)
-- This query checks the hash index pages for dead tuples where the data
-- is inserted, and performs a local VACUUM on a single page.
INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 200) as i;
RESET enable_seqscan;
RESET enable_bitmapscan;
-- Clean up.
DROP TABLE hash_cleanup_heap;
-- Index on temp table.

View file

@ -314,6 +314,23 @@ INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 50) as i;
CHECKPOINT;
VACUUM hash_cleanup_heap;
-- Test cleanup of dead index tuples on single page with INSERT.
TRUNCATE hash_cleanup_heap;
INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 1000) as i;
-- This relies on a rollbacked INSERT instead of a DELETE to make the creation
-- of the dead tuples concurrent-safe.
BEGIN;
INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 500) as i;
ROLLBACK;
SET enable_seqscan = off;
SET enable_bitmapscan = off;
SELECT count(*) FROM hash_cleanup_heap WHERE keycol = 1;
-- This query checks the hash index pages for dead tuples where the data
-- is inserted, and performs a local VACUUM on a single page.
INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 200) as i;
RESET enable_seqscan;
RESET enable_bitmapscan;
-- Clean up.
DROP TABLE hash_cleanup_heap;