1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

PersistHoldablePortal must establish the correct value for ActiveSnapshot

while completing execution of the cursor's query.  Otherwise we get wrong
answers or even crashes from non-volatile functions called by the query.
Per report from andrew@supernews.
This commit is contained in:
Tom Lane
2005-04-11 15:59:34 +00:00
parent 72fd559037
commit 0c400f1bbc

View File

@ -14,7 +14,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.39 2005/03/25 21:57:58 tgl Exp $ * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.40 2005/04/11 15:59:34 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -309,6 +309,7 @@ PersistHoldablePortal(Portal portal)
{ {
QueryDesc *queryDesc = PortalGetQueryDesc(portal); QueryDesc *queryDesc = PortalGetQueryDesc(portal);
Portal saveActivePortal; Portal saveActivePortal;
Snapshot saveActiveSnapshot;
ResourceOwner saveResourceOwner; ResourceOwner saveResourceOwner;
MemoryContext savePortalContext; MemoryContext savePortalContext;
MemoryContext saveQueryContext; MemoryContext saveQueryContext;
@ -350,12 +351,14 @@ PersistHoldablePortal(Portal portal)
* Set up global portal context pointers. * Set up global portal context pointers.
*/ */
saveActivePortal = ActivePortal; saveActivePortal = ActivePortal;
saveActiveSnapshot = ActiveSnapshot;
saveResourceOwner = CurrentResourceOwner; saveResourceOwner = CurrentResourceOwner;
savePortalContext = PortalContext; savePortalContext = PortalContext;
saveQueryContext = QueryContext; saveQueryContext = QueryContext;
PG_TRY(); PG_TRY();
{ {
ActivePortal = portal; ActivePortal = portal;
ActiveSnapshot = queryDesc->snapshot;
CurrentResourceOwner = portal->resowner; CurrentResourceOwner = portal->resowner;
PortalContext = PortalGetHeapMemory(portal); PortalContext = PortalGetHeapMemory(portal);
QueryContext = portal->queryContext; QueryContext = portal->queryContext;
@ -428,6 +431,7 @@ PersistHoldablePortal(Portal portal)
/* Restore global vars and propagate error */ /* Restore global vars and propagate error */
ActivePortal = saveActivePortal; ActivePortal = saveActivePortal;
ActiveSnapshot = saveActiveSnapshot;
CurrentResourceOwner = saveResourceOwner; CurrentResourceOwner = saveResourceOwner;
PortalContext = savePortalContext; PortalContext = savePortalContext;
QueryContext = saveQueryContext; QueryContext = saveQueryContext;
@ -442,6 +446,7 @@ PersistHoldablePortal(Portal portal)
portal->status = PORTAL_READY; portal->status = PORTAL_READY;
ActivePortal = saveActivePortal; ActivePortal = saveActivePortal;
ActiveSnapshot = saveActiveSnapshot;
CurrentResourceOwner = saveResourceOwner; CurrentResourceOwner = saveResourceOwner;
PortalContext = savePortalContext; PortalContext = savePortalContext;
QueryContext = saveQueryContext; QueryContext = saveQueryContext;