You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by es...@apache.org on 2017/02/03 09:00:06 UTC

[04/50] [abbrv] incubator-hawq git commit: HAWQ-1240. Fix bug of plan refinement for cursor operation

HAWQ-1240. Fix bug of plan refinement for cursor operation


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/e25fe8b4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/e25fe8b4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/e25fe8b4

Branch: refs/heads/2.1.0.0-incubating
Commit: e25fe8b4243594809bd673b46318968169f700e4
Parents: cee573a
Author: Paul Guo <pa...@gmail.com>
Authored: Wed Dec 28 10:52:39 2016 +0800
Committer: Paul Guo <pa...@gmail.com>
Committed: Thu Dec 29 14:14:55 2016 +0800

----------------------------------------------------------------------
 src/backend/executor/spi.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e25fe8b4/src/backend/executor/spi.c
----------------------------------------------------------------------
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index c7b7f92..9b6ae9f 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -1145,13 +1145,13 @@ SPI_cursor_open(const char *name, SPIPlanPtr plan,
 	/* Switch to portal's memory and copy the parsetrees and plans to there */
 	oldcontext = MemoryContextSwitchTo(PortalGetHeapMemory(portal));
 	qtlist = copyObject(qtlist);
-	ptlist = copyObject(ptlist);
 
 	Query *queryTree = (Query *) linitial(qtlist);
-	queryTree = copyObject(queryTree);
+	PlannedStmt* stmt = (PlannedStmt *)linitial(ptlist);
 
-	PlannedStmt* stmt = (PlannedStmt*)linitial(ptlist);
-	stmt = refineCachedPlan(stmt, queryTree, 0 ,NULL);
+	PlannedStmt* new_stmt = refineCachedPlan(stmt, queryTree, 0, NULL);
+	if (new_stmt == stmt)
+		new_stmt = copyObject(new_stmt);
 
 	/* If the plan has parameters, set them up */
 	if (spiplan->nargs > 0)
@@ -1199,7 +1199,7 @@ SPI_cursor_open(const char *name, SPIPlanPtr plan,
 					  query_string,
 					  T_SelectStmt,
 					  CreateCommandTag(PortalListGetPrimaryStmt(qtlist)),
-					  ptlist,
+					  list_make1(new_stmt),
 					  PortalGetHeapMemory(portal));
 
 	create_filesystem_credentials(portal);
@@ -1213,13 +1213,10 @@ SPI_cursor_open(const char *name, SPIPlanPtr plan,
 	{
 		int option = CURSOR_OPT_NO_SCROLL;
 		
-		if ( list_length(ptlist) == 1 )
-		{
-			PlannedStmt *stmt = (PlannedStmt *)linitial(ptlist);
-			if ( stmt && stmt->planTree && 
-				ExecSupportsBackwardScan(stmt->planTree) )
-				option = CURSOR_OPT_SCROLL;
-		}
+		if ( new_stmt && new_stmt->planTree &&
+			ExecSupportsBackwardScan(new_stmt->planTree) )
+			option = CURSOR_OPT_SCROLL;
+
 		portal->cursorOptions |= option;
 	}