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

Commitf942974

Browse files
committed
Update SQL spec references in ri_triggers code to match SQL:2008.
Now that what we're implementing isn't SQL92, we probably shouldn't citechapter and verse in that spec anymore. Also fix some comments thattalked about MATCH FULL but in fact were in code that's also used forMATCH SIMPLE.No code changes in this commit, just comments.
1 parentc75be2a commitf942974

File tree

1 file changed

+62
-68
lines changed

1 file changed

+62
-68
lines changed

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

Lines changed: 62 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,13 @@ RI_FKey_check(PG_FUNCTION_ARGS)
309309
pk_rel=heap_open(riinfo.pk_relid,RowShareLock);
310310

311311
/* ----------
312-
* SQL3 11.9 <referential constraint definition>
313-
*General rules 2) a):
312+
* SQL:2008 4.17.3 <Table constraints>
314313
*If Rf and Rt are empty (no columns to compare given)
315314
*constraint is true if 0 < (SELECT COUNT(*) FROM T)
316315
*
317316
*Note: The special case that no columns are given cannot
318-
*occurup to nowin Postgres, it's just there for
319-
*future enhancements.
317+
*occurat presentin Postgres (and is disallowed by the
318+
*standard too); it's just there forfuture enhancements.
320319
* ----------
321320
*/
322321
if (riinfo.nkeys==0)
@@ -376,10 +375,8 @@ RI_FKey_check(PG_FUNCTION_ARGS)
376375
caseRI_KEYS_ALL_NULL:
377376

378377
/*
379-
* No check - if NULLs are allowed at all is already checked by
380-
* NOT NULL constraint.
381-
*
382-
* This is true for MATCH FULL, MATCH PARTIAL, and MATCH SIMPLE.
378+
* No further check needed - an all-NULL key passes every type of
379+
* foreign key constraint.
383380
*/
384381
heap_close(pk_rel,RowShareLock);
385382
returnPointerGetDatum(NULL);
@@ -410,7 +407,8 @@ RI_FKey_check(PG_FUNCTION_ARGS)
410407
caseFKCONSTR_MATCH_SIMPLE:
411408

412409
/*
413-
* MATCH SIMPLE - if ANY column is null, we have a match.
410+
* MATCH SIMPLE - if ANY column is null, the key passes
411+
* the constraint.
414412
*/
415413
heap_close(pk_rel,RowShareLock);
416414
returnPointerGetDatum(NULL);
@@ -578,8 +576,8 @@ ri_Check_Pk_Match(Relation pk_rel, Relation fk_rel,
578576
caseFKCONSTR_MATCH_SIMPLE:
579577

580578
/*
581-
* MATCH SIMPLE/FULL- if ANY column is null,we
582-
*can't be matching to this row already.
579+
* MATCH SIMPLE/FULL - if ANY column is null,nothing
580+
*could have been referencing this row.
583581
*/
584582
return true;
585583

@@ -734,10 +732,10 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS)
734732
switch (riinfo.confmatchtype)
735733
{
736734
/* ----------
737-
*SQL3 11.9 <referential constraint definition>
738-
*General rules6) a) iv):
735+
*SQL:2008 15.17 <Execution of referential actions>
736+
*General rules9) a) iv):
739737
*MATCH SIMPLE/FULL
740-
*... ON DELETECASCADE
738+
*... ON DELETENO ACTION
741739
* ----------
742740
*/
743741
caseFKCONSTR_MATCH_SIMPLE:
@@ -751,8 +749,8 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS)
751749
caseRI_KEYS_SOME_NULL:
752750

753751
/*
754-
* No check- MATCH FULL meansthere cannot be any
755-
*reference to oldkey if it contains NULL
752+
* No checkneeded -there cannot be any reference to old
753+
* key if it contains a NULL
756754
*/
757755
heap_close(fk_rel,RowShareLock);
758756
returnPointerGetDatum(NULL);
@@ -905,10 +903,10 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS)
905903
switch (riinfo.confmatchtype)
906904
{
907905
/* ----------
908-
*SQL3 11.9 <referential constraint definition>
909-
*General rules6) a) iv):
906+
*SQL:2008 15.17 <Execution of referential actions>
907+
*General rules10) a) iv):
910908
*MATCH SIMPLE/FULL
911-
*... ONDELETE CASCADE
909+
*... ONUPDATE NO ACTION
912910
* ----------
913911
*/
914912
caseFKCONSTR_MATCH_SIMPLE:
@@ -922,8 +920,8 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS)
922920
caseRI_KEYS_SOME_NULL:
923921

