Remove pointless HeapTupleHeaderIndicatesMovedPartitions calls
authorAlvaro Herrera <[email protected]>
Mon, 22 Feb 2021 19:51:44 +0000 (16:51 -0300)
committerAlvaro Herrera <[email protected]>
Mon, 22 Feb 2021 19:51:44 +0000 (16:51 -0300)
Pavan Deolasee recently noted that a few of the
HeapTupleHeaderIndicatesMovedPartitions calls added by commit
5db6df0c0117 are useless, since they are done after comparing t_self
with t_ctid.  But because t_self can never be set to the magical values
that indicate that the tuple moved partition, this can never succeed: if
the first test fails (so we know t_self equals t_ctid), necessarily the
second test will also fail.

So these checks can be removed and no harm is done.  There's no bug
here, just a code legibility issue.

Reported-by: Pavan Deolasee <[email protected]>
Discussion: https://postgr.es/m/20200929164411[email protected]

src/backend/access/heap/heapam.c
src/backend/access/heap/heapam_visibility.c

index 9926e2bd546ae01ef9de976638b02646eb07e11f..9c1d590dc714841066335d072cb9e4831b0411e9 100644 (file)
@@ -2769,8 +2769,7 @@ l1:
            HEAP_XMAX_IS_LOCKED_ONLY(tp.t_data->t_infomask) ||
            HeapTupleHeaderIsOnlyLocked(tp.t_data))
            result = TM_Ok;
-       else if (!ItemPointerEquals(&tp.t_self, &tp.t_data->t_ctid) ||
-                HeapTupleHeaderIndicatesMovedPartitions(tp.t_data))
+       else if (!ItemPointerEquals(&tp.t_self, &tp.t_data->t_ctid))
            result = TM_Updated;
        else
            result = TM_Deleted;
@@ -3399,8 +3398,7 @@ l2:
 
        if (can_continue)
            result = TM_Ok;
-       else if (!ItemPointerEquals(&oldtup.t_self, &oldtup.t_data->t_ctid) ||
-                HeapTupleHeaderIndicatesMovedPartitions(oldtup.t_data))
+       else if (!ItemPointerEquals(&oldtup.t_self, &oldtup.t_data->t_ctid))
            result = TM_Updated;
        else
            result = TM_Deleted;
@@ -4636,8 +4634,7 @@ l3:
            HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_data->t_infomask) ||
            HeapTupleHeaderIsOnlyLocked(tuple->t_data))
            result = TM_Ok;
-       else if (!ItemPointerEquals(&tuple->t_self, &tuple->t_data->t_ctid) ||
-                HeapTupleHeaderIndicatesMovedPartitions(tuple->t_data))
+       else if (!ItemPointerEquals(&tuple->t_self, &tuple->t_data->t_ctid))
            result = TM_Updated;
        else
            result = TM_Deleted;
@@ -5210,8 +5207,7 @@ test_lockmode_for_conflict(MultiXactStatus status, TransactionId xid,
                                LOCKMODE_from_mxstatus(wantedstatus)))
        {
            /* bummer */
-           if (!ItemPointerEquals(&tup->t_self, &tup->t_data->t_ctid) ||
-               HeapTupleHeaderIndicatesMovedPartitions(tup->t_data))
+           if (!ItemPointerEquals(&tup->t_self, &tup->t_data->t_ctid))
                return TM_Updated;
            else
                return TM_Deleted;
index 65f91c82599cfe3282dcadc5f580ae53e52890c2..9a1e7288ae8de1b65eda5599d6d3a41df4f38391 100644 (file)
@@ -607,8 +607,7 @@ HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
    {
        if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask))
            return TM_Ok;
-       if (!ItemPointerEquals(&htup->t_self, &tuple->t_ctid) ||
-           HeapTupleHeaderIndicatesMovedPartitions(tuple))
+       if (!ItemPointerEquals(&htup->t_self, &tuple->t_ctid))
            return TM_Updated;  /* updated by other */
        else
            return TM_Deleted;  /* deleted by other */
@@ -653,8 +652,7 @@ HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
 
        if (TransactionIdDidCommit(xmax))
        {
-           if (!ItemPointerEquals(&htup->t_self, &tuple->t_ctid) ||
-               HeapTupleHeaderIndicatesMovedPartitions(tuple))
+           if (!ItemPointerEquals(&htup->t_self, &tuple->t_ctid))
                return TM_Updated;
            else
                return TM_Deleted;
@@ -714,8 +712,7 @@ HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
 
    SetHintBits(tuple, buffer, HEAP_XMAX_COMMITTED,
                HeapTupleHeaderGetRawXmax(tuple));
-   if (!ItemPointerEquals(&htup->t_self, &tuple->t_ctid) ||
-       HeapTupleHeaderIndicatesMovedPartitions(tuple))
+   if (!ItemPointerEquals(&htup->t_self, &tuple->t_ctid))
        return TM_Updated;      /* updated by other */
    else
        return TM_Deleted;      /* deleted by other */