diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 9fc4431..45e62ba 100644
*** a/src/backend/executor/spi.c
--- b/src/backend/executor/spi.c
*************** _SPI_execute_plan(SPIPlanPtr plan, Param
*** 2066,2071 ****
--- 2066,2083 ----
  		spierrcontext.arg = (void *) plansource->query_string;
  
  		/*
+ 		 * In the default non-read-only case, get a new snapshot, replacing
+ 		 * any that we pushed in a previous cycle.
+ 		 */
+ 		if (snapshot == InvalidSnapshot && !read_only)
+ 		{
+ 			if (pushed_active_snap)
+ 				PopActiveSnapshot();
+ 			PushActiveSnapshot(GetTransactionSnapshot());
+ 			pushed_active_snap = true;
+ 		}
+ 
+ 		/*
  		 * If this is a one-shot plan, we still need to do parse analysis.
  		 */
  		if (plan->oneshot)
*************** _SPI_execute_plan(SPIPlanPtr plan, Param
*** 2117,2134 ****
  		cplan = GetCachedPlan(plansource, paramLI, plan->saved, _SPI_current->queryEnv);
  		stmt_list = cplan->stmt_list;
  
- 		/*
- 		 * In the default non-read-only case, get a new snapshot, replacing
- 		 * any that we pushed in a previous cycle.
- 		 */
- 		if (snapshot == InvalidSnapshot && !read_only)
- 		{
- 			if (pushed_active_snap)
- 				PopActiveSnapshot();
- 			PushActiveSnapshot(GetTransactionSnapshot());
- 			pushed_active_snap = true;
- 		}
- 
  		foreach(lc2, stmt_list)
  		{
  			PlannedStmt *stmt = lfirst_node(PlannedStmt, lc2);
--- 2129,2134 ----