924922
/*
925-
* No check- MATCH FULL meansthere cannot be any
926-
*reference to oldkey if it contains NULL
923+
* No checkneeded -there cannot be any reference to old
924+
* key if it contains a NULL
927925
*/
928926
heap_close(fk_rel,RowShareLock);
929927
returnPointerGetDatum(NULL);
@@ -1090,8 +1088,8 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
10901088
switch (riinfo.confmatchtype)
10911089
{
10921090
/* ----------
1093-
*SQL3 11.9 <referential constraint definition>
1094-
*General rules6) a) i):
1091+
*SQL:2008 15.17 <Execution of referential actions>
1092+
*General rules9) a) i):
10951093
*MATCH SIMPLE/FULL
10961094
*... ON DELETE CASCADE
10971095
* ----------
@@ -1107,8 +1105,8 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
11071105
caseRI_KEYS_SOME_NULL:
11081106

11091107
/*
1110-
* No check- MATCH FULL meansthere cannot be any
1111-
*reference to oldkey if it contains NULL
1108+
* No checkneeded -there cannot be any reference to old
1109+
* key if it contains a NULL
11121110
*/
11131111
heap_close(fk_rel,RowExclusiveLock);
11141112
returnPointerGetDatum(NULL);
@@ -1209,7 +1207,7 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
12091207
/* ----------
12101208
* RI_FKey_cascade_upd -
12111209
*
1212-
*Cascaded update/delete foreign key references at update event on PK table.
1210+
*Cascaded update foreign key references at update event on PK table.
12131211
* ----------
12141212
*/
12151213
Datum
@@ -1258,8 +1256,8 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
12581256
switch (riinfo.confmatchtype)
12591257
{
12601258
/* ----------
1261-
*SQL3 11.9 <referential constraint definition>
1262-
*General rules7) a) i):
1259+
*SQL:2008 15.17 <Execution of referential actions>
1260+
*General rules10) a) i):
12631261
*MATCH SIMPLE/FULL
12641262
*... ON UPDATE CASCADE
12651263
* ----------
@@ -1275,8 +1273,8 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
12751273
caseRI_KEYS_SOME_NULL:
12761274

12771275
/*
1278-
* Noupdate - MATCH FULL meansthere cannot be any
1279-
*reference to oldkey if it contains NULL
1276+
* Nocheck needed -there cannot be any reference to old
1277+
* key if it contains a NULL
12801278
*/
12811279
heap_close(fk_rel,RowExclusiveLock);
12821280
returnPointerGetDatum(NULL);
@@ -1401,12 +1399,10 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
14011399
*
14021400
*Restrict delete from PK table to rows unreferenced by foreign key.
14031401
*
1404-
*SQL3 intends that this referential action occur BEFORE the
1405-
*update is performed, rather than after. This appears to be
1406-
*the only difference between "NO ACTION" and "RESTRICT".
1407-
*
1408-
*For now, however, we treat "RESTRICT" and "NO ACTION" as
1409-
*equivalent.
1402+
*The SQL standard intends that this referential action occur BEFORE
1403+
*the delete is performed, rather than after. This appears to be
1404+
*the only difference between "NO ACTION" and "RESTRICT". In Postgres
1405+
*we still implement this as an AFTER trigger, but it's non-deferrable.
14101406
* ----------
14111407
*/
14121408
Datum
@@ -1451,10 +1447,10 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS)
14511447
switch (riinfo.confmatchtype)
14521448
{
14531449
/* ----------
1454-
*SQL3 11.9 <referential constraint definition>
1455-
*General rules6) a) iv):
1450+
*SQL:2008 15.17 <Execution of referential actions>
1451+
*General rules9) a) iv):
14561452
*MATCH SIMPLE/FULL
1457-
*... ON DELETECASCADE
1453+
*... ON DELETERESTRICT
14581454
* ----------
14591455
*/
14601456
caseFKCONSTR_MATCH_SIMPLE:
@@ -1468,8 +1464,8 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS)
14681464
caseRI_KEYS_SOME_NULL:
14691465

14701466
/*
1471-
* No check- MATCH FULL meansthere cannot be any
1472-
*reference to oldkey if it contains NULL
1467+
* No checkneeded -there cannot be any reference to old
1468+
* key if it contains a NULL
14731469
*/
14741470
heap_close(fk_rel,RowShareLock);
14751471
returnPointerGetDatum(NULL);
@@ -1574,12 +1570,10 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS)
15741570
*
15751571
*Restrict update of PK to rows unreferenced by foreign key.
15761572
*
1577-
*SQL3 intends that this referential action occur BEFORE the
1578-
*update is performed, rather than after. This appears to be
1579-
*the only difference between "NO ACTION" and "RESTRICT".
1580-
*
1581-
*For now, however, we treat "RESTRICT" and "NO ACTION" as
1582-
*equivalent.
1573+
*The SQL standard intends that this referential action occur BEFORE
1574+
*the update is performed, rather than after. This appears to be
1575+
*the only difference between "NO ACTION" and "RESTRICT". In Postgres
1576+
*we still implement this as an AFTER trigger, but it's non-deferrable.
15831577
* ----------
15841578
*/
15851579
Datum
@@ -1627,10 +1621,10 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS)
16271621
switch (riinfo.confmatchtype)
16281622
{
16291623
/* ----------
1630-
*SQL3 11.9 <referential constraint definition>
1631-
*General rules6) a) iv):
1624+
*SQL:2008 15.17 <Execution of referential actions>
1625+
*General rules10) a) iv):
16321626
*MATCH SIMPLE/FULL
1633-
*... ONDELETE CASCADE
1627+
*... ONUPDATE RESTRICT
16341628
* ----------
16351629
*/
16361630
caseFKCONSTR_MATCH_SIMPLE:
@@ -1644,8 +1638,8 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS)
16441638
caseRI_KEYS_SOME_NULL:
16451639

