|
|
|
@ -209,8 +209,7 @@ static const RI_ConstraintInfo *ri_FetchConstraintInfo(Trigger *trigger, |
|
|
|
|
Relation trig_rel, bool rel_is_pk); |
|
|
|
|
static const RI_ConstraintInfo *ri_LoadConstraintInfo(Oid constraintOid); |
|
|
|
|
static SPIPlanPtr ri_PlanCheck(const char *querystr, int nargs, Oid *argtypes, |
|
|
|
|
RI_QueryKey *qkey, Relation fk_rel, Relation pk_rel, |
|
|
|
|
bool cache_plan); |
|
|
|
|
RI_QueryKey *qkey, Relation fk_rel, Relation pk_rel); |
|
|
|
|
static bool ri_PerformCheck(const RI_ConstraintInfo *riinfo, |
|
|
|
|
RI_QueryKey *qkey, SPIPlanPtr qplan, |
|
|
|
|
Relation fk_rel, Relation pk_rel, |
|
|
|
@ -385,7 +384,7 @@ RI_FKey_check(TriggerData *trigdata) |
|
|
|
|
|
|
|
|
|
/* Prepare and save the plan */ |
|
|
|
|
qplan = ri_PlanCheck(querybuf.data, riinfo->nkeys, queryoids, |
|
|
|
|
&qkey, fk_rel, pk_rel, true); |
|
|
|
|
&qkey, fk_rel, pk_rel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -512,7 +511,7 @@ ri_Check_Pk_Match(Relation pk_rel, Relation fk_rel, |
|
|
|
|
|
|
|
|
|
/* Prepare and save the plan */ |
|
|
|
|
qplan = ri_PlanCheck(querybuf.data, riinfo->nkeys, queryoids, |
|
|
|
|
&qkey, fk_rel, pk_rel, true); |
|
|
|
|
&qkey, fk_rel, pk_rel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -704,7 +703,7 @@ ri_restrict(TriggerData *trigdata, bool is_no_action) |
|
|
|
|
|
|
|
|
|
/* Prepare and save the plan */ |
|
|
|
|
qplan = ri_PlanCheck(querybuf.data, riinfo->nkeys, queryoids, |
|
|
|
|
&qkey, fk_rel, pk_rel, true); |
|
|
|
|
&qkey, fk_rel, pk_rel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -809,7 +808,7 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS) |
|
|
|
|
|
|
|
|
|
/* Prepare and save the plan */ |
|
|
|
|
qplan = ri_PlanCheck(querybuf.data, riinfo->nkeys, queryoids, |
|
|
|
|
&qkey, fk_rel, pk_rel, true); |
|
|
|
|
&qkey, fk_rel, pk_rel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -931,7 +930,7 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS) |
|
|
|
|
|
|
|
|
|
/* Prepare and save the plan */ |
|
|
|
|
qplan = ri_PlanCheck(querybuf.data, riinfo->nkeys * 2, queryoids, |
|
|
|
|
&qkey, fk_rel, pk_rel, true); |
|
|
|
|
&qkey, fk_rel, pk_rel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -1110,7 +1109,7 @@ ri_set(TriggerData *trigdata, bool is_set_null) |
|
|
|
|
|
|
|
|
|
/* Prepare and save the plan */ |
|
|
|
|
qplan = ri_PlanCheck(querybuf.data, riinfo->nkeys, queryoids, |
|
|
|
|
&qkey, fk_rel, pk_rel, true); |
|
|
|
|
&qkey, fk_rel, pk_rel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -2128,8 +2127,7 @@ InvalidateConstraintCacheCallBack(Datum arg, int cacheid, uint32 hashvalue) |
|
|
|
|
*/ |
|
|
|
|
static SPIPlanPtr |
|
|
|
|
ri_PlanCheck(const char *querystr, int nargs, Oid *argtypes, |
|
|
|
|
RI_QueryKey *qkey, Relation fk_rel, Relation pk_rel, |
|
|
|
|
bool cache_plan) |
|
|
|
|
RI_QueryKey *qkey, Relation fk_rel, Relation pk_rel) |
|
|
|
|
{ |
|
|
|
|
SPIPlanPtr qplan; |
|
|
|
|
Relation query_rel; |
|
|
|
@ -2160,12 +2158,9 @@ ri_PlanCheck(const char *querystr, int nargs, Oid *argtypes, |
|
|
|
|
/* Restore UID and security context */ |
|
|
|
|
SetUserIdAndSecContext(save_userid, save_sec_context); |
|
|
|
|
|
|
|
|
|
/* Save the plan if requested */ |
|
|
|
|
if (cache_plan) |
|
|
|
|
{ |
|
|
|
|
SPI_keepplan(qplan); |
|
|
|
|
ri_HashPreparedPlan(qkey, qplan); |
|
|
|
|
} |
|
|
|
|
/* Save the plan */ |
|
|
|
|
SPI_keepplan(qplan); |
|
|
|
|
ri_HashPreparedPlan(qkey, qplan); |
|
|
|
|
|
|
|
|
|
return qplan; |
|
|
|
|
} |
|
|
|
|