mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
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>
This commit is contained in:
@ -3057,12 +3057,6 @@ plperl_spi_exec(char *query, int limit)
|
||||
ReleaseCurrentSubTransaction();
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
CurrentResourceOwner = oldowner;
|
||||
|
||||
/*
|
||||
* AtEOSubXact_SPI() should not have popped any SPI context, but just
|
||||
* in case it did, make sure we remain connected.
|
||||
*/
|
||||
SPI_restore_connection();
|
||||
}
|
||||
PG_CATCH();
|
||||
{
|
||||
@ -3078,13 +3072,6 @@ plperl_spi_exec(char *query, int limit)
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
CurrentResourceOwner = oldowner;
|
||||
|
||||
/*
|
||||
* If AtEOSubXact_SPI() popped any SPI context of the subxact, it will
|
||||
* have left us in a disconnected state. We need this hack to return
|
||||
* to connected state.
|
||||
*/
|
||||
SPI_restore_connection();
|
||||
|
||||
/* Punt the error to Perl */
|
||||
croak_cstr(edata->message);
|
||||
|
||||
@ -3296,12 +3283,6 @@ plperl_spi_query(char *query)
|
||||
ReleaseCurrentSubTransaction();
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
CurrentResourceOwner = oldowner;
|
||||
|
||||
/*
|
||||
* AtEOSubXact_SPI() should not have popped any SPI context, but just
|
||||
* in case it did, make sure we remain connected.
|
||||
*/
|
||||
SPI_restore_connection();
|
||||
}
|
||||
PG_CATCH();
|
||||
{
|
||||
@ -3317,13 +3298,6 @@ plperl_spi_query(char *query)
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
CurrentResourceOwner = oldowner;
|
||||
|
||||
/*
|
||||
* If AtEOSubXact_SPI() popped any SPI context of the subxact, it will
|
||||
* have left us in a disconnected state. We need this hack to return
|
||||
* to connected state.
|
||||
*/
|
||||
SPI_restore_connection();
|
||||
|
||||
/* Punt the error to Perl */
|
||||
croak_cstr(edata->message);
|
||||
|
||||
@ -3382,12 +3356,6 @@ plperl_spi_fetchrow(char *cursor)
|
||||
ReleaseCurrentSubTransaction();
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
CurrentResourceOwner = oldowner;
|
||||
|
||||
/*
|
||||
* AtEOSubXact_SPI() should not have popped any SPI context, but just
|
||||
* in case it did, make sure we remain connected.
|
||||
*/
|
||||
SPI_restore_connection();
|
||||
}
|
||||
PG_CATCH();
|
||||
{
|
||||
@ -3403,13 +3371,6 @@ plperl_spi_fetchrow(char *cursor)
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
CurrentResourceOwner = oldowner;
|
||||
|
||||
/*
|
||||
* If AtEOSubXact_SPI() popped any SPI context of the subxact, it will
|
||||
* have left us in a disconnected state. We need this hack to return
|
||||
* to connected state.
|
||||
*/
|
||||
SPI_restore_connection();
|
||||
|
||||
/* Punt the error to Perl */
|
||||
croak_cstr(edata->message);
|
||||
|
||||
@ -3543,12 +3504,6 @@ plperl_spi_prepare(char *query, int argc, SV **argv)
|
||||
ReleaseCurrentSubTransaction();
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
CurrentResourceOwner = oldowner;
|
||||
|
||||
/*
|
||||
* AtEOSubXact_SPI() should not have popped any SPI context, but just
|
||||
* in case it did, make sure we remain connected.
|
||||
*/
|
||||
SPI_restore_connection();
|
||||
}
|
||||
PG_CATCH();
|
||||
{
|
||||
@ -3574,13 +3529,6 @@ plperl_spi_prepare(char *query, int argc, SV **argv)
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
CurrentResourceOwner = oldowner;
|
||||
|
||||
/*
|
||||
* If AtEOSubXact_SPI() popped any SPI context of the subxact, it will
|
||||
* have left us in a disconnected state. We need this hack to return
|
||||
* to connected state.
|
||||
*/
|
||||
SPI_restore_connection();
|
||||
|
||||
/* Punt the error to Perl */
|
||||
croak_cstr(edata->message);
|
||||
|
||||
@ -3694,12 +3642,6 @@ plperl_spi_exec_prepared(char *query, HV *attr, int argc, SV **argv)
|
||||
ReleaseCurrentSubTransaction();
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
CurrentResourceOwner = oldowner;
|
||||
|
||||
/*
|
||||
* AtEOSubXact_SPI() should not have popped any SPI context, but just
|
||||
* in case it did, make sure we remain connected.
|
||||
*/
|
||||
SPI_restore_connection();
|
||||
}
|
||||
PG_CATCH();
|
||||
{
|
||||
@ -3715,13 +3657,6 @@ plperl_spi_exec_prepared(char *query, HV *attr, int argc, SV **argv)
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
CurrentResourceOwner = oldowner;
|
||||
|
||||
/*
|
||||
* If AtEOSubXact_SPI() popped any SPI context of the subxact, it will
|
||||
* have left us in a disconnected state. We need this hack to return
|
||||
* to connected state.
|
||||
*/
|
||||
SPI_restore_connection();
|
||||
|
||||
/* Punt the error to Perl */
|
||||
croak_cstr(edata->message);
|
||||
|
||||
@ -3823,12 +3758,6 @@ plperl_spi_query_prepared(char *query, int argc, SV **argv)
|
||||
ReleaseCurrentSubTransaction();
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
CurrentResourceOwner = oldowner;
|
||||
|
||||
/*
|
||||
* AtEOSubXact_SPI() should not have popped any SPI context, but just
|
||||
* in case it did, make sure we remain connected.
|
||||
*/
|
||||
SPI_restore_connection();
|
||||
}
|
||||
PG_CATCH();
|
||||
{
|
||||
@ -3844,13 +3773,6 @@ plperl_spi_query_prepared(char *query, int argc, SV **argv)
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
CurrentResourceOwner = oldowner;
|
||||
|
||||
/*
|
||||
* If AtEOSubXact_SPI() popped any SPI context of the subxact, it will
|
||||
* have left us in a disconnected state. We need this hack to return
|
||||
* to connected state.
|
||||
*/
|
||||
SPI_restore_connection();
|
||||
|
||||
/* Punt the error to Perl */
|
||||
croak_cstr(edata->message);
|
||||
|
||||
|
Reference in New Issue
Block a user