Remove support in ri_triggers.c for zero-column foreign keys? - Mailing list pgsql-hackers

From Tom Lane
Subject Remove support in ri_triggers.c for zero-column foreign keys?
Date
Msg-id 5764.1340226944@sss.pgh.pa.us
Whole thread Raw
Responses Re: Remove support in ri_triggers.c for zero-column foreign keys?  (Andres Freund <andres@2ndquadrant.com>)
List pgsql-hackers
There is a nontrivial amount of code in ri_triggers.c that is concerned
with supporting foreign key constraints having zero columns.  There is
of course no support for this concept in the standard; the semantics
given to the case in the code are made up out of whole cloth.
(Basically, it says that such a constraint is satisfied if there's at
least one row in the PK table; contents don't matter.)  It is also not
possible to create such a constraint in Postgres, of course, which means
that the code in question is utterly untested.  I have no faith that all
the corner cases (most of which are just "do nothing if zero keys") are
correct even granting that the proposed semantics are reasonable.  In
particular, the corner case in ri_restrict_del that makes it do nothing
is certainly wrong, since it would need to disallow deleting the last
row in the PK table unless the FK table is empty.  I don't see exactly
how SET NULL or SET DEFAULT cases ought to behave either, except that
do-nothing is probably not it.

I think we should rip all that code out and instead put one test into
ri_FetchConstraintInfo insisting that the number of keys be > 0.
Alternatively, if we think this is actually a useful corner case,
somebody needs to put significant work into making the feature
accessible and then fixing it to work correctly.

Thoughts?
        regards, tom lane


pgsql-hackers by date:

Previous
From: Cédric Villemain
Date:
Subject: Re: pg_prewarm
Next
From: Andres Freund
Date:
Subject: Re: Remove support in ri_triggers.c for zero-column foreign keys?