diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index 7cd00218c0a559a0ed6946fb7688d243b5dcb396..35dec7f1d96d3ec18668d4454d83fc44d28bebc3 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.37 1998/02/10 04:00:44 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.38 1998/02/13 03:27:42 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -79,6 +79,8 @@ listCopy(List *list)
 static void
 CopyPlanFields(Plan *from, Plan *newnode)
 {
+	extern List	   *SS_pull_subplan (void *expr);
+	
 	newnode->cost = from->cost;
 	newnode->plan_size = from->plan_size;
 	newnode->plan_width = from->plan_width;
@@ -88,6 +90,15 @@ CopyPlanFields(Plan *from, Plan *newnode)
 	newnode->qual = copyObject(from->qual);
 	newnode->lefttree = copyObject(from->lefttree);
 	newnode->righttree = copyObject(from->righttree);
+	newnode->extParam = listCopy (from->extParam);
+	newnode->locParam = listCopy (from->locParam);
+	newnode->chgParam = listCopy (from->chgParam);
+	Node_Copy(from, newnode, initPlan);
+	if ( from->subPlan != NULL )
+		newnode->subPlan = SS_pull_subplan (newnode->qual);
+	else
+		newnode->subPlan = NULL;
+	newnode->nParamExec = from->nParamExec;
 }
 
 /* ----------------
@@ -575,6 +586,22 @@ _copyHash(Hash *from)
 	return newnode;
 }
 
+static SubPlan *
+_copySubPlan(SubPlan *from)
+{
+	SubPlan	   *newnode = makeNode(SubPlan);
+	
+	Node_Copy(from, newnode, plan);
+	newnode->plan_id = from->plan_id;
+	Node_Copy(from, newnode, rtable);
+	newnode->setParam = listCopy (from->setParam);
+	newnode->parParam = listCopy (from->parParam);
+	Node_Copy(from, newnode, sublink);
+	newnode->shutdown = from->shutdown;
+
+	return newnode;
+}
+
 /* ****************************************************************
  *					   primnodes.h copy functions
  * ****************************************************************
@@ -1661,6 +1688,9 @@ copyObject(void *from)
 		case T_Hash:
 			retval = _copyHash(from);
 			break;
+		case T_SubPlan:
+			retval = _copySubPlan(from);
+			break;
 
 			/*
 			 * PRIMITIVE NODES
diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c
index 254b62c9fd6d4556c89af8ff33f6a98d86fba7cf..b0eb91c11fccd0862a304b6592365be949fe6749 100644
--- a/src/backend/nodes/equalfuncs.c
+++ b/src/backend/nodes/equalfuncs.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.14 1998/02/10 04:00:47 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.15 1998/02/13 03:27:44 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -236,6 +236,7 @@ _equalParam(Param *a, Param *b)
 				return (false);
 			break;
 		case PARAM_NUM:
+		case PARAM_EXEC:
 			if (a->paramid != b->paramid)
 				return (false);
 			break;
@@ -503,6 +504,18 @@ _equalIndexScan(IndexScan *a, IndexScan *b)
 	return (true);
 }
 
+static bool
+_equalSubPlan(SubPlan *a, SubPlan *b)
+{
+	if (a->plan_id != b->plan_id)
+		return (false);
+
+	if (!equal((a->sublink->oper), (b->sublink->oper)))
+		return (false);
+	
+	return (true);
+}
+
 static bool
 _equalJInfo(JInfo *a, JInfo *b)
 {
@@ -680,6 +693,9 @@ equal(void *a, void *b)
 		case T_IndexScan:
 			retval = _equalIndexScan(a, b);
 			break;
+		case T_SubPlan:
+			retval = _equalSubPlan(a, b);
+			break;
 		case T_JInfo:
 			retval = _equalJInfo(a, b);
 			break;
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index 1bf18ec19186dad2e5be35cd47e383a4f96fcf25..46fd37cd7f342696402abf4d512340e5cd03210a 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.29 1998/02/10 16:03:21 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.30 1998/02/13 03:27:45 vadim Exp $
  *
  * NOTES
  *	  Every (plan) node in POSTGRES has an associated "out" routine which
@@ -288,7 +288,14 @@ _outPlanInfo(StringInfo str, Plan *node)
 	_outNode(str, node->lefttree);
 	appendStringInfo(str, " :righttree ");
 	_outNode(str, node->righttree);
-
+	appendStringInfo(str, " :extprm ");
+	_outIntList(str, node->extParam);
+	appendStringInfo(str, " :locprm ");
+	_outIntList(str, node->locParam);
+	appendStringInfo(str, " :initplan ");
+	_outNode(str, node->initPlan);
+	sprintf(buf, " :nprm %d ", node->nParamExec);
+	appendStringInfo(str, buf);
 }
 
 /*
@@ -408,6 +415,26 @@ _outHashJoin(StringInfo str, HashJoin *node)
 	appendStringInfo(str, buf);
 }
 
+static void
+_outSubPlan(StringInfo str, SubPlan *node)
+{
+	char		buf[500];
+
+	appendStringInfo(str, "SUBPLAN");
+	appendStringInfo(str, " :plan ");
+	_outNode(str, node->plan);
+	sprintf(buf, " :planid %u ", node->plan_id);
+	appendStringInfo(str, buf);
+	appendStringInfo(str, " :rtable ");
+	_outNode(str, node->rtable);
+	appendStringInfo(str, " :setprm ");
+	_outIntList (str, node->setParam);
+	appendStringInfo(str, " :parprm ");
+	_outIntList (str, node->parParam);
+	appendStringInfo(str, " :slink ");
+	_outNode(str, node->sublink);
+}
+
 /*
  *	Scan is a subclass of Node
  */
@@ -674,6 +701,9 @@ _outExpr(StringInfo str, Expr *node)
 		case NOT_EXPR:
 			opstr = "not";
 			break;
+		case SUBPLAN_EXPR:
+			opstr = "subp";
+			break;
 	}
 	appendStringInfo(str, " :opType ");
 	appendStringInfo(str, opstr);
@@ -1654,6 +1684,9 @@ _outNode(StringInfo str, void *obj)
 			case T_Hash:
 				_outHash(str, obj);
 				break;
+			case T_SubPlan:
+				_outSubPlan(str, obj);
+				break;
 			case T_Tee:
 				_outTee(str, obj);
 				break;
diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c
index 8a74e01c0f349173994f70df6d728e7f1df8ab73..279463312e81a3da72c69726a35be0fde1dd012d 100644
--- a/src/backend/nodes/readfuncs.c
+++ b/src/backend/nodes/readfuncs.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.24 1998/02/10 16:03:23 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.25 1998/02/13 03:27:47 vadim Exp $
  *
  * NOTES
  *	  Most of the read functions for plan nodes are tested. (In fact, they
@@ -777,6 +777,10 @@ _readExpr()
 	{
 		local_node->opType = NOT_EXPR;
 	}
+	else if (!strncmp(token, "subp", 4))
+	{
+		local_node->opType = SUBPLAN_EXPR;
+	}
 
 	token = lsptok(NULL, &length);		/* eat :oper */
 	local_node->oper = nodeRead(true);