foreign_key test is sensitive to the OID counter

Поиск
Список
Период
Сортировка
Искать

foreign_key test is sensitive to the OID counter

От:
Richard Guo <guofenglinux@gmail.com>
Дата:
Вложения:
While running installcheck against a long-lived cluster, I got a diff
in the foreign_key test:

@@ -2045,11 +2045,11 @@
 ORDER BY oid::regclass::text;
   conname   | conenforced | convalidated
 ------------+-------------+--------------
+ selffk_3   | t           | f
+ selffk_3_1 | t           | f
  selffk     | t           | f
  selffk_1   | t           | f
  selffk_2   | t           | f
- selffk_3   | t           | f
- selffk_3_1 | t           | f
 (5 rows)

At first I thought the planner patch I was working on had caused an
unexpected plan diff, and wasted some time chasing that.  But it
turned out to be the "ORDER BY oid::regclass::text" in these queries.

These OIDs are constraint OIDs, not relation OIDs, so the regclass
cast just renders them as numeric strings, and comparing those as text
depends on the number of digits.  Once the OID counter crosses a power
of ten while the test runs, '1000006' sorts before '999987' and the
output order flips.

I plan to push the attached patch to fix it.  Any thoughts?

- Richard

Re: foreign_key test is sensitive to the OID counter

От:
jian he <jian.universality@gmail.com>
Дата:
On Tue, Sep 1, 2026 at 4:32 PM Richard Guo  wrote:
>
> I plan to push the attached patch to fix it.  Any thoughts?
>

 SELECT conname, convalidated, conrelid::regclass FROM pg_constraint
-WHERE conrelid::regclass::text like 'fk_partitioned_fk%' ORDER BY
oid::regclass::text;
+WHERE conrelid::regclass::text like 'fk_partitioned_fk%' ORDER BY oid;

Perhaps what they wanted at the time was

WHERE conrelid::regclass::text like 'fk_partitioned_fk%' ORDER BY
conrelid::regclass::text;

in https://git.postgresql.org/cgit/postgresql.git/commit/?id=6beb38cfc9ddd4cd3d2eb5402981ebdd69a618b4
we use ``::regclass::text COLLATE "C"`` is stable the tests.

IMHO, Using
ORDER BY conrelid::regclass::text COLLATE "C"
is more future-proof.




--
jian
https://www.enterprisedb.com/


Re: foreign_key test is sensitive to the OID counter

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Richard Guo  writes:
> These OIDs are constraint OIDs, not relation OIDs, so the regclass
> cast just renders them as numeric strings, and comparing those as text
> depends on the number of digits.  Once the OID counter crosses a power
> of ten while the test runs, '1000006' sorts before '999987' and the
> output order flips.

Right, that's bogus.

> I plan to push the attached patch to fix it.  Any thoughts?

This is only somewhat less bogus, though: it'd still fail at OID
wraparound.  How about sorting by the constraint name?

			regards, tom lane


FAQ