diff --git a/src/backend/executor/execScan.c b/src/backend/executor/execScan.c
new file mode 100644
index 1bb1094..dcec11e
*** a/src/backend/executor/execScan.c
--- b/src/backend/executor/execScan.c
*************** ExecScan(ScanState *node,
*** 245,253 ****
  void
  ExecAssignScanProjectionInfo(ScanState *node)
  {
! 	Scan	   *scan = (Scan *) node->ps.plan;
  	Index		varno;
  
  	/* Vars in an index-only scan's tlist should be INDEX_VAR */
  	if (IsA(scan, IndexOnlyScan))
  		varno = INDEX_VAR;
--- 245,256 ----
  void
  ExecAssignScanProjectionInfo(ScanState *node)
  {
! 	Scan		*scan;
  	Index		varno;
  
+ 	Assert(node != NULL);
+ 	scan = (Scan *) node->ps.plan;
+ 
  	/* Vars in an index-only scan's tlist should be INDEX_VAR */
  	if (IsA(scan, IndexOnlyScan))
  		varno = INDEX_VAR;
diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c
new file mode 100644
index 6db42e7..f285dc0
*** a/src/backend/executor/execUtils.c
--- b/src/backend/executor/execUtils.c
*************** ExecAssignResultTypeFromTL(PlanState *pl
*** 448,453 ****
--- 448,454 ----
  	bool		hasoid;
  	TupleDesc	tupDesc;
  
+ 	Assert(planstate != NULL);
  	if (ExecContextForcesOids(planstate, &hasoid))
  	{
  		/* context forces OID choice; hasoid is now set correctly */
*************** ExecAssignResultTypeFromTL(PlanState *pl
*** 474,480 ****
  TupleDesc
  ExecGetResultType(PlanState *planstate)
  {
! 	TupleTableSlot *slot = planstate->ps_ResultTupleSlot;
  
  	return slot->tts_tupleDescriptor;
  }
--- 475,484 ----
  TupleDesc
  ExecGetResultType(PlanState *planstate)
  {
! 	TupleTableSlot *slot;
! 
! 	Assert(planstate != NULL);
! 	slot = planstate->ps_ResultTupleSlot;
  
  	return slot->tts_tupleDescriptor;
  }
diff --git a/src/backend/executor/nodeCtescan.c b/src/backend/executor/nodeCtescan.c
new file mode 100644
index 7ab15ac..ab8bfa3
*** a/src/backend/executor/nodeCtescan.c
--- b/src/backend/executor/nodeCtescan.c
*************** ExecInitCteScan(CteScan *node, EState *e
*** 255,271 ****
  	/*
  	 * The scan tuple type (ie, the rowtype we expect to find in the work
  	 * table) is the same as the result rowtype of the CTE query.
  	 */
! 	ExecAssignScanType(&scanstate->ss,
  					   ExecGetResultType(scanstate->cteplanstate));
  
! 	/*
! 	 * Initialize result tuple type and projection info.
! 	 */
! 	ExecAssignResultTypeFromTL(&scanstate->ss.ps);
! 	ExecAssignScanProjectionInfo(&scanstate->ss);
  
! 	scanstate->ss.ps.ps_TupFromTlist = false;
  
  	return scanstate;
  }
--- 255,276 ----
  	/*
  	 * The scan tuple type (ie, the rowtype we expect to find in the work
  	 * table) is the same as the result rowtype of the CTE query.
+ 	 * We must check for NULL because we don't initialize data-modifying
+ 	 * CTE's with a ModifyTable node at the top.
  	 */
! 	if (scanstate->cteplanstate != NULL)
! 	{
! 		ExecAssignScanType(&scanstate->ss,
  					   ExecGetResultType(scanstate->cteplanstate));
  
! 		/*
! 		 * Initialize result tuple type and projection info.
! 		 */
! 		ExecAssignResultTypeFromTL(&scanstate->ss.ps);
! 		ExecAssignScanProjectionInfo(&scanstate->ss);
  
! 		scanstate->ss.ps.ps_TupFromTlist = false;
! 	}
  
  	return scanstate;
  }
