Skip to content

Commit 96b42de

Browse files
committed
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.
1 parent c21c658 commit 96b42de

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/pl/plpgsql/src/pl_exec.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.125 2004/12/19 20:20:17 tgl Exp $
6+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.126 2004/12/21 18:33:35 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -3631,7 +3631,7 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate,
36313631

36323632
/*
36333633
* We have to do some of the things SPI_execute_plan would do,
3634-
* in particular adjust ActiveSnapshot if we are in a non-read-only
3634+
* in particular advance the snapshot if we are in a non-read-only
36353635
* function. Without this, stable functions within the expression
36363636
* would fail to see updates made so far by our own function.
36373637
*/
@@ -3644,7 +3644,11 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate,
36443644

36453645
oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
36463646
if (!estate->readonly_func)
3647+
{
3648+
CommandCounterIncrement();
36473649
ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
3650+
}
3651+
36483652
/*
36493653
* Finally we can call the executor to evaluate the expression
36503654
*/

src/test/regress/expected/plpgsql.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,5 +2089,17 @@ select sp_add_user('user2');
20892089
-1
20902090
(1 row)
20912091

2092+
select sp_add_user('user3');
2093+
sp_add_user
2094+
-------------
2095+
3
2096+
(1 row)
2097+
2098+
select sp_add_user('user3');
2099+
sp_add_user
2100+
-------------
2101+
-1
2102+
(1 row)
2103+
20922104
drop function sp_add_user(text);
20932105
drop function sp_id_user(text);

src/test/regress/sql/plpgsql.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,8 @@ end$$ language plpgsql;
18021802
select sp_add_user('user1');
18031803
select sp_add_user('user2');
18041804
select sp_add_user('user2');
1805+
select sp_add_user('user3');
1806+
select sp_add_user('user3');
18051807

18061808
drop function sp_add_user(text);
18071809
drop function sp_id_user(text);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy