Skip to content

Commit 582bbcf

Browse files
committed
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: Michael Paquier <michael.paquier@gmail.com>
1 parent 9eafa2b commit 582bbcf

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/backend/utils/adt/ri_triggers.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static void ri_ExtractValues(Relation rel, HeapTuple tup,
242242
static void ri_ReportViolation(const RI_ConstraintInfo *riinfo,
243243
Relation pk_rel, Relation fk_rel,
244244
HeapTuple violator, TupleDesc tupdesc,
245-
int queryno, bool spi_err);
245+
int queryno) pg_attribute_noreturn();
246246

247247

248248
/* ----------
@@ -2499,7 +2499,7 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
24992499
ri_ReportViolation(&fake_riinfo,
25002500
pk_rel, fk_rel,
25012501
tuple, tupdesc,
2502-
RI_PLAN_CHECK_LOOKUPPK, false);
2502+
RI_PLAN_CHECK_LOOKUPPK);
25032503
}
25042504

25052505
if (SPI_finish() != SPI_OK_FINISH)
@@ -3147,11 +3147,13 @@ ri_PerformCheck(const RI_ConstraintInfo *riinfo,
31473147
elog(ERROR, "SPI_execute_snapshot returned %d", spi_result);
31483148

31493149
if (expect_OK >= 0 && spi_result != expect_OK)
3150-
ri_ReportViolation(riinfo,
3151-
pk_rel, fk_rel,
3152-
new_tuple ? new_tuple : old_tuple,
3153-
NULL,
3154-
qkey->constr_queryno, true);
3150+
ereport(ERROR,
3151+
(errcode(ERRCODE_INTERNAL_ERROR),
3152+
errmsg("referential integrity query on \"%s\" from constraint \"%s\" on \"%s\" gave unexpected result",
3153+
RelationGetRelationName(pk_rel),
3154+
NameStr(riinfo->conname),
3155+
RelationGetRelationName(fk_rel)),
3156+
errhint("This is most likely due to a rule having rewritten the query.")));
31553157

31563158
/* XXX wouldn't it be clearer to do this part at the caller? */
31573159
if (qkey->constr_queryno != RI_PLAN_CHECK_LOOKUPPK_FROM_PK &&
@@ -3161,7 +3163,7 @@ ri_PerformCheck(const RI_ConstraintInfo *riinfo,
31613163
pk_rel, fk_rel,
31623164
new_tuple ? new_tuple : old_tuple,
31633165
NULL,
3164-
qkey->constr_queryno, false);
3166+
qkey->constr_queryno);
31653167

31663168
return SPI_processed != 0;
31673169
}
@@ -3205,7 +3207,7 @@ static void
32053207
ri_ReportViolation(const RI_ConstraintInfo *riinfo,
32063208
Relation pk_rel, Relation fk_rel,
32073209
HeapTuple violator, TupleDesc tupdesc,
3208-
int queryno, bool spi_err)
3210+
int queryno)
32093211
{
32103212
StringInfoData key_names;
32113213
StringInfoData key_values;
@@ -3216,15 +3218,6 @@ ri_ReportViolation(const RI_ConstraintInfo *riinfo,
32163218
AclResult aclresult;
32173219
bool has_perm = true;
32183220

3219-
if (spi_err)
3220-
ereport(ERROR,
3221-
(errcode(ERRCODE_INTERNAL_ERROR),
3222-
errmsg("referential integrity query on \"%s\" from constraint \"%s\" on \"%s\" gave unexpected result",
3223-
RelationGetRelationName(pk_rel),
3224-
NameStr(riinfo->conname),
3225-
RelationGetRelationName(fk_rel)),
3226-
errhint("This is most likely due to a rule having rewritten the query.")));
3227-
32283221
/*
32293222
* Determine which relation to complain about. If tupdesc wasn't passed
32303223
* by caller, assume the violator tuple came from there.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy