From: | David Christensen <david(dot)christensen(at)crunchydata(dot)com> |
---|---|
To: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: DELETE CASCADE |
Date: | 2021-07-07 18:16:36 |
Message-ID: | lza6myugzf.fsf@veeddrois.attlocal.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
David G. Johnston writes:
> Having the defined FK behaviors be more readily changeable, while not
> mitigating this need, is IMO a more important feature to implement. If
> there is a reason that cannot be implemented (besides no one has bothered
> to take the time) then I would consider that reason to also apply to
> prevent implementing this work-around.
>
> David J.
I assume this would look something like:
ALTER TABLE foo ALTER CONSTRAINT my_fkey ON UPDATE CASCADE ON DELETE RESTRICT
with omitted referential_action implying preserving the existing one.
Seems if we were going to tackle this particular problem, there would be two possible approaches
here:
1) Change the definitions of the RI_FKey_* constraints for (at least) RI_FKey_*_del() to instead
share a single function definition RI_FKey_del() and then pass in the constraint type operation
(restrict, cascade, no action, etc) in as a trigger argument instead of having separate functions for
each constraint type here. This would then ensure that the dispatch function could both change the
constriant just by modifying the trigger arguments, as well as allowing for potential different behavior
depending on how the underlying function is called.
2) Keep the existing RI trigger functions, but allow an ALTER CONSTRAINT variant to replace the
trigger function to the new desired value, preserving (or transforming, as necessary) the original
arguments.
A few things off-hand:
- pg_trigger locking will be necessary as we change the underlying args for the tables in
question. This seems unavoidable.
- partitions; do we need to lock them all in both solutions, or can we get away without it in the
first approach?
- with the first solution you would lose the self-describing name of the trigger functions
themselves (moving to the trigger args instead); while it is a change in a very long-standing
behavior/design, it *should* be an implementation detail, and allows things like the explicit
DELETE [ RESTRICT | CASCADE ] the original patch was pushing for.
- probably more I haven't thought of.
Best,
David
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2021-07-07 18:19:34 | Re: badly calculated width of emoji in psql |
Previous Message | Jacob Champion | 2021-07-07 18:03:34 | Re: badly calculated width of emoji in psql |