ActiveSnapshot must be set to something valid while running deferred
authorTom Lane <[email protected]>
Mon, 6 Dec 2004 23:57:17 +0000 (23:57 +0000)
committerTom Lane <[email protected]>
Mon, 6 Dec 2004 23:57:17 +0000 (23:57 +0000)
triggers during COMMIT.  Per trouble report from Frank van Vugt.

src/backend/commands/trigger.c

index f2cd78236fc61de6f5635876bf80d27828963145..9699bc0b8abe16d4a0d1bc27e3e9379fd7461d93 100644 (file)
@@ -2364,6 +2364,14 @@ AfterTriggerEndXact(void)
        /* ... but not inside a query */
        Assert(afterTriggers->query_depth == -1);
 
+       /*
+        * If there are any triggers to fire, make sure we have set a snapshot
+        * for them to use.  (Since PortalRunUtility doesn't set a snap for
+        * COMMIT, we can't assume ActiveSnapshot is valid on entry.)
+        */
+       if (afterTriggers->events.head != NULL)
+               ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
+
        /*
         * Run all the remaining triggers.  Loop until they are all gone,
         * just in case some trigger queues more for us to do.