aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/portalcmds.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2009-10-02 17:58:21 +0000
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2009-10-02 17:58:21 +0000
commitae35363dced47a99178b4a4129e3ea1f990b829c (patch)
treec0a113330d1b9039764b82a1e59820c420b6fe7a /src/backend/commands/portalcmds.c
parentd4bd8423c9939a30f0f29e70745917e4635b4973 (diff)
downloadpostgresql-ae35363dced47a99178b4a4129e3ea1f990b829c.tar.gz
postgresql-ae35363dced47a99178b4a4129e3ea1f990b829c.zip
Ensure that a cursor has an immutable snapshot throughout its lifespan.
The old coding was using a regular snapshot, referenced elsewhere, that was subject to having its command counter updated. Fix by creating a private copy of the snapshot exclusively for the cursor. Backpatch to 8.4, which is when the bug was introduced during the snapshot management rewrite.
Diffstat (limited to 'src/backend/commands/portalcmds.c')
-rw-r--r--src/backend/commands/portalcmds.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c
index 17192341739..d31fde65b6b 100644
--- a/src/backend/commands/portalcmds.c
+++ b/src/backend/commands/portalcmds.c
@@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.79 2009/06/11 14:48:56 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.79.2.1 2009/10/02 17:58:21 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@@ -47,6 +47,7 @@ PerformCursorOpen(PlannedStmt *stmt, ParamListInfo params,
DeclareCursorStmt *cstmt = (DeclareCursorStmt *) stmt->utilityStmt;
Portal portal;
MemoryContext oldContext;
+ Snapshot snapshot;
if (cstmt == NULL || !IsA(cstmt, DeclareCursorStmt))
elog(ERROR, "PerformCursorOpen called for non-cursor query");
@@ -119,9 +120,17 @@ PerformCursorOpen(PlannedStmt *stmt, ParamListInfo params,
}
/*
+ * Set up snapshot for portal. Note that we need a fresh, independent copy
+ * of the snapshot because we don't want it to be modified by future
+ * CommandCounterIncrement calls. We do not register it, because
+ * portalmem.c will take care of that internally.
+ */
+ snapshot = CopySnapshot(GetActiveSnapshot());
+
+ /*
* Start execution, inserting parameters if any.
*/
- PortalStart(portal, params, GetActiveSnapshot());
+ PortalStart(portal, params, snapshot);
Assert(portal->strategy == PORTAL_ONE_SELECT);