@@ -207,11 +207,6 @@ static void ri_BuildQueryKeyPkCheck(RI_QueryKey *key,
207
207
int32 constr_queryno );
208
208
static bool ri_KeysEqual (Relation rel , HeapTuple oldtup , HeapTuple newtup ,
209
209
const RI_ConstraintInfo * riinfo , bool rel_is_pk );
210
- static bool ri_AllKeysUnequal (Relation rel , HeapTuple oldtup , HeapTuple newtup ,
211
- const RI_ConstraintInfo * riinfo , bool rel_is_pk );
212
- static bool ri_OneKeyEqual (Relation rel , int column ,
213
- HeapTuple oldtup , HeapTuple newtup ,
214
- const RI_ConstraintInfo * riinfo , bool rel_is_pk );
215
210
static bool ri_AttributesEqual (Oid eq_opr , Oid typeid ,
216
211
Datum oldvalue , Datum newvalue );
217
212
static bool ri_Check_Pk_Match (Relation pk_rel , Relation fk_rel ,
@@ -1950,7 +1945,6 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
1950
1945
RI_QueryKey qkey ;
1951
1946
SPIPlanPtr qplan ;
1952
1947
int i ;
1953
- bool use_cached_query ;
1954
1948
1955
1949
/*
1956
1950
* Check that this is a valid trigger call on the right time and event.
@@ -1985,7 +1979,7 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
1985
1979
/* ----------
1986
1980
* SQL3 11.9 <referential constraint definition>
1987
1981
* General rules 7) a) ii) 2):
1988
- * MATCH FULL
1982
+ * MATCH SIMPLE/ FULL
1989
1983
* ... ON UPDATE SET NULL
1990
1984
* ----------
1991
1985
*/
@@ -2026,29 +2020,10 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
2026
2020
if (SPI_connect () != SPI_OK_CONNECT )
2027
2021
elog (ERROR , "SPI_connect failed" );
2028
2022
2029
- /*
2030
- * "MATCH SIMPLE" only changes columns corresponding to the
2031
- * referenced columns that have changed in pk_rel. This means the
2032
- * "SET attrn=NULL [, attrn=NULL]" string will be change as well.
2033
- * In this case, we need to build a temporary plan rather than use
2034
- * our cached plan, unless the update happens to change all
2035
- * columns in the key. Fortunately, for the most common case of a
2036
- * single-column foreign key, this will be true.
2037
- *
2038
- * In case you're wondering, the inequality check works because we
2039
- * know that the old key value has no NULLs (see above).
2040
- */
2041
-
2042
- use_cached_query = (riinfo .confmatchtype == FKCONSTR_MATCH_FULL ) ||
2043
- ri_AllKeysUnequal (pk_rel , old_row , new_row ,
2044
- & riinfo , true);
2045
-
2046
2023
/*
2047
2024
* Fetch or prepare a saved plan for the set null update operation
2048
- * if possible, or build a temporary plan if not.
2049
2025
*/
2050
- if (!use_cached_query ||
2051
- (qplan = ri_FetchPreparedPlan (& qkey )) == NULL )
2026
+ if ((qplan = ri_FetchPreparedPlan (& qkey )) == NULL )
2052
2027
{
2053
2028
StringInfoData querybuf ;
2054
2029
StringInfoData qualbuf ;
@@ -2080,37 +2055,23 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
2080
2055
2081
2056
quoteOneName (attname ,
2082
2057
RIAttName (fk_rel , riinfo .fk_attnums [i ]));
2083
-
2084
- /*
2085
- * MATCH SIMPLE - only change columns corresponding
2086
- * to changed columns in pk_rel's key
2087
- */
2088
- if (riinfo .confmatchtype == FKCONSTR_MATCH_FULL ||
2089
- !ri_OneKeyEqual (pk_rel , i , old_row , new_row ,
2090
- & riinfo , true))
2091
- {
2092
- appendStringInfo (& querybuf ,
2093
- "%s %s = NULL" ,
2094
- querysep , attname );
2095
- querysep = "," ;
2096
- }
2058
+ appendStringInfo (& querybuf ,
2059
+ "%s %s = NULL" ,
2060
+ querysep , attname );
2097
2061
sprintf (paramname , "$%d" , i + 1 );
2098
2062
ri_GenerateQual (& qualbuf , qualsep ,
2099
2063
paramname , pk_type ,
2100
2064
riinfo .pf_eq_oprs [i ],
2101
2065
attname , fk_type );
2066
+ querysep = "," ;
2102
2067
qualsep = "AND" ;
2103
2068
queryoids [i ] = pk_type ;
2104
2069
}
2105
2070
appendStringInfoString (& querybuf , qualbuf .data );
2106
2071
2107
- /*
2108
- * Prepare the plan. Save it only if we're building the
2109
- * "standard" plan.
2110
- */
2072
+ /* Prepare and save the plan */
2111
2073
qplan = ri_PlanCheck (querybuf .data , riinfo .nkeys , queryoids ,
2112
- & qkey , fk_rel , pk_rel ,
2113
- use_cached_query );
2074
+ & qkey , fk_rel , pk_rel , true);
2114
2075
}
2115
2076
2116
2077
/*
@@ -2463,25 +2424,15 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
2463
2424
2464
2425
quoteOneName (attname ,
2465
2426
RIAttName (fk_rel , riinfo .fk_attnums [i ]));
2466
-
2467
- /*
2468
- * MATCH SIMPLE - only change columns corresponding
2469
- * to changed columns in pk_rel's key
2470
- */
2471
- if (riinfo .confmatchtype == FKCONSTR_MATCH_FULL ||
2472
- !ri_OneKeyEqual (pk_rel , i , old_row , new_row ,
2473
- & riinfo , true))
2474
- {
2475
- appendStringInfo (& querybuf ,
2476
- "%s %s = DEFAULT" ,
2477
- querysep , attname );
2478
- querysep = "," ;
2479
- }
2427
+ appendStringInfo (& querybuf ,
2428
+ "%s %s = DEFAULT" ,
2429
+ querysep , attname );
2480
2430
sprintf (paramname , "$%d" , i + 1 );
2481
2431
ri_GenerateQual (& qualbuf , qualsep ,
2482
2432
paramname , pk_type ,
2483
2433
riinfo .pf_eq_oprs [i ],
2484
2434
attname , fk_type );
2435
+ querysep = "," ;
2485
2436
qualsep = "AND" ;
2486
2437
queryoids [i ] = pk_type ;
2487
2438
}
@@ -3857,120 +3808,6 @@ ri_KeysEqual(Relation rel, HeapTuple oldtup, HeapTuple newtup,
3857
3808
}
3858
3809
3859
3810
3860
- /* ----------
3861
- * ri_AllKeysUnequal -
3862
- *
3863
- * Check if all key values in OLD and NEW are not equal.
3864
- * ----------
3865
- */
3866
- static bool
3867
- ri_AllKeysUnequal (Relation rel , HeapTuple oldtup , HeapTuple newtup ,
3868
- const RI_ConstraintInfo * riinfo , bool rel_is_pk )
3869
- {
3870
- TupleDesc tupdesc = RelationGetDescr (rel );
3871
- const int16 * attnums ;
3872
- const Oid * eq_oprs ;
3873
- int i ;
3874
-
3875
- if (rel_is_pk )
3876
- {
3877
- attnums = riinfo -> pk_attnums ;
3878
- eq_oprs = riinfo -> pp_eq_oprs ;
3879
- }
3880
- else
3881
- {
3882
- attnums = riinfo -> fk_attnums ;
3883
- eq_oprs = riinfo -> ff_eq_oprs ;
3884
- }
3885
-
3886
- for (i = 0 ; i < riinfo -> nkeys ; i ++ )
3887
- {
3888
- Datum oldvalue ;
3889
- Datum newvalue ;
3890
- bool isnull ;
3891
-
3892
- /*
3893
- * Get one attribute's oldvalue. If it is NULL - they're not equal.
3894
- */
3895
- oldvalue = SPI_getbinval (oldtup , tupdesc , attnums [i ], & isnull );
3896
- if (isnull )
3897
- continue ;
3898
-
3899
- /*
3900
- * Get one attribute's newvalue. If it is NULL - they're not equal.
3901
- */
3902
- newvalue = SPI_getbinval (newtup , tupdesc , attnums [i ], & isnull );
3903
- if (isnull )
3904
- continue ;
3905
-
3906
- /*
3907
- * Compare them with the appropriate equality operator.
3908
- */
3909
- if (ri_AttributesEqual (eq_oprs [i ], RIAttType (rel , attnums [i ]),
3910
- oldvalue , newvalue ))
3911
- return false; /* found two equal items */
3912
- }
3913
-
3914
- return true;
3915
- }
3916
-
3917
-
3918
- /* ----------
3919
- * ri_OneKeyEqual -
3920
- *
3921
- * Check if one key value in OLD and NEW is equal. Note column is indexed
3922
- * from zero.
3923
- *
3924
- * ri_KeysEqual could call this but would run a bit slower. For
3925
- * now, let's duplicate the code.
3926
- * ----------
3927
- */
3928
- static bool
3929
- ri_OneKeyEqual (Relation rel , int column , HeapTuple oldtup , HeapTuple newtup ,
3930
- const RI_ConstraintInfo * riinfo , bool rel_is_pk )
3931
- {
3932
- TupleDesc tupdesc = RelationGetDescr (rel );
3933
- const int16 * attnums ;
3934
- const Oid * eq_oprs ;
3935
- Datum oldvalue ;
3936
- Datum newvalue ;
3937
- bool isnull ;
3938
-
3939
- if (rel_is_pk )
3940
- {
3941
- attnums = riinfo -> pk_attnums ;
3942
- eq_oprs = riinfo -> pp_eq_oprs ;
3943
- }
3944
- else
3945
- {
3946
- attnums = riinfo -> fk_attnums ;
3947
- eq_oprs = riinfo -> ff_eq_oprs ;
3948
- }
3949
-
3950
- /*
3951
- * Get one attribute's oldvalue. If it is NULL - they're not equal.
3952
- */
3953
- oldvalue = SPI_getbinval (oldtup , tupdesc , attnums [column ], & isnull );
3954
- if (isnull )
3955
- return false;
3956
-
3957
- /*
3958
- * Get one attribute's newvalue. If it is NULL - they're not equal.
3959
- */
3960
- newvalue = SPI_getbinval (newtup , tupdesc , attnums [column ], & isnull );
3961
- if (isnull )
3962
- return false;
3963
-
3964
- /*
3965
- * Compare them with the appropriate equality operator.
3966
- */
3967
- if (!ri_AttributesEqual (eq_oprs [column ], RIAttType (rel , attnums [column ]),
3968
- oldvalue , newvalue ))
3969
- return false;
3970
-
3971
- return true;
3972
- }
3973
-
3974
3811
/* ----------
3975
3812
* ri_AttributesEqual -
3976
3813
*
0 commit comments