Обсуждение: Remove support in ri_triggers.c for zero-column foreign keys?

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

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

От
Tom Lane
Дата:
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


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

От
Andres Freund
Дата:
On Wednesday, June 20, 2012 11:15:44 PM Tom Lane wrote:
> There is a nontrivial amount of code in ri_triggers.c that is concerned
> with supporting foreign key constraints having zero columns.  ...
> 
> 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.
+1. I really find that a strange concept and I have a hard time finding useful 
use-cases.

Thanks for improving that code btw, I tried to read/patch it before and its 
not exactly accessible...

Andres

-- Andres Freund                       http://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Training &
Services


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

От
"Kevin Grittner"
Дата:
Andres Freund <andres@2ndquadrant.com> wrote:
> On Wednesday, June 20, 2012 11:15:44 PM Tom Lane wrote:
>> There is a nontrivial amount of code in ri_triggers.c that is
>> concerned with supporting foreign key constraints having zero
>> columns.  ...
>> 
>> 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.
> +1. I really find that a strange concept and I have a hard time
> finding useful use-cases.
+1
-Kevin