From 6a5c18cdfb13c1f083f77ceb3fe28c81c7967d00 Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Sat, 21 Nov 2026 13:00:56 -0500 Subject: [PATCH] Hash: tighten squeeze redo Assert, show primary bucket block in desc hash_xlog_squeeze_page() registers the write page as block 0 only when it is modified. So when it replays a record with no tuples, the write page must be the previous page, and the Assert can say so. Since the primary bucket page is no longer registered when the operation holds only a pin on it, pg_waldump did not show it at all. Print its block number for DELETE, MOVE_PAGE_CONTENTS and SQUEEZE_PAGE when the record carries it. --- src/backend/access/hash/hash_xlog.c | 8 ++++---- src/backend/access/rmgrdesc/hashdesc.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/backend/access/hash/hash_xlog.c b/src/backend/access/hash/hash_xlog.c index f4816486618..430c7e8c879 100644 --- a/src/backend/access/hash/hash_xlog.c +++ b/src/backend/access/hash/hash_xlog.c @@ -709,11 +709,11 @@ hash_xlog_squeeze_page(XLogReaderState *record) else { /* - * Ensure that the required flags are set when there are no - * tuples. See _hash_freeovflpage(). + * The write page is registered only when it is modified, so with + * no tuples it must be the previous page, whose nextblkno is + * updated below. See _hash_freeovflpage(). */ - Assert(xldata->is_prim_bucket_same_wrt || - xldata->is_prev_bucket_same_wrt); + Assert(xldata->is_prev_bucket_same_wrt); } /* diff --git a/src/backend/access/rmgrdesc/hashdesc.c b/src/backend/access/rmgrdesc/hashdesc.c index 593013afe9c..e16fc2a1539 100644 --- a/src/backend/access/rmgrdesc/hashdesc.c +++ b/src/backend/access/rmgrdesc/hashdesc.c @@ -16,6 +16,24 @@ #include "access/hash_xlog.h" +/* + * Append the block number of the primary bucket page, if the record carries + * it in its main data after a struct of rec_size bytes. It does so when the + * page is not registered because the operation holds only a pin on it. + */ +static void +hash_desc_primary_bucket(StringInfo buf, XLogReaderState *record, Size rec_size) +{ + if (XLogRecGetDataLen(record) >= rec_size + sizeof(BlockNumber)) + { + BlockNumber bucket_blkno; + + memcpy(&bucket_blkno, XLogRecGetData(record) + rec_size, + sizeof(BlockNumber)); + appendStringInfo(buf, ", primary_blkno %u", bucket_blkno); + } +} + void hash_desc(StringInfo buf, XLogReaderState *record) { @@ -83,6 +101,7 @@ hash_desc(StringInfo buf, XLogReaderState *record) appendStringInfo(buf, "ntups %d, is_primary %c", xlrec->ntups, xlrec->is_prim_bucket_same_wrt ? 'T' : 'F'); + hash_desc_primary_bucket(buf, record, SizeOfHashMovePageContents); break; } case XLOG_HASH_SQUEEZE_PAGE: @@ -95,6 +114,7 @@ hash_desc(StringInfo buf, XLogReaderState *record) xlrec->ntups, xlrec->is_prim_bucket_same_wrt ? 'T' : 'F', xlrec->is_prev_bucket_same_wrt ? 'T' : 'F'); + hash_desc_primary_bucket(buf, record, SizeOfHashSqueezePage); break; } case XLOG_HASH_DELETE: @@ -104,6 +124,7 @@ hash_desc(StringInfo buf, XLogReaderState *record) appendStringInfo(buf, "clear_dead_marking %c, is_primary %c", xlrec->clear_dead_marking ? 'T' : 'F', xlrec->is_primary_bucket_page ? 'T' : 'F'); + hash_desc_primary_bucket(buf, record, SizeOfHashDelete); break; } case XLOG_HASH_UPDATE_META_PAGE: -- 2.37.1 (Apple Git-137.1)