Skip to content

Commit 5f2bcef

Browse files
alvherrehopebo
authored andcommitted
Fix broken-FK-detection query in release notes
Commits 53af9491a043 and 2d5fe514052a fixed a number of problems with foreign keys that reference partitioned tables, and a query to detect already broken FKs was supplied with the release notes for 17.1, 16.5, 15.9, 14.14, 13.17. However, that query has a bug that causes it to wrongly report self-referential foreign keys even when they are correct, so if the user was to drop and rebuild the FKs as indicated, the query would continue to report them as needing to be repaired. Here we fix the query to not have that problem. Reported-by: Paul Foerster <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 13-17 (cherry picked from commit 50a8959cd50bb346b2479ac66bb4f0f474409c51)
1 parent fcd95bd commit 5f2bcef

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

doc/src/sgml/release-17.sgml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,10 +3581,14 @@ FROM pg_catalog.pg_constraint c
35813581
WHERE contype = 'f' AND conparentid = 0 AND
35823582
(SELECT count(*) FROM pg_catalog.pg_constraint c2
35833583
WHERE c2.conparentid = c.oid) &lt;&gt;
3584-
(SELECT count(*) FROM pg_catalog.pg_inherits i
3584+
((SELECT count(*) FROM pg_catalog.pg_inherits i
35853585
WHERE (i.inhparent = c.conrelid OR i.inhparent = c.confrelid) AND
35863586
EXISTS (SELECT 1 FROM pg_catalog.pg_partitioned_table
3587-
WHERE partrelid = i.inhparent));
3587+
WHERE partrelid = i.inhparent)) +
3588+
CASE WHEN pg_catalog.pg_partition_root(conrelid) = confrelid THEN
3589+
(SELECT count(*) FROM pg_catalog.pg_partition_tree(confrelid)
3590+
WHERE level = 1)
3591+
ELSE 0 END);
35883592
</programlisting>
35893593
Since it is possible that one or more of the <literal>ADD
35903594
CONSTRAINT</literal> steps will fail, you should save the query's

0 commit comments

Comments
 (0)