16461640
/*
1647-
* No check- MATCH FULL meansthere cannot be any
1648-
*reference to oldkey if it contains NULL
1641+
* No checkneeded -there cannot be any reference to old
1642+
* key if it contains a NULL
16491643
*/
16501644
heap_close(fk_rel,RowShareLock);
16511645
returnPointerGetDatum(NULL);
@@ -1802,8 +1796,8 @@ RI_FKey_setnull_del(PG_FUNCTION_ARGS)
18021796
switch (riinfo.confmatchtype)
18031797
{
18041798
/* ----------
1805-
*SQL3 11.9 <referential constraint definition>
1806-
*General rules6) a) ii):
1799+
*SQL:2008 15.17 <Execution of referential actions>
1800+
*General rules9) a) ii):
18071801
*MATCH SIMPLE/FULL
18081802
*... ON DELETE SET NULL
18091803
* ----------
@@ -1819,8 +1813,8 @@ RI_FKey_setnull_del(PG_FUNCTION_ARGS)
18191813
caseRI_KEYS_SOME_NULL:
18201814

18211815
/*
1822-
* Noupdate - MATCH FULL meansthere cannot be any
1823-
*reference to oldkey if it contains NULL
1816+
* Nocheck needed -there cannot be any reference to old
1817+
* key if it contains a NULL
18241818
*/
18251819
heap_close(fk_rel,RowExclusiveLock);
18261820
returnPointerGetDatum(NULL);
@@ -1977,8 +1971,8 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
19771971
switch (riinfo.confmatchtype)
19781972
{
19791973
/* ----------
1980-
*SQL3 11.9 <referential constraint definition>
1981-
*General rules7) a) ii) 2):
1974+
*SQL:2008 15.17 <Execution of referential actions>
1975+
*General rules10) a) ii):
19821976
*MATCH SIMPLE/FULL
19831977
*... ON UPDATE SET NULL
19841978
* ----------
@@ -1994,8 +1988,8 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
19941988
caseRI_KEYS_SOME_NULL:
19951989

19961990
/*
1997-
* Noupdate - MATCH FULL meansthere cannot be any
1998-
*reference to oldkey if it contains NULL
1991+
* Nocheck needed -there cannot be any reference to old
1992+
* key if it contains a NULL
19991993
*/
20001994
heap_close(fk_rel,RowExclusiveLock);
20011995
returnPointerGetDatum(NULL);
@@ -2158,8 +2152,8 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
21582152
switch (riinfo.confmatchtype)
21592153
{
21602154
/* ----------
2161-
*SQL3 11.9 <referential constraint definition>
2162-
*General rules6) a) iii):
2155+
*SQL:2008 15.17 <Execution of referential actions>
2156+
*General rules9) a) iii):
21632157
*MATCH SIMPLE/FULL
21642158
*... ON DELETE SET DEFAULT
21652159
* ----------
@@ -2175,8 +2169,8 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
21752169
caseRI_KEYS_SOME_NULL:
21762170

21772171
/*
2178-
* Noupdate - MATCH FULL meansthere cannot be any
2179-
*reference to oldkey if it contains NULL
2172+
* Nocheck needed -there cannot be any reference to old
2173+
* key if it contains a NULL
21802174
*/
21812175
heap_close(fk_rel,RowExclusiveLock);
21822176
returnPointerGetDatum(NULL);
@@ -2344,8 +2338,8 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
23442338
switch (riinfo.confmatchtype)
23452339
{
23462340
/* ----------
2347-
*SQL3 11.9 <referential constraint definition>
2348-
*General rules7) a) iii):
2341+
*SQL:2008 15.17 <Execution of referential actions>
2342+
*General rules10) a) iii):
23492343
*MATCH SIMPLE/FULL
23502344
*... ON UPDATE SET DEFAULT
23512345
* ----------
@@ -2361,8 +2355,8 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
23612355
caseRI_KEYS_SOME_NULL:
23622356

23632357
/*
2364-
* Noupdate - MATCH FULL meansthere cannot be any
2365-
*reference to oldkey if it contains NULL
2358+
* Nocheck needed -there cannot be any reference to old
2359+
* key if it contains a NULL
23662360
*/
23672361
heap_close(fk_rel,RowExclusiveLock);
23682362
returnPointerGetDatum(NULL);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp