Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit48756be

Browse files
committed
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 turnoff the RI_FKey_keyequal_upd_fk event filter temporarily?)
1 parente8c9fd5 commit48756be

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

‎src/backend/utils/adt/ri_triggers.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,12 +2227,16 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
22272227
heap_close(fk_rel,RowExclusiveLock);
22282228

22292229
/*
2230-
* In the case we delete the row who's key is equal to the default
2231-
* values AND a referencing row in the foreign key table exists,
2232-
* we would just have updated it to the same values. We need to do
2233-
* another lookup now and in case a reference exists, abort the
2234-
* operation. That is already implemented in the NO ACTION
2235-
* trigger.
2230+
* If we just deleted the PK row whose key was equal to the FK
2231+
* columns' default values, and a referencing row exists in the FK
2232+
* table, we would have updated that row to the same values it
2233+
* already had --- and RI_FKey_keyequal_upd_fk would therefore
2234+
* believe no check is necessary. So we need to do another lookup
2235+
* now and in case a reference still exists, abort the operation.
2236+
* That is already implemented in the NO ACTION trigger, so just
2237+
* run it. (This recheck is only needed in the SET DEFAULT case,
2238+
* since CASCADE would remove such rows, while SET NULL is certain
2239+
* to result in rows that satisfy the FK constraint.)
22362240
*/
22372241
RI_FKey_noaction_del(fcinfo);
22382242

@@ -2420,12 +2424,16 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
24202424
heap_close(fk_rel,RowExclusiveLock);
24212425

24222426
/*
2423-
* In the case we updated the row who's key was equal to the
2424-
* default values AND a referencing row in the foreign key table
2425-
* exists, we would just have updated it to the same values. We
2426-
* need to do another lookup now and in case a reference exists,
2427-
* abort the operation. That is already implemented in the NO
2428-
* ACTION trigger.
2427+
* If we just updated the PK row whose key was equal to the FK
2428+
* columns' default values, and a referencing row exists in the FK
2429+
* table, we would have updated that row to the same values it
2430+
* already had --- and RI_FKey_keyequal_upd_fk would therefore
2431+
* believe no check is necessary. So we need to do another lookup
2432+
* now and in case a reference still exists, abort the operation.
2433+
* That is already implemented in the NO ACTION trigger, so just
2434+
* run it. (This recheck is only needed in the SET DEFAULT case,
2435+
* since CASCADE must change the FK key values, while SET NULL is
2436+
* certain to result in rows that satisfy the FK constraint.)
24292437
*/
24302438
RI_FKey_noaction_upd(fcinfo);
24312439

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp