Tom Lane escribió: > Alvaro Herrera <alvherre@xxxxxxxxxxxxxxxxx> writes: > > Tom Lane escribió: > >> Well, the first problem is that 8.4 is failing to duplicate the > >> historical behavior. > > > Oh! That's easy. > > I don't think that testing rowMarks is the right thing at all here. > That tells you whether it's a SELECT FOR UPDATE, but actually we > want any cursor (and only cursors) to have a private snapshot. The attached patch implements this. I intend to apply to 8.4 and HEAD shortly. -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.
Index: src/backend/commands/portalcmds.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/commands/portalcmds.c,v retrieving revision 1.79 diff -c -p -r1.79 portalcmds.c *** src/backend/commands/portalcmds.c 11 Jun 2009 14:48:56 -0000 1.79 --- src/backend/commands/portalcmds.c 1 Oct 2009 19:35:15 -0000 *************** PerformCursorOpen(PlannedStmt *stmt, Par *** 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"); *************** PerformCursorOpen(PlannedStmt *stmt, Par *** 119,127 **** } /* * Start execution, inserting parameters if any. */ ! PortalStart(portal, params, GetActiveSnapshot()); Assert(portal->strategy == PORTAL_ONE_SELECT); --- 120,136 ---- } /* + * 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. + */ + snapshot = RegisterCopiedSnapshot(GetActiveSnapshot(), + portal->resowner); + + /* * Start execution, inserting parameters if any. */ ! PortalStart(portal, params, snapshot); Assert(portal->strategy == PORTAL_ONE_SELECT); Index: src/backend/utils/time/snapmgr.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/utils/time/snapmgr.c,v retrieving revision 1.10 diff -c -p -r1.10 snapmgr.c *** src/backend/utils/time/snapmgr.c 11 Jun 2009 14:49:06 -0000 1.10 --- src/backend/utils/time/snapmgr.c 1 Oct 2009 17:24:40 -0000 *************** RegisterSnapshotOnOwner(Snapshot snapsho *** 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 Index: src/include/utils/snapmgr.h =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/include/utils/snapmgr.h,v retrieving revision 1.5 diff -c -p -r1.5 snapmgr.h *** src/include/utils/snapmgr.h 11 Jun 2009 14:49:13 -0000 1.5 --- src/include/utils/snapmgr.h 1 Oct 2009 17:24:40 -0000 *************** extern bool ActiveSnapshotSet(void); *** 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