mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Improve comments about why SET DEFAULT triggers must recheck for matches.
I was confused about this, so try to make it clearer for the next person. (This seems like a fairly inefficient way of dealing with a corner case, but I don't have a better idea offhand. Maybe if there were a way to turn off the RI_FKey_keyequal_upd_fk event filter temporarily?)
This commit is contained in:
@ -2227,12 +2227,16 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
|
|||||||
heap_close(fk_rel, RowExclusiveLock);
|
heap_close(fk_rel, RowExclusiveLock);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In the case we delete the row who's key is equal to the default
|
* If we just deleted the PK row whose key was equal to the FK
|
||||||
* values AND a referencing row in the foreign key table exists,
|
* columns' default values, and a referencing row exists in the FK
|
||||||
* we would just have updated it to the same values. We need to do
|
* table, we would have updated that row to the same values it
|
||||||
* another lookup now and in case a reference exists, abort the
|
* already had --- and RI_FKey_keyequal_upd_fk would therefore
|
||||||
* operation. That is already implemented in the NO ACTION
|
* believe no check is necessary. So we need to do another lookup
|
||||||
* trigger.
|
* now and in case a reference still exists, abort the operation.
|
||||||
|
* That is already implemented in the NO ACTION trigger, so just
|
||||||
|
* run it. (This recheck is only needed in the SET DEFAULT case,
|
||||||
|
* since CASCADE would remove such rows, while SET NULL is certain
|
||||||
|
* to result in rows that satisfy the FK constraint.)
|
||||||
*/
|
*/
|
||||||
RI_FKey_noaction_del(fcinfo);
|
RI_FKey_noaction_del(fcinfo);
|
||||||
|
|
||||||
@ -2420,12 +2424,16 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
|
|||||||
heap_close(fk_rel, RowExclusiveLock);
|
heap_close(fk_rel, RowExclusiveLock);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In the case we updated the row who's key was equal to the
|
* If we just updated the PK row whose key was equal to the FK
|
||||||
* default values AND a referencing row in the foreign key table
|
* columns' default values, and a referencing row exists in the FK
|
||||||
* exists, we would just have updated it to the same values. We
|
* table, we would have updated that row to the same values it
|
||||||
* need to do another lookup now and in case a reference exists,
|
* already had --- and RI_FKey_keyequal_upd_fk would therefore
|
||||||
* abort the operation. That is already implemented in the NO
|
* believe no check is necessary. So we need to do another lookup
|
||||||
* ACTION trigger.
|
* now and in case a reference still exists, abort the operation.
|
||||||
|
* That is already implemented in the NO ACTION trigger, so just
|
||||||
|
* run it. (This recheck is only needed in the SET DEFAULT case,
|
||||||
|
* since CASCADE must change the FK key values, while SET NULL is
|
||||||
|
* certain to result in rows that satisfy the FK constraint.)
|
||||||
*/
|
*/
|
||||||
RI_FKey_noaction_upd(fcinfo);
|
RI_FKey_noaction_upd(fcinfo);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user