Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b2c4071

Browse files
committed
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.
1 parent d695288 commit b2c4071

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1737
-807
lines changed

contrib/tablefunc/tablefunc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ crosstab(PG_FUNCTION_ARGS)
386386
elog(ERROR, "crosstab: SPI_connect returned %d", ret);
387387

388388
/* Retrieve the desired rows */
389-
ret = SPI_exec(sql, 0);
389+
ret = SPI_execute(sql, true, 0);
390390
proc = SPI_processed;
391391

392392
/* Check for qualifying tuples */
@@ -777,7 +777,7 @@ load_categories_hash(char *cats_sql, MemoryContext per_query_ctx)
777777
elog(ERROR, "load_categories_hash: SPI_connect returned %d", ret);
778778

779779
/* Retrieve the category name rows */
780-
ret = SPI_exec(cats_sql, 0);
780+
ret = SPI_execute(cats_sql, true, 0);
781781
num_categories = proc = SPI_processed;
782782

783783
/* Check for qualifying tuples */
@@ -855,7 +855,7 @@ get_crosstab_tuplestore(char *sql,
855855
elog(ERROR, "get_crosstab_tuplestore: SPI_connect returned %d", ret);
856856

857857
/* Now retrieve the crosstab source rows */
858-
ret = SPI_exec(sql, 0);
858+
ret = SPI_execute(sql, true, 0);
859859
proc = SPI_processed;
860860

861861
/* Check for qualifying tuples */
@@ -1376,7 +1376,7 @@ build_tuplestore_recursively(char *key_fld,
13761376
}
13771377

13781378
/* Retrieve the desired rows */
1379-
ret = SPI_exec(sql->data, 0);
1379+
ret = SPI_execute(sql->data, true, 0);
13801380
proc = SPI_processed;
13811381

13821382
/* Check for qualifying tuples */

contrib/tsearch2/ts_stat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ ts_stat_sql(text *txt, text *ws)
446446
/* internal error */
447447
elog(ERROR, "SPI_prepare('%s') returns NULL", query);
448448

449-
if ((portal = SPI_cursor_open(NULL, plan, NULL, NULL)) == NULL)
449+
if ((portal = SPI_cursor_open(NULL, plan, NULL, NULL, false)) == NULL)
450450
/* internal error */
451451
elog(ERROR, "SPI_cursor_open('%s') returns NULL", query);
452452

doc/src/sgml/plpython.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpython.sgml,v 1.23 2004/05/16 23:22:07 neilc Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/plpython.sgml,v 1.24 2004/09/13 20:05:18 tgl Exp $ -->
22

33
<chapter id="plpython">
44
<title>PL/Python - Python Procedural Language</title>
@@ -175,7 +175,7 @@ def __plpython_procedure_myfunc_23456():
175175
row number and column name. It has these additional methods:
176176
<function>nrows</function> which returns the number of rows
177177
returned by the query, and <function>status</function> which is the
178-
<function>SPI_exec()</function> return value. The result object
178+
<function>SPI_execute()</function> return value. The result object
179179
can be modified.
180180
</para>
181181

doc/src/sgml/ref/create_function.sgml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_function.sgml,v 1.58 2004/07/11 23:23:43 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_function.sgml,v 1.59 2004/09/13 20:05:38 tgl Exp $
33
-->
44

55
<refentry id="SQL-CREATEFUNCTION">
@@ -172,7 +172,7 @@ CREATE [ OR REPLACE ] FUNCTION <replaceable class="parameter">name</replaceable>
172172
These attributes inform the system whether it is safe to
173173
replace multiple evaluations of the function with a single
174174
evaluation, for run-time optimization. At most one choice
175-
should be specified. If none of these appear,
175+
may be specified. If none of these appear,
176176
<literal>VOLATILE</literal> is the default assumption.
177177
</para>
178178

@@ -206,6 +206,10 @@ CREATE [ OR REPLACE ] FUNCTION <replaceable class="parameter">name</replaceable>
206206
to prevent calls from being optimized away; an example is
207207
<literal>setval()</>.
208208
</para>
209+
210+
<para>
211+
For additional details see <xref linkend="xfunc-volatility">.
212+
</para>
209213
</listitem>
210214
</varlistentry>
211215

doc/src/sgml/release.sgml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.295 2004/09/10 18:39:54 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.296 2004/09/13 20:05:18 tgl Exp $
33
-->
44

55
<appendix id="release">
@@ -337,6 +337,26 @@ $PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.295 2004/09/10 18:39:54 tgl Exp
337337
</para>
338338
</listitem>
339339

340+
<listitem>
341+
<para>
342+
In <literal>READ COMMITTED</> serialization mode, volatile functions
343+
now see the results of concurrent transactions committed up to the
344+
beginning of each statement within the function, rather than up to the
345+
beginning of the interactive command that called the function.
346+
</para>
347+
</listitem>
348+
349+
<listitem>
350+
<para>
351+
Functions declared <literal>STABLE</> or <literal>IMMUTABLE</> always
352+
use the snapshot of the calling query, and therefore do not see the
353+
effects of actions taken after the calling query starts, whether in
354+
their own transaction or other transactions. Such a function must be
355+
read-only, too, meaning that it cannot use any SQL commands other than
356+
<command>SELECT</>.
357+
</para>
358+
</listitem>
359+
340360
<listitem>
341361
<para>
342362
Non-deferred AFTER triggers are now fired immediately after completion
@@ -1434,6 +1454,26 @@ $PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.295 2004/09/10 18:39:54 tgl Exp
14341454
<title>Server-Side Language Changes</title>
14351455
<itemizedlist>
14361456

1457+
<listitem>
1458+
<para>
1459+
In <literal>READ COMMITTED</> serialization mode, volatile functions
1460+
now see the results of concurrent transactions committed up to the
1461+
beginning of each statement within the function, rather than up to the
1462+
beginning of the interactive command that called the function.
1463+
</para>
1464+
</listitem>
1465+
1466+
<listitem>
1467+
<para>
1468+
Functions declared <literal>STABLE</> or <literal>IMMUTABLE</> always
1469+
use the snapshot of the calling query, and therefore do not see the
1470+
effects of actions taken after the calling query starts, whether in
1471+
their own transaction or other transactions. Such a function must be
1472+
read-only, too, meaning that it cannot use any SQL commands other than
1473+
<command>SELECT</>.
1474+
</para>
1475+
</listitem>
1476+
14371477
<listitem>
14381478
<para>
14391479
Non-deferred AFTER triggers are now fired immediately after completion

0 commit comments

Comments
 (0)