]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add test for single-page VACUUM of hash index on INSERT
authorMichael Paquier <michael@paquier.xyz>
Sun, 22 Mar 2026 06:24:33 +0000 (15:24 +0900)
committerMichael Paquier <michael@paquier.xyz>
Sun, 22 Mar 2026 06:24:33 +0000 (15:24 +0900)
_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

src/test/regress/expected/hash_index.out
src/test/regress/sql/hash_index.sql

index 04035400f12b7e225aaa47598efae271a01f033b..0b099b9e771d326759855cd34d90ee06ff86f3aa 100644 (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.
index 60571f6cdf14b803a778f6cb05e2f8fa3ee4de91..3ebdaeaf17289a5d5097d310bbe1a3d0fb0ed947 100644 (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;