diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2024-09-09 12:18:32 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2024-09-09 12:18:34 -0400 |
commit | 218527d01456b65decdc7596c6f6d5ac2bdeb78b (patch) | |
tree | 6aceaaac941dd92421d0a16dd65ded4426f421d0 /src/backend | |
parent | cdb6b0fdb0b2face270406905d31f8f513b015cc (diff) | |
download | postgresql-218527d01456b65decdc7596c6f6d5ac2bdeb78b.tar.gz postgresql-218527d01456b65decdc7596c6f6d5ac2bdeb78b.zip |
Don't bother checking the result of SPI_connect[_ext] anymore.
SPI_connect/SPI_connect_ext have not returned any value other than
SPI_OK_CONNECT since commit 1833f1a1c in v10; any errors are thrown
via ereport. (The most likely failure is out-of-memory, which has
always been thrown that way, so callers had better be prepared for
such errors.) This makes it somewhat pointless to check these
functions' result, and some callers within our code haven't been
bothering; indeed, the only usage example within spi.sgml doesn't
bother. So it's likely that the omission has propagated into
extensions too.
Hence, let's standardize on not checking, and document the return
value as historical, while not actually changing these functions'
behavior. (The original proposal was to change their return type
to "void", but that would needlessly break extensions that are
conforming to the old practice.) This saves a small amount of
boilerplate code in a lot of places.
Stepan Neretin
Discussion: https://postgr.es/m/CAMaYL5Z9Uk8cD9qGz9QaZ2UBJFOu7jFx5Mwbznz-1tBbPDQZow@mail.gmail.com
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/commands/matview.c | 3 | ||||
-rw-r--r-- | src/backend/utils/adt/ri_triggers.c | 24 | ||||
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 6 |
3 files changed, 11 insertions, 22 deletions
diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c index b2457f121a7..010097873d1 100644 --- a/src/backend/commands/matview.c +++ b/src/backend/commands/matview.c @@ -639,8 +639,7 @@ refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner, relnatts = RelationGetNumberOfAttributes(matviewRel); /* Open SPI context. */ - if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "SPI_connect failed"); + SPI_connect(); /* Analyze the temp table with the new contents. */ appendStringInfo(&querybuf, "ANALYZE %s", tempname); diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c index 62601a6d80c..25931f397f7 100644 --- a/src/backend/utils/adt/ri_triggers.c +++ b/src/backend/utils/adt/ri_triggers.c @@ -340,8 +340,7 @@ RI_FKey_check(TriggerData *trigdata) break; } - if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "SPI_connect failed"); + SPI_connect(); /* Fetch or prepare a saved plan for the real check */ ri_BuildQueryKey(&qkey, riinfo, RI_PLAN_CHECK_LOOKUPPK); @@ -469,8 +468,7 @@ ri_Check_Pk_Match(Relation pk_rel, Relation fk_rel, /* Only called for non-null rows */ Assert(ri_NullCheck(RelationGetDescr(pk_rel), oldslot, riinfo, true) == RI_KEYS_NONE_NULL); - if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "SPI_connect failed"); + SPI_connect(); /* * Fetch or prepare a saved plan for checking PK table with values coming @@ -656,8 +654,7 @@ ri_restrict(TriggerData *trigdata, bool is_no_action) return PointerGetDatum(NULL); } - if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "SPI_connect failed"); + SPI_connect(); /* * Fetch or prepare a saved plan for the restrict lookup (it's the same @@ -766,8 +763,7 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS) pk_rel = trigdata->tg_relation; oldslot = trigdata->tg_trigslot; - if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "SPI_connect failed"); + SPI_connect(); /* Fetch or prepare a saved plan for the cascaded delete */ ri_BuildQueryKey(&qkey, riinfo, RI_PLAN_CASCADE_ONDELETE); @@ -875,8 +871,7 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS) newslot = trigdata->tg_newslot; oldslot = trigdata->tg_trigslot; - if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "SPI_connect failed"); + SPI_connect(); /* Fetch or prepare a saved plan for the cascaded update */ ri_BuildQueryKey(&qkey, riinfo, RI_PLAN_CASCADE_ONUPDATE); @@ -1051,8 +1046,7 @@ ri_set(TriggerData *trigdata, bool is_set_null, int tgkind) pk_rel = trigdata->tg_relation; oldslot = trigdata->tg_trigslot; - if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "SPI_connect failed"); + SPI_connect(); /* * Fetch or prepare a saved plan for the trigger. @@ -1547,8 +1541,7 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel) PGC_USERSET, PGC_S_SESSION, GUC_ACTION_SAVE, true, 0, false); - if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "SPI_connect failed"); + SPI_connect(); /* * Generate the plan. We don't need to cache it, and there are no @@ -1787,8 +1780,7 @@ RI_PartitionRemove_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel) PGC_USERSET, PGC_S_SESSION, GUC_ACTION_SAVE, true, 0, false); - if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "SPI_connect failed"); + SPI_connect(); /* * Generate the plan. We don't need to cache it, and there are no diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index cd9c3eddd1d..54b3542894b 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -589,8 +589,7 @@ pg_get_ruledef_worker(Oid ruleoid, int prettyFlags) /* * Connect to SPI manager */ - if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "SPI_connect failed"); + SPI_connect(); /* * On the first call prepare the plan to lookup pg_rewrite. We read @@ -782,8 +781,7 @@ pg_get_viewdef_worker(Oid viewoid, int prettyFlags, int wrapColumn) /* * Connect to SPI manager */ - if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "SPI_connect failed"); + SPI_connect(); /* * On the first call prepare the plan to lookup pg_rewrite. We read |