Fix OID-counter-sensitive row ordering in foreign_key test

Several queries in the foreign_key test sort pg_constraint rows with
"ORDER BY oid::regclass::text".  These OIDs are constraint OIDs, not
relation OIDs, so the regclass cast renders them as numeric strings,
and text comparison of numeric strings depends on digit count.  If the
OID counter crosses a power of ten while the test runs, the output
order flips, causing spurious test failures.  This cannot happen in a
fresh cluster, but installcheck against a long-lived cluster can hit
it.

To fix, sort by constraint name, which is unique within each of these
queries, and use COLLATE "C" so that the order does not depend on the
database's default collation either.

Author: Richard Guo <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Reviewed-by: jian he <[email protected]>
Discussion: 
https://postgr.es/m/cambws49kajfgs4rfbwk+ymhptxz+pjtmj12iaz7ruzdsk+s...@mail.gmail.com
Backpatch-through: 18

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/262f2eea958d21fdbe90a3e92ccc3e5c3f0d8059

Modified Files
--------------
src/test/regress/expected/foreign_key.out | 36 +++++++++++++++----------------
src/test/regress/sql/foreign_key.sql      | 18 ++++++++--------
2 files changed, 27 insertions(+), 27 deletions(-)

Reply via email to