1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-18 02:02:55 +03:00

Insert conditional SPI_push/SPI_pop calls into InputFunctionCall,

OutputFunctionCall, and friends.  This allows SPI-using functions to invoke
datatype I/O without concern for the possibility that a SPI-using function
will be called (which could be either the I/O function itself, or a function
used in a domain check constraint).  It's a tad ugly, but not nearly as ugly
as what'd be needed to make this work via retail insertion of push/pop
operations in all the PLs.

This reverts my patch of 2007-01-30 that inserted some retail SPI_push/pop
calls into plpgsql; that approach only fixed plpgsql, and not any other PLs.
But the other PLs have the issue too, as illustrated by a recent gripe from
Christian Schröder.

Back-patch to 8.2, which is as far back as this solution will work.  It's
also as far back as we need to worry about the domain-constraint case, since
earlier versions did not attempt to check domain constraints within datatype
input.  I'm not aware of any old I/O functions that use SPI themselves, so
this should be sufficient for a back-patch.
This commit is contained in:
Tom Lane
2009-01-07 20:39:15 +00:00
parent 7673ed269a
commit c23bd9232f
4 changed files with 77 additions and 40 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.180.2.6 2008/09/01 22:30:48 tgl Exp $
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.180.2.7 2009/01/07 20:39:15 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -4288,27 +4288,11 @@ make_tuple_from_row(PLpgSQL_execstate *estate,
static char *
convert_value_to_string(Datum value, Oid valtype)
{
char *str;
Oid typoutput;
bool typIsVarlena;
getTypeOutputInfo(valtype, &typoutput, &typIsVarlena);
/*
* We do SPI_push to allow the datatype output function to use SPI.
* However we do not mess around with CommandCounterIncrement or advancing
* the snapshot, which means that a stable output function would not see
* updates made so far by our own function. The use-case for such
* scenarios seems too narrow to justify the cycles that would be
* expended.
*/
SPI_push();
str = OidOutputFunctionCall(typoutput, value);
SPI_pop();
return str;
return OidOutputFunctionCall(typoutput, value);
}
/* ----------
@@ -4334,25 +4318,14 @@ exec_cast_value(Datum value, Oid valtype,
char *extval;
extval = convert_value_to_string(value, valtype);
/* Allow input function to use SPI ... see notes above */
SPI_push();
value = InputFunctionCall(reqinput, extval,
reqtypioparam, reqtypmod);
SPI_pop();
pfree(extval);
}
else
{
SPI_push();
value = InputFunctionCall(reqinput, NULL,
reqtypioparam, reqtypmod);
SPI_pop();
}
}