diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 5cfc15c3391b64426bba238640ce7c4722548d0e..755a64a9446f9a7ac05aced19c7650dcfb860e81 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1994-5, Regents of the University of California
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.143 2006/02/05 02:59:16 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.144 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -233,6 +233,7 @@ ExplainOnePlan(QueryDesc *queryDesc, ExplainStmt *stmt,
 	double		totaltime = 0;
 	ExplainState *es;
 	StringInfo	str;
+	int			eflags;
 
 	INSTR_TIME_SET_CURRENT(starttime);
 
@@ -240,8 +241,14 @@ ExplainOnePlan(QueryDesc *queryDesc, ExplainStmt *stmt,
 	if (stmt->analyze)
 		AfterTriggerBeginQuery();
 
+	/* Select execution options */
+	if (stmt->analyze)
+		eflags = 0;				/* default run-to-completion flags */
+	else
+		eflags = EXEC_FLAG_EXPLAIN_ONLY;
+
 	/* call ExecutorStart to prepare the plan for execution */
-	ExecutorStart(queryDesc, !stmt->analyze);
+	ExecutorStart(queryDesc, eflags);
 
 	/* Execute the plan for statistics if asked for */
 	if (stmt->analyze)
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 57570a5cc0c7a4c85e1a13a497472b878b7a7028..48449e39551103a8c1ae906e3312ed338c2daf87 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -26,7 +26,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.267 2006/02/21 23:01:54 neilc Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.268 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -63,7 +63,7 @@ typedef struct evalPlanQual
 } evalPlanQual;
 
 /* decls for local routines only used within this module */
-static void InitPlan(QueryDesc *queryDesc, bool explainOnly);
+static void InitPlan(QueryDesc *queryDesc, int eflags);
 static void initResultRelInfo(ResultRelInfo *resultRelInfo,
 				  Index resultRelationIndex,
 				  List *rangeTable,
@@ -105,15 +105,14 @@ static void EvalPlanQualStop(evalPlanQual *epq);
  * field of the QueryDesc is filled in to describe the tuples that will be
  * returned, and the internal fields (estate and planstate) are set up.
  *
- * If explainOnly is true, we are not actually intending to run the plan,
- * only to set up for EXPLAIN; so skip unwanted side-effects.
+ * eflags contains flag bits as described in executor.h.
  *
  * NB: the CurrentMemoryContext when this is called will become the parent
  * of the per-query context used for this Executor invocation.
  * ----------------------------------------------------------------
  */
 void
-ExecutorStart(QueryDesc *queryDesc, bool explainOnly)
+ExecutorStart(QueryDesc *queryDesc, int eflags)
 {
 	EState	   *estate;
 	MemoryContext oldcontext;
@@ -124,9 +123,9 @@ ExecutorStart(QueryDesc *queryDesc, bool explainOnly)
 
 	/*
 	 * If the transaction is read-only, we need to check if any writes are
-	 * planned to non-temporary tables.
+	 * planned to non-temporary tables.  EXPLAIN is considered read-only.
 	 */
-	if (XactReadOnly && !explainOnly)
+	if (XactReadOnly && !(eflags & EXEC_FLAG_EXPLAIN_ONLY))
 		ExecCheckXactReadOnly(queryDesc->parsetree);
 
 	/*
@@ -156,7 +155,7 @@ ExecutorStart(QueryDesc *queryDesc, bool explainOnly)
 	/*
 	 * Initialize the plan state tree
 	 */
-	InitPlan(queryDesc, explainOnly);
+	InitPlan(queryDesc, eflags);
 
 	MemoryContextSwitchTo(oldcontext);
 }
@@ -442,7 +441,7 @@ fail:
  * ----------------------------------------------------------------
  */
 static void
-InitPlan(QueryDesc *queryDesc, bool explainOnly)
+InitPlan(QueryDesc *queryDesc, int eflags)
 {
 	CmdType		operation = queryDesc->operation;
 	Query	   *parseTree = queryDesc->parsetree;
@@ -608,7 +607,7 @@ InitPlan(QueryDesc *queryDesc, bool explainOnly)
 	 * tree.  This opens files, allocates storage and leaves us ready to start
 	 * processing tuples.
 	 */
-	planstate = ExecInitNode(plan, estate);
+	planstate = ExecInitNode(plan, estate, eflags);
 
 	/*
 	 * Get the tuple descriptor describing the type of tuples to return. (this
@@ -727,7 +726,7 @@ InitPlan(QueryDesc *queryDesc, bool explainOnly)
 	 */
 	intoRelationDesc = NULL;
 
-	if (do_select_into && !explainOnly)
+	if (do_select_into && !(eflags & EXEC_FLAG_EXPLAIN_ONLY))
 	{
 		char	   *intoName;
 		Oid			namespaceId;
@@ -2283,7 +2282,7 @@ EvalPlanQualStart(evalPlanQual *epq, EState *estate, evalPlanQual *priorepq)
 	epqstate->es_tupleTable =
 		ExecCreateTupleTable(estate->es_tupleTable->size);
 
-	epq->planstate = ExecInitNode(estate->es_topPlan, epqstate);
+	epq->planstate = ExecInitNode(estate->es_topPlan, epqstate, 0);
 
 	MemoryContextSwitchTo(oldcontext);
 }
diff --git a/src/backend/executor/execProcnode.c b/src/backend/executor/execProcnode.c
index c8b8d41951281c9267f42bc2a5576d0510c8a527..d7d3e541fa6b72b17788cc82dbbf60366f23175f 100644
--- a/src/backend/executor/execProcnode.c
+++ b/src/backend/executor/execProcnode.c
@@ -12,7 +12,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/execProcnode.c,v 1.52 2005/12/07 15:27:42 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/execProcnode.c,v 1.53 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -45,7 +45,7 @@
  *					DEPT		  EMP
  *				(name = "shoe")
  *
- *		ExecStart() is called first.
+ *		ExecutorStart() is called first.
  *		It calls InitPlan() which calls ExecInitNode() on
  *		the root of the plan -- the nest loop node.
  *
@@ -108,18 +108,19 @@
 /* ------------------------------------------------------------------------
  *		ExecInitNode
  *
- *		Recursively initializes all the nodes in the plan rooted
+ *		Recursively initializes all the nodes in the plan tree rooted
  *		at 'node'.
  *
- *		Initial States:
- *		  'node' is the plan produced by the query planner
- *		  'estate' is the shared execution state for the query tree
+ *		Inputs:
+ *		  'node' is the current node of the plan produced by the query planner
+ *		  'estate' is the shared execution state for the plan tree
+ *		  'eflags' is a bitwise OR of flag bits described in executor.h
  *
  *		Returns a PlanState node corresponding to the given Plan node.
  * ------------------------------------------------------------------------
  */
 PlanState *
-ExecInitNode(Plan *node, EState *estate)
+ExecInitNode(Plan *node, EState *estate, int eflags)
 {
 	PlanState  *result;
 	List	   *subps;
@@ -137,100 +138,122 @@ ExecInitNode(Plan *node, EState *estate)
 			 * control nodes
 			 */
 		case T_Result:
-			result = (PlanState *) ExecInitResult((Result *) node, estate);
+			result = (PlanState *) ExecInitResult((Result *) node,
+												  estate, eflags);
 			break;
 
 		case T_Append:
-			result = (PlanState *) ExecInitAppend((Append *) node, estate);
+			result = (PlanState *) ExecInitAppend((Append *) node,
+												  estate, eflags);
 			break;
 
 		case T_BitmapAnd:
-			result = (PlanState *) ExecInitBitmapAnd((BitmapAnd *) node, estate);
+			result = (PlanState *) ExecInitBitmapAnd((BitmapAnd *) node,
+													 estate, eflags);
 			break;
 
 		case T_BitmapOr:
-			result = (PlanState *) ExecInitBitmapOr((BitmapOr *) node, estate);
+			result = (PlanState *) ExecInitBitmapOr((BitmapOr *) node,
+													estate, eflags);
 			break;
 
 			/*
 			 * scan nodes
 			 */
 		case T_SeqScan:
-			result = (PlanState *) ExecInitSeqScan((SeqScan *) node, estate);
+			result = (PlanState *) ExecInitSeqScan((SeqScan *) node,
+												   estate, eflags);
 			break;
 
 		case T_IndexScan:
-			result = (PlanState *) ExecInitIndexScan((IndexScan *) node, estate);
+			result = (PlanState *) ExecInitIndexScan((IndexScan *) node,
+													 estate, eflags);
 			break;
 
 		case T_BitmapIndexScan:
-			result = (PlanState *) ExecInitBitmapIndexScan((BitmapIndexScan *) node, estate);
+			result = (PlanState *) ExecInitBitmapIndexScan((BitmapIndexScan *) node,
+														   estate, eflags);
 			break;
 
 		case T_BitmapHeapScan:
-			result = (PlanState *) ExecInitBitmapHeapScan((BitmapHeapScan *) node, estate);
+			result = (PlanState *) ExecInitBitmapHeapScan((BitmapHeapScan *) node,
+														  estate, eflags);
 			break;
 
 		case T_TidScan:
-			result = (PlanState *) ExecInitTidScan((TidScan *) node, estate);
+			result = (PlanState *) ExecInitTidScan((TidScan *) node,
+												   estate, eflags);
 			break;
 
 		case T_SubqueryScan:
-			result = (PlanState *) ExecInitSubqueryScan((SubqueryScan *) node, estate);
+			result = (PlanState *) ExecInitSubqueryScan((SubqueryScan *) node,
+														estate, eflags);
 			break;
 
 		case T_FunctionScan:
-			result = (PlanState *) ExecInitFunctionScan((FunctionScan *) node, estate);
+			result = (PlanState *) ExecInitFunctionScan((FunctionScan *) node,
+														estate, eflags);
 			break;
 
 			/*
 			 * join nodes
 			 */
 		case T_NestLoop:
-			result = (PlanState *) ExecInitNestLoop((NestLoop *) node, estate);
+			result = (PlanState *) ExecInitNestLoop((NestLoop *) node,
+													estate, eflags);
 			break;
 
 		case T_MergeJoin:
-			result = (PlanState *) ExecInitMergeJoin((MergeJoin *) node, estate);
+			result = (PlanState *) ExecInitMergeJoin((MergeJoin *) node,
+													 estate, eflags);
 			break;
 
 		case T_HashJoin:
-			result = (PlanState *) ExecInitHashJoin((HashJoin *) node, estate);
+			result = (PlanState *) ExecInitHashJoin((HashJoin *) node,
+													estate, eflags);
 			break;
 
 			/*
 			 * materialization nodes
 			 */
 		case T_Material:
-			result = (PlanState *) ExecInitMaterial((Material *) node, estate);
+			result = (PlanState *) ExecInitMaterial((Material *) node,
+													estate, eflags);
 			break;
 
 		case T_Sort:
-			result = (PlanState *) ExecInitSort((Sort *) node, estate);
+			result = (PlanState *) ExecInitSort((Sort *) node,
+												estate, eflags);
 			break;
 
 		case T_Group:
-			result = (PlanState *) ExecInitGroup((Group *) node, estate);
+			result = (PlanState *) ExecInitGroup((Group *) node,
+												 estate, eflags);
 			break;
 
 		case T_Agg:
-			result = (PlanState *) ExecInitAgg((Agg *) node, estate);
+			result = (PlanState *) ExecInitAgg((Agg *) node,
+											   estate, eflags);
 			break;
 
 		case T_Unique:
-			result = (PlanState *) ExecInitUnique((Unique *) node, estate);
+			result = (PlanState *) ExecInitUnique((Unique *) node,
+												  estate, eflags);
 			break;
 
 		case T_Hash:
-			result = (PlanState *) ExecInitHash((Hash *) node, estate);
+			result = (PlanState *) ExecInitHash((Hash *) node,
+												estate, eflags);
 			break;
 
 		case T_SetOp:
-			result = (PlanState *) ExecInitSetOp((SetOp *) node, estate);
+			result = (PlanState *) ExecInitSetOp((SetOp *) node,
+												 estate, eflags);
 			break;
 
 		case T_Limit:
-			result = (PlanState *) ExecInitLimit((Limit *) node, estate);
+			result = (PlanState *) ExecInitLimit((Limit *) node,
+												 estate, eflags);
 			break;
 
 		default:
@@ -251,7 +274,7 @@ ExecInitNode(Plan *node, EState *estate)
 
 		Assert(IsA(subplan, SubPlan));
 		sstate = ExecInitExprInitPlan(subplan, result);
-		ExecInitSubPlan(sstate, estate);
+		ExecInitSubPlan(sstate, estate, eflags);
 		subps = lappend(subps, sstate);
 	}
 	result->initPlan = subps;
@@ -267,7 +290,7 @@ ExecInitNode(Plan *node, EState *estate)
 		SubPlanState *sstate = (SubPlanState *) lfirst(l);
 
 		Assert(IsA(sstate, SubPlanState));
-		ExecInitSubPlan(sstate, estate);
+		ExecInitSubPlan(sstate, estate, eflags);
 	}
 
 	/* Set up instrumentation for this node if requested */
diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c
index 35f66b878a96b95c4d716dc82640c5a2b2948eb1..0196b64e19286b125276723c7787ac8138c6ee3f 100644
--- a/src/backend/executor/functions.c
+++ b/src/backend/executor/functions.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.99 2005/11/22 18:17:10 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.100 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -330,7 +330,7 @@ postquel_start(execution_state *es, SQLFunctionCachePtr fcache)
 	if (es->qd->operation != CMD_UTILITY)
 	{
 		AfterTriggerBeginQuery();
-		ExecutorStart(es->qd, false);
+		ExecutorStart(es->qd, 0);
 	}
 
 	es->status = F_EXEC_RUN;
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c
index 6832cdfbee66a46d4989b8c9ab30777d9da62f32..83ea3e43841a5c37ca2aedfab4db7134f8ea5c8a 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -61,7 +61,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.136 2005/11/22 18:17:10 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.137 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1031,7 +1031,7 @@ agg_retrieve_hash_table(AggState *aggstate)
  * -----------------
  */
 AggState *
-ExecInitAgg(Agg *node, EState *estate)
+ExecInitAgg(Agg *node, EState *estate, int eflags)
 {
 	AggState   *aggstate;
 	AggStatePerAgg peragg;
@@ -1041,6 +1041,9 @@ ExecInitAgg(Agg *node, EState *estate)
 				aggno;
 	ListCell   *l;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
+
 	/*
 	 * create state structure
 	 */
@@ -1107,9 +1110,14 @@ ExecInitAgg(Agg *node, EState *estate)
 
 	/*
 	 * initialize child nodes
+	 *
+	 * If we are doing a hashed aggregation then the child plan does not
+	 * need to handle REWIND efficiently; see ExecReScanAgg.
 	 */
+	if (node->aggstrategy == AGG_HASHED)
+		eflags &= ~EXEC_FLAG_REWIND;
 	outerPlan = outerPlan(node);
-	outerPlanState(aggstate) = ExecInitNode(outerPlan, estate);
+	outerPlanState(aggstate) = ExecInitNode(outerPlan, estate, eflags);
 
 	/*
 	 * initialize source tuple type.
diff --git a/src/backend/executor/nodeAppend.c b/src/backend/executor/nodeAppend.c
index 0b5e81096d7cf92acac9d74e821ba943624e77be..c2ea48d68249cee30552fc771c0b4cb7f00eea04 100644
--- a/src/backend/executor/nodeAppend.c
+++ b/src/backend/executor/nodeAppend.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeAppend.c,v 1.66 2006/02/05 02:59:16 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeAppend.c,v 1.67 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -140,7 +140,7 @@ exec_append_initialize_next(AppendState *appendstate)
  * ----------------------------------------------------------------
  */
 AppendState *
-ExecInitAppend(Append *node, EState *estate)
+ExecInitAppend(Append *node, EState *estate, int eflags)
 {
 	AppendState *appendstate = makeNode(AppendState);
 	PlanState **appendplanstates;
@@ -148,6 +148,9 @@ ExecInitAppend(Append *node, EState *estate)
 	int			i;
 	Plan	   *initNode;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & EXEC_FLAG_MARK));
+
 	CXT1_printf("ExecInitAppend: context is %d\n", CurrentMemoryContext);
 
 	/*
@@ -213,7 +216,7 @@ ExecInitAppend(Append *node, EState *estate)
 		exec_append_initialize_next(appendstate);
 
 		initNode = (Plan *) list_nth(node->appendplans, i);
-		appendplanstates[i] = ExecInitNode(initNode, estate);
+		appendplanstates[i] = ExecInitNode(initNode, estate, eflags);
 	}
 
 	/*
diff --git a/src/backend/executor/nodeBitmapAnd.c b/src/backend/executor/nodeBitmapAnd.c
index a9e63cbfccba87c195fbffe26770afe8d805e00f..8218ecfb9de373135acac2db182e6c13b9482363 100644
--- a/src/backend/executor/nodeBitmapAnd.c
+++ b/src/backend/executor/nodeBitmapAnd.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeBitmapAnd.c,v 1.4 2005/10/15 02:49:17 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeBitmapAnd.c,v 1.5 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -40,7 +40,7 @@
  * ----------------------------------------------------------------
  */
 BitmapAndState *
-ExecInitBitmapAnd(BitmapAnd *node, EState *estate)
+ExecInitBitmapAnd(BitmapAnd *node, EState *estate, int eflags)
 {
 	BitmapAndState *bitmapandstate = makeNode(BitmapAndState);
 	PlanState **bitmapplanstates;
@@ -49,6 +49,9 @@ ExecInitBitmapAnd(BitmapAnd *node, EState *estate)
 	ListCell   *l;
 	Plan	   *initNode;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
+
 	CXT1_printf("ExecInitBitmapAnd: context is %d\n", CurrentMemoryContext);
 
 	/*
@@ -83,7 +86,7 @@ ExecInitBitmapAnd(BitmapAnd *node, EState *estate)
 	foreach(l, node->bitmapplans)
 	{
 		initNode = (Plan *) lfirst(l);
-		bitmapplanstates[i] = ExecInitNode(initNode, estate);
+		bitmapplanstates[i] = ExecInitNode(initNode, estate, eflags);
 		i++;
 	}
 
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index 959b559d1b013d339e95bd44f8f013f3cce12fb5..df276b87b1f1d7f89cd138e3a93d14ed729489d7 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -21,7 +21,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.8 2005/12/02 20:03:40 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.9 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -459,11 +459,14 @@ ExecEndBitmapHeapScan(BitmapHeapScanState *node)
  * ----------------------------------------------------------------
  */
 BitmapHeapScanState *
-ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate)
+ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate, int eflags)
 {
 	BitmapHeapScanState *scanstate;
 	Relation	currentRelation;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
+
 	/*
 	 * Assert caller didn't ask for an unsafe snapshot --- see comments
 	 * at head of file.
@@ -552,7 +555,7 @@ ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate)
 	 * relation's indexes, and we want to be sure we have acquired a lock
 	 * on the relation first.
 	 */
-	outerPlanState(scanstate) = ExecInitNode(outerPlan(node), estate);
+	outerPlanState(scanstate) = ExecInitNode(outerPlan(node), estate, eflags);
 
 	/*
 	 * all done.
diff --git a/src/backend/executor/nodeBitmapIndexscan.c b/src/backend/executor/nodeBitmapIndexscan.c
index 37839c0255b33660dc60387dfa92b21d60ade424..327c85264438d6e7a92ee53fa0f02e0f4b66e48f 100644
--- a/src/backend/executor/nodeBitmapIndexscan.c
+++ b/src/backend/executor/nodeBitmapIndexscan.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeBitmapIndexscan.c,v 1.15 2006/01/25 20:29:23 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeBitmapIndexscan.c,v 1.16 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -211,11 +211,14 @@ ExecEndBitmapIndexScan(BitmapIndexScanState *node)
  * ----------------------------------------------------------------
  */
 BitmapIndexScanState *
-ExecInitBitmapIndexScan(BitmapIndexScan *node, EState *estate)
+ExecInitBitmapIndexScan(BitmapIndexScan *node, EState *estate, int eflags)
 {
 	BitmapIndexScanState *indexstate;
 	bool		relistarget;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
+
 	/*
 	 * create state structure
 	 */
diff --git a/src/backend/executor/nodeBitmapOr.c b/src/backend/executor/nodeBitmapOr.c
index 772b948cc52c04f3758701e9b0013a03497dfe6c..94512393d80bcdcd70a361e14f123331721b4967 100644
--- a/src/backend/executor/nodeBitmapOr.c
+++ b/src/backend/executor/nodeBitmapOr.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeBitmapOr.c,v 1.3 2005/10/15 02:49:17 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeBitmapOr.c,v 1.4 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -41,7 +41,7 @@
  * ----------------------------------------------------------------
  */
 BitmapOrState *
-ExecInitBitmapOr(BitmapOr *node, EState *estate)
+ExecInitBitmapOr(BitmapOr *node, EState *estate, int eflags)
 {
 	BitmapOrState *bitmaporstate = makeNode(BitmapOrState);
 	PlanState **bitmapplanstates;
@@ -50,6 +50,9 @@ ExecInitBitmapOr(BitmapOr *node, EState *estate)
 	ListCell   *l;
 	Plan	   *initNode;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
+
 	CXT1_printf("ExecInitBitmapOr: context is %d\n", CurrentMemoryContext);
 
 	/*
@@ -84,7 +87,7 @@ ExecInitBitmapOr(BitmapOr *node, EState *estate)
 	foreach(l, node->bitmapplans)
 	{
 		initNode = (Plan *) lfirst(l);
-		bitmapplanstates[i] = ExecInitNode(initNode, estate);
+		bitmapplanstates[i] = ExecInitNode(initNode, estate, eflags);
 		i++;
 	}
 
diff --git a/src/backend/executor/nodeFunctionscan.c b/src/backend/executor/nodeFunctionscan.c
index a0178e8fa17f59acd8b21b18449df30b37fc2714..547e5ba80107dbfad9acb96c92c6ab5bcb1ede7d 100644
--- a/src/backend/executor/nodeFunctionscan.c
+++ b/src/backend/executor/nodeFunctionscan.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.35 2005/10/15 02:49:17 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.36 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -120,7 +120,7 @@ ExecFunctionScan(FunctionScanState *node)
  * ----------------------------------------------------------------
  */
 FunctionScanState *
-ExecInitFunctionScan(FunctionScan *node, EState *estate)
+ExecInitFunctionScan(FunctionScan *node, EState *estate, int eflags)
 {
 	FunctionScanState *scanstate;
 	RangeTblEntry *rte;
diff --git a/src/backend/executor/nodeGroup.c b/src/backend/executor/nodeGroup.c
index 91a08add4d9653c10f9b289f963be2b83b233718..3bc394831553f0067fde727ac514f2202f61f900 100644
--- a/src/backend/executor/nodeGroup.c
+++ b/src/backend/executor/nodeGroup.c
@@ -15,7 +15,7 @@
  *	  locate group boundaries.
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeGroup.c,v 1.62 2005/10/15 02:49:17 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeGroup.c,v 1.63 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -154,10 +154,13 @@ ExecGroup(GroupState *node)
  * -----------------
  */
 GroupState *
-ExecInitGroup(Group *node, EState *estate)
+ExecInitGroup(Group *node, EState *estate, int eflags)
 {
 	GroupState *grpstate;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
+
 	/*
 	 * create state structure
 	 */
@@ -192,7 +195,7 @@ ExecInitGroup(Group *node, EState *estate)
 	/*
 	 * initialize child nodes
 	 */
-	outerPlanState(grpstate) = ExecInitNode(outerPlan(node), estate);
+	outerPlanState(grpstate) = ExecInitNode(outerPlan(node), estate, eflags);
 
 	/*
 	 * initialize tuple type.
diff --git a/src/backend/executor/nodeHash.c b/src/backend/executor/nodeHash.c
index 82f05855e668d9f8cf93116d891be96d67f0ec33..a4dc6026c197818d712cc0fb36ceb47abd150367 100644
--- a/src/backend/executor/nodeHash.c
+++ b/src/backend/executor/nodeHash.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeHash.c,v 1.99 2005/11/23 20:27:57 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeHash.c,v 1.100 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -116,10 +116,13 @@ MultiExecHash(HashState *node)
  * ----------------------------------------------------------------
  */
 HashState *
-ExecInitHash(Hash *node, EState *estate)
+ExecInitHash(Hash *node, EState *estate, int eflags)
 {
 	HashState  *hashstate;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
+
 	SO_printf("ExecInitHash: initializing hash node\n");
 
 	/*
@@ -158,7 +161,7 @@ ExecInitHash(Hash *node, EState *estate)
 	/*
 	 * initialize child nodes
 	 */
-	outerPlanState(hashstate) = ExecInitNode(outerPlan(node), estate);
+	outerPlanState(hashstate) = ExecInitNode(outerPlan(node), estate, eflags);
 
 	/*
 	 * initialize tuple type. no need to initialize projection info because
diff --git a/src/backend/executor/nodeHashjoin.c b/src/backend/executor/nodeHashjoin.c
index 7363ab2a2cdd3df8f9cf994128f4e61601999d4d..a21184a3a80fbd2568520dcd2ec8322cbb2888b6 100644
--- a/src/backend/executor/nodeHashjoin.c
+++ b/src/backend/executor/nodeHashjoin.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeHashjoin.c,v 1.79 2005/11/28 23:46:03 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeHashjoin.c,v 1.80 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -335,7 +335,7 @@ ExecHashJoin(HashJoinState *node)
  * ----------------------------------------------------------------
  */
 HashJoinState *
-ExecInitHashJoin(HashJoin *node, EState *estate)
+ExecInitHashJoin(HashJoin *node, EState *estate, int eflags)
 {
 	HashJoinState *hjstate;
 	Plan	   *outerNode;
@@ -345,6 +345,9 @@ ExecInitHashJoin(HashJoin *node, EState *estate)
 	List	   *hoperators;
 	ListCell   *l;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
+
 	/*
 	 * create state structure
 	 */
@@ -378,12 +381,16 @@ ExecInitHashJoin(HashJoin *node, EState *estate)
 
 	/*
 	 * initialize child nodes
+	 *
+	 * Note: we could suppress the REWIND flag for the inner input, which
+	 * would amount to betting that the hash will be a single batch.  Not
+	 * clear if this would be a win or not.
 	 */
 	outerNode = outerPlan(node);
 	hashNode = (Hash *) innerPlan(node);
 
-	outerPlanState(hjstate) = ExecInitNode(outerNode, estate);
-	innerPlanState(hjstate) = ExecInitNode((Plan *) hashNode, estate);
+	outerPlanState(hjstate) = ExecInitNode(outerNode, estate, eflags);
+	innerPlanState(hjstate) = ExecInitNode((Plan *) hashNode, estate, eflags);
 
 #define HASHJOIN_NSLOTS 3
 
diff --git a/src/backend/executor/nodeIndexscan.c b/src/backend/executor/nodeIndexscan.c
index 16406c784f45aca7485ac8ca5c224311811537f5..b5f3d1121438f0f75fa6108b61d2fee9f4f92dde 100644
--- a/src/backend/executor/nodeIndexscan.c
+++ b/src/backend/executor/nodeIndexscan.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.110 2006/01/25 20:29:23 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.111 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -458,7 +458,7 @@ ExecIndexRestrPos(IndexScanState *node)
  * ----------------------------------------------------------------
  */
 IndexScanState *
-ExecInitIndexScan(IndexScan *node, EState *estate)
+ExecInitIndexScan(IndexScan *node, EState *estate, int eflags)
 {
 	IndexScanState *indexstate;
 	Relation	currentRelation;
diff --git a/src/backend/executor/nodeLimit.c b/src/backend/executor/nodeLimit.c
index f9397dc475c0239737db3ea29d65e5c5511f1771..237dcc565ceba9532426ec41864fa9a8de30f7c1 100644
--- a/src/backend/executor/nodeLimit.c
+++ b/src/backend/executor/nodeLimit.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeLimit.c,v 1.23 2005/11/23 20:27:57 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeLimit.c,v 1.24 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -280,11 +280,14 @@ recompute_limits(LimitState *node)
  * ----------------------------------------------------------------
  */
 LimitState *
-ExecInitLimit(Limit *node, EState *estate)
+ExecInitLimit(Limit *node, EState *estate, int eflags)
 {
 	LimitState *limitstate;
 	Plan	   *outerPlan;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & EXEC_FLAG_MARK));
+
 	/*
 	 * create state structure
 	 */
@@ -321,7 +324,7 @@ ExecInitLimit(Limit *node, EState *estate)
 	 * then initialize outer plan
 	 */
 	outerPlan = outerPlan(node);
-	outerPlanState(limitstate) = ExecInitNode(outerPlan, estate);
+	outerPlanState(limitstate) = ExecInitNode(outerPlan, estate, eflags);
 
 	/*
 	 * limit nodes do no projections, so initialize projection info for this
diff --git a/src/backend/executor/nodeMaterial.c b/src/backend/executor/nodeMaterial.c
index 558797c380dc779fc327a660a6f483c8817191a7..641fe3afc2d264ab8d3e47322cacd5b3d0588a93 100644
--- a/src/backend/executor/nodeMaterial.c
+++ b/src/backend/executor/nodeMaterial.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeMaterial.c,v 1.51 2005/11/23 20:27:57 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeMaterial.c,v 1.52 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -153,7 +153,7 @@ ExecMaterial(MaterialState *node)
  * ----------------------------------------------------------------
  */
 MaterialState *
-ExecInitMaterial(Material *node, EState *estate)
+ExecInitMaterial(Material *node, EState *estate, int eflags)
 {
 	MaterialState *matstate;
 	Plan	   *outerPlan;
@@ -186,10 +186,15 @@ ExecInitMaterial(Material *node, EState *estate)
 	ExecInitScanTupleSlot(estate, &matstate->ss);
 
 	/*
-	 * initializes child nodes
+	 * initialize child nodes
+	 *
+	 * We shield the child node from the need to support REWIND, BACKWARD,
+	 * or MARK/RESTORE.
 	 */
+	eflags &= ~(EXEC_FLAG_REWIND | EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK);
+
 	outerPlan = outerPlan(node);
-	outerPlanState(matstate) = ExecInitNode(outerPlan, estate);
+	outerPlanState(matstate) = ExecInitNode(outerPlan, estate, eflags);
 
 	/*
 	 * initialize tuple type.  no need to initialize projection info because
diff --git a/src/backend/executor/nodeMergejoin.c b/src/backend/executor/nodeMergejoin.c
index 43a464f1bfcc5a84035c80fa50f732630a67cb79..6aeab2122a49865d6b955d8ac0b6d9eef2064a9a 100644
--- a/src/backend/executor/nodeMergejoin.c
+++ b/src/backend/executor/nodeMergejoin.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeMergejoin.c,v 1.76 2005/11/22 18:17:10 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeMergejoin.c,v 1.77 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1466,10 +1466,13 @@ ExecMergeJoin(MergeJoinState *node)
  * ----------------------------------------------------------------
  */
 MergeJoinState *
-ExecInitMergeJoin(MergeJoin *node, EState *estate)
+ExecInitMergeJoin(MergeJoin *node, EState *estate, int eflags)
 {
 	MergeJoinState *mergestate;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
+
 	MJ1_printf("ExecInitMergeJoin: %s\n",
 			   "initializing node");
 
@@ -1512,9 +1515,12 @@ ExecInitMergeJoin(MergeJoin *node, EState *estate)
 
 	/*
 	 * initialize child nodes
+	 *
+	 * inner child must support MARK/RESTORE.
 	 */
-	outerPlanState(mergestate) = ExecInitNode(outerPlan(node), estate);
-	innerPlanState(mergestate) = ExecInitNode(innerPlan(node), estate);
+	outerPlanState(mergestate) = ExecInitNode(outerPlan(node), estate, eflags);
+	innerPlanState(mergestate) = ExecInitNode(innerPlan(node), estate,
+											  eflags | EXEC_FLAG_MARK);
 
 #define MERGEJOIN_NSLOTS 4
 
diff --git a/src/backend/executor/nodeNestloop.c b/src/backend/executor/nodeNestloop.c
index e205b218bdc6f4aa9f2848fdb9f35551043280eb..4611a809af552720c28054af8e89eb9c048f75da 100644
--- a/src/backend/executor/nodeNestloop.c
+++ b/src/backend/executor/nodeNestloop.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeNestloop.c,v 1.40 2005/11/22 18:17:10 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeNestloop.c,v 1.41 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -272,10 +272,13 @@ ExecNestLoop(NestLoopState *node)
  * ----------------------------------------------------------------
  */
 NestLoopState *
-ExecInitNestLoop(NestLoop *node, EState *estate)
+ExecInitNestLoop(NestLoop *node, EState *estate, int eflags)
 {
 	NestLoopState *nlstate;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
+
 	NL1_printf("ExecInitNestLoop: %s\n",
 			   "initializing node");
 
@@ -309,9 +312,16 @@ ExecInitNestLoop(NestLoop *node, EState *estate)
 
 	/*
 	 * initialize child nodes
+	 *
+	 * Tell the inner child that cheap rescans would be good.  (This is
+	 * unnecessary if we are doing nestloop with inner indexscan, because
+	 * the rescan will always be with a fresh parameter --- but since
+	 * nodeIndexscan doesn't actually care about REWIND, there's no point
+	 * in dealing with that refinement.)
 	 */
-	outerPlanState(nlstate) = ExecInitNode(outerPlan(node), estate);
-	innerPlanState(nlstate) = ExecInitNode(innerPlan(node), estate);
+	outerPlanState(nlstate) = ExecInitNode(outerPlan(node), estate, eflags);
+	innerPlanState(nlstate) = ExecInitNode(innerPlan(node), estate,
+										   eflags | EXEC_FLAG_REWIND);
 
 #define NESTLOOP_NSLOTS 2
 
diff --git a/src/backend/executor/nodeResult.c b/src/backend/executor/nodeResult.c
index 013c4e99794a48b341c8c28aaa1218cfe16690f0..e821b63a10799da927b03b708caf189cdd891686 100644
--- a/src/backend/executor/nodeResult.c
+++ b/src/backend/executor/nodeResult.c
@@ -38,7 +38,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeResult.c,v 1.32 2005/10/15 02:49:17 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeResult.c,v 1.33 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -170,15 +170,19 @@ ExecResult(ResultState *node)
  *		ExecInitResult
  *
  *		Creates the run-time state information for the result node
- *		produced by the planner and initailizes outer relations
+ *		produced by the planner and initializes outer relations
  *		(child nodes).
  * ----------------------------------------------------------------
  */
 ResultState *
-ExecInitResult(Result *node, EState *estate)
+ExecInitResult(Result *node, EState *estate, int eflags)
 {
 	ResultState *resstate;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & EXEC_FLAG_MARK));
+	Assert(!(eflags & EXEC_FLAG_BACKWARD) || outerPlan(node) != NULL);
+
 	/*
 	 * create state structure
 	 */
@@ -218,7 +222,7 @@ ExecInitResult(Result *node, EState *estate)
 	/*
 	 * initialize child nodes
 	 */
-	outerPlanState(resstate) = ExecInitNode(outerPlan(node), estate);
+	outerPlanState(resstate) = ExecInitNode(outerPlan(node), estate, eflags);
 
 	/*
 	 * we don't use inner plan
diff --git a/src/backend/executor/nodeSeqscan.c b/src/backend/executor/nodeSeqscan.c
index 5e8ba95ee2dc3b52c2f85215a9a92f73e9ce1cdd..6fbf9c7ad216b98645dbfac9f4053e151e0a0b36 100644
--- a/src/backend/executor/nodeSeqscan.c
+++ b/src/backend/executor/nodeSeqscan.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeSeqscan.c,v 1.56 2005/12/02 20:03:40 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeSeqscan.c,v 1.57 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -168,7 +168,7 @@ InitScanRelation(SeqScanState *node, EState *estate)
  * ----------------------------------------------------------------
  */
 SeqScanState *
-ExecInitSeqScan(SeqScan *node, EState *estate)
+ExecInitSeqScan(SeqScan *node, EState *estate, int eflags)
 {
 	SeqScanState *scanstate;
 
diff --git a/src/backend/executor/nodeSetOp.c b/src/backend/executor/nodeSetOp.c
index 2a7d254287058fcb5b73ac96f7575b1fb61ec984..105b615bcfee03a8401959b5123fb706d1a6bb11 100644
--- a/src/backend/executor/nodeSetOp.c
+++ b/src/backend/executor/nodeSetOp.c
@@ -21,7 +21,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeSetOp.c,v 1.19 2005/11/23 20:27:57 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeSetOp.c,v 1.20 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -213,10 +213,13 @@ ExecSetOp(SetOpState *node)
  * ----------------------------------------------------------------
  */
 SetOpState *
-ExecInitSetOp(SetOp *node, EState *estate)
+ExecInitSetOp(SetOp *node, EState *estate, int eflags)
 {
 	SetOpState *setopstate;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
+
 	/*
 	 * create state structure
 	 */
@@ -252,7 +255,7 @@ ExecInitSetOp(SetOp *node, EState *estate)
 	/*
 	 * then initialize outer plan
 	 */
-	outerPlanState(setopstate) = ExecInitNode(outerPlan(node), estate);
+	outerPlanState(setopstate) = ExecInitNode(outerPlan(node), estate, eflags);
 
 	/*
 	 * setop nodes do no projections, so initialize projection info for this
diff --git a/src/backend/executor/nodeSort.c b/src/backend/executor/nodeSort.c
index 255ffcff25ed1c01c0192d2976aa6ccbf06d0fa7..367adbfbe20c2d073f5d8b066b01456a69c0d000 100644
--- a/src/backend/executor/nodeSort.c
+++ b/src/backend/executor/nodeSort.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeSort.c,v 1.53 2006/02/26 22:58:12 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeSort.c,v 1.54 2006/02/28 04:10:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -146,11 +146,11 @@ ExecSort(SortState *node)
  *		ExecInitSort
  *
  *		Creates the run-time state information for the sort node
- *		produced by the planner and initailizes its outer subtree.
+ *		produced by the planner and initializes its outer subtree.
  * ----------------------------------------------------------------
  */
 SortState *
-ExecInitSort(Sort *node, EState *estate)
+ExecInitSort(Sort *node, EState *estate, int eflags)
 {
 	SortState  *sortstate;
 
@@ -185,9 +185,14 @@ ExecInitSort(Sort *node, EState *estate)
 	ExecInitScanTupleSlot(estate, &sortstate->ss);
 
 	/*
-	 * initializes child nodes
+	 * initialize child nodes
+	 *
+	 * We shield the child node from the need to support REWIND, BACKWARD,
+	 * or MARK/RESTORE.
 	 */
-	outerPlanState(sortstate) = ExecInitNode(outerPlan(node), estate);
+	eflags &= ~(EXEC_FLAG_REWIND | EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK);
+
+	outerPlanState(sortstate) = ExecInitNode(outerPlan(node), estate, eflags);
 
 	/*
 	 * initialize tuple type.  no need to initialize projection info because
diff --git a/src/backend/executor/nodeSubplan.c b/src/backend/executor/nodeSubplan.c
index 80679d9f63fc9c6c01edc32b2ef44ebfd3f26573..fd74cdc618bdd8f94343642a04420f3df3a4f928 100644
--- a/src/backend/executor/nodeSubplan.c
+++ b/src/backend/executor/nodeSubplan.c
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeSubplan.c,v 1.72 2005/12/28 01:29:59 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeSubplan.c,v 1.73 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -625,10 +625,14 @@ slotNoNulls(TupleTableSlot *slot)
 
 /* ----------------------------------------------------------------
  *		ExecInitSubPlan
+ *
+ * Note: the eflags are those passed to the parent plan node of this
+ * subplan; they don't directly describe the execution conditions the
+ * subplan will face.
  * ----------------------------------------------------------------
  */
 void
-ExecInitSubPlan(SubPlanState *node, EState *estate)
+ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags)
 {
 	SubPlan    *subplan = (SubPlan *) node->xprstate.expr;
 	EState	   *sp_estate;
@@ -678,8 +682,16 @@ ExecInitSubPlan(SubPlanState *node, EState *estate)
 
 	/*
 	 * Start up the subplan (this is a very cut-down form of InitPlan())
+	 *
+	 * The subplan will never need to do BACKWARD scan or MARK/RESTORE.
+	 * If it is a parameterless subplan (not initplan), we suggest that it
+	 * be prepared to handle REWIND efficiently; otherwise there is no need.
 	 */
-	node->planstate = ExecInitNode(subplan->plan, sp_estate);
+	eflags &= EXEC_FLAG_EXPLAIN_ONLY;
+	if (subplan->parParam == NIL && subplan->setParam == NIL)
+		eflags |= EXEC_FLAG_REWIND;
+
+	node->planstate = ExecInitNode(subplan->plan, sp_estate, eflags);
 
 	node->needShutdown = true;	/* now we need to shutdown the subplan */
 
diff --git a/src/backend/executor/nodeSubqueryscan.c b/src/backend/executor/nodeSubqueryscan.c
index 9b1bd25143505c5114f56ed7b9fd625c46b2f16e..b9b93ec1477591c8746b499f96dd75d78168fede 100644
--- a/src/backend/executor/nodeSubqueryscan.c
+++ b/src/backend/executor/nodeSubqueryscan.c
@@ -12,7 +12,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.27 2005/10/15 02:49:17 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.28 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -111,13 +111,16 @@ ExecSubqueryScan(SubqueryScanState *node)
  * ----------------------------------------------------------------
  */
 SubqueryScanState *
-ExecInitSubqueryScan(SubqueryScan *node, EState *estate)
+ExecInitSubqueryScan(SubqueryScan *node, EState *estate, int eflags)
 {
 	SubqueryScanState *subquerystate;
 	RangeTblEntry *rte;
 	EState	   *sp_estate;
 	MemoryContext oldcontext;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & EXEC_FLAG_MARK));
+
 	/*
 	 * SubqueryScan should not have any "normal" children.
 	 */
@@ -192,7 +195,7 @@ ExecInitSubqueryScan(SubqueryScan *node, EState *estate)
 	/*
 	 * Start up the subplan (this is a very cut-down form of InitPlan())
 	 */
-	subquerystate->subplan = ExecInitNode(node->subplan, sp_estate);
+	subquerystate->subplan = ExecInitNode(node->subplan, sp_estate, eflags);
 
 	MemoryContextSwitchTo(oldcontext);
 
diff --git a/src/backend/executor/nodeTidscan.c b/src/backend/executor/nodeTidscan.c
index e6d61c78a6c9d7437540d269e08c3bd9dfef1218..193cebbc846cd2759ab2d27db5e35333d81ca8b4 100644
--- a/src/backend/executor/nodeTidscan.c
+++ b/src/backend/executor/nodeTidscan.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.46 2005/12/02 20:03:41 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.47 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -465,7 +465,7 @@ ExecTidRestrPos(TidScanState *node)
  * ----------------------------------------------------------------
  */
 TidScanState *
-ExecInitTidScan(TidScan *node, EState *estate)
+ExecInitTidScan(TidScan *node, EState *estate, int eflags)
 {
 	TidScanState *tidstate;
 	Relation	currentRelation;
diff --git a/src/backend/executor/nodeUnique.c b/src/backend/executor/nodeUnique.c
index 0c033502c39365420d4543cc09b5c512b54bd617..0881a9159edd21a9d63100d50c389014c879d50a 100644
--- a/src/backend/executor/nodeUnique.c
+++ b/src/backend/executor/nodeUnique.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeUnique.c,v 1.50 2005/11/23 20:27:57 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeUnique.c,v 1.51 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -109,10 +109,13 @@ ExecUnique(UniqueState *node)
  * ----------------------------------------------------------------
  */
 UniqueState *
-ExecInitUnique(Unique *node, EState *estate)
+ExecInitUnique(Unique *node, EState *estate, int eflags)
 {
 	UniqueState *uniquestate;
 
+	/* check for unsupported flags */
+	Assert(!(eflags & EXEC_FLAG_MARK));
+
 	/*
 	 * create state structure
 	 */
@@ -144,7 +147,7 @@ ExecInitUnique(Unique *node, EState *estate)
 	/*
 	 * then initialize outer plan
 	 */
-	outerPlanState(uniquestate) = ExecInitNode(outerPlan(node), estate);
+	outerPlanState(uniquestate) = ExecInitNode(outerPlan(node), estate, eflags);
 
 	/*
 	 * unique nodes do no projections, so initialize projection info for this
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 278860600b46e08ae8a6436965bba26de298c534..e4a2c952d1d02e0363986afc24ef9ca2cb9acbe4 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.146 2006/01/18 06:49:27 neilc Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.147 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1553,7 +1553,7 @@ _SPI_pquery(QueryDesc *queryDesc, long tcount)
 
 	AfterTriggerBeginQuery();
 
-	ExecutorStart(queryDesc, false);
+	ExecutorStart(queryDesc, 0);
 
 	ExecutorRun(queryDesc, ForwardScanDirection, tcount);
 
diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c
index 001be06521ba763449b3c28410f261d868fa458c..37ee0d4f2037a9f8870c6a06b82c666538113309 100644
--- a/src/backend/tcop/pquery.c
+++ b/src/backend/tcop/pquery.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.99 2006/02/21 23:01:54 neilc Exp $
+ *	  $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.100 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -164,9 +164,9 @@ ProcessQuery(Query *parsetree,
 	AfterTriggerBeginQuery();
 
 	/*
-	 * Call ExecStart to prepare the plan for execution
+	 * Call ExecutorStart to prepare the plan for execution
 	 */
-	ExecutorStart(queryDesc, false);
+	ExecutorStart(queryDesc, 0);
 
 	/*
 	 * Run the plan to completion.
@@ -329,6 +329,7 @@ PortalStart(Portal portal, ParamListInfo params, Snapshot snapshot)
 	MemoryContext savePortalContext;
 	MemoryContext oldContext;
 	QueryDesc  *queryDesc;
+	int			eflags;
 
 	AssertArg(PortalIsValid(portal));
 	AssertState(portal->queryContext != NULL);	/* query defined? */
@@ -394,9 +395,18 @@ PortalStart(Portal portal, ParamListInfo params, Snapshot snapshot)
 				 */
 
 				/*
-				 * Call ExecStart to prepare the plan for execution
+				 * If it's a scrollable cursor, executor needs to support
+				 * REWIND and backwards scan.
 				 */
-				ExecutorStart(queryDesc, false);
+				if (portal->cursorOptions & CURSOR_OPT_SCROLL)
+					eflags = EXEC_FLAG_REWIND | EXEC_FLAG_BACKWARD;
+				else
+					eflags = 0;		/* default run-to-completion flags */
+
+				/*
+				 * Call ExecutorStart to prepare the plan for execution
+				 */
+				ExecutorStart(queryDesc, eflags);
 
 				/*
 				 * This tells PortalCleanup to shut down the executor
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
index e320a8bf92641cfe74e101793f2bd5d8b8508188..725eed3a8cb16cf616eac57ed7da495337ca760c 100644
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.124 2006/01/12 21:48:53 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.125 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,6 +17,39 @@
 #include "executor/execdesc.h"
 
 
+/*
+ * The "eflags" argument to ExecutorStart and the various ExecInitNode
+ * routines is a bitwise OR of the following flag bits, which tell the
+ * called plan node what to expect.  Note that the flags will get modified
+ * as they are passed down the plan tree, since an upper node may require
+ * functionality in its subnode not demanded of the plan as a whole
+ * (example: MergeJoin requires mark/restore capability in its inner input),
+ * or an upper node may shield its input from some functionality requirement
+ * (example: Materialize shields its input from needing to do backward scan).
+ *
+ * EXPLAIN_ONLY indicates that the plan tree is being initialized just so
+ * EXPLAIN can print it out; it will not be run.  Hence, no side-effects
+ * of startup should occur (such as creating a SELECT INTO target table).
+ * However, error checks (such as permission checks) should be performed.
+ *
+ * REWIND indicates that the plan node should try to efficiently support
+ * rescans without parameter changes.  (Nodes must support ExecReScan calls
+ * in any case, but if this flag was not given, they are at liberty to do it
+ * through complete recalculation.  Note that a parameter change forces a
+ * full recalculation in any case.)
+ *
+ * BACKWARD indicates that the plan node must respect the es_direction flag.
+ * When this is not passed, the plan node will only be run forwards.
+ *
+ * MARK indicates that the plan node must support Mark/Restore calls.
+ * When this is not passed, no Mark/Restore will occur.
+ */
+#define EXEC_FLAG_EXPLAIN_ONLY	0x0001		/* EXPLAIN, no ANALYZE */
+#define EXEC_FLAG_REWIND		0x0002		/* need efficient rescan */
+#define EXEC_FLAG_BACKWARD		0x0004		/* need backward scan */
+#define EXEC_FLAG_MARK			0x0008		/* need mark/restore */
+
+
 /*
  * ExecEvalExpr was formerly a function containing a switch statement;
  * now it's just a macro invoking the function pointed to by an ExprState
@@ -87,7 +120,7 @@ extern HeapTuple ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot);
 /*
  * prototypes from functions in execMain.c
  */
-extern void ExecutorStart(QueryDesc *queryDesc, bool explainOnly);
+extern void ExecutorStart(QueryDesc *queryDesc, int eflags);
 extern TupleTableSlot *ExecutorRun(QueryDesc *queryDesc,
 			ScanDirection direction, long count);
 extern void ExecutorEnd(QueryDesc *queryDesc);
@@ -103,7 +136,7 @@ extern TupleTableSlot *EvalPlanQual(EState *estate, Index rti,
 /*
  * prototypes from functions in execProcnode.c
  */
-extern PlanState *ExecInitNode(Plan *node, EState *estate);
+extern PlanState *ExecInitNode(Plan *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecProcNode(PlanState *node);
 extern Node *MultiExecProcNode(PlanState *node);
 extern int	ExecCountSlotsNode(Plan *node);
diff --git a/src/include/executor/nodeAgg.h b/src/include/executor/nodeAgg.h
index 41dd57a8acb8efd55398c57a43f482fb060ad6bc..4899f7d53e9d97b484bed19b1e889d84c81e200e 100644
--- a/src/include/executor/nodeAgg.h
+++ b/src/include/executor/nodeAgg.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeAgg.h,v 1.24 2005/01/28 19:34:18 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeAgg.h,v 1.25 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -18,7 +18,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsAgg(Agg *node);
-extern AggState *ExecInitAgg(Agg *node, EState *estate);
+extern AggState *ExecInitAgg(Agg *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecAgg(AggState *node);
 extern void ExecEndAgg(AggState *node);
 extern void ExecReScanAgg(AggState *node, ExprContext *exprCtxt);
diff --git a/src/include/executor/nodeAppend.h b/src/include/executor/nodeAppend.h
index ce42e5b072bda90942eeaae7a1c28668005eebd3..6b2cbf3671da291e24fc2edec7229b034c8911cd 100644
--- a/src/include/executor/nodeAppend.h
+++ b/src/include/executor/nodeAppend.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeAppend.h,v 1.23 2004/12/31 22:03:29 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeAppend.h,v 1.24 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsAppend(Append *node);
-extern AppendState *ExecInitAppend(Append *node, EState *estate);
+extern AppendState *ExecInitAppend(Append *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecAppend(AppendState *node);
 extern void ExecEndAppend(AppendState *node);
 extern void ExecReScanAppend(AppendState *node, ExprContext *exprCtxt);
diff --git a/src/include/executor/nodeBitmapAnd.h b/src/include/executor/nodeBitmapAnd.h
index 320fc71ab7c811e762ce87aae95c2f0e3fb2a8e4..b13ca7e6fa530af8592b7522fec6719cc4a27e17 100644
--- a/src/include/executor/nodeBitmapAnd.h
+++ b/src/include/executor/nodeBitmapAnd.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeBitmapAnd.h,v 1.1 2005/04/19 22:35:17 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeBitmapAnd.h,v 1.2 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsBitmapAnd(BitmapAnd *node);
-extern BitmapAndState *ExecInitBitmapAnd(BitmapAnd *node, EState *estate);
+extern BitmapAndState *ExecInitBitmapAnd(BitmapAnd *node, EState *estate, int eflags);
 extern Node *MultiExecBitmapAnd(BitmapAndState *node);
 extern void ExecEndBitmapAnd(BitmapAndState *node);
 extern void ExecReScanBitmapAnd(BitmapAndState *node, ExprContext *exprCtxt);
diff --git a/src/include/executor/nodeBitmapHeapscan.h b/src/include/executor/nodeBitmapHeapscan.h
index 48c4b6ad79af7c1e1d81fd8c9302649d9d2ef727..f61fd8946dbf0d4aa42bb8487332ac33acecda51 100644
--- a/src/include/executor/nodeBitmapHeapscan.h
+++ b/src/include/executor/nodeBitmapHeapscan.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeBitmapHeapscan.h,v 1.1 2005/04/19 22:35:17 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeBitmapHeapscan.h,v 1.2 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsBitmapHeapScan(BitmapHeapScan *node);
-extern BitmapHeapScanState *ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate);
+extern BitmapHeapScanState *ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecBitmapHeapScan(BitmapHeapScanState *node);
 extern void ExecEndBitmapHeapScan(BitmapHeapScanState *node);
 extern void ExecBitmapHeapReScan(BitmapHeapScanState *node, ExprContext *exprCtxt);
diff --git a/src/include/executor/nodeBitmapIndexscan.h b/src/include/executor/nodeBitmapIndexscan.h
index 7ca5553abbd2151a57c92ab7fcf43b55fb2fc78c..0dedb96804fedae090f8903dfcdd98077ac9cf00 100644
--- a/src/include/executor/nodeBitmapIndexscan.h
+++ b/src/include/executor/nodeBitmapIndexscan.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeBitmapIndexscan.h,v 1.1 2005/04/19 22:35:17 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeBitmapIndexscan.h,v 1.2 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsBitmapIndexScan(BitmapIndexScan *node);
-extern BitmapIndexScanState *ExecInitBitmapIndexScan(BitmapIndexScan *node, EState *estate);
+extern BitmapIndexScanState *ExecInitBitmapIndexScan(BitmapIndexScan *node, EState *estate, int eflags);
 extern Node *MultiExecBitmapIndexScan(BitmapIndexScanState *node);
 extern void ExecEndBitmapIndexScan(BitmapIndexScanState *node);
 extern void ExecBitmapIndexReScan(BitmapIndexScanState *node, ExprContext *exprCtxt);
diff --git a/src/include/executor/nodeBitmapOr.h b/src/include/executor/nodeBitmapOr.h
index 927231a708a248cf8043e42f3b86ca91cffdf0f1..6e716664485f3c7c8ae01799c545b1572ace021b 100644
--- a/src/include/executor/nodeBitmapOr.h
+++ b/src/include/executor/nodeBitmapOr.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeBitmapOr.h,v 1.1 2005/04/19 22:35:17 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeBitmapOr.h,v 1.2 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsBitmapOr(BitmapOr *node);
-extern BitmapOrState *ExecInitBitmapOr(BitmapOr *node, EState *estate);
+extern BitmapOrState *ExecInitBitmapOr(BitmapOr *node, EState *estate, int eflags);
 extern Node *MultiExecBitmapOr(BitmapOrState *node);
 extern void ExecEndBitmapOr(BitmapOrState *node);
 extern void ExecReScanBitmapOr(BitmapOrState *node, ExprContext *exprCtxt);
diff --git a/src/include/executor/nodeFunctionscan.h b/src/include/executor/nodeFunctionscan.h
index e4bb8eb57c47605e18771d58919141758c3bfda6..7d8abfa837cb07d80e8a4a9ff04af97b6d3a1a66 100644
--- a/src/include/executor/nodeFunctionscan.h
+++ b/src/include/executor/nodeFunctionscan.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeFunctionscan.h,v 1.7 2004/12/31 22:03:29 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeFunctionscan.h,v 1.8 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsFunctionScan(FunctionScan *node);
-extern FunctionScanState *ExecInitFunctionScan(FunctionScan *node, EState *estate);
+extern FunctionScanState *ExecInitFunctionScan(FunctionScan *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecFunctionScan(FunctionScanState *node);
 extern void ExecEndFunctionScan(FunctionScanState *node);
 extern void ExecFunctionMarkPos(FunctionScanState *node);
diff --git a/src/include/executor/nodeGroup.h b/src/include/executor/nodeGroup.h
index 719e1ff4942f0b9083202b4b54f4f3b1f5926e82..173e85278f6e28ded2cdacd25bf4229d58ed1d1c 100644
--- a/src/include/executor/nodeGroup.h
+++ b/src/include/executor/nodeGroup.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeGroup.h,v 1.28 2004/12/31 22:03:29 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeGroup.h,v 1.29 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsGroup(Group *node);
-extern GroupState *ExecInitGroup(Group *node, EState *estate);
+extern GroupState *ExecInitGroup(Group *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecGroup(GroupState *node);
 extern void ExecEndGroup(GroupState *node);
 extern void ExecReScanGroup(GroupState *node, ExprContext *exprCtxt);
diff --git a/src/include/executor/nodeHash.h b/src/include/executor/nodeHash.h
index 55715c8a60c7b43215f7a5191480eb71c439ca48..61dfafb0244299e0df5ffd9bd79401de0a57c0b3 100644
--- a/src/include/executor/nodeHash.h
+++ b/src/include/executor/nodeHash.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeHash.h,v 1.38 2005/10/15 02:49:44 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeHash.h,v 1.39 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsHash(Hash *node);
-extern HashState *ExecInitHash(Hash *node, EState *estate);
+extern HashState *ExecInitHash(Hash *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecHash(HashState *node);
 extern Node *MultiExecHash(HashState *node);
 extern void ExecEndHash(HashState *node);
diff --git a/src/include/executor/nodeHashjoin.h b/src/include/executor/nodeHashjoin.h
index 8590d6b1898bf65333ac3c56cb535f32e8612880..8cdb3857fca2ea9a378d64783f05d71e461c0400 100644
--- a/src/include/executor/nodeHashjoin.h
+++ b/src/include/executor/nodeHashjoin.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeHashjoin.h,v 1.30 2005/10/15 02:49:44 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeHashjoin.h,v 1.31 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -18,7 +18,7 @@
 #include "storage/buffile.h"
 
 extern int	ExecCountSlotsHashJoin(HashJoin *node);
-extern HashJoinState *ExecInitHashJoin(HashJoin *node, EState *estate);
+extern HashJoinState *ExecInitHashJoin(HashJoin *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecHashJoin(HashJoinState *node);
 extern void ExecEndHashJoin(HashJoinState *node);
 extern void ExecReScanHashJoin(HashJoinState *node, ExprContext *exprCtxt);
diff --git a/src/include/executor/nodeIndexscan.h b/src/include/executor/nodeIndexscan.h
index d36defaa0161c17bee01601dec0c14118bb6566a..52376172463efe3cd11dccc2c466f2d91d85cc5b 100644
--- a/src/include/executor/nodeIndexscan.h
+++ b/src/include/executor/nodeIndexscan.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeIndexscan.h,v 1.26 2006/01/25 20:29:24 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeIndexscan.h,v 1.27 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsIndexScan(IndexScan *node);
-extern IndexScanState *ExecInitIndexScan(IndexScan *node, EState *estate);
+extern IndexScanState *ExecInitIndexScan(IndexScan *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecIndexScan(IndexScanState *node);
 extern void ExecEndIndexScan(IndexScanState *node);
 extern void ExecIndexMarkPos(IndexScanState *node);
diff --git a/src/include/executor/nodeLimit.h b/src/include/executor/nodeLimit.h
index 8722766e596fbd67715202bf23b7367d4b994b34..cecaf663e3ec7493ebcca5b46a6d3251a12aa1a7 100644
--- a/src/include/executor/nodeLimit.h
+++ b/src/include/executor/nodeLimit.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeLimit.h,v 1.11 2004/12/31 22:03:29 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeLimit.h,v 1.12 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsLimit(Limit *node);
-extern LimitState *ExecInitLimit(Limit *node, EState *estate);
+extern LimitState *ExecInitLimit(Limit *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecLimit(LimitState *node);
 extern void ExecEndLimit(LimitState *node);
 extern void ExecReScanLimit(LimitState *node, ExprContext *exprCtxt);
diff --git a/src/include/executor/nodeMaterial.h b/src/include/executor/nodeMaterial.h
index 80eee49dcd4ab8b2189a32b63f4ae276eb9c9df9..f1caf02625cdc3ae6435f661a9e12b2e48ebd318 100644
--- a/src/include/executor/nodeMaterial.h
+++ b/src/include/executor/nodeMaterial.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeMaterial.h,v 1.23 2004/12/31 22:03:29 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeMaterial.h,v 1.24 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsMaterial(Material *node);
-extern MaterialState *ExecInitMaterial(Material *node, EState *estate);
+extern MaterialState *ExecInitMaterial(Material *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecMaterial(MaterialState *node);
 extern void ExecEndMaterial(MaterialState *node);
 extern void ExecMaterialMarkPos(MaterialState *node);
diff --git a/src/include/executor/nodeMergejoin.h b/src/include/executor/nodeMergejoin.h
index 66ef0bbf417a0e3c19d7e02a4b905637b3e1826c..4247af4a7833a7b05a537150e9d2903dcae20c79 100644
--- a/src/include/executor/nodeMergejoin.h
+++ b/src/include/executor/nodeMergejoin.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeMergejoin.h,v 1.22 2004/12/31 22:03:29 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeMergejoin.h,v 1.23 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsMergeJoin(MergeJoin *node);
-extern MergeJoinState *ExecInitMergeJoin(MergeJoin *node, EState *estate);
+extern MergeJoinState *ExecInitMergeJoin(MergeJoin *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecMergeJoin(MergeJoinState *node);
 extern void ExecEndMergeJoin(MergeJoinState *node);
 extern void ExecReScanMergeJoin(MergeJoinState *node, ExprContext *exprCtxt);
diff --git a/src/include/executor/nodeNestloop.h b/src/include/executor/nodeNestloop.h
index 00bbafae00b76d67da0f2f2bdb8b706d5f6093eb..9705585d5e8f2e94abb4c5e195eee398a6a71c7e 100644
--- a/src/include/executor/nodeNestloop.h
+++ b/src/include/executor/nodeNestloop.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeNestloop.h,v 1.23 2004/12/31 22:03:29 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeNestloop.h,v 1.24 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsNestLoop(NestLoop *node);
-extern NestLoopState *ExecInitNestLoop(NestLoop *node, EState *estate);
+extern NestLoopState *ExecInitNestLoop(NestLoop *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecNestLoop(NestLoopState *node);
 extern void ExecEndNestLoop(NestLoopState *node);
 extern void ExecReScanNestLoop(NestLoopState *node, ExprContext *exprCtxt);
diff --git a/src/include/executor/nodeResult.h b/src/include/executor/nodeResult.h
index 87fe93eeb3d2ca5a3f49cbff2ff9c43f23f8aeb3..b32b5299a938d60ce101f3e5a091314646b68f0d 100644
--- a/src/include/executor/nodeResult.h
+++ b/src/include/executor/nodeResult.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeResult.h,v 1.20 2004/12/31 22:03:29 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeResult.h,v 1.21 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsResult(Result *node);
-extern ResultState *ExecInitResult(Result *node, EState *estate);
+extern ResultState *ExecInitResult(Result *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecResult(ResultState *node);
 extern void ExecEndResult(ResultState *node);
 extern void ExecReScanResult(ResultState *node, ExprContext *exprCtxt);
diff --git a/src/include/executor/nodeSeqscan.h b/src/include/executor/nodeSeqscan.h
index c768571dd47420d6da5e29909f224f2a404515c9..a3e78779958e2bd53a52a0dbc28153ee3042784c 100644
--- a/src/include/executor/nodeSeqscan.h
+++ b/src/include/executor/nodeSeqscan.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeSeqscan.h,v 1.22 2004/12/31 22:03:29 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeSeqscan.h,v 1.23 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsSeqScan(SeqScan *node);
-extern SeqScanState *ExecInitSeqScan(SeqScan *node, EState *estate);
+extern SeqScanState *ExecInitSeqScan(SeqScan *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecSeqScan(SeqScanState *node);
 extern void ExecEndSeqScan(SeqScanState *node);
 extern void ExecSeqMarkPos(SeqScanState *node);
diff --git a/src/include/executor/nodeSetOp.h b/src/include/executor/nodeSetOp.h
index a276f016be8a65d144d7f1a85dbf6ff029ecc18e..2c2aaf202af907b4b2ef3503c6d21107ec6327d6 100644
--- a/src/include/executor/nodeSetOp.h
+++ b/src/include/executor/nodeSetOp.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeSetOp.h,v 1.11 2004/12/31 22:03:29 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeSetOp.h,v 1.12 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsSetOp(SetOp *node);
-extern SetOpState *ExecInitSetOp(SetOp *node, EState *estate);
+extern SetOpState *ExecInitSetOp(SetOp *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecSetOp(SetOpState *node);
 extern void ExecEndSetOp(SetOpState *node);
 extern void ExecReScanSetOp(SetOpState *node, ExprContext *exprCtxt);
diff --git a/src/include/executor/nodeSort.h b/src/include/executor/nodeSort.h
index cf50914dce0fb9b6722680811bb4cbeea91241b0..e27ed0f3a2f78dff5d2aed87b9b3a849949cd192 100644
--- a/src/include/executor/nodeSort.h
+++ b/src/include/executor/nodeSort.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeSort.h,v 1.20 2004/12/31 22:03:29 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeSort.h,v 1.21 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsSort(Sort *node);
-extern SortState *ExecInitSort(Sort *node, EState *estate);
+extern SortState *ExecInitSort(Sort *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecSort(SortState *node);
 extern void ExecEndSort(SortState *node);
 extern void ExecSortMarkPos(SortState *node);
diff --git a/src/include/executor/nodeSubplan.h b/src/include/executor/nodeSubplan.h
index 8e6450c43de93c655f850ec9c695288b016b0ad3..a005ac127ceaf7eb7c55621afd52bd5d44314ffc 100644
--- a/src/include/executor/nodeSubplan.h
+++ b/src/include/executor/nodeSubplan.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeSubplan.h,v 1.22 2004/12/31 22:03:29 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeSubplan.h,v 1.23 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -16,7 +16,7 @@
 
 #include "nodes/execnodes.h"
 
-extern void ExecInitSubPlan(SubPlanState *node, EState *estate);
+extern void ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags);
 extern Datum ExecSubPlan(SubPlanState *node,
 			ExprContext *econtext,
 			bool *isNull,
diff --git a/src/include/executor/nodeSubqueryscan.h b/src/include/executor/nodeSubqueryscan.h
index 180a9ab7115b0255a55a1437dc9c524c55e198bc..488dd8b9147ac183c005d7bdac03ef4de8e9c260 100644
--- a/src/include/executor/nodeSubqueryscan.h
+++ b/src/include/executor/nodeSubqueryscan.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeSubqueryscan.h,v 1.11 2004/12/31 22:03:29 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeSubqueryscan.h,v 1.12 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsSubqueryScan(SubqueryScan *node);
-extern SubqueryScanState *ExecInitSubqueryScan(SubqueryScan *node, EState *estate);
+extern SubqueryScanState *ExecInitSubqueryScan(SubqueryScan *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecSubqueryScan(SubqueryScanState *node);
 extern void ExecEndSubqueryScan(SubqueryScanState *node);
 extern void ExecSubqueryReScan(SubqueryScanState *node, ExprContext *exprCtxt);
diff --git a/src/include/executor/nodeTidscan.h b/src/include/executor/nodeTidscan.h
index 49491f74c8b522fe60291b2b62faa970a4d72862..25c1224b7f8d37e5f5e49731398449560f4c2237 100644
--- a/src/include/executor/nodeTidscan.h
+++ b/src/include/executor/nodeTidscan.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeTidscan.h,v 1.15 2004/12/31 22:03:29 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeTidscan.h,v 1.16 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsTidScan(TidScan *node);
-extern TidScanState *ExecInitTidScan(TidScan *node, EState *estate);
+extern TidScanState *ExecInitTidScan(TidScan *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecTidScan(TidScanState *node);
 extern void ExecEndTidScan(TidScanState *node);
 extern void ExecTidMarkPos(TidScanState *node);
diff --git a/src/include/executor/nodeUnique.h b/src/include/executor/nodeUnique.h
index 0142974a419c40cd1e9671865fa5401f20c52c9c..db62436260299a7892affa199e3507ae0b6a2017 100644
--- a/src/include/executor/nodeUnique.h
+++ b/src/include/executor/nodeUnique.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/executor/nodeUnique.h,v 1.20 2004/12/31 22:03:29 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/executor/nodeUnique.h,v 1.21 2006/02/28 04:10:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,7 +17,7 @@
 #include "nodes/execnodes.h"
 
 extern int	ExecCountSlotsUnique(Unique *node);
-extern UniqueState *ExecInitUnique(Unique *node, EState *estate);
+extern UniqueState *ExecInitUnique(Unique *node, EState *estate, int eflags);
 extern TupleTableSlot *ExecUnique(UniqueState *node);
 extern void ExecEndUnique(UniqueState *node);
 extern void ExecReScanUnique(UniqueState *node, ExprContext *exprCtxt);