Commit 582bbcf3 authored by Peter Eisentraut's avatar Peter Eisentraut

Move SPI error reporting out of ri_ReportViolation()

These are two completely unrelated code paths, so it doesn't make sense
to pack them into one function.

Add attribute noreturn to ri_ReportViolation().
Reviewed-by: default avatarMichael Paquier <michael.paquier@gmail.com>
parent 9eafa2b5
...@@ -242,7 +242,7 @@ static void ri_ExtractValues(Relation rel, HeapTuple tup, ...@@ -242,7 +242,7 @@ static void ri_ExtractValues(Relation rel, HeapTuple tup,
static void ri_ReportViolation(const RI_ConstraintInfo *riinfo, static void ri_ReportViolation(const RI_ConstraintInfo *riinfo,
Relation pk_rel, Relation fk_rel, Relation pk_rel, Relation fk_rel,
HeapTuple violator, TupleDesc tupdesc, HeapTuple violator, TupleDesc tupdesc,
int queryno, bool spi_err); int queryno) pg_attribute_noreturn();
/* ---------- /* ----------
...@@ -2499,7 +2499,7 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel) ...@@ -2499,7 +2499,7 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
ri_ReportViolation(&fake_riinfo, ri_ReportViolation(&fake_riinfo,
pk_rel, fk_rel, pk_rel, fk_rel,
tuple, tupdesc, tuple, tupdesc,
RI_PLAN_CHECK_LOOKUPPK, false); RI_PLAN_CHECK_LOOKUPPK);
} }
if (SPI_finish() != SPI_OK_FINISH) if (SPI_finish() != SPI_OK_FINISH)
...@@ -3147,11 +3147,13 @@ ri_PerformCheck(const RI_ConstraintInfo *riinfo, ...@@ -3147,11 +3147,13 @@ ri_PerformCheck(const RI_ConstraintInfo *riinfo,
elog(ERROR, "SPI_execute_snapshot returned %d", spi_result); elog(ERROR, "SPI_execute_snapshot returned %d", spi_result);
if (expect_OK >= 0 && spi_result != expect_OK) if (expect_OK >= 0 && spi_result != expect_OK)
ri_ReportViolation(riinfo, ereport(ERROR,
pk_rel, fk_rel, (errcode(ERRCODE_INTERNAL_ERROR),
new_tuple ? new_tuple : old_tuple, errmsg("referential integrity query on \"%s\" from constraint \"%s\" on \"%s\" gave unexpected result",
NULL, RelationGetRelationName(pk_rel),
qkey->constr_queryno, true); NameStr(riinfo->conname),
RelationGetRelationName(fk_rel)),
errhint("This is most likely due to a rule having rewritten the query.")));
/* XXX wouldn't it be clearer to do this part at the caller? */ /* XXX wouldn't it be clearer to do this part at the caller? */
if (qkey->constr_queryno != RI_PLAN_CHECK_LOOKUPPK_FROM_PK && if (qkey->constr_queryno != RI_PLAN_CHECK_LOOKUPPK_FROM_PK &&
...@@ -3161,7 +3163,7 @@ ri_PerformCheck(const RI_ConstraintInfo *riinfo, ...@@ -3161,7 +3163,7 @@ ri_PerformCheck(const RI_ConstraintInfo *riinfo,
pk_rel, fk_rel, pk_rel, fk_rel,
new_tuple ? new_tuple : old_tuple, new_tuple ? new_tuple : old_tuple,
NULL, NULL,
qkey->constr_queryno, false); qkey->constr_queryno);
return SPI_processed != 0; return SPI_processed != 0;
} }
...@@ -3205,7 +3207,7 @@ static void ...@@ -3205,7 +3207,7 @@ static void
ri_ReportViolation(const RI_ConstraintInfo *riinfo, ri_ReportViolation(const RI_ConstraintInfo *riinfo,
Relation pk_rel, Relation fk_rel, Relation pk_rel, Relation fk_rel,
HeapTuple violator, TupleDesc tupdesc, HeapTuple violator, TupleDesc tupdesc,
int queryno, bool spi_err) int queryno)
{ {
StringInfoData key_names; StringInfoData key_names;
StringInfoData key_values; StringInfoData key_values;
...@@ -3216,15 +3218,6 @@ ri_ReportViolation(const RI_ConstraintInfo *riinfo, ...@@ -3216,15 +3218,6 @@ ri_ReportViolation(const RI_ConstraintInfo *riinfo,
AclResult aclresult; AclResult aclresult;
bool has_perm = true; bool has_perm = true;
if (spi_err)
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("referential integrity query on \"%s\" from constraint \"%s\" on \"%s\" gave unexpected result",
RelationGetRelationName(pk_rel),
NameStr(riinfo->conname),
RelationGetRelationName(fk_rel)),
errhint("This is most likely due to a rule having rewritten the query.")));
/* /*
* Determine which relation to complain about. If tupdesc wasn't passed * Determine which relation to complain about. If tupdesc wasn't passed
* by caller, assume the violator tuple came from there. * by caller, assume the violator tuple came from there.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment