Remove redundant MultiXactIdIsRunning() check in HeapTupleSatisfiesUpdate()

From: Zhao Song <songzhao(dot)asm(at)icloud(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Remove redundant MultiXactIdIsRunning() check in HeapTupleSatisfiesUpdate()
Date: 2026-10-08 15:54:19
Message-ID: 7201E833-0100-4BDE-9161-45B9FFA4F458@icloud.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hi,

I noticed a redundant MultiXactIdIsRunning() check in HeapTupleSatisfiesUpdate(), when xmax is a multixact containing an update (the HEAP_XMAX_IS_MULTI branch in heapam_visibility.c).

The relevant code is:

    if (MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple), false))

        return TM_BeingModified;

    if (TransactionIdDidCommit(xmax))

        { ... return TM_Updated / TM_Deleted; }

    /*

     * By here, the update in the Xmax is either aborted or crashed, but

     * what about the other members?

     */

    if (!MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple), false))

    {

        SetHintBits(tuple, buffer, HEAP_XMAX_INVALID, InvalidTransactionId);

        return TM_Ok;

    }

    else

    {

        /* There are lockers running */

        return TM_BeingModified;

    }

The else branch can't be reached. The first MultiXactIdIsRunning() call already returns if any member, updater or locker, is still running. Between the two calls, we only check TransactionIdDidCommit(xmax). Since the members of a MultiXactId never change (as the comment in MultiXactIdIsRunning() says, "it is not legal to add members to an existing MultiXactId"), and a member that wasn't running at the first check can't become running again, the second call must always return false.

I went through the commit history to understand why this check exists:

* 1ce150b7bb1 added the second check and changed the first one to TransactionIdIsInProgress(xmax), which only checked the updater.

* 07aeb1fec57 added the else branch to handle the case where lockers were still running.

* 05315498012 changed the first check back to MultiXactIdIsRunning(..., false), covering all members again.

So since 05315498012, the second check is redundant and its else branch unreachable.

The attached patch removes the second MultiXactIdIsRunning() call and the unreachable branch. This should not change any behavior, but avoids an unnecessary multixact member lookup and proc array scan when the updater has aborted, and makes the code easier to understand.

Regards,

Zhao Song


Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Álvaro Herrera 2026-10-08 16:10:49 Re: Adding init-po and update-po targets to the meson build system
Previous Message Peter Eisentraut 2026-10-08 15:41:26 Re: Adding init-po and update-po targets to the meson build system