Never store 0 as the nextMXact
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 12 Dec 2025 08:47:34 +0000 (10:47 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 12 Dec 2025 08:47:34 +0000 (10:47 +0200)
commit87a350e1f284bb99591f9185c0be0ae28899f38a
treebf205dfebb3d59e4a46d5be35eb7b1b178ed2e77
parentb4cbc106a6ced69a0a13a980e1b4b212bb127458
Never store 0 as the nextMXact

Before this commit, when multixid wraparound happens,
MultiXactState->nextMXact goes to 0, which is invalid. All the readers
need to deal with that possibility and skip over the 0. That's
error-prone and we've missed it a few times in the past. This commit
changes the responsibility so that all the writers of
MultiXactState->nextMXact skip over the zero already, and readers can
trust that it's never 0.

We were already doing that for MultiXactState->oldestMultiXactId; none
of its writers would set it to 0. ReadMultiXactIdRange() was
nevertheless checking for that possibility. For clarity, remove that
check.

Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Maxim Orlov <orlovmg@gmail.com>
Discussion: https://www.postgresql.org/message-id/3624730d-6dae-42bf-9458-76c4c965fb27@iki.fi
src/backend/access/transam/multixact.c
src/bin/pg_resetwal/pg_resetwal.c
src/bin/pg_resetwal/t/001_basic.pl