Backpatch tuplesort.c assertion.
authorPeter Geoghegan <pg@bowt.ie>
Wed, 29 Jul 2020 23:00:54 +0000 (16:00 -0700)
committerPeter Geoghegan <pg@bowt.ie>
Wed, 29 Jul 2020 23:00:54 +0000 (16:00 -0700)
Backpatch an assertion (that was originally added to Postgres 12 by
commit dd299df8189) that seems broadly useful.  The assertion can detect
violations of the HOT invariant (i.e. no two index tuples can point to
the same heap TID) when CREATE INDEX somehow incorrectly allows that to
take place.

For example, a IndexBuildHeapScan/heapam_index_build_range_scan bug
might result in two tuples that both point to the same heap TID.  If
these two tuples also happen to be duplicates, the assertion will fail.

Discussion: https://postgr.es/m/CAH2-WzmBxu4o=pMsniur+bwHqCGCmV_AOLkuK6BuU7ngA6evqw@mail.gmail.com
Backpatch: 9.5-11 only

src/backend/utils/sort/tuplesort.c

index 549baf4b4f683df2dcb6845f95a67098715bb6f4..f770b570eb6072f145ac49f3fc5a41fffd5bed7b 100644 (file)
@@ -4076,6 +4076,9 @@ comparetup_index_btree(const SortTuple *a, const SortTuple *b,
            return (pos1 < pos2) ? -1 : 1;
    }
 
+   /* ItemPointer values should never be equal */
+   Assert(false);
+
    return 0;
 }
 
@@ -4128,6 +4131,9 @@ comparetup_index_hash(const SortTuple *a, const SortTuple *b,
            return (pos1 < pos2) ? -1 : 1;
    }
 
+   /* ItemPointer values should never be equal */
+   Assert(false);
+
    return 0;
 }