pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@postgresql.org
Subject: pgsql: Simplify code by getting rid of SPI_push, SPI_pop, SPI_restore_c
Date: Tue, 08 Nov 2016 22:40:08 +0000
Message-ID: <E1c4F3o-00057I-VF@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>

Simplify code by getting rid of SPI_push, SPI_pop, SPI_restore_connection.

The idea behind SPI_push was to allow transitioning back into an
"unconnected" state when a SPI-using procedure calls unrelated code that
might or might not invoke SPI.  That sounds good, but in practice the only
thing it does for us is to catch cases where a called SPI-using function
forgets to call SPI_connect --- which is a highly improbable failure mode,
since it would be exposed immediately by direct testing of said function.
As against that, we've had multiple bugs induced by forgetting to call
SPI_push/SPI_pop around code that might invoke SPI-using functions; these
are much harder to catch and indeed have gone undetected for years in some
cases.  And we've had to band-aid around some problems of this ilk by
introducing conditional push/pop pairs in some places, which really kind
of defeats the purpose altogether; if we can't draw bright lines between
connected and unconnected code, what's the point?

Hence, get rid of SPI_push[_conditional], SPI_pop[_conditional], and the
underlying state variable _SPI_curid.  It turns out SPI_restore_connection
can go away too, which is a nice side benefit since it was never more than
a kluge.  Provide no-op macros for the deleted functions so as to avoid an
API break for external modules.

A side effect of this removal is that SPI_palloc and allied functions no
longer permit being called when unconnected; they'll throw an error
instead.  The apparent usefulness of the previous behavior was a mirage
as well, because it was depended on by only a few places (which I fixed in
preceding commits), and it posed a risk of allocations being unexpectedly
long-lived if someone forgot a SPI_push call.

Discussion: <20808.1478481403@sss.pgh.pa.us>

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/1833f1a1c3b0e12b3ea40d49bf11898eedae5248

Modified Files
--------------
doc/src/sgml/spi.sgml                | 180 ++++++++-----------------------
src/backend/executor/spi.c           | 200 +++++++++--------------------------
src/backend/utils/adt/xml.c          |   6 --
src/backend/utils/cache/plancache.c  |  13 ---
src/backend/utils/fmgr/fmgr.c        |  48 +--------
src/include/executor/spi.h           |  12 ++-
src/pl/plperl/plperl.c               |  78 --------------
src/pl/plpgsql/src/pl_exec.c         |  21 ----
src/pl/plpython/plpy_exec.c          |   2 -
src/pl/plpython/plpy_spi.c           |  13 ---
src/pl/plpython/plpy_subxactobject.c |   7 --
src/pl/tcl/pltcl.c                   |  18 ----
12 files changed, 105 insertions(+), 493 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


Message-ID: <E1c4F3o-00057I-VF@gemulon.postgresql.org>
Permalink:  ../E1c4F3o-00057I-VF@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1c4F3o-00057I-VF@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Simplify code by getting rid of SPI_push, SPI_pop, SPI_restore_c
  In-Reply-To: <E1c4F3o-00057I-VF@gemulon.postgresql.org>
  References: <E1c4F3o-00057I-VF@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox