From: Michael Paquier Date: Sun, 22 Mar 2026 06:24:33 +0000 (+0900) Subject: Add test for single-page VACUUM of hash index on INSERT X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f7947a48d0c4b802f986ac32dc0e95b6f7f8f8f;p=thirdparty%2Fpostgresql.git 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 Reviewed-by: Heikki Linnakangas Discussion: https://postgr.es/m/CALzhyqxrc1ZHYmf5V8NE+yMboqVg7xZrQM7K2c7VS0p1v8z42w@mail.gmail.com --- diff --git a/src/test/regress/expected/hash_index.out b/src/test/regress/expected/hash_index.out index 04035400f12..0b099b9e771 100644 --- a/src/test/regress/expected/hash_index.out +++ b/src/test/regress/expected/hash_index.out @@ -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. diff --git a/src/test/regress/sql/hash_index.sql b/src/test/regress/sql/hash_index.sql index 60571f6cdf1..3ebdaeaf172 100644 --- a/src/test/regress/sql/hash_index.sql +++ b/src/test/regress/sql/hash_index.sql @@ -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;