Remove support in ri_triggers.c for zero-column foreign keys?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: Remove support in ri_triggers.c for zero-column foreign keys?
Date: 2012-06-20 21:15:44
Message-ID: 5764.1340226944@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2012-06-20 21:24:14 Re: Remove support in ri_triggers.c for zero-column foreign keys?
Previous Message Cédric Villemain 2012-06-20 21:02:23 Re: pg_prewarm