@ -3,7 +3,7 @@
* procedural language
* procedural language
*
*
* IDENTIFICATION
* IDENTIFICATION
* $ PostgreSQL : pgsql / src / pl / plpgsql / src / pl_exec . c , v 1.154 .2 .3 2006 / 01 / 17 17 : 33 : 22 tgl Exp $
* $ PostgreSQL : pgsql / src / pl / plpgsql / src / pl_exec . c , v 1.154 .2 .4 2006 / 03 / 02 05 : 34 : 17 tgl Exp $
*
*
* This software is copyrighted by Jan Wieck - Hamburg .
* This software is copyrighted by Jan Wieck - Hamburg .
*
*
@ -64,12 +64,8 @@ static const char *const raise_skip_msg = "RAISE";
* function call creates its own " eval_econtext " ExprContext within this
* function call creates its own " eval_econtext " ExprContext within this
* estate . We destroy the estate at transaction shutdown to ensure there
* estate . We destroy the estate at transaction shutdown to ensure there
* is no permanent leakage of memory ( especially for xact abort case ) .
* is no permanent leakage of memory ( especially for xact abort case ) .
*
* If a simple PLpgSQL_expr has been used in the current xact , it is
* linked into the active_simple_exprs list .
*/
*/
static EState * simple_eval_estate = NULL ;
static EState * simple_eval_estate = NULL ;
static PLpgSQL_expr * active_simple_exprs = NULL ;
/************************************************************
/************************************************************
* Local function forward declarations
* Local function forward declarations
@ -3799,6 +3795,7 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate,
{
{
Datum retval ;
Datum retval ;
ExprContext * econtext = estate - > eval_econtext ;
ExprContext * econtext = estate - > eval_econtext ;
TransactionId curxid = GetTopTransactionId ( ) ;
ParamListInfo paramLI ;
ParamListInfo paramLI ;
int i ;
int i ;
Snapshot saveActiveSnapshot ;
Snapshot saveActiveSnapshot ;
@ -3812,13 +3809,11 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate,
* Prepare the expression for execution , if it ' s not been done already in
* Prepare the expression for execution , if it ' s not been done already in
* the current transaction .
* the current transaction .
*/
*/
if ( expr - > expr_simple_state = = NULL )
if ( expr - > expr_simple_xid ! = curxid )
{
{
expr - > expr_simple_state = ExecPrepareExpr ( expr - > expr_simple_expr ,
expr - > expr_simple_state = ExecPrepareExpr ( expr - > expr_simple_expr ,
simple_eval_estate ) ;
simple_eval_estate ) ;
/* Add it to list for cleanup */
expr - > expr_simple_xid = curxid ;
expr - > expr_simple_next = active_simple_exprs ;
active_simple_exprs = expr ;
}
}
/*
/*
@ -4458,11 +4453,11 @@ exec_simple_check_plan(PLpgSQL_expr *expr)
/*
/*
* Yes - this is a simple expression . Mark it as such , and initialize
* Yes - this is a simple expression . Mark it as such , and initialize
* state to " not executing " .
* state to " not valid in current transaction " .
*/
*/
expr - > expr_simple_expr = tle - > expr ;
expr - > expr_simple_expr = tle - > expr ;
expr - > expr_simple_state = NULL ;
expr - > expr_simple_state = NULL ;
expr - > expr_simple_next = NULL ;
expr - > expr_simple_xid = InvalidTransactionId ;
/* Also stash away the expression result type */
/* Also stash away the expression result type */
expr - > expr_simple_type = exprType ( ( Node * ) tle - > expr ) ;
expr - > expr_simple_type = exprType ( ( Node * ) tle - > expr ) ;
}
}
@ -4506,8 +4501,7 @@ exec_set_found(PLpgSQL_execstate *estate, bool state)
* plpgsql_xact_cb - - - post - transaction - commit - or - abort cleanup
* plpgsql_xact_cb - - - post - transaction - commit - or - abort cleanup
*
*
* If a simple_eval_estate was created in the current transaction ,
* If a simple_eval_estate was created in the current transaction ,
* it has to be cleaned up , and we have to mark all active PLpgSQL_expr
* it has to be cleaned up .
* structs that are using it as no longer active .
*
*
* XXX Do we need to do anything at subtransaction events ?
* XXX Do we need to do anything at subtransaction events ?
* Maybe subtransactions need to have their own simple_eval_estate ?
* Maybe subtransactions need to have their own simple_eval_estate ?
@ -4516,18 +4510,6 @@ exec_set_found(PLpgSQL_execstate *estate, bool state)
void
void
plpgsql_xact_cb ( XactEvent event , void * arg )
plpgsql_xact_cb ( XactEvent event , void * arg )
{
{
PLpgSQL_expr * expr ;
PLpgSQL_expr * enext ;
/* Mark all active exprs as inactive */
for ( expr = active_simple_exprs ; expr ; expr = enext )
{
enext = expr - > expr_simple_next ;
expr - > expr_simple_state = NULL ;
expr - > expr_simple_next = NULL ;
}
active_simple_exprs = NULL ;
/*
/*
* If we are doing a clean transaction shutdown , free the EState ( so that
* If we are doing a clean transaction shutdown , free the EState ( so that
* any remaining resources will be released correctly ) . In an abort , we
* any remaining resources will be released correctly ) . In an abort , we