diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-09-13 20:10:13 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-09-13 20:10:13 +0000 |
commit | b2c4071299e02ed96d48d3c8e776de2fab36f88c (patch) | |
tree | ff0db14826870f1c3fe46d94ea3a1e1697c658a7 /src/pl/plperl/spi_internal.c | |
parent | d69528881ab72eac5a9f154f23dbf549789c264d (diff) | |
download | postgresql-b2c4071299e02ed96d48d3c8e776de2fab36f88c.tar.gz postgresql-b2c4071299e02ed96d48d3c8e776de2fab36f88c.zip |
Redesign query-snapshot timing so that volatile functions in READ COMMITTED
mode see a fresh snapshot for each command in the function, rather than
using the latest interactive command's snapshot. Also, suppress fresh
snapshots as well as CommandCounterIncrement inside STABLE and IMMUTABLE
functions, instead using the snapshot taken for the most closely nested
regular query. (This behavior is only sane for read-only functions, so
the patch also enforces that such functions contain only SELECT commands.)
As per my proposal of 6-Sep-2004; I note that I floated essentially the
same proposal on 19-Jun-2002, but that discussion tailed off without any
action. Since 8.0 seems like the right place to be taking possibly
nontrivial backwards compatibility hits, let's get it done now.
Diffstat (limited to 'src/pl/plperl/spi_internal.c')
-rw-r--r-- | src/pl/plperl/spi_internal.c | 85 |
1 files changed, 2 insertions, 83 deletions
diff --git a/src/pl/plperl/spi_internal.c b/src/pl/plperl/spi_internal.c index 5c3bb38a534..390e76a7e77 100644 --- a/src/pl/plperl/spi_internal.c +++ b/src/pl/plperl/spi_internal.c @@ -1,15 +1,12 @@ -#include "postgres.h" -#include "executor/spi.h" -#include "utils/syscache.h" /* * This kludge is necessary because of the conflicting * definitions of 'DEBUG' between postgres and perl. * we'll live. */ -#include "spi_internal.h" +#include "postgres.h" -static HV *plperl_spi_execute_fetch_result(SPITupleTable *, int, int); +#include "spi_internal.h" int @@ -47,81 +44,3 @@ spi_ERROR(void) { return ERROR; } - -HV * -plperl_spi_exec(char *query, int limit) -{ - HV *ret_hv; - int spi_rv; - - spi_rv = SPI_exec(query, limit); - ret_hv = plperl_spi_execute_fetch_result(SPI_tuptable, SPI_processed, spi_rv); - - return ret_hv; -} - -static HV * -plperl_hash_from_tuple(HeapTuple tuple, TupleDesc tupdesc) -{ - int i; - char *attname; - char *attdata; - - HV *array; - - array = newHV(); - - for (i = 0; i < tupdesc->natts; i++) - { - /************************************************************ - * Get the attribute name - ************************************************************/ - attname = tupdesc->attrs[i]->attname.data; - - /************************************************************ - * Get the attributes value - ************************************************************/ - attdata = SPI_getvalue(tuple, tupdesc, i + 1); - if (attdata) - hv_store(array, attname, strlen(attname), newSVpv(attdata, 0), 0); - else - hv_store(array, attname, strlen(attname), newSVpv("undef", 0), 0); - } - return array; -} - -static HV * -plperl_spi_execute_fetch_result(SPITupleTable *tuptable, int processed, int status) -{ - HV *result; - - result = newHV(); - - hv_store(result, "status", strlen("status"), - newSVpv((char *) SPI_result_code_string(status), 0), 0); - hv_store(result, "processed", strlen("processed"), - newSViv(processed), 0); - - if (status == SPI_OK_SELECT) - { - if (processed) - { - AV *rows; - HV *row; - int i; - - rows = newAV(); - for (i = 0; i < processed; i++) - { - row = plperl_hash_from_tuple(tuptable->vals[i], tuptable->tupdesc); - av_store(rows, i, newRV_noinc((SV *) row)); - } - hv_store(result, "rows", strlen("rows"), - newRV_noinc((SV *) rows), 0); - } - } - - SPI_freetuptable(tuptable); - - return result; -} |