summaryrefslogtreecommitdiff
path: root/src/pl
diff options
context:
space:
mode:
authorAlvaro Herrera2008-05-12 20:02:02 +0000
committerAlvaro Herrera2008-05-12 20:02:02 +0000
commit5da9da71c44f27ba48fdad08ef263bf70e43e689 (patch)
treed8afb52acd9386a59c1862a265d4f8e6d2fdbaba /src/pl
parentaa82790fcab98b8d3d4eca2e2f6f7bfce57870bc (diff)
Improve snapshot manager by keeping explicit track of snapshots.
There are two ways to track a snapshot: there's the "registered" list, which is used for arbitrary long-lived snapshots; and there's the "active stack", which is used for the snapshot that is considered "active" at any time. This also allows users of snapshots to stop worrying about snapshot memory allocation and freeing, and about using PG_TRY blocks around ActiveSnapshot assignment. This is all done automatically now. As a consequence, this allows us to reset MyProc->xmin when there are no more snapshots registered in the current backend, reducing the impact that long-running transactions have on VACUUM.
Diffstat (limited to 'src/pl')
-rw-r--r--src/pl/plpgsql/src/pl_exec.c45
1 files changed, 17 insertions, 28 deletions
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index cd0ed39168..b248384af4 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.212 2008/05/12 00:00:54 alvherre Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.213 2008/05/12 20:02:02 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@@ -4129,7 +4129,7 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate,
CachedPlan *cplan;
ParamListInfo paramLI;
int i;
- Snapshot saveActiveSnapshot;
+ MemoryContext oldcontext;
/*
* Forget it if expression wasn't simple before.
@@ -4218,37 +4218,26 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate,
* updates made so far by our own function.
*/
SPI_push();
- saveActiveSnapshot = ActiveSnapshot;
- PG_TRY();
+ oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
+ if (!estate->readonly_func)
{
- MemoryContext oldcontext;
+ CommandCounterIncrement();
+ PushActiveSnapshot(GetTransactionSnapshot());
+ }
- 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
+ */
+ *result = ExecEvalExpr(expr->expr_simple_state,
+ econtext,
+ isNull,
+ NULL);
+ MemoryContextSwitchTo(oldcontext);
- /*
- * Finally we can call the executor to evaluate the expression
- */
- *result = ExecEvalExpr(expr->expr_simple_state,
- econtext,
- isNull,
- NULL);
- MemoryContextSwitchTo(oldcontext);
- }
- PG_CATCH();
- {
- /* Restore global vars and propagate error */
- ActiveSnapshot = saveActiveSnapshot;
- PG_RE_THROW();
- }
- PG_END_TRY();
+ if (!estate->readonly_func)
+ PopActiveSnapshot();
- ActiveSnapshot = saveActiveSnapshot;
SPI_pop();
/*