Commit 8b510838 authored by Tom Lane's avatar Tom Lane

Restructure plpgsql's caching of 'simple' expression evaluation trees

to be less dangerous, and often faster as well.  ExprState trees are
not kept across transaction boundaries; this eliminates problems with
resource leakage in failed transactions.  But by keeping them in a
per-transaction EState, we can safely arrange for a single ExprState
to be shared by all the expression evaluations done in a given plpgsql
function call.  (Formerly it seemed necessary to create and destroy an
ExprState for each exec_eval_simple_expr() call.)  This saves time in
any scenario where a plpgsql function executes more than one expression.
Seems to be about as fast as 7.3 for simple cases, and significantly
faster for functions that do a lot of calculations.
parent 89347900
This diff is collapsed.
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_handler.c,v 1.17 2003/08/04 00:43:33 momjian Exp $ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_handler.c,v 1.18 2003/09/28 23:37:45 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -46,7 +46,6 @@ ...@@ -46,7 +46,6 @@
static int plpgsql_firstcall = 1; static int plpgsql_firstcall = 1;
void plpgsql_init(void);
static void plpgsql_init_all(void); static void plpgsql_init_all(void);
...@@ -64,6 +63,8 @@ plpgsql_init(void) ...@@ -64,6 +63,8 @@ plpgsql_init(void)
plpgsql_HashTableInit(); plpgsql_HashTableInit();
RegisterEOXactCallback(plpgsql_eoxact, NULL);
plpgsql_firstcall = 0; plpgsql_firstcall = 0;
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.41 2003/09/25 23:02:12 tgl Exp $ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.42 2003/09/28 23:37:45 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -166,18 +166,22 @@ typedef struct ...@@ -166,18 +166,22 @@ typedef struct
} PLpgSQL_datum; } PLpgSQL_datum;
typedef struct typedef struct PLpgSQL_expr
{ /* SQL Query to plan and execute */ { /* SQL Query to plan and execute */
int dtype; int dtype;
int exprno; int exprno;
char *query; char *query;
void *plan; void *plan;
ExprState *plan_simple_expr;
EState *plan_simple_estate;
Oid plan_simple_type;
Oid *plan_argtypes; Oid *plan_argtypes;
/* fields for "simple expression" fast-path execution: */
Expr *expr_simple_expr; /* NULL means not a simple expr */
Oid expr_simple_type;
/* if expr is simple AND in use in current xact, these fields are set: */
ExprState *expr_simple_state;
struct PLpgSQL_expr *expr_simple_next;
/* params to pass to expr */
int nparams; int nparams;
int params[1]; int params[1]; /* VARIABLE SIZE ARRAY ... must be last */
} PLpgSQL_expr; } PLpgSQL_expr;
...@@ -636,6 +640,7 @@ extern void plpgsql_HashTableInit(void); ...@@ -636,6 +640,7 @@ extern void plpgsql_HashTableInit(void);
* Functions in pl_handler.c * Functions in pl_handler.c
* ---------- * ----------
*/ */
extern void plpgsql_init(void);
extern Datum plpgsql_call_handler(PG_FUNCTION_ARGS); extern Datum plpgsql_call_handler(PG_FUNCTION_ARGS);
/* ---------- /* ----------
...@@ -646,7 +651,7 @@ extern Datum plpgsql_exec_function(PLpgSQL_function * func, ...@@ -646,7 +651,7 @@ extern Datum plpgsql_exec_function(PLpgSQL_function * func,
FunctionCallInfo fcinfo); FunctionCallInfo fcinfo);
extern HeapTuple plpgsql_exec_trigger(PLpgSQL_function * func, extern HeapTuple plpgsql_exec_trigger(PLpgSQL_function * func,
TriggerData *trigdata); TriggerData *trigdata);
extern void plpgsql_eoxact(bool isCommit, void *arg);
/* ---------- /* ----------
* Functions for the dynamic string handling in pl_funcs.c * Functions for the dynamic string handling in pl_funcs.c
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment