3
3
* procedural language
4
4
*
5
5
* IDENTIFICATION
6
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.160 2006/01/10 18:50:43 neilc Exp $
6
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.161 2006/03/02 05:34:12 tgl Exp $
7
7
*
8
8
* This software is copyrighted by Jan Wieck - Hamburg.
9
9
*
@@ -64,12 +64,8 @@ static const char *const raise_skip_msg = "RAISE";
64
64
* function call creates its own "eval_econtext" ExprContext within this
65
65
* estate. We destroy the estate at transaction shutdown to ensure there
66
66
* is no permanent leakage of memory (especially for xact abort case).
67
- *
68
- * If a simple PLpgSQL_expr has been used in the current xact, it is
69
- * linked into the active_simple_exprs list.
70
67
*/
71
68
static EState * simple_eval_estate = NULL ;
72
- static PLpgSQL_expr * active_simple_exprs = NULL ;
73
69
74
70
/************************************************************
75
71
* Local function forward declarations
@@ -3783,6 +3779,7 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate,
3783
3779
{
3784
3780
Datum retval ;
3785
3781
ExprContext * econtext = estate -> eval_econtext ;
3782
+ TransactionId curxid = GetTopTransactionId ();
3786
3783
ParamListInfo paramLI ;
3787
3784
int i ;
3788
3785
Snapshot saveActiveSnapshot ;
@@ -3796,13 +3793,11 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate,
3796
3793
* Prepare the expression for execution, if it's not been done already in
3797
3794
* the current transaction.
3798
3795
*/
3799
- if (expr -> expr_simple_state == NULL )
3796
+ if (expr -> expr_simple_xid != curxid )
3800
3797
{
3801
3798
expr -> expr_simple_state = ExecPrepareExpr (expr -> expr_simple_expr ,
3802
3799
simple_eval_estate );
3803
- /* Add it to list for cleanup */
3804
- expr -> expr_simple_next = active_simple_exprs ;
3805
- active_simple_exprs = expr ;
3800
+ expr -> expr_simple_xid = curxid ;
3806
3801
}
3807
3802
3808
3803
/*
@@ -4454,11 +4449,11 @@ exec_simple_check_plan(PLpgSQL_expr *expr)
4454
4449
4455
4450
/*
4456
4451
* Yes - this is a simple expression. Mark it as such, and initialize
4457
- * state to "not executing ".
4452
+ * state to "not valid in current transaction ".
4458
4453
*/
4459
4454
expr -> expr_simple_expr = tle -> expr ;
4460
4455
expr -> expr_simple_state = NULL ;
4461
- expr -> expr_simple_next = NULL ;
4456
+ expr -> expr_simple_xid = InvalidTransactionId ;
4462
4457
/* Also stash away the expression result type */
4463
4458
expr -> expr_simple_type = exprType ((Node * ) tle -> expr );
4464
4459
}
@@ -4502,8 +4497,7 @@ exec_set_found(PLpgSQL_execstate *estate, bool state)
4502
4497
* plpgsql_xact_cb --- post-transaction-commit-or-abort cleanup
4503
4498
*
4504
4499
* If a simple_eval_estate was created in the current transaction,
4505
- * it has to be cleaned up, and we have to mark all active PLpgSQL_expr
4506
- * structs that are using it as no longer active.
4500
+ * it has to be cleaned up.
4507
4501
*
4508
4502
* XXX Do we need to do anything at subtransaction events?
4509
4503
* Maybe subtransactions need to have their own simple_eval_estate?
@@ -4512,18 +4506,6 @@ exec_set_found(PLpgSQL_execstate *estate, bool state)
4512
4506
void
4513
4507
plpgsql_xact_cb (XactEvent event , void * arg )
4514
4508
{
4515
- PLpgSQL_expr * expr ;
4516
- PLpgSQL_expr * enext ;
4517
-
4518
- /* Mark all active exprs as inactive */
4519
- for (expr = active_simple_exprs ; expr ; expr = enext )
4520
- {
4521
- enext = expr -> expr_simple_next ;
4522
- expr -> expr_simple_state = NULL ;
4523
- expr -> expr_simple_next = NULL ;
4524
- }
4525
- active_simple_exprs = NULL ;
4526
-
4527
4509
/*
4528
4510
* If we are doing a clean transaction shutdown, free the EState (so that
4529
4511
* any remaining resources will be released correctly). In an abort, we
0 commit comments