Fix an uninitialized access in hash_xlog_squeeze_page().
authorAmit Kapila <akapila@postgresql.org>
Fri, 1 Dec 2023 04:44:36 +0000 (10:14 +0530)
committerAmit Kapila <akapila@postgresql.org>
Fri, 1 Dec 2023 04:52:13 +0000 (10:22 +0530)
Commit 861f86beea changed hash_xlog_squeeze_page() to start reading
the write buffer conditionally but forgot to initialize it leading to an
uninitialized access.

Reported-by: Alexander Lakhin
Author: Hayato Kuroda
Reviewed-by: Alexander Lakhin, Amit Kapila
Discussion: http://postgr.es/m/62ed1a9f-746a-8e86-904b-51b9b806a1d9@gmail.com

src/backend/access/hash/hash_xlog.c
src/test/regress/expected/hash_index.out
src/test/regress/sql/hash_index.sql

index 40debf402884ace2ea1238fba91c8bd60f118c34..f1e233a817339593e18e0ba789df3a86e02cc5da 100644 (file)
@@ -632,7 +632,7 @@ hash_xlog_squeeze_page(XLogReaderState *record)
        XLogRecPtr      lsn = record->EndRecPtr;
        xl_hash_squeeze_page *xldata = (xl_hash_squeeze_page *) XLogRecGetData(record);
        Buffer          bucketbuf = InvalidBuffer;
-       Buffer          writebuf;
+       Buffer          writebuf = InvalidBuffer;
        Buffer          ovflbuf;
        Buffer          prevbuf = InvalidBuffer;
        Buffer          mapbuf;
index 0df348b5dd88245bc9854f301fa4ce3a1a9af800..0d4bdb2adefaeaf6cdb8e27efb29497018eba9d2 100644 (file)
@@ -298,6 +298,20 @@ ROLLBACK;
 INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 500) as i;
 CHECKPOINT;
 VACUUM hash_cleanup_heap;
+TRUNCATE hash_cleanup_heap;
+-- Insert tuples to both the primary bucket page and overflow pages.
+INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 500) as i;
+-- Fill overflow pages by "dead" tuples.
+BEGIN;
+INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 1500) as i;
+ROLLBACK;
+-- And insert some tuples again. During squeeze operation, these will be moved
+-- to other overflow pages and also allow overflow pages filled by dead tuples
+-- to be freed. Note the main purpose of this test is to test the case where
+-- we don't need to move any tuple from the overflow page being freed.
+INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 50) as i;
+CHECKPOINT;
+VACUUM hash_cleanup_heap;
 -- Clean up.
 DROP TABLE hash_cleanup_heap;
 -- Index on temp table.
index 943bd0ecf17e7baa0d1a0d5ac0ab1f82393a2d4b..219da829816d541da2768c0260554584034f52c3 100644 (file)
@@ -284,6 +284,23 @@ INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 500) as i;
 CHECKPOINT;
 VACUUM hash_cleanup_heap;
 
+TRUNCATE hash_cleanup_heap;
+
+-- Insert tuples to both the primary bucket page and overflow pages.
+INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 500) as i;
+-- Fill overflow pages by "dead" tuples.
+BEGIN;
+INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 1500) as i;
+ROLLBACK;
+-- And insert some tuples again. During squeeze operation, these will be moved
+-- to other overflow pages and also allow overflow pages filled by dead tuples
+-- to be freed. Note the main purpose of this test is to test the case where
+-- we don't need to move any tuple from the overflow page being freed.
+INSERT INTO hash_cleanup_heap SELECT 1 FROM generate_series(1, 50) as i;
+
+CHECKPOINT;
+VACUUM hash_cleanup_heap;
+
 -- Clean up.
 DROP TABLE hash_cleanup_heap;