Tom Lane escribió: > Alvaro Herrera <alvherre@xxxxxxxxxxxxxxxxx> writes: > > Tom Lane escribi� >> I think we need to ensure that when a cursor is created, it obtains a > >> private copy of the current snapshot ... but I'm not sure where that > >> ought to happen. Thoughts? > > > Maybe you are right, but I don't think that's the only bug here. > > Well, the first problem is that 8.4 is failing to duplicate the > historical behavior. Oh! That's easy. > After that we can think about whether we'd like to > change the historical behavior. I'm not entirely convinced about that > yet (and it certainly wouldn't be something I'd want to back-patch). I don't care enough about that to spend much time on it ... -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.
*** src/backend/commands/portalcmds.c 11 Jun 2009 14:48:56 -0000 1.79 --- src/backend/commands/portalcmds.c 1 Oct 2009 01:24:11 -0000 *************** *** 47,52 **** --- 47,53 ---- 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"); *************** *** 118,127 **** portal->cursorOptions |= CURSOR_OPT_NO_SCROLL; } /* * Start execution, inserting parameters if any. */ ! PortalStart(portal, params, GetActiveSnapshot()); Assert(portal->strategy == PORTAL_ONE_SELECT); --- 119,135 ---- portal->cursorOptions |= CURSOR_OPT_NO_SCROLL; } + /* Set up snapshot for portal */ + if (stmt->rowMarks != NIL) + snapshot = RegisterCopiedSnapshot(GetActiveSnapshot(), + portal->resowner); + else + snapshot = GetActiveSnapshot(); + /* * Start execution, inserting parameters if any. */ ! PortalStart(portal, params, snapshot); Assert(portal->strategy == PORTAL_ONE_SELECT); *** src/backend/utils/time/snapmgr.c 11 Jun 2009 14:49:06 -0000 1.10 --- src/backend/utils/time/snapmgr.c 1 Oct 2009 01:19:51 -0000 *************** *** 385,390 **** --- 385,403 ---- } /* + * As above, but create a new, independeny copy of the snapshot. + */ + Snapshot + RegisterCopiedSnapshot(Snapshot snapshot, ResourceOwner owner) + { + if (snapshot == InvalidSnapshot) + return InvalidSnapshot; + + snapshot = CopySnapshot(snapshot); + return RegisterSnapshotOnOwner(snapshot, owner); + } + + /* * UnregisterSnapshot * * Decrement the reference count of a snapshot, remove the corresponding *** src/include/utils/snapmgr.h 11 Jun 2009 14:49:13 -0000 1.5 --- src/include/utils/snapmgr.h 1 Oct 2009 01:20:12 -0000 *************** *** 36,41 **** --- 36,42 ---- extern Snapshot RegisterSnapshot(Snapshot snapshot); extern void UnregisterSnapshot(Snapshot snapshot); extern Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner); + extern Snapshot RegisterCopiedSnapshot(Snapshot snapshot, ResourceOwner owner); extern void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner); extern void AtSubCommit_Snapshot(int level);
-- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general