From: Tom Lane Date: Tue, 21 Dec 2004 18:33:36 +0000 (+0000) Subject: exec_eval_simple_expr() needs to do CommandCounterIncrement() not just X-Git-Tag: REL8_0_0RC3~45 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=96b42de9a8f72fd42bc95abca820f7daaa4c7add;p=postgresql exec_eval_simple_expr() needs to do CommandCounterIncrement() not just GetTransactionSnapshot() to ensure ActiveSnapshot advances properly. Sigh. Extend regression test so it reveals this error too. --- diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c index 5366cd1acf..90dfc3c0d1 100644 --- a/src/pl/plpgsql/src/pl_exec.c +++ b/src/pl/plpgsql/src/pl_exec.c @@ -3,7 +3,7 @@ * procedural language * * IDENTIFICATION - * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.125 2004/12/19 20:20:17 tgl Exp $ + * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.126 2004/12/21 18:33:35 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -3631,7 +3631,7 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate, /* * We have to do some of the things SPI_execute_plan would do, - * in particular adjust ActiveSnapshot if we are in a non-read-only + * in particular advance the snapshot if we are in a non-read-only * function. Without this, stable functions within the expression * would fail to see updates made so far by our own function. */ @@ -3644,7 +3644,11 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate, oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory); if (!estate->readonly_func) + { + CommandCounterIncrement(); ActiveSnapshot = CopySnapshot(GetTransactionSnapshot()); + } + /* * Finally we can call the executor to evaluate the expression */ diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out index 1f11bbb75c..10df82cfc2 100644 --- a/src/test/regress/expected/plpgsql.out +++ b/src/test/regress/expected/plpgsql.out @@ -2089,5 +2089,17 @@ select sp_add_user('user2'); -1 (1 row) +select sp_add_user('user3'); + sp_add_user +------------- + 3 +(1 row) + +select sp_add_user('user3'); + sp_add_user +------------- + -1 +(1 row) + drop function sp_add_user(text); drop function sp_id_user(text); diff --git a/src/test/regress/sql/plpgsql.sql b/src/test/regress/sql/plpgsql.sql index 48618b9508..62aa354347 100644 --- a/src/test/regress/sql/plpgsql.sql +++ b/src/test/regress/sql/plpgsql.sql @@ -1802,6 +1802,8 @@ end$$ language plpgsql; select sp_add_user('user1'); select sp_add_user('user2'); select sp_add_user('user2'); +select sp_add_user('user3'); +select sp_add_user('user3'); drop function sp_add_user(text); drop function sp_id_user(text);