From d5f23af6bfbc454e86dd16e5c7a0bfc0cf6189d0 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Wed, 7 Dec 2011 21:46:56 +0200
Subject: [PATCH] Add const qualifiers to node inspection functions

Thomas Munro
---
 src/backend/nodes/copyfuncs.c        | 518 +++++++++++++--------------
 src/backend/nodes/equalfuncs.c       | 364 +++++++++----------
 src/backend/nodes/list.c             |  74 ++--
 src/backend/nodes/nodeFuncs.c        | 306 ++++++++--------
 src/backend/nodes/outfuncs.c         | 440 +++++++++++------------
 src/backend/nodes/print.c            |  34 +-
 src/backend/optimizer/util/clauses.c |   8 +-
 src/include/nodes/nodeFuncs.h        |  12 +-
 src/include/nodes/nodes.h            |   8 +-
 src/include/nodes/pg_list.h          |  44 +--
 src/include/nodes/print.h            |  14 +-
 src/include/optimizer/clauses.h      |   4 +-
 12 files changed, 913 insertions(+), 913 deletions(-)

diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index c70a5bdf388..7178b529a2e 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -72,7 +72,7 @@
  * _copyPlannedStmt
  */
 static PlannedStmt *
-_copyPlannedStmt(PlannedStmt *from)
+_copyPlannedStmt(const PlannedStmt *from)
 {
 	PlannedStmt *newnode = makeNode(PlannedStmt);
 
@@ -103,7 +103,7 @@ _copyPlannedStmt(PlannedStmt *from)
  *		all the copy functions for classes which inherit from Plan.
  */
 static void
-CopyPlanFields(Plan *from, Plan *newnode)
+CopyPlanFields(const Plan *from, Plan *newnode)
 {
 	COPY_SCALAR_FIELD(startup_cost);
 	COPY_SCALAR_FIELD(total_cost);
@@ -122,7 +122,7 @@ CopyPlanFields(Plan *from, Plan *newnode)
  * _copyPlan
  */
 static Plan *
-_copyPlan(Plan *from)
+_copyPlan(const Plan *from)
 {
 	Plan	   *newnode = makeNode(Plan);
 
@@ -139,14 +139,14 @@ _copyPlan(Plan *from)
  * _copyResult
  */
 static Result *
-_copyResult(Result *from)
+_copyResult(const Result *from)
 {
 	Result	   *newnode = makeNode(Result);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -160,14 +160,14 @@ _copyResult(Result *from)
  * _copyModifyTable
  */
 static ModifyTable *
-_copyModifyTable(ModifyTable *from)
+_copyModifyTable(const ModifyTable *from)
 {
 	ModifyTable *newnode = makeNode(ModifyTable);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -188,14 +188,14 @@ _copyModifyTable(ModifyTable *from)
  * _copyAppend
  */
 static Append *
-_copyAppend(Append *from)
+_copyAppend(const Append *from)
 {
 	Append	   *newnode = makeNode(Append);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -209,14 +209,14 @@ _copyAppend(Append *from)
  * _copyMergeAppend
  */
 static MergeAppend *
-_copyMergeAppend(MergeAppend *from)
+_copyMergeAppend(const MergeAppend *from)
 {
 	MergeAppend *newnode = makeNode(MergeAppend);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -235,14 +235,14 @@ _copyMergeAppend(MergeAppend *from)
  * _copyRecursiveUnion
  */
 static RecursiveUnion *
-_copyRecursiveUnion(RecursiveUnion *from)
+_copyRecursiveUnion(const RecursiveUnion *from)
 {
 	RecursiveUnion *newnode = makeNode(RecursiveUnion);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -263,14 +263,14 @@ _copyRecursiveUnion(RecursiveUnion *from)
  * _copyBitmapAnd
  */
 static BitmapAnd *
-_copyBitmapAnd(BitmapAnd *from)
+_copyBitmapAnd(const BitmapAnd *from)
 {
 	BitmapAnd  *newnode = makeNode(BitmapAnd);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -284,14 +284,14 @@ _copyBitmapAnd(BitmapAnd *from)
  * _copyBitmapOr
  */
 static BitmapOr *
-_copyBitmapOr(BitmapOr *from)
+_copyBitmapOr(const BitmapOr *from)
 {
 	BitmapOr   *newnode = makeNode(BitmapOr);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -309,9 +309,9 @@ _copyBitmapOr(BitmapOr *from)
  *		all the copy functions for classes which inherit from Scan.
  */
 static void
-CopyScanFields(Scan *from, Scan *newnode)
+CopyScanFields(const Scan *from, Scan *newnode)
 {
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	COPY_SCALAR_FIELD(scanrelid);
 }
@@ -320,14 +320,14 @@ CopyScanFields(Scan *from, Scan *newnode)
  * _copyScan
  */
 static Scan *
-_copyScan(Scan *from)
+_copyScan(const Scan *from)
 {
 	Scan	   *newnode = makeNode(Scan);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyScanFields((Scan *) from, (Scan *) newnode);
+	CopyScanFields((const Scan *) from, (Scan *) newnode);
 
 	return newnode;
 }
@@ -336,14 +336,14 @@ _copyScan(Scan *from)
  * _copySeqScan
  */
 static SeqScan *
-_copySeqScan(SeqScan *from)
+_copySeqScan(const SeqScan *from)
 {
 	SeqScan    *newnode = makeNode(SeqScan);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyScanFields((Scan *) from, (Scan *) newnode);
+	CopyScanFields((const Scan *) from, (Scan *) newnode);
 
 	return newnode;
 }
@@ -352,14 +352,14 @@ _copySeqScan(SeqScan *from)
  * _copyIndexScan
  */
 static IndexScan *
-_copyIndexScan(IndexScan *from)
+_copyIndexScan(const IndexScan *from)
 {
 	IndexScan  *newnode = makeNode(IndexScan);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyScanFields((Scan *) from, (Scan *) newnode);
+	CopyScanFields((const Scan *) from, (Scan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -378,14 +378,14 @@ _copyIndexScan(IndexScan *from)
  * _copyIndexOnlyScan
  */
 static IndexOnlyScan *
-_copyIndexOnlyScan(IndexOnlyScan *from)
+_copyIndexOnlyScan(const IndexOnlyScan *from)
 {
 	IndexOnlyScan  *newnode = makeNode(IndexOnlyScan);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyScanFields((Scan *) from, (Scan *) newnode);
+	CopyScanFields((const Scan *) from, (Scan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -403,14 +403,14 @@ _copyIndexOnlyScan(IndexOnlyScan *from)
  * _copyBitmapIndexScan
  */
 static BitmapIndexScan *
-_copyBitmapIndexScan(BitmapIndexScan *from)
+_copyBitmapIndexScan(const BitmapIndexScan *from)
 {
 	BitmapIndexScan *newnode = makeNode(BitmapIndexScan);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyScanFields((Scan *) from, (Scan *) newnode);
+	CopyScanFields((const Scan *) from, (Scan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -426,14 +426,14 @@ _copyBitmapIndexScan(BitmapIndexScan *from)
  * _copyBitmapHeapScan
  */
 static BitmapHeapScan *
-_copyBitmapHeapScan(BitmapHeapScan *from)
+_copyBitmapHeapScan(const BitmapHeapScan *from)
 {
 	BitmapHeapScan *newnode = makeNode(BitmapHeapScan);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyScanFields((Scan *) from, (Scan *) newnode);
+	CopyScanFields((const Scan *) from, (Scan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -447,14 +447,14 @@ _copyBitmapHeapScan(BitmapHeapScan *from)
  * _copyTidScan
  */
 static TidScan *
-_copyTidScan(TidScan *from)
+_copyTidScan(const TidScan *from)
 {
 	TidScan    *newnode = makeNode(TidScan);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyScanFields((Scan *) from, (Scan *) newnode);
+	CopyScanFields((const Scan *) from, (Scan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -468,14 +468,14 @@ _copyTidScan(TidScan *from)
  * _copySubqueryScan
  */
 static SubqueryScan *
-_copySubqueryScan(SubqueryScan *from)
+_copySubqueryScan(const SubqueryScan *from)
 {
 	SubqueryScan *newnode = makeNode(SubqueryScan);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyScanFields((Scan *) from, (Scan *) newnode);
+	CopyScanFields((const Scan *) from, (Scan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -489,14 +489,14 @@ _copySubqueryScan(SubqueryScan *from)
  * _copyFunctionScan
  */
 static FunctionScan *
-_copyFunctionScan(FunctionScan *from)
+_copyFunctionScan(const FunctionScan *from)
 {
 	FunctionScan *newnode = makeNode(FunctionScan);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyScanFields((Scan *) from, (Scan *) newnode);
+	CopyScanFields((const Scan *) from, (Scan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -514,14 +514,14 @@ _copyFunctionScan(FunctionScan *from)
  * _copyValuesScan
  */
 static ValuesScan *
-_copyValuesScan(ValuesScan *from)
+_copyValuesScan(const ValuesScan *from)
 {
 	ValuesScan *newnode = makeNode(ValuesScan);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyScanFields((Scan *) from, (Scan *) newnode);
+	CopyScanFields((const Scan *) from, (Scan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -535,14 +535,14 @@ _copyValuesScan(ValuesScan *from)
  * _copyCteScan
  */
 static CteScan *
-_copyCteScan(CteScan *from)
+_copyCteScan(const CteScan *from)
 {
 	CteScan    *newnode = makeNode(CteScan);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyScanFields((Scan *) from, (Scan *) newnode);
+	CopyScanFields((const Scan *) from, (Scan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -557,14 +557,14 @@ _copyCteScan(CteScan *from)
  * _copyWorkTableScan
  */
 static WorkTableScan *
-_copyWorkTableScan(WorkTableScan *from)
+_copyWorkTableScan(const WorkTableScan *from)
 {
 	WorkTableScan *newnode = makeNode(WorkTableScan);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyScanFields((Scan *) from, (Scan *) newnode);
+	CopyScanFields((const Scan *) from, (Scan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -578,14 +578,14 @@ _copyWorkTableScan(WorkTableScan *from)
  * _copyForeignScan
  */
 static ForeignScan *
-_copyForeignScan(ForeignScan *from)
+_copyForeignScan(const ForeignScan *from)
 {
 	ForeignScan *newnode = makeNode(ForeignScan);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyScanFields((Scan *) from, (Scan *) newnode);
+	CopyScanFields((const Scan *) from, (Scan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -600,7 +600,7 @@ _copyForeignScan(ForeignScan *from)
  * _copyFdwPlan
  */
 static FdwPlan *
-_copyFdwPlan(FdwPlan *from)
+_copyFdwPlan(const FdwPlan *from)
 {
 	FdwPlan    *newnode = makeNode(FdwPlan);
 
@@ -618,9 +618,9 @@ _copyFdwPlan(FdwPlan *from)
  *		all the copy functions for classes which inherit from Join.
  */
 static void
-CopyJoinFields(Join *from, Join *newnode)
+CopyJoinFields(const Join *from, Join *newnode)
 {
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	COPY_SCALAR_FIELD(jointype);
 	COPY_NODE_FIELD(joinqual);
@@ -631,7 +631,7 @@ CopyJoinFields(Join *from, Join *newnode)
  * _copyJoin
  */
 static Join *
-_copyJoin(Join *from)
+_copyJoin(const Join *from)
 {
 	Join	   *newnode = makeNode(Join);
 
@@ -648,14 +648,14 @@ _copyJoin(Join *from)
  * _copyNestLoop
  */
 static NestLoop *
-_copyNestLoop(NestLoop *from)
+_copyNestLoop(const NestLoop *from)
 {
 	NestLoop   *newnode = makeNode(NestLoop);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyJoinFields((Join *) from, (Join *) newnode);
+	CopyJoinFields((const Join *) from, (Join *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -670,7 +670,7 @@ _copyNestLoop(NestLoop *from)
  * _copyMergeJoin
  */
 static MergeJoin *
-_copyMergeJoin(MergeJoin *from)
+_copyMergeJoin(const MergeJoin *from)
 {
 	MergeJoin  *newnode = makeNode(MergeJoin);
 	int			numCols;
@@ -678,7 +678,7 @@ _copyMergeJoin(MergeJoin *from)
 	/*
 	 * copy node superclass fields
 	 */
-	CopyJoinFields((Join *) from, (Join *) newnode);
+	CopyJoinFields((const Join *) from, (Join *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -697,14 +697,14 @@ _copyMergeJoin(MergeJoin *from)
  * _copyHashJoin
  */
 static HashJoin *
-_copyHashJoin(HashJoin *from)
+_copyHashJoin(const HashJoin *from)
 {
 	HashJoin   *newnode = makeNode(HashJoin);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyJoinFields((Join *) from, (Join *) newnode);
+	CopyJoinFields((const Join *) from, (Join *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -719,14 +719,14 @@ _copyHashJoin(HashJoin *from)
  * _copyMaterial
  */
 static Material *
-_copyMaterial(Material *from)
+_copyMaterial(const Material *from)
 {
 	Material   *newnode = makeNode(Material);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	return newnode;
 }
@@ -736,14 +736,14 @@ _copyMaterial(Material *from)
  * _copySort
  */
 static Sort *
-_copySort(Sort *from)
+_copySort(const Sort *from)
 {
 	Sort	   *newnode = makeNode(Sort);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	COPY_SCALAR_FIELD(numCols);
 	COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
@@ -759,11 +759,11 @@ _copySort(Sort *from)
  * _copyGroup
  */
 static Group *
-_copyGroup(Group *from)
+_copyGroup(const Group *from)
 {
 	Group	   *newnode = makeNode(Group);
 
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	COPY_SCALAR_FIELD(numCols);
 	COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
@@ -776,11 +776,11 @@ _copyGroup(Group *from)
  * _copyAgg
  */
 static Agg *
-_copyAgg(Agg *from)
+_copyAgg(const Agg *from)
 {
 	Agg		   *newnode = makeNode(Agg);
 
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	COPY_SCALAR_FIELD(aggstrategy);
 	COPY_SCALAR_FIELD(numCols);
@@ -798,11 +798,11 @@ _copyAgg(Agg *from)
  * _copyWindowAgg
  */
 static WindowAgg *
-_copyWindowAgg(WindowAgg *from)
+_copyWindowAgg(const WindowAgg *from)
 {
 	WindowAgg  *newnode = makeNode(WindowAgg);
 
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	COPY_SCALAR_FIELD(winref);
 	COPY_SCALAR_FIELD(partNumCols);
@@ -828,14 +828,14 @@ _copyWindowAgg(WindowAgg *from)
  * _copyUnique
  */
 static Unique *
-_copyUnique(Unique *from)
+_copyUnique(const Unique *from)
 {
 	Unique	   *newnode = makeNode(Unique);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -851,14 +851,14 @@ _copyUnique(Unique *from)
  * _copyHash
  */
 static Hash *
-_copyHash(Hash *from)
+_copyHash(const Hash *from)
 {
 	Hash	   *newnode = makeNode(Hash);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -876,14 +876,14 @@ _copyHash(Hash *from)
  * _copySetOp
  */
 static SetOp *
-_copySetOp(SetOp *from)
+_copySetOp(const SetOp *from)
 {
 	SetOp	   *newnode = makeNode(SetOp);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -904,14 +904,14 @@ _copySetOp(SetOp *from)
  * _copyLockRows
  */
 static LockRows *
-_copyLockRows(LockRows *from)
+_copyLockRows(const LockRows *from)
 {
 	LockRows   *newnode = makeNode(LockRows);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -926,14 +926,14 @@ _copyLockRows(LockRows *from)
  * _copyLimit
  */
 static Limit *
-_copyLimit(Limit *from)
+_copyLimit(const Limit *from)
 {
 	Limit	   *newnode = makeNode(Limit);
 
 	/*
 	 * copy node superclass fields
 	 */
-	CopyPlanFields((Plan *) from, (Plan *) newnode);
+	CopyPlanFields((const Plan *) from, (Plan *) newnode);
 
 	/*
 	 * copy remainder of node
@@ -948,7 +948,7 @@ _copyLimit(Limit *from)
  * _copyNestLoopParam
  */
 static NestLoopParam *
-_copyNestLoopParam(NestLoopParam *from)
+_copyNestLoopParam(const NestLoopParam *from)
 {
 	NestLoopParam *newnode = makeNode(NestLoopParam);
 
@@ -962,7 +962,7 @@ _copyNestLoopParam(NestLoopParam *from)
  * _copyPlanRowMark
  */
 static PlanRowMark *
-_copyPlanRowMark(PlanRowMark *from)
+_copyPlanRowMark(const PlanRowMark *from)
 {
 	PlanRowMark *newnode = makeNode(PlanRowMark);
 
@@ -980,7 +980,7 @@ _copyPlanRowMark(PlanRowMark *from)
  * _copyPlanInvalItem
  */
 static PlanInvalItem *
-_copyPlanInvalItem(PlanInvalItem *from)
+_copyPlanInvalItem(const PlanInvalItem *from)
 {
 	PlanInvalItem *newnode = makeNode(PlanInvalItem);
 
@@ -999,7 +999,7 @@ _copyPlanInvalItem(PlanInvalItem *from)
  * _copyAlias
  */
 static Alias *
-_copyAlias(Alias *from)
+_copyAlias(const Alias *from)
 {
 	Alias	   *newnode = makeNode(Alias);
 
@@ -1013,7 +1013,7 @@ _copyAlias(Alias *from)
  * _copyRangeVar
  */
 static RangeVar *
-_copyRangeVar(RangeVar *from)
+_copyRangeVar(const RangeVar *from)
 {
 	RangeVar   *newnode = makeNode(RangeVar);
 
@@ -1032,7 +1032,7 @@ _copyRangeVar(RangeVar *from)
  * _copyIntoClause
  */
 static IntoClause *
-_copyIntoClause(IntoClause *from)
+_copyIntoClause(const IntoClause *from)
 {
 	IntoClause *newnode = makeNode(IntoClause);
 
@@ -1057,7 +1057,7 @@ _copyIntoClause(IntoClause *from)
  * _copyVar
  */
 static Var *
-_copyVar(Var *from)
+_copyVar(const Var *from)
 {
 	Var		   *newnode = makeNode(Var);
 
@@ -1078,7 +1078,7 @@ _copyVar(Var *from)
  * _copyConst
  */
 static Const *
-_copyConst(Const *from)
+_copyConst(const Const *from)
 {
 	Const	   *newnode = makeNode(Const);
 
@@ -1116,7 +1116,7 @@ _copyConst(Const *from)
  * _copyParam
  */
 static Param *
-_copyParam(Param *from)
+_copyParam(const Param *from)
 {
 	Param	   *newnode = makeNode(Param);
 
@@ -1134,7 +1134,7 @@ _copyParam(Param *from)
  * _copyAggref
  */
 static Aggref *
-_copyAggref(Aggref *from)
+_copyAggref(const Aggref *from)
 {
 	Aggref	   *newnode = makeNode(Aggref);
 
@@ -1156,7 +1156,7 @@ _copyAggref(Aggref *from)
  * _copyWindowFunc
  */
 static WindowFunc *
-_copyWindowFunc(WindowFunc *from)
+_copyWindowFunc(const WindowFunc *from)
 {
 	WindowFunc *newnode = makeNode(WindowFunc);
 
@@ -1177,7 +1177,7 @@ _copyWindowFunc(WindowFunc *from)
  * _copyArrayRef
  */
 static ArrayRef *
-_copyArrayRef(ArrayRef *from)
+_copyArrayRef(const ArrayRef *from)
 {
 	ArrayRef   *newnode = makeNode(ArrayRef);
 
@@ -1197,7 +1197,7 @@ _copyArrayRef(ArrayRef *from)
  * _copyFuncExpr
  */
 static FuncExpr *
-_copyFuncExpr(FuncExpr *from)
+_copyFuncExpr(const FuncExpr *from)
 {
 	FuncExpr   *newnode = makeNode(FuncExpr);
 
@@ -1217,7 +1217,7 @@ _copyFuncExpr(FuncExpr *from)
  * _copyNamedArgExpr *
  */
 static NamedArgExpr *
-_copyNamedArgExpr(NamedArgExpr *from)
+_copyNamedArgExpr(const NamedArgExpr *from)
 {
 	NamedArgExpr *newnode = makeNode(NamedArgExpr);
 
@@ -1233,7 +1233,7 @@ _copyNamedArgExpr(NamedArgExpr *from)
  * _copyOpExpr
  */
 static OpExpr *
-_copyOpExpr(OpExpr *from)
+_copyOpExpr(const OpExpr *from)
 {
 	OpExpr	   *newnode = makeNode(OpExpr);
 
@@ -1253,7 +1253,7 @@ _copyOpExpr(OpExpr *from)
  * _copyDistinctExpr (same as OpExpr)
  */
 static DistinctExpr *
-_copyDistinctExpr(DistinctExpr *from)
+_copyDistinctExpr(const DistinctExpr *from)
 {
 	DistinctExpr *newnode = makeNode(DistinctExpr);
 
@@ -1273,7 +1273,7 @@ _copyDistinctExpr(DistinctExpr *from)
  * _copyNullIfExpr (same as OpExpr)
  */
 static NullIfExpr *
-_copyNullIfExpr(NullIfExpr *from)
+_copyNullIfExpr(const NullIfExpr *from)
 {
 	NullIfExpr *newnode = makeNode(NullIfExpr);
 
@@ -1293,7 +1293,7 @@ _copyNullIfExpr(NullIfExpr *from)
  * _copyScalarArrayOpExpr
  */
 static ScalarArrayOpExpr *
-_copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
+_copyScalarArrayOpExpr(const ScalarArrayOpExpr *from)
 {
 	ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
 
@@ -1311,7 +1311,7 @@ _copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
  * _copyBoolExpr
  */
 static BoolExpr *
-_copyBoolExpr(BoolExpr *from)
+_copyBoolExpr(const BoolExpr *from)
 {
 	BoolExpr   *newnode = makeNode(BoolExpr);
 
@@ -1326,7 +1326,7 @@ _copyBoolExpr(BoolExpr *from)
  * _copySubLink
  */
 static SubLink *
-_copySubLink(SubLink *from)
+_copySubLink(const SubLink *from)
 {
 	SubLink    *newnode = makeNode(SubLink);
 
@@ -1343,7 +1343,7 @@ _copySubLink(SubLink *from)
  * _copySubPlan
  */
 static SubPlan *
-_copySubPlan(SubPlan *from)
+_copySubPlan(const SubPlan *from)
 {
 	SubPlan    *newnode = makeNode(SubPlan);
 
@@ -1370,7 +1370,7 @@ _copySubPlan(SubPlan *from)
  * _copyAlternativeSubPlan
  */
 static AlternativeSubPlan *
-_copyAlternativeSubPlan(AlternativeSubPlan *from)
+_copyAlternativeSubPlan(const AlternativeSubPlan *from)
 {
 	AlternativeSubPlan *newnode = makeNode(AlternativeSubPlan);
 
@@ -1383,7 +1383,7 @@ _copyAlternativeSubPlan(AlternativeSubPlan *from)
  * _copyFieldSelect
  */
 static FieldSelect *
-_copyFieldSelect(FieldSelect *from)
+_copyFieldSelect(const FieldSelect *from)
 {
 	FieldSelect *newnode = makeNode(FieldSelect);
 
@@ -1400,7 +1400,7 @@ _copyFieldSelect(FieldSelect *from)
  * _copyFieldStore
  */
 static FieldStore *
-_copyFieldStore(FieldStore *from)
+_copyFieldStore(const FieldStore *from)
 {
 	FieldStore *newnode = makeNode(FieldStore);
 
@@ -1416,7 +1416,7 @@ _copyFieldStore(FieldStore *from)
  * _copyRelabelType
  */
 static RelabelType *
-_copyRelabelType(RelabelType *from)
+_copyRelabelType(const RelabelType *from)
 {
 	RelabelType *newnode = makeNode(RelabelType);
 
@@ -1434,7 +1434,7 @@ _copyRelabelType(RelabelType *from)
  * _copyCoerceViaIO
  */
 static CoerceViaIO *
-_copyCoerceViaIO(CoerceViaIO *from)
+_copyCoerceViaIO(const CoerceViaIO *from)
 {
 	CoerceViaIO *newnode = makeNode(CoerceViaIO);
 
@@ -1451,7 +1451,7 @@ _copyCoerceViaIO(CoerceViaIO *from)
  * _copyArrayCoerceExpr
  */
 static ArrayCoerceExpr *
-_copyArrayCoerceExpr(ArrayCoerceExpr *from)
+_copyArrayCoerceExpr(const ArrayCoerceExpr *from)
 {
 	ArrayCoerceExpr *newnode = makeNode(ArrayCoerceExpr);
 
@@ -1471,7 +1471,7 @@ _copyArrayCoerceExpr(ArrayCoerceExpr *from)
  * _copyConvertRowtypeExpr
  */
 static ConvertRowtypeExpr *
-_copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
+_copyConvertRowtypeExpr(const ConvertRowtypeExpr *from)
 {
 	ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);
 
@@ -1487,7 +1487,7 @@ _copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
  * _copyCollateExpr
  */
 static CollateExpr *
-_copyCollateExpr(CollateExpr *from)
+_copyCollateExpr(const CollateExpr *from)
 {
 	CollateExpr *newnode = makeNode(CollateExpr);
 
@@ -1502,7 +1502,7 @@ _copyCollateExpr(CollateExpr *from)
  * _copyCaseExpr
  */
 static CaseExpr *
-_copyCaseExpr(CaseExpr *from)
+_copyCaseExpr(const CaseExpr *from)
 {
 	CaseExpr   *newnode = makeNode(CaseExpr);
 
@@ -1520,7 +1520,7 @@ _copyCaseExpr(CaseExpr *from)
  * _copyCaseWhen
  */
 static CaseWhen *
-_copyCaseWhen(CaseWhen *from)
+_copyCaseWhen(const CaseWhen *from)
 {
 	CaseWhen   *newnode = makeNode(CaseWhen);
 
@@ -1535,7 +1535,7 @@ _copyCaseWhen(CaseWhen *from)
  * _copyCaseTestExpr
  */
 static CaseTestExpr *
-_copyCaseTestExpr(CaseTestExpr *from)
+_copyCaseTestExpr(const CaseTestExpr *from)
 {
 	CaseTestExpr *newnode = makeNode(CaseTestExpr);
 
@@ -1550,7 +1550,7 @@ _copyCaseTestExpr(CaseTestExpr *from)
  * _copyArrayExpr
  */
 static ArrayExpr *
-_copyArrayExpr(ArrayExpr *from)
+_copyArrayExpr(const ArrayExpr *from)
 {
 	ArrayExpr  *newnode = makeNode(ArrayExpr);
 
@@ -1568,7 +1568,7 @@ _copyArrayExpr(ArrayExpr *from)
  * _copyRowExpr
  */
 static RowExpr *
-_copyRowExpr(RowExpr *from)
+_copyRowExpr(const RowExpr *from)
 {
 	RowExpr    *newnode = makeNode(RowExpr);
 
@@ -1585,7 +1585,7 @@ _copyRowExpr(RowExpr *from)
  * _copyRowCompareExpr
  */
 static RowCompareExpr *
-_copyRowCompareExpr(RowCompareExpr *from)
+_copyRowCompareExpr(const RowCompareExpr *from)
 {
 	RowCompareExpr *newnode = makeNode(RowCompareExpr);
 
@@ -1603,7 +1603,7 @@ _copyRowCompareExpr(RowCompareExpr *from)
  * _copyCoalesceExpr
  */
 static CoalesceExpr *
-_copyCoalesceExpr(CoalesceExpr *from)
+_copyCoalesceExpr(const CoalesceExpr *from)
 {
 	CoalesceExpr *newnode = makeNode(CoalesceExpr);
 
@@ -1619,7 +1619,7 @@ _copyCoalesceExpr(CoalesceExpr *from)
  * _copyMinMaxExpr
  */
 static MinMaxExpr *
-_copyMinMaxExpr(MinMaxExpr *from)
+_copyMinMaxExpr(const MinMaxExpr *from)
 {
 	MinMaxExpr *newnode = makeNode(MinMaxExpr);
 
@@ -1637,7 +1637,7 @@ _copyMinMaxExpr(MinMaxExpr *from)
  * _copyXmlExpr
  */
 static XmlExpr *
-_copyXmlExpr(XmlExpr *from)
+_copyXmlExpr(const XmlExpr *from)
 {
 	XmlExpr    *newnode = makeNode(XmlExpr);
 
@@ -1658,7 +1658,7 @@ _copyXmlExpr(XmlExpr *from)
  * _copyNullTest
  */
 static NullTest *
-_copyNullTest(NullTest *from)
+_copyNullTest(const NullTest *from)
 {
 	NullTest   *newnode = makeNode(NullTest);
 
@@ -1673,7 +1673,7 @@ _copyNullTest(NullTest *from)
  * _copyBooleanTest
  */
 static BooleanTest *
-_copyBooleanTest(BooleanTest *from)
+_copyBooleanTest(const BooleanTest *from)
 {
 	BooleanTest *newnode = makeNode(BooleanTest);
 
@@ -1687,7 +1687,7 @@ _copyBooleanTest(BooleanTest *from)
  * _copyCoerceToDomain
  */
 static CoerceToDomain *
-_copyCoerceToDomain(CoerceToDomain *from)
+_copyCoerceToDomain(const CoerceToDomain *from)
 {
 	CoerceToDomain *newnode = makeNode(CoerceToDomain);
 
@@ -1705,7 +1705,7 @@ _copyCoerceToDomain(CoerceToDomain *from)
  * _copyCoerceToDomainValue
  */
 static CoerceToDomainValue *
-_copyCoerceToDomainValue(CoerceToDomainValue *from)
+_copyCoerceToDomainValue(const CoerceToDomainValue *from)
 {
 	CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
 
@@ -1721,7 +1721,7 @@ _copyCoerceToDomainValue(CoerceToDomainValue *from)
  * _copySetToDefault
  */
 static SetToDefault *
-_copySetToDefault(SetToDefault *from)
+_copySetToDefault(const SetToDefault *from)
 {
 	SetToDefault *newnode = makeNode(SetToDefault);
 
@@ -1737,7 +1737,7 @@ _copySetToDefault(SetToDefault *from)
  * _copyCurrentOfExpr
  */
 static CurrentOfExpr *
-_copyCurrentOfExpr(CurrentOfExpr *from)
+_copyCurrentOfExpr(const CurrentOfExpr *from)
 {
 	CurrentOfExpr *newnode = makeNode(CurrentOfExpr);
 
@@ -1752,7 +1752,7 @@ _copyCurrentOfExpr(CurrentOfExpr *from)
  * _copyTargetEntry
  */
 static TargetEntry *
-_copyTargetEntry(TargetEntry *from)
+_copyTargetEntry(const TargetEntry *from)
 {
 	TargetEntry *newnode = makeNode(TargetEntry);
 
@@ -1771,7 +1771,7 @@ _copyTargetEntry(TargetEntry *from)
  * _copyRangeTblRef
  */
 static RangeTblRef *
-_copyRangeTblRef(RangeTblRef *from)
+_copyRangeTblRef(const RangeTblRef *from)
 {
 	RangeTblRef *newnode = makeNode(RangeTblRef);
 
@@ -1784,7 +1784,7 @@ _copyRangeTblRef(RangeTblRef *from)
  * _copyJoinExpr
  */
 static JoinExpr *
-_copyJoinExpr(JoinExpr *from)
+_copyJoinExpr(const JoinExpr *from)
 {
 	JoinExpr   *newnode = makeNode(JoinExpr);
 
@@ -1804,7 +1804,7 @@ _copyJoinExpr(JoinExpr *from)
  * _copyFromExpr
  */
 static FromExpr *
-_copyFromExpr(FromExpr *from)
+_copyFromExpr(const FromExpr *from)
 {
 	FromExpr   *newnode = makeNode(FromExpr);
 
@@ -1826,7 +1826,7 @@ _copyFromExpr(FromExpr *from)
  * _copyPathKey
  */
 static PathKey *
-_copyPathKey(PathKey *from)
+_copyPathKey(const PathKey *from)
 {
 	PathKey    *newnode = makeNode(PathKey);
 
@@ -1843,7 +1843,7 @@ _copyPathKey(PathKey *from)
  * _copyRestrictInfo
  */
 static RestrictInfo *
-_copyRestrictInfo(RestrictInfo *from)
+_copyRestrictInfo(const RestrictInfo *from)
 {
 	RestrictInfo *newnode = makeNode(RestrictInfo);
 
@@ -1883,7 +1883,7 @@ _copyRestrictInfo(RestrictInfo *from)
  * _copyPlaceHolderVar
  */
 static PlaceHolderVar *
-_copyPlaceHolderVar(PlaceHolderVar *from)
+_copyPlaceHolderVar(const PlaceHolderVar *from)
 {
 	PlaceHolderVar *newnode = makeNode(PlaceHolderVar);
 
@@ -1899,7 +1899,7 @@ _copyPlaceHolderVar(PlaceHolderVar *from)
  * _copySpecialJoinInfo
  */
 static SpecialJoinInfo *
-_copySpecialJoinInfo(SpecialJoinInfo *from)
+_copySpecialJoinInfo(const SpecialJoinInfo *from)
 {
 	SpecialJoinInfo *newnode = makeNode(SpecialJoinInfo);
 
@@ -1919,7 +1919,7 @@ _copySpecialJoinInfo(SpecialJoinInfo *from)
  * _copyAppendRelInfo
  */
 static AppendRelInfo *
-_copyAppendRelInfo(AppendRelInfo *from)
+_copyAppendRelInfo(const AppendRelInfo *from)
 {
 	AppendRelInfo *newnode = makeNode(AppendRelInfo);
 
@@ -1937,7 +1937,7 @@ _copyAppendRelInfo(AppendRelInfo *from)
  * _copyPlaceHolderInfo
  */
 static PlaceHolderInfo *
-_copyPlaceHolderInfo(PlaceHolderInfo *from)
+_copyPlaceHolderInfo(const PlaceHolderInfo *from)
 {
 	PlaceHolderInfo *newnode = makeNode(PlaceHolderInfo);
 
@@ -1957,7 +1957,7 @@ _copyPlaceHolderInfo(PlaceHolderInfo *from)
  */
 
 static RangeTblEntry *
-_copyRangeTblEntry(RangeTblEntry *from)
+_copyRangeTblEntry(const RangeTblEntry *from)
 {
 	RangeTblEntry *newnode = makeNode(RangeTblEntry);
 
@@ -1992,7 +1992,7 @@ _copyRangeTblEntry(RangeTblEntry *from)
 }
 
 static SortGroupClause *
-_copySortGroupClause(SortGroupClause *from)
+_copySortGroupClause(const SortGroupClause *from)
 {
 	SortGroupClause *newnode = makeNode(SortGroupClause);
 
@@ -2006,7 +2006,7 @@ _copySortGroupClause(SortGroupClause *from)
 }
 
 static WindowClause *
-_copyWindowClause(WindowClause *from)
+_copyWindowClause(const WindowClause *from)
 {
 	WindowClause *newnode = makeNode(WindowClause);
 
@@ -2024,7 +2024,7 @@ _copyWindowClause(WindowClause *from)
 }
 
 static RowMarkClause *
-_copyRowMarkClause(RowMarkClause *from)
+_copyRowMarkClause(const RowMarkClause *from)
 {
 	RowMarkClause *newnode = makeNode(RowMarkClause);
 
@@ -2037,7 +2037,7 @@ _copyRowMarkClause(RowMarkClause *from)
 }
 
 static WithClause *
-_copyWithClause(WithClause *from)
+_copyWithClause(const WithClause *from)
 {
 	WithClause *newnode = makeNode(WithClause);
 
@@ -2049,7 +2049,7 @@ _copyWithClause(WithClause *from)
 }
 
 static CommonTableExpr *
-_copyCommonTableExpr(CommonTableExpr *from)
+_copyCommonTableExpr(const CommonTableExpr *from)
 {
 	CommonTableExpr *newnode = makeNode(CommonTableExpr);
 
@@ -2068,7 +2068,7 @@ _copyCommonTableExpr(CommonTableExpr *from)
 }
 
 static A_Expr *
-_copyAExpr(A_Expr *from)
+_copyAExpr(const A_Expr *from)
 {
 	A_Expr	   *newnode = makeNode(A_Expr);
 
@@ -2082,7 +2082,7 @@ _copyAExpr(A_Expr *from)
 }
 
 static ColumnRef *
-_copyColumnRef(ColumnRef *from)
+_copyColumnRef(const ColumnRef *from)
 {
 	ColumnRef  *newnode = makeNode(ColumnRef);
 
@@ -2093,7 +2093,7 @@ _copyColumnRef(ColumnRef *from)
 }
 
 static ParamRef *
-_copyParamRef(ParamRef *from)
+_copyParamRef(const ParamRef *from)
 {
 	ParamRef   *newnode = makeNode(ParamRef);
 
@@ -2104,7 +2104,7 @@ _copyParamRef(ParamRef *from)
 }
 
 static A_Const *
-_copyAConst(A_Const *from)
+_copyAConst(const A_Const *from)
 {
 	A_Const    *newnode = makeNode(A_Const);
 
@@ -2135,7 +2135,7 @@ _copyAConst(A_Const *from)
 }
 
 static FuncCall *
-_copyFuncCall(FuncCall *from)
+_copyFuncCall(const FuncCall *from)
 {
 	FuncCall   *newnode = makeNode(FuncCall);
 
@@ -2152,7 +2152,7 @@ _copyFuncCall(FuncCall *from)
 }
 
 static A_Star *
-_copyAStar(A_Star *from)
+_copyAStar(const A_Star *from)
 {
 	A_Star	   *newnode = makeNode(A_Star);
 
@@ -2160,7 +2160,7 @@ _copyAStar(A_Star *from)
 }
 
 static A_Indices *
-_copyAIndices(A_Indices *from)
+_copyAIndices(const A_Indices *from)
 {
 	A_Indices  *newnode = makeNode(A_Indices);
 
@@ -2171,7 +2171,7 @@ _copyAIndices(A_Indices *from)
 }
 
 static A_Indirection *
-_copyA_Indirection(A_Indirection *from)
+_copyA_Indirection(const A_Indirection *from)
 {
 	A_Indirection *newnode = makeNode(A_Indirection);
 
@@ -2182,7 +2182,7 @@ _copyA_Indirection(A_Indirection *from)
 }
 
 static A_ArrayExpr *
-_copyA_ArrayExpr(A_ArrayExpr *from)
+_copyA_ArrayExpr(const A_ArrayExpr *from)
 {
 	A_ArrayExpr *newnode = makeNode(A_ArrayExpr);
 
@@ -2193,7 +2193,7 @@ _copyA_ArrayExpr(A_ArrayExpr *from)
 }
 
 static ResTarget *
-_copyResTarget(ResTarget *from)
+_copyResTarget(const ResTarget *from)
 {
 	ResTarget  *newnode = makeNode(ResTarget);
 
@@ -2206,7 +2206,7 @@ _copyResTarget(ResTarget *from)
 }
 
 static TypeName *
-_copyTypeName(TypeName *from)
+_copyTypeName(const TypeName *from)
 {
 	TypeName   *newnode = makeNode(TypeName);
 
@@ -2223,7 +2223,7 @@ _copyTypeName(TypeName *from)
 }
 
 static SortBy *
-_copySortBy(SortBy *from)
+_copySortBy(const SortBy *from)
 {
 	SortBy	   *newnode = makeNode(SortBy);
 
@@ -2237,7 +2237,7 @@ _copySortBy(SortBy *from)
 }
 
 static WindowDef *
-_copyWindowDef(WindowDef *from)
+_copyWindowDef(const WindowDef *from)
 {
 	WindowDef  *newnode = makeNode(WindowDef);
 
@@ -2254,7 +2254,7 @@ _copyWindowDef(WindowDef *from)
 }
 
 static RangeSubselect *
-_copyRangeSubselect(RangeSubselect *from)
+_copyRangeSubselect(const RangeSubselect *from)
 {
 	RangeSubselect *newnode = makeNode(RangeSubselect);
 
@@ -2265,7 +2265,7 @@ _copyRangeSubselect(RangeSubselect *from)
 }
 
 static RangeFunction *
-_copyRangeFunction(RangeFunction *from)
+_copyRangeFunction(const RangeFunction *from)
 {
 	RangeFunction *newnode = makeNode(RangeFunction);
 
@@ -2277,7 +2277,7 @@ _copyRangeFunction(RangeFunction *from)
 }
 
 static TypeCast *
-_copyTypeCast(TypeCast *from)
+_copyTypeCast(const TypeCast *from)
 {
 	TypeCast   *newnode = makeNode(TypeCast);
 
@@ -2289,7 +2289,7 @@ _copyTypeCast(TypeCast *from)
 }
 
 static CollateClause *
-_copyCollateClause(CollateClause *from)
+_copyCollateClause(const CollateClause *from)
 {
 	CollateClause *newnode = makeNode(CollateClause);
 
@@ -2301,7 +2301,7 @@ _copyCollateClause(CollateClause *from)
 }
 
 static IndexElem *
-_copyIndexElem(IndexElem *from)
+_copyIndexElem(const IndexElem *from)
 {
 	IndexElem  *newnode = makeNode(IndexElem);
 
@@ -2317,7 +2317,7 @@ _copyIndexElem(IndexElem *from)
 }
 
 static ColumnDef *
-_copyColumnDef(ColumnDef *from)
+_copyColumnDef(const ColumnDef *from)
 {
 	ColumnDef  *newnode = makeNode(ColumnDef);
 
@@ -2339,7 +2339,7 @@ _copyColumnDef(ColumnDef *from)
 }
 
 static Constraint *
-_copyConstraint(Constraint *from)
+_copyConstraint(const Constraint *from)
 {
 	Constraint *newnode = makeNode(Constraint);
 
@@ -2370,7 +2370,7 @@ _copyConstraint(Constraint *from)
 }
 
 static DefElem *
-_copyDefElem(DefElem *from)
+_copyDefElem(const DefElem *from)
 {
 	DefElem    *newnode = makeNode(DefElem);
 
@@ -2383,7 +2383,7 @@ _copyDefElem(DefElem *from)
 }
 
 static LockingClause *
-_copyLockingClause(LockingClause *from)
+_copyLockingClause(const LockingClause *from)
 {
 	LockingClause *newnode = makeNode(LockingClause);
 
@@ -2395,7 +2395,7 @@ _copyLockingClause(LockingClause *from)
 }
 
 static XmlSerialize *
-_copyXmlSerialize(XmlSerialize *from)
+_copyXmlSerialize(const XmlSerialize *from)
 {
 	XmlSerialize *newnode = makeNode(XmlSerialize);
 
@@ -2408,7 +2408,7 @@ _copyXmlSerialize(XmlSerialize *from)
 }
 
 static Query *
-_copyQuery(Query *from)
+_copyQuery(const Query *from)
 {
 	Query	   *newnode = makeNode(Query);
 
@@ -2445,7 +2445,7 @@ _copyQuery(Query *from)
 }
 
 static InsertStmt *
-_copyInsertStmt(InsertStmt *from)
+_copyInsertStmt(const InsertStmt *from)
 {
 	InsertStmt *newnode = makeNode(InsertStmt);
 
@@ -2459,7 +2459,7 @@ _copyInsertStmt(InsertStmt *from)
 }
 
 static DeleteStmt *
-_copyDeleteStmt(DeleteStmt *from)
+_copyDeleteStmt(const DeleteStmt *from)
 {
 	DeleteStmt *newnode = makeNode(DeleteStmt);
 
@@ -2473,7 +2473,7 @@ _copyDeleteStmt(DeleteStmt *from)
 }
 
 static UpdateStmt *
-_copyUpdateStmt(UpdateStmt *from)
+_copyUpdateStmt(const UpdateStmt *from)
 {
 	UpdateStmt *newnode = makeNode(UpdateStmt);
 
@@ -2488,7 +2488,7 @@ _copyUpdateStmt(UpdateStmt *from)
 }
 
 static SelectStmt *
-_copySelectStmt(SelectStmt *from)
+_copySelectStmt(const SelectStmt *from)
 {
 	SelectStmt *newnode = makeNode(SelectStmt);
 
@@ -2515,7 +2515,7 @@ _copySelectStmt(SelectStmt *from)
 }
 
 static SetOperationStmt *
-_copySetOperationStmt(SetOperationStmt *from)
+_copySetOperationStmt(const SetOperationStmt *from)
 {
 	SetOperationStmt *newnode = makeNode(SetOperationStmt);
 
@@ -2532,7 +2532,7 @@ _copySetOperationStmt(SetOperationStmt *from)
 }
 
 static AlterTableStmt *
-_copyAlterTableStmt(AlterTableStmt *from)
+_copyAlterTableStmt(const AlterTableStmt *from)
 {
 	AlterTableStmt *newnode = makeNode(AlterTableStmt);
 
@@ -2544,7 +2544,7 @@ _copyAlterTableStmt(AlterTableStmt *from)
 }
 
 static AlterTableCmd *
-_copyAlterTableCmd(AlterTableCmd *from)
+_copyAlterTableCmd(const AlterTableCmd *from)
 {
 	AlterTableCmd *newnode = makeNode(AlterTableCmd);
 
@@ -2558,7 +2558,7 @@ _copyAlterTableCmd(AlterTableCmd *from)
 }
 
 static AlterDomainStmt *
-_copyAlterDomainStmt(AlterDomainStmt *from)
+_copyAlterDomainStmt(const AlterDomainStmt *from)
 {
 	AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
 
@@ -2572,7 +2572,7 @@ _copyAlterDomainStmt(AlterDomainStmt *from)
 }
 
 static GrantStmt *
-_copyGrantStmt(GrantStmt *from)
+_copyGrantStmt(const GrantStmt *from)
 {
 	GrantStmt  *newnode = makeNode(GrantStmt);
 
@@ -2589,7 +2589,7 @@ _copyGrantStmt(GrantStmt *from)
 }
 
 static PrivGrantee *
-_copyPrivGrantee(PrivGrantee *from)
+_copyPrivGrantee(const PrivGrantee *from)
 {
 	PrivGrantee *newnode = makeNode(PrivGrantee);
 
@@ -2599,7 +2599,7 @@ _copyPrivGrantee(PrivGrantee *from)
 }
 
 static FuncWithArgs *
-_copyFuncWithArgs(FuncWithArgs *from)
+_copyFuncWithArgs(const FuncWithArgs *from)
 {
 	FuncWithArgs *newnode = makeNode(FuncWithArgs);
 
@@ -2610,7 +2610,7 @@ _copyFuncWithArgs(FuncWithArgs *from)
 }
 
 static AccessPriv *
-_copyAccessPriv(AccessPriv *from)
+_copyAccessPriv(const AccessPriv *from)
 {
 	AccessPriv *newnode = makeNode(AccessPriv);
 
@@ -2621,7 +2621,7 @@ _copyAccessPriv(AccessPriv *from)
 }
 
 static GrantRoleStmt *
-_copyGrantRoleStmt(GrantRoleStmt *from)
+_copyGrantRoleStmt(const GrantRoleStmt *from)
 {
 	GrantRoleStmt *newnode = makeNode(GrantRoleStmt);
 
@@ -2636,7 +2636,7 @@ _copyGrantRoleStmt(GrantRoleStmt *from)
 }
 
 static AlterDefaultPrivilegesStmt *
-_copyAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt *from)
+_copyAlterDefaultPrivilegesStmt(const AlterDefaultPrivilegesStmt *from)
 {
 	AlterDefaultPrivilegesStmt *newnode = makeNode(AlterDefaultPrivilegesStmt);
 
@@ -2647,7 +2647,7 @@ _copyAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt *from)
 }
 
 static DeclareCursorStmt *
-_copyDeclareCursorStmt(DeclareCursorStmt *from)
+_copyDeclareCursorStmt(const DeclareCursorStmt *from)
 {
 	DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
 
@@ -2659,7 +2659,7 @@ _copyDeclareCursorStmt(DeclareCursorStmt *from)
 }
 
 static ClosePortalStmt *
-_copyClosePortalStmt(ClosePortalStmt *from)
+_copyClosePortalStmt(const ClosePortalStmt *from)
 {
 	ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
 
@@ -2669,7 +2669,7 @@ _copyClosePortalStmt(ClosePortalStmt *from)
 }
 
 static ClusterStmt *
-_copyClusterStmt(ClusterStmt *from)
+_copyClusterStmt(const ClusterStmt *from)
 {
 	ClusterStmt *newnode = makeNode(ClusterStmt);
 
@@ -2681,7 +2681,7 @@ _copyClusterStmt(ClusterStmt *from)
 }
 
 static CopyStmt *
-_copyCopyStmt(CopyStmt *from)
+_copyCopyStmt(const CopyStmt *from)
 {
 	CopyStmt   *newnode = makeNode(CopyStmt);
 
@@ -2702,7 +2702,7 @@ _copyCopyStmt(CopyStmt *from)
  *		copy functions for classes which inherit from CreateStmt.
  */
 static void
-CopyCreateStmtFields(CreateStmt *from, CreateStmt *newnode)
+CopyCreateStmtFields(const CreateStmt *from, CreateStmt *newnode)
 {
 	COPY_NODE_FIELD(relation);
 	COPY_NODE_FIELD(tableElts);
@@ -2716,7 +2716,7 @@ CopyCreateStmtFields(CreateStmt *from, CreateStmt *newnode)
 }
 
 static CreateStmt *
-_copyCreateStmt(CreateStmt *from)
+_copyCreateStmt(const CreateStmt *from)
 {
 	CreateStmt *newnode = makeNode(CreateStmt);
 
@@ -2726,7 +2726,7 @@ _copyCreateStmt(CreateStmt *from)
 }
 
 static InhRelation *
-_copyInhRelation(InhRelation *from)
+_copyInhRelation(const InhRelation *from)
 {
 	InhRelation *newnode = makeNode(InhRelation);
 
@@ -2737,7 +2737,7 @@ _copyInhRelation(InhRelation *from)
 }
 
 static DefineStmt *
-_copyDefineStmt(DefineStmt *from)
+_copyDefineStmt(const DefineStmt *from)
 {
 	DefineStmt *newnode = makeNode(DefineStmt);
 
@@ -2751,7 +2751,7 @@ _copyDefineStmt(DefineStmt *from)
 }
 
 static DropStmt *
-_copyDropStmt(DropStmt *from)
+_copyDropStmt(const DropStmt *from)
 {
 	DropStmt   *newnode = makeNode(DropStmt);
 
@@ -2765,7 +2765,7 @@ _copyDropStmt(DropStmt *from)
 }
 
 static TruncateStmt *
-_copyTruncateStmt(TruncateStmt *from)
+_copyTruncateStmt(const TruncateStmt *from)
 {
 	TruncateStmt *newnode = makeNode(TruncateStmt);
 
@@ -2777,7 +2777,7 @@ _copyTruncateStmt(TruncateStmt *from)
 }
 
 static CommentStmt *
-_copyCommentStmt(CommentStmt *from)
+_copyCommentStmt(const CommentStmt *from)
 {
 	CommentStmt *newnode = makeNode(CommentStmt);
 
@@ -2790,7 +2790,7 @@ _copyCommentStmt(CommentStmt *from)
 }
 
 static SecLabelStmt *
-_copySecLabelStmt(SecLabelStmt *from)
+_copySecLabelStmt(const SecLabelStmt *from)
 {
 	SecLabelStmt *newnode = makeNode(SecLabelStmt);
 
@@ -2804,7 +2804,7 @@ _copySecLabelStmt(SecLabelStmt *from)
 }
 
 static FetchStmt *
-_copyFetchStmt(FetchStmt *from)
+_copyFetchStmt(const FetchStmt *from)
 {
 	FetchStmt  *newnode = makeNode(FetchStmt);
 
@@ -2817,7 +2817,7 @@ _copyFetchStmt(FetchStmt *from)
 }
 
 static IndexStmt *
-_copyIndexStmt(IndexStmt *from)
+_copyIndexStmt(const IndexStmt *from)
 {
 	IndexStmt  *newnode = makeNode(IndexStmt);
 
@@ -2842,7 +2842,7 @@ _copyIndexStmt(IndexStmt *from)
 }
 
 static CreateFunctionStmt *
-_copyCreateFunctionStmt(CreateFunctionStmt *from)
+_copyCreateFunctionStmt(const CreateFunctionStmt *from)
 {
 	CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
 
@@ -2857,7 +2857,7 @@ _copyCreateFunctionStmt(CreateFunctionStmt *from)
 }
 
 static FunctionParameter *
-_copyFunctionParameter(FunctionParameter *from)
+_copyFunctionParameter(const FunctionParameter *from)
 {
 	FunctionParameter *newnode = makeNode(FunctionParameter);
 
@@ -2870,7 +2870,7 @@ _copyFunctionParameter(FunctionParameter *from)
 }
 
 static AlterFunctionStmt *
-_copyAlterFunctionStmt(AlterFunctionStmt *from)
+_copyAlterFunctionStmt(const AlterFunctionStmt *from)
 {
 	AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);
 
@@ -2881,7 +2881,7 @@ _copyAlterFunctionStmt(AlterFunctionStmt *from)
 }
 
 static DoStmt *
-_copyDoStmt(DoStmt *from)
+_copyDoStmt(const DoStmt *from)
 {
 	DoStmt	   *newnode = makeNode(DoStmt);
 
@@ -2891,7 +2891,7 @@ _copyDoStmt(DoStmt *from)
 }
 
 static RenameStmt *
-_copyRenameStmt(RenameStmt *from)
+_copyRenameStmt(const RenameStmt *from)
 {
 	RenameStmt *newnode = makeNode(RenameStmt);
 
@@ -2907,7 +2907,7 @@ _copyRenameStmt(RenameStmt *from)
 }
 
 static AlterObjectSchemaStmt *
-_copyAlterObjectSchemaStmt(AlterObjectSchemaStmt *from)
+_copyAlterObjectSchemaStmt(const AlterObjectSchemaStmt *from)
 {
 	AlterObjectSchemaStmt *newnode = makeNode(AlterObjectSchemaStmt);
 
@@ -2922,7 +2922,7 @@ _copyAlterObjectSchemaStmt(AlterObjectSchemaStmt *from)
 }
 
 static AlterOwnerStmt *
-_copyAlterOwnerStmt(AlterOwnerStmt *from)
+_copyAlterOwnerStmt(const AlterOwnerStmt *from)
 {
 	AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);
 
@@ -2937,7 +2937,7 @@ _copyAlterOwnerStmt(AlterOwnerStmt *from)
 }
 
 static RuleStmt *
-_copyRuleStmt(RuleStmt *from)
+_copyRuleStmt(const RuleStmt *from)
 {
 	RuleStmt   *newnode = makeNode(RuleStmt);
 
@@ -2953,7 +2953,7 @@ _copyRuleStmt(RuleStmt *from)
 }
 
 static NotifyStmt *
-_copyNotifyStmt(NotifyStmt *from)
+_copyNotifyStmt(const NotifyStmt *from)
 {
 	NotifyStmt *newnode = makeNode(NotifyStmt);
 
@@ -2964,7 +2964,7 @@ _copyNotifyStmt(NotifyStmt *from)
 }
 
 static ListenStmt *
-_copyListenStmt(ListenStmt *from)
+_copyListenStmt(const ListenStmt *from)
 {
 	ListenStmt *newnode = makeNode(ListenStmt);
 
@@ -2974,7 +2974,7 @@ _copyListenStmt(ListenStmt *from)
 }
 
 static UnlistenStmt *
-_copyUnlistenStmt(UnlistenStmt *from)
+_copyUnlistenStmt(const UnlistenStmt *from)
 {
 	UnlistenStmt *newnode = makeNode(UnlistenStmt);
 
@@ -2984,7 +2984,7 @@ _copyUnlistenStmt(UnlistenStmt *from)
 }
 
 static TransactionStmt *
-_copyTransactionStmt(TransactionStmt *from)
+_copyTransactionStmt(const TransactionStmt *from)
 {
 	TransactionStmt *newnode = makeNode(TransactionStmt);
 
@@ -2996,7 +2996,7 @@ _copyTransactionStmt(TransactionStmt *from)
 }
 
 static CompositeTypeStmt *
-_copyCompositeTypeStmt(CompositeTypeStmt *from)
+_copyCompositeTypeStmt(const CompositeTypeStmt *from)
 {
 	CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
 
@@ -3007,7 +3007,7 @@ _copyCompositeTypeStmt(CompositeTypeStmt *from)
 }
 
 static CreateEnumStmt *
-_copyCreateEnumStmt(CreateEnumStmt *from)
+_copyCreateEnumStmt(const CreateEnumStmt *from)
 {
 	CreateEnumStmt *newnode = makeNode(CreateEnumStmt);
 
@@ -3018,7 +3018,7 @@ _copyCreateEnumStmt(CreateEnumStmt *from)
 }
 
 static CreateRangeStmt *
-_copyCreateRangeStmt(CreateRangeStmt *from)
+_copyCreateRangeStmt(const CreateRangeStmt *from)
 {
 	CreateRangeStmt *newnode = makeNode(CreateRangeStmt);
 
@@ -3029,7 +3029,7 @@ _copyCreateRangeStmt(CreateRangeStmt *from)
 }
 
 static AlterEnumStmt *
-_copyAlterEnumStmt(AlterEnumStmt *from)
+_copyAlterEnumStmt(const AlterEnumStmt *from)
 {
 	AlterEnumStmt *newnode = makeNode(AlterEnumStmt);
 
@@ -3042,7 +3042,7 @@ _copyAlterEnumStmt(AlterEnumStmt *from)
 }
 
 static ViewStmt *
-_copyViewStmt(ViewStmt *from)
+_copyViewStmt(const ViewStmt *from)
 {
 	ViewStmt   *newnode = makeNode(ViewStmt);
 
@@ -3055,7 +3055,7 @@ _copyViewStmt(ViewStmt *from)
 }
 
 static LoadStmt *
-_copyLoadStmt(LoadStmt *from)
+_copyLoadStmt(const LoadStmt *from)
 {
 	LoadStmt   *newnode = makeNode(LoadStmt);
 
@@ -3065,7 +3065,7 @@ _copyLoadStmt(LoadStmt *from)
 }
 
 static CreateDomainStmt *
-_copyCreateDomainStmt(CreateDomainStmt *from)
+_copyCreateDomainStmt(const CreateDomainStmt *from)
 {
 	CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
 
@@ -3078,7 +3078,7 @@ _copyCreateDomainStmt(CreateDomainStmt *from)
 }
 
 static CreateOpClassStmt *
-_copyCreateOpClassStmt(CreateOpClassStmt *from)
+_copyCreateOpClassStmt(const CreateOpClassStmt *from)
 {
 	CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
 
@@ -3093,7 +3093,7 @@ _copyCreateOpClassStmt(CreateOpClassStmt *from)
 }
 
 static CreateOpClassItem *
-_copyCreateOpClassItem(CreateOpClassItem *from)
+_copyCreateOpClassItem(const CreateOpClassItem *from)
 {
 	CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
 
@@ -3109,7 +3109,7 @@ _copyCreateOpClassItem(CreateOpClassItem *from)
 }
 
 static CreateOpFamilyStmt *
-_copyCreateOpFamilyStmt(CreateOpFamilyStmt *from)
+_copyCreateOpFamilyStmt(const CreateOpFamilyStmt *from)
 {
 	CreateOpFamilyStmt *newnode = makeNode(CreateOpFamilyStmt);
 
@@ -3120,7 +3120,7 @@ _copyCreateOpFamilyStmt(CreateOpFamilyStmt *from)
 }
 
 static AlterOpFamilyStmt *
-_copyAlterOpFamilyStmt(AlterOpFamilyStmt *from)
+_copyAlterOpFamilyStmt(const AlterOpFamilyStmt *from)
 {
 	AlterOpFamilyStmt *newnode = makeNode(AlterOpFamilyStmt);
 
@@ -3133,7 +3133,7 @@ _copyAlterOpFamilyStmt(AlterOpFamilyStmt *from)
 }
 
 static CreatedbStmt *
-_copyCreatedbStmt(CreatedbStmt *from)
+_copyCreatedbStmt(const CreatedbStmt *from)
 {
 	CreatedbStmt *newnode = makeNode(CreatedbStmt);
 
@@ -3144,7 +3144,7 @@ _copyCreatedbStmt(CreatedbStmt *from)
 }
 
 static AlterDatabaseStmt *
-_copyAlterDatabaseStmt(AlterDatabaseStmt *from)
+_copyAlterDatabaseStmt(const AlterDatabaseStmt *from)
 {
 	AlterDatabaseStmt *newnode = makeNode(AlterDatabaseStmt);
 
@@ -3155,7 +3155,7 @@ _copyAlterDatabaseStmt(AlterDatabaseStmt *from)
 }
 
 static AlterDatabaseSetStmt *
-_copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
+_copyAlterDatabaseSetStmt(const AlterDatabaseSetStmt *from)
 {
 	AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
 
@@ -3166,7 +3166,7 @@ _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
 }
 
 static DropdbStmt *
-_copyDropdbStmt(DropdbStmt *from)
+_copyDropdbStmt(const DropdbStmt *from)
 {
 	DropdbStmt *newnode = makeNode(DropdbStmt);
 
@@ -3177,7 +3177,7 @@ _copyDropdbStmt(DropdbStmt *from)
 }
 
 static VacuumStmt *
-_copyVacuumStmt(VacuumStmt *from)
+_copyVacuumStmt(const VacuumStmt *from)
 {
 	VacuumStmt *newnode = makeNode(VacuumStmt);
 
@@ -3191,7 +3191,7 @@ _copyVacuumStmt(VacuumStmt *from)
 }
 
 static ExplainStmt *
-_copyExplainStmt(ExplainStmt *from)
+_copyExplainStmt(const ExplainStmt *from)
 {
 	ExplainStmt *newnode = makeNode(ExplainStmt);
 
@@ -3202,7 +3202,7 @@ _copyExplainStmt(ExplainStmt *from)
 }
 
 static CreateSeqStmt *
-_copyCreateSeqStmt(CreateSeqStmt *from)
+_copyCreateSeqStmt(const CreateSeqStmt *from)
 {
 	CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
 
@@ -3214,7 +3214,7 @@ _copyCreateSeqStmt(CreateSeqStmt *from)
 }
 
 static AlterSeqStmt *
-_copyAlterSeqStmt(AlterSeqStmt *from)
+_copyAlterSeqStmt(const AlterSeqStmt *from)
 {
 	AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
 
@@ -3225,7 +3225,7 @@ _copyAlterSeqStmt(AlterSeqStmt *from)
 }
 
 static VariableSetStmt *
-_copyVariableSetStmt(VariableSetStmt *from)
+_copyVariableSetStmt(const VariableSetStmt *from)
 {
 	VariableSetStmt *newnode = makeNode(VariableSetStmt);
 
@@ -3238,7 +3238,7 @@ _copyVariableSetStmt(VariableSetStmt *from)
 }
 
 static VariableShowStmt *
-_copyVariableShowStmt(VariableShowStmt *from)
+_copyVariableShowStmt(const VariableShowStmt *from)
 {
 	VariableShowStmt *newnode = makeNode(VariableShowStmt);
 
@@ -3248,7 +3248,7 @@ _copyVariableShowStmt(VariableShowStmt *from)
 }
 
 static DiscardStmt *
-_copyDiscardStmt(DiscardStmt *from)
+_copyDiscardStmt(const DiscardStmt *from)
 {
 	DiscardStmt *newnode = makeNode(DiscardStmt);
 
@@ -3258,7 +3258,7 @@ _copyDiscardStmt(DiscardStmt *from)
 }
 
 static CreateTableSpaceStmt *
-_copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
+_copyCreateTableSpaceStmt(const CreateTableSpaceStmt *from)
 {
 	CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
 
@@ -3270,7 +3270,7 @@ _copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
 }
 
 static DropTableSpaceStmt *
-_copyDropTableSpaceStmt(DropTableSpaceStmt *from)
+_copyDropTableSpaceStmt(const DropTableSpaceStmt *from)
 {
 	DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);
 
@@ -3281,7 +3281,7 @@ _copyDropTableSpaceStmt(DropTableSpaceStmt *from)
 }
 
 static AlterTableSpaceOptionsStmt *
-_copyAlterTableSpaceOptionsStmt(AlterTableSpaceOptionsStmt *from)
+_copyAlterTableSpaceOptionsStmt(const AlterTableSpaceOptionsStmt *from)
 {
 	AlterTableSpaceOptionsStmt *newnode = makeNode(AlterTableSpaceOptionsStmt);
 
@@ -3293,7 +3293,7 @@ _copyAlterTableSpaceOptionsStmt(AlterTableSpaceOptionsStmt *from)
 }
 
 static CreateExtensionStmt *
-_copyCreateExtensionStmt(CreateExtensionStmt *from)
+_copyCreateExtensionStmt(const CreateExtensionStmt *from)
 {
 	CreateExtensionStmt *newnode = makeNode(CreateExtensionStmt);
 
@@ -3305,7 +3305,7 @@ _copyCreateExtensionStmt(CreateExtensionStmt *from)
 }
 
 static AlterExtensionStmt *
-_copyAlterExtensionStmt(AlterExtensionStmt *from)
+_copyAlterExtensionStmt(const AlterExtensionStmt *from)
 {
 	AlterExtensionStmt *newnode = makeNode(AlterExtensionStmt);
 
@@ -3316,7 +3316,7 @@ _copyAlterExtensionStmt(AlterExtensionStmt *from)
 }
 
 static AlterExtensionContentsStmt *
-_copyAlterExtensionContentsStmt(AlterExtensionContentsStmt *from)
+_copyAlterExtensionContentsStmt(const AlterExtensionContentsStmt *from)
 {
 	AlterExtensionContentsStmt *newnode = makeNode(AlterExtensionContentsStmt);
 
@@ -3330,7 +3330,7 @@ _copyAlterExtensionContentsStmt(AlterExtensionContentsStmt *from)
 }
 
 static CreateFdwStmt *
-_copyCreateFdwStmt(CreateFdwStmt *from)
+_copyCreateFdwStmt(const CreateFdwStmt *from)
 {
 	CreateFdwStmt *newnode = makeNode(CreateFdwStmt);
 
@@ -3342,7 +3342,7 @@ _copyCreateFdwStmt(CreateFdwStmt *from)
 }
 
 static AlterFdwStmt *
-_copyAlterFdwStmt(AlterFdwStmt *from)
+_copyAlterFdwStmt(const AlterFdwStmt *from)
 {
 	AlterFdwStmt *newnode = makeNode(AlterFdwStmt);
 
@@ -3354,7 +3354,7 @@ _copyAlterFdwStmt(AlterFdwStmt *from)
 }
 
 static CreateForeignServerStmt *
-_copyCreateForeignServerStmt(CreateForeignServerStmt *from)
+_copyCreateForeignServerStmt(const CreateForeignServerStmt *from)
 {
 	CreateForeignServerStmt *newnode = makeNode(CreateForeignServerStmt);
 
@@ -3368,7 +3368,7 @@ _copyCreateForeignServerStmt(CreateForeignServerStmt *from)
 }
 
 static AlterForeignServerStmt *
-_copyAlterForeignServerStmt(AlterForeignServerStmt *from)
+_copyAlterForeignServerStmt(const AlterForeignServerStmt *from)
 {
 	AlterForeignServerStmt *newnode = makeNode(AlterForeignServerStmt);
 
@@ -3381,7 +3381,7 @@ _copyAlterForeignServerStmt(AlterForeignServerStmt *from)
 }
 
 static CreateUserMappingStmt *
-_copyCreateUserMappingStmt(CreateUserMappingStmt *from)
+_copyCreateUserMappingStmt(const CreateUserMappingStmt *from)
 {
 	CreateUserMappingStmt *newnode = makeNode(CreateUserMappingStmt);
 
@@ -3393,7 +3393,7 @@ _copyCreateUserMappingStmt(CreateUserMappingStmt *from)
 }
 
 static AlterUserMappingStmt *
-_copyAlterUserMappingStmt(AlterUserMappingStmt *from)
+_copyAlterUserMappingStmt(const AlterUserMappingStmt *from)
 {
 	AlterUserMappingStmt *newnode = makeNode(AlterUserMappingStmt);
 
@@ -3405,7 +3405,7 @@ _copyAlterUserMappingStmt(AlterUserMappingStmt *from)
 }
 
 static DropUserMappingStmt *
-_copyDropUserMappingStmt(DropUserMappingStmt *from)
+_copyDropUserMappingStmt(const DropUserMappingStmt *from)
 {
 	DropUserMappingStmt *newnode = makeNode(DropUserMappingStmt);
 
@@ -3417,11 +3417,11 @@ _copyDropUserMappingStmt(DropUserMappingStmt *from)
 }
 
 static CreateForeignTableStmt *
-_copyCreateForeignTableStmt(CreateForeignTableStmt *from)
+_copyCreateForeignTableStmt(const CreateForeignTableStmt *from)
 {
 	CreateForeignTableStmt *newnode = makeNode(CreateForeignTableStmt);
 
-	CopyCreateStmtFields((CreateStmt *) from, (CreateStmt *) newnode);
+	CopyCreateStmtFields((const CreateStmt *) from, (CreateStmt *) newnode);
 
 	COPY_STRING_FIELD(servername);
 	COPY_NODE_FIELD(options);
@@ -3430,7 +3430,7 @@ _copyCreateForeignTableStmt(CreateForeignTableStmt *from)
 }
 
 static CreateTrigStmt *
-_copyCreateTrigStmt(CreateTrigStmt *from)
+_copyCreateTrigStmt(const CreateTrigStmt *from)
 {
 	CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
 
@@ -3452,7 +3452,7 @@ _copyCreateTrigStmt(CreateTrigStmt *from)
 }
 
 static CreatePLangStmt *
-_copyCreatePLangStmt(CreatePLangStmt *from)
+_copyCreatePLangStmt(const CreatePLangStmt *from)
 {
 	CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
 
@@ -3467,7 +3467,7 @@ _copyCreatePLangStmt(CreatePLangStmt *from)
 }
 
 static CreateRoleStmt *
-_copyCreateRoleStmt(CreateRoleStmt *from)
+_copyCreateRoleStmt(const CreateRoleStmt *from)
 {
 	CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
 
@@ -3479,7 +3479,7 @@ _copyCreateRoleStmt(CreateRoleStmt *from)
 }
 
 static AlterRoleStmt *
-_copyAlterRoleStmt(AlterRoleStmt *from)
+_copyAlterRoleStmt(const AlterRoleStmt *from)
 {
 	AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
 
@@ -3491,7 +3491,7 @@ _copyAlterRoleStmt(AlterRoleStmt *from)
 }
 
 static AlterRoleSetStmt *
-_copyAlterRoleSetStmt(AlterRoleSetStmt *from)
+_copyAlterRoleSetStmt(const AlterRoleSetStmt *from)
 {
 	AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
 
@@ -3503,7 +3503,7 @@ _copyAlterRoleSetStmt(AlterRoleSetStmt *from)
 }
 
 static DropRoleStmt *
-_copyDropRoleStmt(DropRoleStmt *from)
+_copyDropRoleStmt(const DropRoleStmt *from)
 {
 	DropRoleStmt *newnode = makeNode(DropRoleStmt);
 
@@ -3514,7 +3514,7 @@ _copyDropRoleStmt(DropRoleStmt *from)
 }
 
 static LockStmt *
-_copyLockStmt(LockStmt *from)
+_copyLockStmt(const LockStmt *from)
 {
 	LockStmt   *newnode = makeNode(LockStmt);
 
@@ -3526,7 +3526,7 @@ _copyLockStmt(LockStmt *from)
 }
 
 static ConstraintsSetStmt *
-_copyConstraintsSetStmt(ConstraintsSetStmt *from)
+_copyConstraintsSetStmt(const ConstraintsSetStmt *from)
 {
 	ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
 
@@ -3537,7 +3537,7 @@ _copyConstraintsSetStmt(ConstraintsSetStmt *from)
 }
 
 static ReindexStmt *
-_copyReindexStmt(ReindexStmt *from)
+_copyReindexStmt(const ReindexStmt *from)
 {
 	ReindexStmt *newnode = makeNode(ReindexStmt);
 
@@ -3551,7 +3551,7 @@ _copyReindexStmt(ReindexStmt *from)
 }
 
 static CreateSchemaStmt *
-_copyCreateSchemaStmt(CreateSchemaStmt *from)
+_copyCreateSchemaStmt(const CreateSchemaStmt *from)
 {
 	CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
 
@@ -3563,7 +3563,7 @@ _copyCreateSchemaStmt(CreateSchemaStmt *from)
 }
 
 static CreateConversionStmt *
-_copyCreateConversionStmt(CreateConversionStmt *from)
+_copyCreateConversionStmt(const CreateConversionStmt *from)
 {
 	CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
 
@@ -3577,7 +3577,7 @@ _copyCreateConversionStmt(CreateConversionStmt *from)
 }
 
 static CreateCastStmt *
-_copyCreateCastStmt(CreateCastStmt *from)
+_copyCreateCastStmt(const CreateCastStmt *from)
 {
 	CreateCastStmt *newnode = makeNode(CreateCastStmt);
 
@@ -3591,7 +3591,7 @@ _copyCreateCastStmt(CreateCastStmt *from)
 }
 
 static PrepareStmt *
-_copyPrepareStmt(PrepareStmt *from)
+_copyPrepareStmt(const PrepareStmt *from)
 {
 	PrepareStmt *newnode = makeNode(PrepareStmt);
 
@@ -3603,7 +3603,7 @@ _copyPrepareStmt(PrepareStmt *from)
 }
 
 static ExecuteStmt *
-_copyExecuteStmt(ExecuteStmt *from)
+_copyExecuteStmt(const ExecuteStmt *from)
 {
 	ExecuteStmt *newnode = makeNode(ExecuteStmt);
 
@@ -3615,7 +3615,7 @@ _copyExecuteStmt(ExecuteStmt *from)
 }
 
 static DeallocateStmt *
-_copyDeallocateStmt(DeallocateStmt *from)
+_copyDeallocateStmt(const DeallocateStmt *from)
 {
 	DeallocateStmt *newnode = makeNode(DeallocateStmt);
 
@@ -3625,7 +3625,7 @@ _copyDeallocateStmt(DeallocateStmt *from)
 }
 
 static DropOwnedStmt *
-_copyDropOwnedStmt(DropOwnedStmt *from)
+_copyDropOwnedStmt(const DropOwnedStmt *from)
 {
 	DropOwnedStmt *newnode = makeNode(DropOwnedStmt);
 
@@ -3636,7 +3636,7 @@ _copyDropOwnedStmt(DropOwnedStmt *from)
 }
 
 static ReassignOwnedStmt *
-_copyReassignOwnedStmt(ReassignOwnedStmt *from)
+_copyReassignOwnedStmt(const ReassignOwnedStmt *from)
 {
 	ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt);
 
@@ -3647,7 +3647,7 @@ _copyReassignOwnedStmt(ReassignOwnedStmt *from)
 }
 
 static AlterTSDictionaryStmt *
-_copyAlterTSDictionaryStmt(AlterTSDictionaryStmt *from)
+_copyAlterTSDictionaryStmt(const AlterTSDictionaryStmt *from)
 {
 	AlterTSDictionaryStmt *newnode = makeNode(AlterTSDictionaryStmt);
 
@@ -3658,7 +3658,7 @@ _copyAlterTSDictionaryStmt(AlterTSDictionaryStmt *from)
 }
 
 static AlterTSConfigurationStmt *
-_copyAlterTSConfigurationStmt(AlterTSConfigurationStmt *from)
+_copyAlterTSConfigurationStmt(const AlterTSConfigurationStmt *from)
 {
 	AlterTSConfigurationStmt *newnode = makeNode(AlterTSConfigurationStmt);
 
@@ -3687,7 +3687,7 @@ _copyAlterTSConfigurationStmt(AlterTSConfigurationStmt *from)
 	lfirst(new) = copyObject(lfirst(old));
 
 static List *
-_copyList(List *from)
+_copyList(const List *from)
 {
 	List	   *new;
 	ListCell   *curr_old;
@@ -3719,7 +3719,7 @@ _copyList(List *from)
  * ****************************************************************
  */
 static Value *
-_copyValue(Value *from)
+_copyValue(const Value *from)
 {
 	Value	   *newnode = makeNode(Value);
 
@@ -3754,7 +3754,7 @@ _copyValue(Value *from)
  * substructure is copied too, recursively.
  */
 void *
-copyObject(void *from)
+copyObject(const void *from)
 {
 	void	   *retval;
 
@@ -4460,7 +4460,7 @@ copyObject(void *from)
 
 		default:
 			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
-			retval = from;		/* keep compiler quiet */
+			retval = 0;		/* keep compiler quiet */
 			break;
 	}
 
diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c
index f490a7ab2ef..9f7daf4eda2 100644
--- a/src/backend/nodes/equalfuncs.c
+++ b/src/backend/nodes/equalfuncs.c
@@ -89,7 +89,7 @@
  */
 
 static bool
-_equalAlias(Alias *a, Alias *b)
+_equalAlias(const Alias *a, const Alias *b)
 {
 	COMPARE_STRING_FIELD(aliasname);
 	COMPARE_NODE_FIELD(colnames);
@@ -98,7 +98,7 @@ _equalAlias(Alias *a, Alias *b)
 }
 
 static bool
-_equalRangeVar(RangeVar *a, RangeVar *b)
+_equalRangeVar(const RangeVar *a, const RangeVar *b)
 {
 	COMPARE_STRING_FIELD(catalogname);
 	COMPARE_STRING_FIELD(schemaname);
@@ -112,7 +112,7 @@ _equalRangeVar(RangeVar *a, RangeVar *b)
 }
 
 static bool
-_equalIntoClause(IntoClause *a, IntoClause *b)
+_equalIntoClause(const IntoClause *a, const IntoClause *b)
 {
 	COMPARE_NODE_FIELD(rel);
 	COMPARE_NODE_FIELD(colNames);
@@ -132,7 +132,7 @@ _equalIntoClause(IntoClause *a, IntoClause *b)
  */
 
 static bool
-_equalVar(Var *a, Var *b)
+_equalVar(const Var *a, const Var *b)
 {
 	COMPARE_SCALAR_FIELD(varno);
 	COMPARE_SCALAR_FIELD(varattno);
@@ -148,7 +148,7 @@ _equalVar(Var *a, Var *b)
 }
 
 static bool
-_equalConst(Const *a, Const *b)
+_equalConst(const Const *a, const Const *b)
 {
 	COMPARE_SCALAR_FIELD(consttype);
 	COMPARE_SCALAR_FIELD(consttypmod);
@@ -169,7 +169,7 @@ _equalConst(Const *a, Const *b)
 }
 
 static bool
-_equalParam(Param *a, Param *b)
+_equalParam(const Param *a, const Param *b)
 {
 	COMPARE_SCALAR_FIELD(paramkind);
 	COMPARE_SCALAR_FIELD(paramid);
@@ -182,7 +182,7 @@ _equalParam(Param *a, Param *b)
 }
 
 static bool
-_equalAggref(Aggref *a, Aggref *b)
+_equalAggref(const Aggref *a, const Aggref *b)
 {
 	COMPARE_SCALAR_FIELD(aggfnoid);
 	COMPARE_SCALAR_FIELD(aggtype);
@@ -199,7 +199,7 @@ _equalAggref(Aggref *a, Aggref *b)
 }
 
 static bool
-_equalWindowFunc(WindowFunc *a, WindowFunc *b)
+_equalWindowFunc(const WindowFunc *a, const WindowFunc *b)
 {
 	COMPARE_SCALAR_FIELD(winfnoid);
 	COMPARE_SCALAR_FIELD(wintype);
@@ -215,7 +215,7 @@ _equalWindowFunc(WindowFunc *a, WindowFunc *b)
 }
 
 static bool
-_equalArrayRef(ArrayRef *a, ArrayRef *b)
+_equalArrayRef(const ArrayRef *a, const ArrayRef *b)
 {
 	COMPARE_SCALAR_FIELD(refarraytype);
 	COMPARE_SCALAR_FIELD(refelemtype);
@@ -230,7 +230,7 @@ _equalArrayRef(ArrayRef *a, ArrayRef *b)
 }
 
 static bool
-_equalFuncExpr(FuncExpr *a, FuncExpr *b)
+_equalFuncExpr(const FuncExpr *a, const FuncExpr *b)
 {
 	COMPARE_SCALAR_FIELD(funcid);
 	COMPARE_SCALAR_FIELD(funcresulttype);
@@ -254,7 +254,7 @@ _equalFuncExpr(FuncExpr *a, FuncExpr *b)
 }
 
 static bool
-_equalNamedArgExpr(NamedArgExpr *a, NamedArgExpr *b)
+_equalNamedArgExpr(const NamedArgExpr *a, const NamedArgExpr *b)
 {
 	COMPARE_NODE_FIELD(arg);
 	COMPARE_STRING_FIELD(name);
@@ -265,7 +265,7 @@ _equalNamedArgExpr(NamedArgExpr *a, NamedArgExpr *b)
 }
 
 static bool
-_equalOpExpr(OpExpr *a, OpExpr *b)
+_equalOpExpr(const OpExpr *a, const OpExpr *b)
 {
 	COMPARE_SCALAR_FIELD(opno);
 
@@ -291,7 +291,7 @@ _equalOpExpr(OpExpr *a, OpExpr *b)
 }
 
 static bool
-_equalDistinctExpr(DistinctExpr *a, DistinctExpr *b)
+_equalDistinctExpr(const DistinctExpr *a, const DistinctExpr *b)
 {
 	COMPARE_SCALAR_FIELD(opno);
 
@@ -317,7 +317,7 @@ _equalDistinctExpr(DistinctExpr *a, DistinctExpr *b)
 }
 
 static bool
-_equalNullIfExpr(NullIfExpr *a, NullIfExpr *b)
+_equalNullIfExpr(const NullIfExpr *a, const NullIfExpr *b)
 {
 	COMPARE_SCALAR_FIELD(opno);
 
@@ -343,7 +343,7 @@ _equalNullIfExpr(NullIfExpr *a, NullIfExpr *b)
 }
 
 static bool
-_equalScalarArrayOpExpr(ScalarArrayOpExpr *a, ScalarArrayOpExpr *b)
+_equalScalarArrayOpExpr(const ScalarArrayOpExpr *a, const ScalarArrayOpExpr *b)
 {
 	COMPARE_SCALAR_FIELD(opno);
 
@@ -367,7 +367,7 @@ _equalScalarArrayOpExpr(ScalarArrayOpExpr *a, ScalarArrayOpExpr *b)
 }
 
 static bool
-_equalBoolExpr(BoolExpr *a, BoolExpr *b)
+_equalBoolExpr(const BoolExpr *a, const BoolExpr *b)
 {
 	COMPARE_SCALAR_FIELD(boolop);
 	COMPARE_NODE_FIELD(args);
@@ -377,7 +377,7 @@ _equalBoolExpr(BoolExpr *a, BoolExpr *b)
 }
 
 static bool
-_equalSubLink(SubLink *a, SubLink *b)
+_equalSubLink(const SubLink *a, const SubLink *b)
 {
 	COMPARE_SCALAR_FIELD(subLinkType);
 	COMPARE_NODE_FIELD(testexpr);
@@ -389,7 +389,7 @@ _equalSubLink(SubLink *a, SubLink *b)
 }
 
 static bool
-_equalSubPlan(SubPlan *a, SubPlan *b)
+_equalSubPlan(const SubPlan *a, const SubPlan *b)
 {
 	COMPARE_SCALAR_FIELD(subLinkType);
 	COMPARE_NODE_FIELD(testexpr);
@@ -411,7 +411,7 @@ _equalSubPlan(SubPlan *a, SubPlan *b)
 }
 
 static bool
-_equalAlternativeSubPlan(AlternativeSubPlan *a, AlternativeSubPlan *b)
+_equalAlternativeSubPlan(const AlternativeSubPlan *a, const AlternativeSubPlan *b)
 {
 	COMPARE_NODE_FIELD(subplans);
 
@@ -419,7 +419,7 @@ _equalAlternativeSubPlan(AlternativeSubPlan *a, AlternativeSubPlan *b)
 }
 
 static bool
-_equalFieldSelect(FieldSelect *a, FieldSelect *b)
+_equalFieldSelect(const FieldSelect *a, const FieldSelect *b)
 {
 	COMPARE_NODE_FIELD(arg);
 	COMPARE_SCALAR_FIELD(fieldnum);
@@ -431,7 +431,7 @@ _equalFieldSelect(FieldSelect *a, FieldSelect *b)
 }
 
 static bool
-_equalFieldStore(FieldStore *a, FieldStore *b)
+_equalFieldStore(const FieldStore *a, const FieldStore *b)
 {
 	COMPARE_NODE_FIELD(arg);
 	COMPARE_NODE_FIELD(newvals);
@@ -442,7 +442,7 @@ _equalFieldStore(FieldStore *a, FieldStore *b)
 }
 
 static bool
-_equalRelabelType(RelabelType *a, RelabelType *b)
+_equalRelabelType(const RelabelType *a, const RelabelType *b)
 {
 	COMPARE_NODE_FIELD(arg);
 	COMPARE_SCALAR_FIELD(resulttype);
@@ -464,7 +464,7 @@ _equalRelabelType(RelabelType *a, RelabelType *b)
 }
 
 static bool
-_equalCoerceViaIO(CoerceViaIO *a, CoerceViaIO *b)
+_equalCoerceViaIO(const CoerceViaIO *a, const CoerceViaIO *b)
 {
 	COMPARE_NODE_FIELD(arg);
 	COMPARE_SCALAR_FIELD(resulttype);
@@ -485,7 +485,7 @@ _equalCoerceViaIO(CoerceViaIO *a, CoerceViaIO *b)
 }
 
 static bool
-_equalArrayCoerceExpr(ArrayCoerceExpr *a, ArrayCoerceExpr *b)
+_equalArrayCoerceExpr(const ArrayCoerceExpr *a, const ArrayCoerceExpr *b)
 {
 	COMPARE_NODE_FIELD(arg);
 	COMPARE_SCALAR_FIELD(elemfuncid);
@@ -509,7 +509,7 @@ _equalArrayCoerceExpr(ArrayCoerceExpr *a, ArrayCoerceExpr *b)
 }
 
 static bool
-_equalConvertRowtypeExpr(ConvertRowtypeExpr *a, ConvertRowtypeExpr *b)
+_equalConvertRowtypeExpr(const ConvertRowtypeExpr *a, const ConvertRowtypeExpr *b)
 {
 	COMPARE_NODE_FIELD(arg);
 	COMPARE_SCALAR_FIELD(resulttype);
@@ -529,7 +529,7 @@ _equalConvertRowtypeExpr(ConvertRowtypeExpr *a, ConvertRowtypeExpr *b)
 }
 
 static bool
-_equalCollateExpr(CollateExpr *a, CollateExpr *b)
+_equalCollateExpr(const CollateExpr *a, const CollateExpr *b)
 {
 	COMPARE_NODE_FIELD(arg);
 	COMPARE_SCALAR_FIELD(collOid);
@@ -539,7 +539,7 @@ _equalCollateExpr(CollateExpr *a, CollateExpr *b)
 }
 
 static bool
-_equalCaseExpr(CaseExpr *a, CaseExpr *b)
+_equalCaseExpr(const CaseExpr *a, const CaseExpr *b)
 {
 	COMPARE_SCALAR_FIELD(casetype);
 	COMPARE_SCALAR_FIELD(casecollid);
@@ -552,7 +552,7 @@ _equalCaseExpr(CaseExpr *a, CaseExpr *b)
 }
 
 static bool
-_equalCaseWhen(CaseWhen *a, CaseWhen *b)
+_equalCaseWhen(const CaseWhen *a, const CaseWhen *b)
 {
 	COMPARE_NODE_FIELD(expr);
 	COMPARE_NODE_FIELD(result);
@@ -562,7 +562,7 @@ _equalCaseWhen(CaseWhen *a, CaseWhen *b)
 }
 
 static bool
-_equalCaseTestExpr(CaseTestExpr *a, CaseTestExpr *b)
+_equalCaseTestExpr(const CaseTestExpr *a, const CaseTestExpr *b)
 {
 	COMPARE_SCALAR_FIELD(typeId);
 	COMPARE_SCALAR_FIELD(typeMod);
@@ -572,7 +572,7 @@ _equalCaseTestExpr(CaseTestExpr *a, CaseTestExpr *b)
 }
 
 static bool
-_equalArrayExpr(ArrayExpr *a, ArrayExpr *b)
+_equalArrayExpr(const ArrayExpr *a, const ArrayExpr *b)
 {
 	COMPARE_SCALAR_FIELD(array_typeid);
 	COMPARE_SCALAR_FIELD(array_collid);
@@ -585,7 +585,7 @@ _equalArrayExpr(ArrayExpr *a, ArrayExpr *b)
 }
 
 static bool
-_equalRowExpr(RowExpr *a, RowExpr *b)
+_equalRowExpr(const RowExpr *a, const RowExpr *b)
 {
 	COMPARE_NODE_FIELD(args);
 	COMPARE_SCALAR_FIELD(row_typeid);
@@ -606,7 +606,7 @@ _equalRowExpr(RowExpr *a, RowExpr *b)
 }
 
 static bool
-_equalRowCompareExpr(RowCompareExpr *a, RowCompareExpr *b)
+_equalRowCompareExpr(const RowCompareExpr *a, const RowCompareExpr *b)
 {
 	COMPARE_SCALAR_FIELD(rctype);
 	COMPARE_NODE_FIELD(opnos);
@@ -619,7 +619,7 @@ _equalRowCompareExpr(RowCompareExpr *a, RowCompareExpr *b)
 }
 
 static bool
-_equalCoalesceExpr(CoalesceExpr *a, CoalesceExpr *b)
+_equalCoalesceExpr(const CoalesceExpr *a, const CoalesceExpr *b)
 {
 	COMPARE_SCALAR_FIELD(coalescetype);
 	COMPARE_SCALAR_FIELD(coalescecollid);
@@ -630,7 +630,7 @@ _equalCoalesceExpr(CoalesceExpr *a, CoalesceExpr *b)
 }
 
 static bool
-_equalMinMaxExpr(MinMaxExpr *a, MinMaxExpr *b)
+_equalMinMaxExpr(const MinMaxExpr *a, const MinMaxExpr *b)
 {
 	COMPARE_SCALAR_FIELD(minmaxtype);
 	COMPARE_SCALAR_FIELD(minmaxcollid);
@@ -643,7 +643,7 @@ _equalMinMaxExpr(MinMaxExpr *a, MinMaxExpr *b)
 }
 
 static bool
-_equalXmlExpr(XmlExpr *a, XmlExpr *b)
+_equalXmlExpr(const XmlExpr *a, const XmlExpr *b)
 {
 	COMPARE_SCALAR_FIELD(op);
 	COMPARE_STRING_FIELD(name);
@@ -659,7 +659,7 @@ _equalXmlExpr(XmlExpr *a, XmlExpr *b)
 }
 
 static bool
-_equalNullTest(NullTest *a, NullTest *b)
+_equalNullTest(const NullTest *a, const NullTest *b)
 {
 	COMPARE_NODE_FIELD(arg);
 	COMPARE_SCALAR_FIELD(nulltesttype);
@@ -669,7 +669,7 @@ _equalNullTest(NullTest *a, NullTest *b)
 }
 
 static bool
-_equalBooleanTest(BooleanTest *a, BooleanTest *b)
+_equalBooleanTest(const BooleanTest *a, const BooleanTest *b)
 {
 	COMPARE_NODE_FIELD(arg);
 	COMPARE_SCALAR_FIELD(booltesttype);
@@ -678,7 +678,7 @@ _equalBooleanTest(BooleanTest *a, BooleanTest *b)
 }
 
 static bool
-_equalCoerceToDomain(CoerceToDomain *a, CoerceToDomain *b)
+_equalCoerceToDomain(const CoerceToDomain *a, const CoerceToDomain *b)
 {
 	COMPARE_NODE_FIELD(arg);
 	COMPARE_SCALAR_FIELD(resulttype);
@@ -700,7 +700,7 @@ _equalCoerceToDomain(CoerceToDomain *a, CoerceToDomain *b)
 }
 
 static bool
-_equalCoerceToDomainValue(CoerceToDomainValue *a, CoerceToDomainValue *b)
+_equalCoerceToDomainValue(const CoerceToDomainValue *a, const CoerceToDomainValue *b)
 {
 	COMPARE_SCALAR_FIELD(typeId);
 	COMPARE_SCALAR_FIELD(typeMod);
@@ -711,7 +711,7 @@ _equalCoerceToDomainValue(CoerceToDomainValue *a, CoerceToDomainValue *b)
 }
 
 static bool
-_equalSetToDefault(SetToDefault *a, SetToDefault *b)
+_equalSetToDefault(const SetToDefault *a, const SetToDefault *b)
 {
 	COMPARE_SCALAR_FIELD(typeId);
 	COMPARE_SCALAR_FIELD(typeMod);
@@ -722,7 +722,7 @@ _equalSetToDefault(SetToDefault *a, SetToDefault *b)
 }
 
 static bool
-_equalCurrentOfExpr(CurrentOfExpr *a, CurrentOfExpr *b)
+_equalCurrentOfExpr(const CurrentOfExpr *a, const CurrentOfExpr *b)
 {
 	COMPARE_SCALAR_FIELD(cvarno);
 	COMPARE_STRING_FIELD(cursor_name);
@@ -732,7 +732,7 @@ _equalCurrentOfExpr(CurrentOfExpr *a, CurrentOfExpr *b)
 }
 
 static bool
-_equalTargetEntry(TargetEntry *a, TargetEntry *b)
+_equalTargetEntry(const TargetEntry *a, const TargetEntry *b)
 {
 	COMPARE_NODE_FIELD(expr);
 	COMPARE_SCALAR_FIELD(resno);
@@ -746,7 +746,7 @@ _equalTargetEntry(TargetEntry *a, TargetEntry *b)
 }
 
 static bool
-_equalRangeTblRef(RangeTblRef *a, RangeTblRef *b)
+_equalRangeTblRef(const RangeTblRef *a, const RangeTblRef *b)
 {
 	COMPARE_SCALAR_FIELD(rtindex);
 
@@ -754,7 +754,7 @@ _equalRangeTblRef(RangeTblRef *a, RangeTblRef *b)
 }
 
 static bool
-_equalJoinExpr(JoinExpr *a, JoinExpr *b)
+_equalJoinExpr(const JoinExpr *a, const JoinExpr *b)
 {
 	COMPARE_SCALAR_FIELD(jointype);
 	COMPARE_SCALAR_FIELD(isNatural);
@@ -769,7 +769,7 @@ _equalJoinExpr(JoinExpr *a, JoinExpr *b)
 }
 
 static bool
-_equalFromExpr(FromExpr *a, FromExpr *b)
+_equalFromExpr(const FromExpr *a, const FromExpr *b)
 {
 	COMPARE_NODE_FIELD(fromlist);
 	COMPARE_NODE_FIELD(quals);
@@ -783,7 +783,7 @@ _equalFromExpr(FromExpr *a, FromExpr *b)
  */
 
 static bool
-_equalPathKey(PathKey *a, PathKey *b)
+_equalPathKey(const PathKey *a, const PathKey *b)
 {
 	/*
 	 * This is normally used on non-canonicalized PathKeys, so must chase up
@@ -809,7 +809,7 @@ _equalPathKey(PathKey *a, PathKey *b)
 }
 
 static bool
-_equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
+_equalRestrictInfo(const RestrictInfo *a, const RestrictInfo *b)
 {
 	COMPARE_NODE_FIELD(clause);
 	COMPARE_SCALAR_FIELD(is_pushed_down);
@@ -826,7 +826,7 @@ _equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
 }
 
 static bool
-_equalPlaceHolderVar(PlaceHolderVar *a, PlaceHolderVar *b)
+_equalPlaceHolderVar(const PlaceHolderVar *a, const PlaceHolderVar *b)
 {
 	/*
 	 * We intentionally do not compare phexpr.	Two PlaceHolderVars with the
@@ -847,7 +847,7 @@ _equalPlaceHolderVar(PlaceHolderVar *a, PlaceHolderVar *b)
 }
 
 static bool
-_equalSpecialJoinInfo(SpecialJoinInfo *a, SpecialJoinInfo *b)
+_equalSpecialJoinInfo(const SpecialJoinInfo *a, const SpecialJoinInfo *b)
 {
 	COMPARE_BITMAPSET_FIELD(min_lefthand);
 	COMPARE_BITMAPSET_FIELD(min_righthand);
@@ -862,7 +862,7 @@ _equalSpecialJoinInfo(SpecialJoinInfo *a, SpecialJoinInfo *b)
 }
 
 static bool
-_equalAppendRelInfo(AppendRelInfo *a, AppendRelInfo *b)
+_equalAppendRelInfo(const AppendRelInfo *a, const AppendRelInfo *b)
 {
 	COMPARE_SCALAR_FIELD(parent_relid);
 	COMPARE_SCALAR_FIELD(child_relid);
@@ -875,7 +875,7 @@ _equalAppendRelInfo(AppendRelInfo *a, AppendRelInfo *b)
 }
 
 static bool
-_equalPlaceHolderInfo(PlaceHolderInfo *a, PlaceHolderInfo *b)
+_equalPlaceHolderInfo(const PlaceHolderInfo *a, const PlaceHolderInfo *b)
 {
 	COMPARE_SCALAR_FIELD(phid);
 	COMPARE_NODE_FIELD(ph_var);
@@ -893,7 +893,7 @@ _equalPlaceHolderInfo(PlaceHolderInfo *a, PlaceHolderInfo *b)
  */
 
 static bool
-_equalQuery(Query *a, Query *b)
+_equalQuery(const Query *a, const Query *b)
 {
 	COMPARE_SCALAR_FIELD(commandType);
 	COMPARE_SCALAR_FIELD(querySource);
@@ -928,7 +928,7 @@ _equalQuery(Query *a, Query *b)
 }
 
 static bool
-_equalInsertStmt(InsertStmt *a, InsertStmt *b)
+_equalInsertStmt(const InsertStmt *a, const InsertStmt *b)
 {
 	COMPARE_NODE_FIELD(relation);
 	COMPARE_NODE_FIELD(cols);
@@ -940,7 +940,7 @@ _equalInsertStmt(InsertStmt *a, InsertStmt *b)
 }
 
 static bool
-_equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
+_equalDeleteStmt(const DeleteStmt *a, const DeleteStmt *b)
 {
 	COMPARE_NODE_FIELD(relation);
 	COMPARE_NODE_FIELD(usingClause);
@@ -952,7 +952,7 @@ _equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
 }
 
 static bool
-_equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
+_equalUpdateStmt(const UpdateStmt *a, const UpdateStmt *b)
 {
 	COMPARE_NODE_FIELD(relation);
 	COMPARE_NODE_FIELD(targetList);
@@ -965,7 +965,7 @@ _equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
 }
 
 static bool
-_equalSelectStmt(SelectStmt *a, SelectStmt *b)
+_equalSelectStmt(const SelectStmt *a, const SelectStmt *b)
 {
 	COMPARE_NODE_FIELD(distinctClause);
 	COMPARE_NODE_FIELD(intoClause);
@@ -990,7 +990,7 @@ _equalSelectStmt(SelectStmt *a, SelectStmt *b)
 }
 
 static bool
-_equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
+_equalSetOperationStmt(const SetOperationStmt *a, const SetOperationStmt *b)
 {
 	COMPARE_SCALAR_FIELD(op);
 	COMPARE_SCALAR_FIELD(all);
@@ -1005,7 +1005,7 @@ _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
 }
 
 static bool
-_equalAlterTableStmt(AlterTableStmt *a, AlterTableStmt *b)
+_equalAlterTableStmt(const AlterTableStmt *a, const AlterTableStmt *b)
 {
 	COMPARE_NODE_FIELD(relation);
 	COMPARE_NODE_FIELD(cmds);
@@ -1015,7 +1015,7 @@ _equalAlterTableStmt(AlterTableStmt *a, AlterTableStmt *b)
 }
 
 static bool
-_equalAlterTableCmd(AlterTableCmd *a, AlterTableCmd *b)
+_equalAlterTableCmd(const AlterTableCmd *a, const AlterTableCmd *b)
 {
 	COMPARE_SCALAR_FIELD(subtype);
 	COMPARE_STRING_FIELD(name);
@@ -1027,7 +1027,7 @@ _equalAlterTableCmd(AlterTableCmd *a, AlterTableCmd *b)
 }
 
 static bool
-_equalAlterDomainStmt(AlterDomainStmt *a, AlterDomainStmt *b)
+_equalAlterDomainStmt(const AlterDomainStmt *a, const AlterDomainStmt *b)
 {
 	COMPARE_SCALAR_FIELD(subtype);
 	COMPARE_NODE_FIELD(typeName);
@@ -1039,7 +1039,7 @@ _equalAlterDomainStmt(AlterDomainStmt *a, AlterDomainStmt *b)
 }
 
 static bool
-_equalGrantStmt(GrantStmt *a, GrantStmt *b)
+_equalGrantStmt(const GrantStmt *a, const GrantStmt *b)
 {
 	COMPARE_SCALAR_FIELD(is_grant);
 	COMPARE_SCALAR_FIELD(targtype);
@@ -1054,7 +1054,7 @@ _equalGrantStmt(GrantStmt *a, GrantStmt *b)
 }
 
 static bool
-_equalPrivGrantee(PrivGrantee *a, PrivGrantee *b)
+_equalPrivGrantee(const PrivGrantee *a, const PrivGrantee *b)
 {
 	COMPARE_STRING_FIELD(rolname);
 
@@ -1062,7 +1062,7 @@ _equalPrivGrantee(PrivGrantee *a, PrivGrantee *b)
 }
 
 static bool
-_equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
+_equalFuncWithArgs(const FuncWithArgs *a, const FuncWithArgs *b)
 {
 	COMPARE_NODE_FIELD(funcname);
 	COMPARE_NODE_FIELD(funcargs);
@@ -1071,7 +1071,7 @@ _equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
 }
 
 static bool
-_equalAccessPriv(AccessPriv *a, AccessPriv *b)
+_equalAccessPriv(const AccessPriv *a, const AccessPriv *b)
 {
 	COMPARE_STRING_FIELD(priv_name);
 	COMPARE_NODE_FIELD(cols);
@@ -1080,7 +1080,7 @@ _equalAccessPriv(AccessPriv *a, AccessPriv *b)
 }
 
 static bool
-_equalGrantRoleStmt(GrantRoleStmt *a, GrantRoleStmt *b)
+_equalGrantRoleStmt(const GrantRoleStmt *a, const GrantRoleStmt *b)
 {
 	COMPARE_NODE_FIELD(granted_roles);
 	COMPARE_NODE_FIELD(grantee_roles);
@@ -1093,7 +1093,7 @@ _equalGrantRoleStmt(GrantRoleStmt *a, GrantRoleStmt *b)
 }
 
 static bool
-_equalAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt *a, AlterDefaultPrivilegesStmt *b)
+_equalAlterDefaultPrivilegesStmt(const AlterDefaultPrivilegesStmt *a, const AlterDefaultPrivilegesStmt *b)
 {
 	COMPARE_NODE_FIELD(options);
 	COMPARE_NODE_FIELD(action);
@@ -1102,7 +1102,7 @@ _equalAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt *a, AlterDefaultPriv
 }
 
 static bool
-_equalDeclareCursorStmt(DeclareCursorStmt *a, DeclareCursorStmt *b)
+_equalDeclareCursorStmt(const DeclareCursorStmt *a, const DeclareCursorStmt *b)
 {
 	COMPARE_STRING_FIELD(portalname);
 	COMPARE_SCALAR_FIELD(options);
@@ -1112,7 +1112,7 @@ _equalDeclareCursorStmt(DeclareCursorStmt *a, DeclareCursorStmt *b)
 }
 
 static bool
-_equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
+_equalClosePortalStmt(const ClosePortalStmt *a, const ClosePortalStmt *b)
 {
 	COMPARE_STRING_FIELD(portalname);
 
@@ -1120,7 +1120,7 @@ _equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
 }
 
 static bool
-_equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
+_equalClusterStmt(const ClusterStmt *a, const ClusterStmt *b)
 {
 	COMPARE_NODE_FIELD(relation);
 	COMPARE_STRING_FIELD(indexname);
@@ -1130,7 +1130,7 @@ _equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
 }
 
 static bool
-_equalCopyStmt(CopyStmt *a, CopyStmt *b)
+_equalCopyStmt(const CopyStmt *a, const CopyStmt *b)
 {
 	COMPARE_NODE_FIELD(relation);
 	COMPARE_NODE_FIELD(query);
@@ -1143,7 +1143,7 @@ _equalCopyStmt(CopyStmt *a, CopyStmt *b)
 }
 
 static bool
-_equalCreateStmt(CreateStmt *a, CreateStmt *b)
+_equalCreateStmt(const CreateStmt *a, const CreateStmt *b)
 {
 	COMPARE_NODE_FIELD(relation);
 	COMPARE_NODE_FIELD(tableElts);
@@ -1159,7 +1159,7 @@ _equalCreateStmt(CreateStmt *a, CreateStmt *b)
 }
 
 static bool
-_equalInhRelation(InhRelation *a, InhRelation *b)
+_equalInhRelation(const InhRelation *a, const InhRelation *b)
 {
 	COMPARE_NODE_FIELD(relation);
 	COMPARE_SCALAR_FIELD(options);
@@ -1168,7 +1168,7 @@ _equalInhRelation(InhRelation *a, InhRelation *b)
 }
 
 static bool
-_equalDefineStmt(DefineStmt *a, DefineStmt *b)
+_equalDefineStmt(const DefineStmt *a, const DefineStmt *b)
 {
 	COMPARE_SCALAR_FIELD(kind);
 	COMPARE_SCALAR_FIELD(oldstyle);
@@ -1180,7 +1180,7 @@ _equalDefineStmt(DefineStmt *a, DefineStmt *b)
 }
 
 static bool
-_equalDropStmt(DropStmt *a, DropStmt *b)
+_equalDropStmt(const DropStmt *a, const DropStmt *b)
 {
 	COMPARE_NODE_FIELD(objects);
 	COMPARE_NODE_FIELD(arguments);
@@ -1192,7 +1192,7 @@ _equalDropStmt(DropStmt *a, DropStmt *b)
 }
 
 static bool
-_equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
+_equalTruncateStmt(const TruncateStmt *a, const TruncateStmt *b)
 {
 	COMPARE_NODE_FIELD(relations);
 	COMPARE_SCALAR_FIELD(restart_seqs);
@@ -1202,7 +1202,7 @@ _equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
 }
 
 static bool
-_equalCommentStmt(CommentStmt *a, CommentStmt *b)
+_equalCommentStmt(const CommentStmt *a, const CommentStmt *b)
 {
 	COMPARE_SCALAR_FIELD(objtype);
 	COMPARE_NODE_FIELD(objname);
@@ -1213,7 +1213,7 @@ _equalCommentStmt(CommentStmt *a, CommentStmt *b)
 }
 
 static bool
-_equalSecLabelStmt(SecLabelStmt *a, SecLabelStmt *b)
+_equalSecLabelStmt(const SecLabelStmt *a, const SecLabelStmt *b)
 {
 	COMPARE_SCALAR_FIELD(objtype);
 	COMPARE_NODE_FIELD(objname);
@@ -1225,7 +1225,7 @@ _equalSecLabelStmt(SecLabelStmt *a, SecLabelStmt *b)
 }
 
 static bool
-_equalFetchStmt(FetchStmt *a, FetchStmt *b)
+_equalFetchStmt(const FetchStmt *a, const FetchStmt *b)
 {
 	COMPARE_SCALAR_FIELD(direction);
 	COMPARE_SCALAR_FIELD(howMany);
@@ -1236,7 +1236,7 @@ _equalFetchStmt(FetchStmt *a, FetchStmt *b)
 }
 
 static bool
-_equalIndexStmt(IndexStmt *a, IndexStmt *b)
+_equalIndexStmt(const IndexStmt *a, const IndexStmt *b)
 {
 	COMPARE_STRING_FIELD(idxname);
 	COMPARE_NODE_FIELD(relation);
@@ -1259,7 +1259,7 @@ _equalIndexStmt(IndexStmt *a, IndexStmt *b)
 }
 
 static bool
-_equalCreateFunctionStmt(CreateFunctionStmt *a, CreateFunctionStmt *b)
+_equalCreateFunctionStmt(const CreateFunctionStmt *a, const CreateFunctionStmt *b)
 {
 	COMPARE_SCALAR_FIELD(replace);
 	COMPARE_NODE_FIELD(funcname);
@@ -1272,7 +1272,7 @@ _equalCreateFunctionStmt(CreateFunctionStmt *a, CreateFunctionStmt *b)
 }
 
 static bool
-_equalFunctionParameter(FunctionParameter *a, FunctionParameter *b)
+_equalFunctionParameter(const FunctionParameter *a, const FunctionParameter *b)
 {
 	COMPARE_STRING_FIELD(name);
 	COMPARE_NODE_FIELD(argType);
@@ -1283,7 +1283,7 @@ _equalFunctionParameter(FunctionParameter *a, FunctionParameter *b)
 }
 
 static bool
-_equalAlterFunctionStmt(AlterFunctionStmt *a, AlterFunctionStmt *b)
+_equalAlterFunctionStmt(const AlterFunctionStmt *a, const AlterFunctionStmt *b)
 {
 	COMPARE_NODE_FIELD(func);
 	COMPARE_NODE_FIELD(actions);
@@ -1292,7 +1292,7 @@ _equalAlterFunctionStmt(AlterFunctionStmt *a, AlterFunctionStmt *b)
 }
 
 static bool
-_equalDoStmt(DoStmt *a, DoStmt *b)
+_equalDoStmt(const DoStmt *a, const DoStmt *b)
 {
 	COMPARE_NODE_FIELD(args);
 
@@ -1300,7 +1300,7 @@ _equalDoStmt(DoStmt *a, DoStmt *b)
 }
 
 static bool
-_equalRenameStmt(RenameStmt *a, RenameStmt *b)
+_equalRenameStmt(const RenameStmt *a, const RenameStmt *b)
 {
 	COMPARE_SCALAR_FIELD(renameType);
 	COMPARE_NODE_FIELD(relation);
@@ -1314,7 +1314,7 @@ _equalRenameStmt(RenameStmt *a, RenameStmt *b)
 }
 
 static bool
-_equalAlterObjectSchemaStmt(AlterObjectSchemaStmt *a, AlterObjectSchemaStmt *b)
+_equalAlterObjectSchemaStmt(const AlterObjectSchemaStmt *a, const AlterObjectSchemaStmt *b)
 {
 	COMPARE_SCALAR_FIELD(objectType);
 	COMPARE_NODE_FIELD(relation);
@@ -1327,7 +1327,7 @@ _equalAlterObjectSchemaStmt(AlterObjectSchemaStmt *a, AlterObjectSchemaStmt *b)
 }
 
 static bool
-_equalAlterOwnerStmt(AlterOwnerStmt *a, AlterOwnerStmt *b)
+_equalAlterOwnerStmt(const AlterOwnerStmt *a, const AlterOwnerStmt *b)
 {
 	COMPARE_SCALAR_FIELD(objectType);
 	COMPARE_NODE_FIELD(relation);
@@ -1340,7 +1340,7 @@ _equalAlterOwnerStmt(AlterOwnerStmt *a, AlterOwnerStmt *b)
 }
 
 static bool
-_equalRuleStmt(RuleStmt *a, RuleStmt *b)
+_equalRuleStmt(const RuleStmt *a, const RuleStmt *b)
 {
 	COMPARE_NODE_FIELD(relation);
 	COMPARE_STRING_FIELD(rulename);
@@ -1354,7 +1354,7 @@ _equalRuleStmt(RuleStmt *a, RuleStmt *b)
 }
 
 static bool
-_equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
+_equalNotifyStmt(const NotifyStmt *a, const NotifyStmt *b)
 {
 	COMPARE_STRING_FIELD(conditionname);
 	COMPARE_STRING_FIELD(payload);
@@ -1363,7 +1363,7 @@ _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
 }
 
 static bool
-_equalListenStmt(ListenStmt *a, ListenStmt *b)
+_equalListenStmt(const ListenStmt *a, const ListenStmt *b)
 {
 	COMPARE_STRING_FIELD(conditionname);
 
@@ -1371,7 +1371,7 @@ _equalListenStmt(ListenStmt *a, ListenStmt *b)
 }
 
 static bool
-_equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
+_equalUnlistenStmt(const UnlistenStmt *a, const UnlistenStmt *b)
 {
 	COMPARE_STRING_FIELD(conditionname);
 
@@ -1379,7 +1379,7 @@ _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
 }
 
 static bool
-_equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
+_equalTransactionStmt(const TransactionStmt *a, const TransactionStmt *b)
 {
 	COMPARE_SCALAR_FIELD(kind);
 	COMPARE_NODE_FIELD(options);
@@ -1389,7 +1389,7 @@ _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
 }
 
 static bool
-_equalCompositeTypeStmt(CompositeTypeStmt *a, CompositeTypeStmt *b)
+_equalCompositeTypeStmt(const CompositeTypeStmt *a, const CompositeTypeStmt *b)
 {
 	COMPARE_NODE_FIELD(typevar);
 	COMPARE_NODE_FIELD(coldeflist);
@@ -1398,7 +1398,7 @@ _equalCompositeTypeStmt(CompositeTypeStmt *a, CompositeTypeStmt *b)
 }
 
 static bool
-_equalCreateEnumStmt(CreateEnumStmt *a, CreateEnumStmt *b)
+_equalCreateEnumStmt(const CreateEnumStmt *a, const CreateEnumStmt *b)
 {
 	COMPARE_NODE_FIELD(typeName);
 	COMPARE_NODE_FIELD(vals);
@@ -1407,7 +1407,7 @@ _equalCreateEnumStmt(CreateEnumStmt *a, CreateEnumStmt *b)
 }
 
 static bool
-_equalCreateRangeStmt(CreateRangeStmt *a, CreateRangeStmt *b)
+_equalCreateRangeStmt(const CreateRangeStmt *a, const CreateRangeStmt *b)
 {
 	COMPARE_NODE_FIELD(typeName);
 	COMPARE_NODE_FIELD(params);
@@ -1416,7 +1416,7 @@ _equalCreateRangeStmt(CreateRangeStmt *a, CreateRangeStmt *b)
 }
 
 static bool
-_equalAlterEnumStmt(AlterEnumStmt *a, AlterEnumStmt *b)
+_equalAlterEnumStmt(const AlterEnumStmt *a, const AlterEnumStmt *b)
 {
 	COMPARE_NODE_FIELD(typeName);
 	COMPARE_STRING_FIELD(newVal);
@@ -1427,7 +1427,7 @@ _equalAlterEnumStmt(AlterEnumStmt *a, AlterEnumStmt *b)
 }
 
 static bool
-_equalViewStmt(ViewStmt *a, ViewStmt *b)
+_equalViewStmt(const ViewStmt *a, const ViewStmt *b)
 {
 	COMPARE_NODE_FIELD(view);
 	COMPARE_NODE_FIELD(aliases);
@@ -1438,7 +1438,7 @@ _equalViewStmt(ViewStmt *a, ViewStmt *b)
 }
 
 static bool
-_equalLoadStmt(LoadStmt *a, LoadStmt *b)
+_equalLoadStmt(const LoadStmt *a, const LoadStmt *b)
 {
 	COMPARE_STRING_FIELD(filename);
 
@@ -1446,7 +1446,7 @@ _equalLoadStmt(LoadStmt *a, LoadStmt *b)
 }
 
 static bool
-_equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
+_equalCreateDomainStmt(const CreateDomainStmt *a, const CreateDomainStmt *b)
 {
 	COMPARE_NODE_FIELD(domainname);
 	COMPARE_NODE_FIELD(typeName);
@@ -1457,7 +1457,7 @@ _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
 }
 
 static bool
-_equalCreateOpClassStmt(CreateOpClassStmt *a, CreateOpClassStmt *b)
+_equalCreateOpClassStmt(const CreateOpClassStmt *a, const CreateOpClassStmt *b)
 {
 	COMPARE_NODE_FIELD(opclassname);
 	COMPARE_NODE_FIELD(opfamilyname);
@@ -1470,7 +1470,7 @@ _equalCreateOpClassStmt(CreateOpClassStmt *a, CreateOpClassStmt *b)
 }
 
 static bool
-_equalCreateOpClassItem(CreateOpClassItem *a, CreateOpClassItem *b)
+_equalCreateOpClassItem(const CreateOpClassItem *a, const CreateOpClassItem *b)
 {
 	COMPARE_SCALAR_FIELD(itemtype);
 	COMPARE_NODE_FIELD(name);
@@ -1484,7 +1484,7 @@ _equalCreateOpClassItem(CreateOpClassItem *a, CreateOpClassItem *b)
 }
 
 static bool
-_equalCreateOpFamilyStmt(CreateOpFamilyStmt *a, CreateOpFamilyStmt *b)
+_equalCreateOpFamilyStmt(const CreateOpFamilyStmt *a, const CreateOpFamilyStmt *b)
 {
 	COMPARE_NODE_FIELD(opfamilyname);
 	COMPARE_STRING_FIELD(amname);
@@ -1493,7 +1493,7 @@ _equalCreateOpFamilyStmt(CreateOpFamilyStmt *a, CreateOpFamilyStmt *b)
 }
 
 static bool
-_equalAlterOpFamilyStmt(AlterOpFamilyStmt *a, AlterOpFamilyStmt *b)
+_equalAlterOpFamilyStmt(const AlterOpFamilyStmt *a, const AlterOpFamilyStmt *b)
 {
 	COMPARE_NODE_FIELD(opfamilyname);
 	COMPARE_STRING_FIELD(amname);
@@ -1504,7 +1504,7 @@ _equalAlterOpFamilyStmt(AlterOpFamilyStmt *a, AlterOpFamilyStmt *b)
 }
 
 static bool
-_equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
+_equalCreatedbStmt(const CreatedbStmt *a, const CreatedbStmt *b)
 {
 	COMPARE_STRING_FIELD(dbname);
 	COMPARE_NODE_FIELD(options);
@@ -1513,7 +1513,7 @@ _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
 }
 
 static bool
-_equalAlterDatabaseStmt(AlterDatabaseStmt *a, AlterDatabaseStmt *b)
+_equalAlterDatabaseStmt(const AlterDatabaseStmt *a, const AlterDatabaseStmt *b)
 {
 	COMPARE_STRING_FIELD(dbname);
 	COMPARE_NODE_FIELD(options);
@@ -1522,7 +1522,7 @@ _equalAlterDatabaseStmt(AlterDatabaseStmt *a, AlterDatabaseStmt *b)
 }
 
 static bool
-_equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
+_equalAlterDatabaseSetStmt(const AlterDatabaseSetStmt *a, const AlterDatabaseSetStmt *b)
 {
 	COMPARE_STRING_FIELD(dbname);
 	COMPARE_NODE_FIELD(setstmt);
@@ -1531,7 +1531,7 @@ _equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
 }
 
 static bool
-_equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
+_equalDropdbStmt(const DropdbStmt *a, const DropdbStmt *b)
 {
 	COMPARE_STRING_FIELD(dbname);
 	COMPARE_SCALAR_FIELD(missing_ok);
@@ -1540,7 +1540,7 @@ _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
 }
 
 static bool
-_equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
+_equalVacuumStmt(const VacuumStmt *a, const VacuumStmt *b)
 {
 	COMPARE_SCALAR_FIELD(options);
 	COMPARE_SCALAR_FIELD(freeze_min_age);
@@ -1552,7 +1552,7 @@ _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
 }
 
 static bool
-_equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
+_equalExplainStmt(const ExplainStmt *a, const ExplainStmt *b)
 {
 	COMPARE_NODE_FIELD(query);
 	COMPARE_NODE_FIELD(options);
@@ -1561,7 +1561,7 @@ _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
 }
 
 static bool
-_equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
+_equalCreateSeqStmt(const CreateSeqStmt *a, const CreateSeqStmt *b)
 {
 	COMPARE_NODE_FIELD(sequence);
 	COMPARE_NODE_FIELD(options);
@@ -1571,7 +1571,7 @@ _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
 }
 
 static bool
-_equalAlterSeqStmt(AlterSeqStmt *a, AlterSeqStmt *b)
+_equalAlterSeqStmt(const AlterSeqStmt *a, const AlterSeqStmt *b)
 {
 	COMPARE_NODE_FIELD(sequence);
 	COMPARE_NODE_FIELD(options);
@@ -1580,7 +1580,7 @@ _equalAlterSeqStmt(AlterSeqStmt *a, AlterSeqStmt *b)
 }
 
 static bool
-_equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
+_equalVariableSetStmt(const VariableSetStmt *a, const VariableSetStmt *b)
 {
 	COMPARE_SCALAR_FIELD(kind);
 	COMPARE_STRING_FIELD(name);
@@ -1591,7 +1591,7 @@ _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
 }
 
 static bool
-_equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
+_equalVariableShowStmt(const VariableShowStmt *a, const VariableShowStmt *b)
 {
 	COMPARE_STRING_FIELD(name);
 
@@ -1599,7 +1599,7 @@ _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
 }
 
 static bool
-_equalDiscardStmt(DiscardStmt *a, DiscardStmt *b)
+_equalDiscardStmt(const DiscardStmt *a, const DiscardStmt *b)
 {
 	COMPARE_SCALAR_FIELD(target);
 
@@ -1607,7 +1607,7 @@ _equalDiscardStmt(DiscardStmt *a, DiscardStmt *b)
 }
 
 static bool
-_equalCreateTableSpaceStmt(CreateTableSpaceStmt *a, CreateTableSpaceStmt *b)
+_equalCreateTableSpaceStmt(const CreateTableSpaceStmt *a, const CreateTableSpaceStmt *b)
 {
 	COMPARE_STRING_FIELD(tablespacename);
 	COMPARE_STRING_FIELD(owner);
@@ -1617,7 +1617,7 @@ _equalCreateTableSpaceStmt(CreateTableSpaceStmt *a, CreateTableSpaceStmt *b)
 }
 
 static bool
-_equalDropTableSpaceStmt(DropTableSpaceStmt *a, DropTableSpaceStmt *b)
+_equalDropTableSpaceStmt(const DropTableSpaceStmt *a, const DropTableSpaceStmt *b)
 {
 	COMPARE_STRING_FIELD(tablespacename);
 	COMPARE_SCALAR_FIELD(missing_ok);
@@ -1626,8 +1626,8 @@ _equalDropTableSpaceStmt(DropTableSpaceStmt *a, DropTableSpaceStmt *b)
 }
 
 static bool
-_equalAlterTableSpaceOptionsStmt(AlterTableSpaceOptionsStmt *a,
-								 AlterTableSpaceOptionsStmt *b)
+_equalAlterTableSpaceOptionsStmt(const AlterTableSpaceOptionsStmt *a,
+								 const AlterTableSpaceOptionsStmt *b)
 {
 	COMPARE_STRING_FIELD(tablespacename);
 	COMPARE_NODE_FIELD(options);
@@ -1637,7 +1637,7 @@ _equalAlterTableSpaceOptionsStmt(AlterTableSpaceOptionsStmt *a,
 }
 
 static bool
-_equalCreateExtensionStmt(CreateExtensionStmt *a, CreateExtensionStmt *b)
+_equalCreateExtensionStmt(const CreateExtensionStmt *a, const CreateExtensionStmt *b)
 {
 	COMPARE_STRING_FIELD(extname);
 	COMPARE_SCALAR_FIELD(if_not_exists);
@@ -1647,7 +1647,7 @@ _equalCreateExtensionStmt(CreateExtensionStmt *a, CreateExtensionStmt *b)
 }
 
 static bool
-_equalAlterExtensionStmt(AlterExtensionStmt *a, AlterExtensionStmt *b)
+_equalAlterExtensionStmt(const AlterExtensionStmt *a, const AlterExtensionStmt *b)
 {
 	COMPARE_STRING_FIELD(extname);
 	COMPARE_NODE_FIELD(options);
@@ -1656,7 +1656,7 @@ _equalAlterExtensionStmt(AlterExtensionStmt *a, AlterExtensionStmt *b)
 }
 
 static bool
-_equalAlterExtensionContentsStmt(AlterExtensionContentsStmt *a, AlterExtensionContentsStmt *b)
+_equalAlterExtensionContentsStmt(const AlterExtensionContentsStmt *a, const AlterExtensionContentsStmt *b)
 {
 	COMPARE_STRING_FIELD(extname);
 	COMPARE_SCALAR_FIELD(action);
@@ -1668,7 +1668,7 @@ _equalAlterExtensionContentsStmt(AlterExtensionContentsStmt *a, AlterExtensionCo
 }
 
 static bool
-_equalCreateFdwStmt(CreateFdwStmt *a, CreateFdwStmt *b)
+_equalCreateFdwStmt(const CreateFdwStmt *a, const CreateFdwStmt *b)
 {
 	COMPARE_STRING_FIELD(fdwname);
 	COMPARE_NODE_FIELD(func_options);
@@ -1678,7 +1678,7 @@ _equalCreateFdwStmt(CreateFdwStmt *a, CreateFdwStmt *b)
 }
 
 static bool
-_equalAlterFdwStmt(AlterFdwStmt *a, AlterFdwStmt *b)
+_equalAlterFdwStmt(const AlterFdwStmt *a, const AlterFdwStmt *b)
 {
 	COMPARE_STRING_FIELD(fdwname);
 	COMPARE_NODE_FIELD(func_options);
@@ -1688,7 +1688,7 @@ _equalAlterFdwStmt(AlterFdwStmt *a, AlterFdwStmt *b)
 }
 
 static bool
-_equalCreateForeignServerStmt(CreateForeignServerStmt *a, CreateForeignServerStmt *b)
+_equalCreateForeignServerStmt(const CreateForeignServerStmt *a, const CreateForeignServerStmt *b)
 {
 	COMPARE_STRING_FIELD(servername);
 	COMPARE_STRING_FIELD(servertype);
@@ -1700,7 +1700,7 @@ _equalCreateForeignServerStmt(CreateForeignServerStmt *a, CreateForeignServerStm
 }
 
 static bool
-_equalAlterForeignServerStmt(AlterForeignServerStmt *a, AlterForeignServerStmt *b)
+_equalAlterForeignServerStmt(const AlterForeignServerStmt *a, const AlterForeignServerStmt *b)
 {
 	COMPARE_STRING_FIELD(servername);
 	COMPARE_STRING_FIELD(version);
@@ -1711,7 +1711,7 @@ _equalAlterForeignServerStmt(AlterForeignServerStmt *a, AlterForeignServerStmt *
 }
 
 static bool
-_equalCreateUserMappingStmt(CreateUserMappingStmt *a, CreateUserMappingStmt *b)
+_equalCreateUserMappingStmt(const CreateUserMappingStmt *a, const CreateUserMappingStmt *b)
 {
 	COMPARE_STRING_FIELD(username);
 	COMPARE_STRING_FIELD(servername);
@@ -1721,7 +1721,7 @@ _equalCreateUserMappingStmt(CreateUserMappingStmt *a, CreateUserMappingStmt *b)
 }
 
 static bool
-_equalAlterUserMappingStmt(AlterUserMappingStmt *a, AlterUserMappingStmt *b)
+_equalAlterUserMappingStmt(const AlterUserMappingStmt *a, const AlterUserMappingStmt *b)
 {
 	COMPARE_STRING_FIELD(username);
 	COMPARE_STRING_FIELD(servername);
@@ -1731,7 +1731,7 @@ _equalAlterUserMappingStmt(AlterUserMappingStmt *a, AlterUserMappingStmt *b)
 }
 
 static bool
-_equalDropUserMappingStmt(DropUserMappingStmt *a, DropUserMappingStmt *b)
+_equalDropUserMappingStmt(const DropUserMappingStmt *a, const DropUserMappingStmt *b)
 {
 	COMPARE_STRING_FIELD(username);
 	COMPARE_STRING_FIELD(servername);
@@ -1741,7 +1741,7 @@ _equalDropUserMappingStmt(DropUserMappingStmt *a, DropUserMappingStmt *b)
 }
 
 static bool
-_equalCreateForeignTableStmt(CreateForeignTableStmt *a, CreateForeignTableStmt *b)
+_equalCreateForeignTableStmt(const CreateForeignTableStmt *a, const CreateForeignTableStmt *b)
 {
 	if (!_equalCreateStmt(&a->base, &b->base))
 		return false;
@@ -1753,7 +1753,7 @@ _equalCreateForeignTableStmt(CreateForeignTableStmt *a, CreateForeignTableStmt *
 }
 
 static bool
-_equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
+_equalCreateTrigStmt(const CreateTrigStmt *a, const CreateTrigStmt *b)
 {
 	COMPARE_STRING_FIELD(trigname);
 	COMPARE_NODE_FIELD(relation);
@@ -1773,7 +1773,7 @@ _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
 }
 
 static bool
-_equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
+_equalCreatePLangStmt(const CreatePLangStmt *a, const CreatePLangStmt *b)
 {
 	COMPARE_SCALAR_FIELD(replace);
 	COMPARE_STRING_FIELD(plname);
@@ -1786,7 +1786,7 @@ _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
 }
 
 static bool
-_equalCreateRoleStmt(CreateRoleStmt *a, CreateRoleStmt *b)
+_equalCreateRoleStmt(const CreateRoleStmt *a, const CreateRoleStmt *b)
 {
 	COMPARE_SCALAR_FIELD(stmt_type);
 	COMPARE_STRING_FIELD(role);
@@ -1796,7 +1796,7 @@ _equalCreateRoleStmt(CreateRoleStmt *a, CreateRoleStmt *b)
 }
 
 static bool
-_equalAlterRoleStmt(AlterRoleStmt *a, AlterRoleStmt *b)
+_equalAlterRoleStmt(const AlterRoleStmt *a, const AlterRoleStmt *b)
 {
 	COMPARE_STRING_FIELD(role);
 	COMPARE_NODE_FIELD(options);
@@ -1806,7 +1806,7 @@ _equalAlterRoleStmt(AlterRoleStmt *a, AlterRoleStmt *b)
 }
 
 static bool
-_equalAlterRoleSetStmt(AlterRoleSetStmt *a, AlterRoleSetStmt *b)
+_equalAlterRoleSetStmt(const AlterRoleSetStmt *a, const AlterRoleSetStmt *b)
 {
 	COMPARE_STRING_FIELD(role);
 	COMPARE_STRING_FIELD(database);
@@ -1816,7 +1816,7 @@ _equalAlterRoleSetStmt(AlterRoleSetStmt *a, AlterRoleSetStmt *b)
 }
 
 static bool
-_equalDropRoleStmt(DropRoleStmt *a, DropRoleStmt *b)
+_equalDropRoleStmt(const DropRoleStmt *a, const DropRoleStmt *b)
 {
 	COMPARE_NODE_FIELD(roles);
 	COMPARE_SCALAR_FIELD(missing_ok);
@@ -1825,7 +1825,7 @@ _equalDropRoleStmt(DropRoleStmt *a, DropRoleStmt *b)
 }
 
 static bool
-_equalLockStmt(LockStmt *a, LockStmt *b)
+_equalLockStmt(const LockStmt *a, const LockStmt *b)
 {
 	COMPARE_NODE_FIELD(relations);
 	COMPARE_SCALAR_FIELD(mode);
@@ -1835,7 +1835,7 @@ _equalLockStmt(LockStmt *a, LockStmt *b)
 }
 
 static bool
-_equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
+_equalConstraintsSetStmt(const ConstraintsSetStmt *a, const ConstraintsSetStmt *b)
 {
 	COMPARE_NODE_FIELD(constraints);
 	COMPARE_SCALAR_FIELD(deferred);
@@ -1844,7 +1844,7 @@ _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
 }
 
 static bool
-_equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
+_equalReindexStmt(const ReindexStmt *a, const ReindexStmt *b)
 {
 	COMPARE_SCALAR_FIELD(kind);
 	COMPARE_NODE_FIELD(relation);
@@ -1856,7 +1856,7 @@ _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
 }
 
 static bool
-_equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
+_equalCreateSchemaStmt(const CreateSchemaStmt *a, const CreateSchemaStmt *b)
 {
 	COMPARE_STRING_FIELD(schemaname);
 	COMPARE_STRING_FIELD(authid);
@@ -1866,7 +1866,7 @@ _equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
 }
 
 static bool
-_equalCreateConversionStmt(CreateConversionStmt *a, CreateConversionStmt *b)
+_equalCreateConversionStmt(const CreateConversionStmt *a, const CreateConversionStmt *b)
 {
 	COMPARE_NODE_FIELD(conversion_name);
 	COMPARE_STRING_FIELD(for_encoding_name);
@@ -1878,7 +1878,7 @@ _equalCreateConversionStmt(CreateConversionStmt *a, CreateConversionStmt *b)
 }
 
 static bool
-_equalCreateCastStmt(CreateCastStmt *a, CreateCastStmt *b)
+_equalCreateCastStmt(const CreateCastStmt *a, const CreateCastStmt *b)
 {
 	COMPARE_NODE_FIELD(sourcetype);
 	COMPARE_NODE_FIELD(targettype);
@@ -1890,7 +1890,7 @@ _equalCreateCastStmt(CreateCastStmt *a, CreateCastStmt *b)
 }
 
 static bool
-_equalPrepareStmt(PrepareStmt *a, PrepareStmt *b)
+_equalPrepareStmt(const PrepareStmt *a, const PrepareStmt *b)
 {
 	COMPARE_STRING_FIELD(name);
 	COMPARE_NODE_FIELD(argtypes);
@@ -1900,7 +1900,7 @@ _equalPrepareStmt(PrepareStmt *a, PrepareStmt *b)
 }
 
 static bool
-_equalExecuteStmt(ExecuteStmt *a, ExecuteStmt *b)
+_equalExecuteStmt(const ExecuteStmt *a, const ExecuteStmt *b)
 {
 	COMPARE_STRING_FIELD(name);
 	COMPARE_NODE_FIELD(into);
@@ -1910,7 +1910,7 @@ _equalExecuteStmt(ExecuteStmt *a, ExecuteStmt *b)
 }
 
 static bool
-_equalDeallocateStmt(DeallocateStmt *a, DeallocateStmt *b)
+_equalDeallocateStmt(const DeallocateStmt *a, const DeallocateStmt *b)
 {
 	COMPARE_STRING_FIELD(name);
 
@@ -1918,7 +1918,7 @@ _equalDeallocateStmt(DeallocateStmt *a, DeallocateStmt *b)
 }
 
 static bool
-_equalDropOwnedStmt(DropOwnedStmt *a, DropOwnedStmt *b)
+_equalDropOwnedStmt(const DropOwnedStmt *a, const DropOwnedStmt *b)
 {
 	COMPARE_NODE_FIELD(roles);
 	COMPARE_SCALAR_FIELD(behavior);
@@ -1927,7 +1927,7 @@ _equalDropOwnedStmt(DropOwnedStmt *a, DropOwnedStmt *b)
 }
 
 static bool
-_equalReassignOwnedStmt(ReassignOwnedStmt *a, ReassignOwnedStmt *b)
+_equalReassignOwnedStmt(const ReassignOwnedStmt *a, const ReassignOwnedStmt *b)
 {
 	COMPARE_NODE_FIELD(roles);
 	COMPARE_NODE_FIELD(newrole);
@@ -1936,7 +1936,7 @@ _equalReassignOwnedStmt(ReassignOwnedStmt *a, ReassignOwnedStmt *b)
 }
 
 static bool
-_equalAlterTSDictionaryStmt(AlterTSDictionaryStmt *a, AlterTSDictionaryStmt *b)
+_equalAlterTSDictionaryStmt(const AlterTSDictionaryStmt *a, const AlterTSDictionaryStmt *b)
 {
 	COMPARE_NODE_FIELD(dictname);
 	COMPARE_NODE_FIELD(options);
@@ -1945,8 +1945,8 @@ _equalAlterTSDictionaryStmt(AlterTSDictionaryStmt *a, AlterTSDictionaryStmt *b)
 }
 
 static bool
-_equalAlterTSConfigurationStmt(AlterTSConfigurationStmt *a,
-							   AlterTSConfigurationStmt *b)
+_equalAlterTSConfigurationStmt(const AlterTSConfigurationStmt *a,
+							   const AlterTSConfigurationStmt *b)
 {
 	COMPARE_NODE_FIELD(cfgname);
 	COMPARE_NODE_FIELD(tokentype);
@@ -1959,7 +1959,7 @@ _equalAlterTSConfigurationStmt(AlterTSConfigurationStmt *a,
 }
 
 static bool
-_equalAExpr(A_Expr *a, A_Expr *b)
+_equalAExpr(const A_Expr *a, const A_Expr *b)
 {
 	COMPARE_SCALAR_FIELD(kind);
 	COMPARE_NODE_FIELD(name);
@@ -1971,7 +1971,7 @@ _equalAExpr(A_Expr *a, A_Expr *b)
 }
 
 static bool
-_equalColumnRef(ColumnRef *a, ColumnRef *b)
+_equalColumnRef(const ColumnRef *a, const ColumnRef *b)
 {
 	COMPARE_NODE_FIELD(fields);
 	COMPARE_LOCATION_FIELD(location);
@@ -1980,7 +1980,7 @@ _equalColumnRef(ColumnRef *a, ColumnRef *b)
 }
 
 static bool
-_equalParamRef(ParamRef *a, ParamRef *b)
+_equalParamRef(const ParamRef *a, const ParamRef *b)
 {
 	COMPARE_SCALAR_FIELD(number);
 	COMPARE_LOCATION_FIELD(location);
@@ -1989,7 +1989,7 @@ _equalParamRef(ParamRef *a, ParamRef *b)
 }
 
 static bool
-_equalAConst(A_Const *a, A_Const *b)
+_equalAConst(const A_Const *a, const A_Const *b)
 {
 	if (!equal(&a->val, &b->val))		/* hack for in-line Value field */
 		return false;
@@ -1999,7 +1999,7 @@ _equalAConst(A_Const *a, A_Const *b)
 }
 
 static bool
-_equalFuncCall(FuncCall *a, FuncCall *b)
+_equalFuncCall(const FuncCall *a, const FuncCall *b)
 {
 	COMPARE_NODE_FIELD(funcname);
 	COMPARE_NODE_FIELD(args);
@@ -2014,13 +2014,13 @@ _equalFuncCall(FuncCall *a, FuncCall *b)
 }
 
 static bool
-_equalAStar(A_Star *a, A_Star *b)
+_equalAStar(const A_Star *a, const A_Star *b)
 {
 	return true;
 }
 
 static bool
-_equalAIndices(A_Indices *a, A_Indices *b)
+_equalAIndices(const A_Indices *a, const A_Indices *b)
 {
 	COMPARE_NODE_FIELD(lidx);
 	COMPARE_NODE_FIELD(uidx);
@@ -2029,7 +2029,7 @@ _equalAIndices(A_Indices *a, A_Indices *b)
 }
 
 static bool
-_equalA_Indirection(A_Indirection *a, A_Indirection *b)
+_equalA_Indirection(const A_Indirection *a, const A_Indirection *b)
 {
 	COMPARE_NODE_FIELD(arg);
 	COMPARE_NODE_FIELD(indirection);
@@ -2038,7 +2038,7 @@ _equalA_Indirection(A_Indirection *a, A_Indirection *b)
 }
 
 static bool
-_equalA_ArrayExpr(A_ArrayExpr *a, A_ArrayExpr *b)
+_equalA_ArrayExpr(const A_ArrayExpr *a, const A_ArrayExpr *b)
 {
 	COMPARE_NODE_FIELD(elements);
 	COMPARE_LOCATION_FIELD(location);
@@ -2047,7 +2047,7 @@ _equalA_ArrayExpr(A_ArrayExpr *a, A_ArrayExpr *b)
 }
 
 static bool
-_equalResTarget(ResTarget *a, ResTarget *b)
+_equalResTarget(const ResTarget *a, const ResTarget *b)
 {
 	COMPARE_STRING_FIELD(name);
 	COMPARE_NODE_FIELD(indirection);
@@ -2058,7 +2058,7 @@ _equalResTarget(ResTarget *a, ResTarget *b)
 }
 
 static bool
-_equalTypeName(TypeName *a, TypeName *b)
+_equalTypeName(const TypeName *a, const TypeName *b)
 {
 	COMPARE_NODE_FIELD(names);
 	COMPARE_SCALAR_FIELD(typeOid);
@@ -2073,7 +2073,7 @@ _equalTypeName(TypeName *a, TypeName *b)
 }
 
 static bool
-_equalTypeCast(TypeCast *a, TypeCast *b)
+_equalTypeCast(const TypeCast *a, const TypeCast *b)
 {
 	COMPARE_NODE_FIELD(arg);
 	COMPARE_NODE_FIELD(typeName);
@@ -2083,7 +2083,7 @@ _equalTypeCast(TypeCast *a, TypeCast *b)
 }
 
 static bool
-_equalCollateClause(CollateClause *a, CollateClause *b)
+_equalCollateClause(const CollateClause *a, const CollateClause *b)
 {
 	COMPARE_NODE_FIELD(arg);
 	COMPARE_NODE_FIELD(collname);
@@ -2093,7 +2093,7 @@ _equalCollateClause(CollateClause *a, CollateClause *b)
 }
 
 static bool
-_equalSortBy(SortBy *a, SortBy *b)
+_equalSortBy(const SortBy *a, const SortBy *b)
 {
 	COMPARE_NODE_FIELD(node);
 	COMPARE_SCALAR_FIELD(sortby_dir);
@@ -2105,7 +2105,7 @@ _equalSortBy(SortBy *a, SortBy *b)
 }
 
 static bool
-_equalWindowDef(WindowDef *a, WindowDef *b)
+_equalWindowDef(const WindowDef *a, const WindowDef *b)
 {
 	COMPARE_STRING_FIELD(name);
 	COMPARE_STRING_FIELD(refname);
@@ -2120,7 +2120,7 @@ _equalWindowDef(WindowDef *a, WindowDef *b)
 }
 
 static bool
-_equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
+_equalRangeSubselect(const RangeSubselect *a, const RangeSubselect *b)
 {
 	COMPARE_NODE_FIELD(subquery);
 	COMPARE_NODE_FIELD(alias);
@@ -2129,7 +2129,7 @@ _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
 }
 
 static bool
-_equalRangeFunction(RangeFunction *a, RangeFunction *b)
+_equalRangeFunction(const RangeFunction *a, const RangeFunction *b)
 {
 	COMPARE_NODE_FIELD(funccallnode);
 	COMPARE_NODE_FIELD(alias);
@@ -2139,7 +2139,7 @@ _equalRangeFunction(RangeFunction *a, RangeFunction *b)
 }
 
 static bool
-_equalIndexElem(IndexElem *a, IndexElem *b)
+_equalIndexElem(const IndexElem *a, const IndexElem *b)
 {
 	COMPARE_STRING_FIELD(name);
 	COMPARE_NODE_FIELD(expr);
@@ -2153,7 +2153,7 @@ _equalIndexElem(IndexElem *a, IndexElem *b)
 }
 
 static bool
-_equalColumnDef(ColumnDef *a, ColumnDef *b)
+_equalColumnDef(const ColumnDef *a, const ColumnDef *b)
 {
 	COMPARE_STRING_FIELD(colname);
 	COMPARE_NODE_FIELD(typeName);
@@ -2172,7 +2172,7 @@ _equalColumnDef(ColumnDef *a, ColumnDef *b)
 }
 
 static bool
-_equalConstraint(Constraint *a, Constraint *b)
+_equalConstraint(const Constraint *a, const Constraint *b)
 {
 	COMPARE_SCALAR_FIELD(contype);
 	COMPARE_STRING_FIELD(conname);
@@ -2201,7 +2201,7 @@ _equalConstraint(Constraint *a, Constraint *b)
 }
 
 static bool
-_equalDefElem(DefElem *a, DefElem *b)
+_equalDefElem(const DefElem *a, const DefElem *b)
 {
 	COMPARE_STRING_FIELD(defnamespace);
 	COMPARE_STRING_FIELD(defname);
@@ -2212,7 +2212,7 @@ _equalDefElem(DefElem *a, DefElem *b)
 }
 
 static bool
-_equalLockingClause(LockingClause *a, LockingClause *b)
+_equalLockingClause(const LockingClause *a, const LockingClause *b)
 {
 	COMPARE_NODE_FIELD(lockedRels);
 	COMPARE_SCALAR_FIELD(forUpdate);
@@ -2222,7 +2222,7 @@ _equalLockingClause(LockingClause *a, LockingClause *b)
 }
 
 static bool
-_equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
+_equalRangeTblEntry(const RangeTblEntry *a, const RangeTblEntry *b)
 {
 	COMPARE_SCALAR_FIELD(rtekind);
 	COMPARE_SCALAR_FIELD(relid);
@@ -2255,7 +2255,7 @@ _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
 }
 
 static bool
-_equalSortGroupClause(SortGroupClause *a, SortGroupClause *b)
+_equalSortGroupClause(const SortGroupClause *a, const SortGroupClause *b)
 {
 	COMPARE_SCALAR_FIELD(tleSortGroupRef);
 	COMPARE_SCALAR_FIELD(eqop);
@@ -2267,7 +2267,7 @@ _equalSortGroupClause(SortGroupClause *a, SortGroupClause *b)
 }
 
 static bool
-_equalWindowClause(WindowClause *a, WindowClause *b)
+_equalWindowClause(const WindowClause *a, const WindowClause *b)
 {
 	COMPARE_STRING_FIELD(name);
 	COMPARE_STRING_FIELD(refname);
@@ -2283,7 +2283,7 @@ _equalWindowClause(WindowClause *a, WindowClause *b)
 }
 
 static bool
-_equalRowMarkClause(RowMarkClause *a, RowMarkClause *b)
+_equalRowMarkClause(const RowMarkClause *a, const RowMarkClause *b)
 {
 	COMPARE_SCALAR_FIELD(rti);
 	COMPARE_SCALAR_FIELD(forUpdate);
@@ -2294,7 +2294,7 @@ _equalRowMarkClause(RowMarkClause *a, RowMarkClause *b)
 }
 
 static bool
-_equalWithClause(WithClause *a, WithClause *b)
+_equalWithClause(const WithClause *a, const WithClause *b)
 {
 	COMPARE_NODE_FIELD(ctes);
 	COMPARE_SCALAR_FIELD(recursive);
@@ -2304,7 +2304,7 @@ _equalWithClause(WithClause *a, WithClause *b)
 }
 
 static bool
-_equalCommonTableExpr(CommonTableExpr *a, CommonTableExpr *b)
+_equalCommonTableExpr(const CommonTableExpr *a, const CommonTableExpr *b)
 {
 	COMPARE_STRING_FIELD(ctename);
 	COMPARE_NODE_FIELD(aliascolnames);
@@ -2321,7 +2321,7 @@ _equalCommonTableExpr(CommonTableExpr *a, CommonTableExpr *b)
 }
 
 static bool
-_equalXmlSerialize(XmlSerialize *a, XmlSerialize *b)
+_equalXmlSerialize(const XmlSerialize *a, const XmlSerialize *b)
 {
 	COMPARE_SCALAR_FIELD(xmloption);
 	COMPARE_NODE_FIELD(expr);
@@ -2336,10 +2336,10 @@ _equalXmlSerialize(XmlSerialize *a, XmlSerialize *b)
  */
 
 static bool
-_equalList(List *a, List *b)
+_equalList(const List *a, const List *b)
 {
-	ListCell   *item_a;
-	ListCell   *item_b;
+	const ListCell   *item_a;
+	const ListCell   *item_b;
 
 	/*
 	 * Try to reject by simple scalar checks before grovelling through all the
@@ -2395,7 +2395,7 @@ _equalList(List *a, List *b)
  */
 
 static bool
-_equalValue(Value *a, Value *b)
+_equalValue(const Value *a, const Value *b)
 {
 	COMPARE_SCALAR_FIELD(type);
 
@@ -2425,7 +2425,7 @@ _equalValue(Value *a, Value *b)
  *	  returns whether two nodes are equal
  */
 bool
-equal(void *a, void *b)
+equal(const void *a, const void *b)
 {
 	bool		retval;
 
diff --git a/src/backend/nodes/list.c b/src/backend/nodes/list.c
index d4684d3cc82..add172ec777 100644
--- a/src/backend/nodes/list.c
+++ b/src/backend/nodes/list.c
@@ -31,7 +31,7 @@
  * Check that the specified List is valid (so far as we can tell).
  */
 static void
-check_list_invariants(List *list)
+check_list_invariants(const List *list)
 {
 	if (list == NIL)
 		return;
@@ -383,7 +383,7 @@ list_truncate(List *list, int new_size)
  * failure if there is no such cell.
  */
 static ListCell *
-list_nth_cell(List *list, int n)
+list_nth_cell(const List *list, int n)
 {
 	ListCell   *match;
 
@@ -407,7 +407,7 @@ list_nth_cell(List *list, int n)
  * specified list. (List elements begin at 0.)
  */
 void *
-list_nth(List *list, int n)
+list_nth(const List *list, int n)
 {
 	Assert(IsPointerList(list));
 	return lfirst(list_nth_cell(list, n));
@@ -418,7 +418,7 @@ list_nth(List *list, int n)
  * specified list.
  */
 int
-list_nth_int(List *list, int n)
+list_nth_int(const List *list, int n)
 {
 	Assert(IsIntegerList(list));
 	return lfirst_int(list_nth_cell(list, n));
@@ -429,7 +429,7 @@ list_nth_int(List *list, int n)
  * list.
  */
 Oid
-list_nth_oid(List *list, int n)
+list_nth_oid(const List *list, int n)
 {
 	Assert(IsOidList(list));
 	return lfirst_oid(list_nth_cell(list, n));
@@ -441,9 +441,9 @@ list_nth_oid(List *list, int n)
  * Node as 'datum'.
  */
 bool
-list_member(List *list, void *datum)
+list_member(const List *list, const void *datum)
 {
-	ListCell   *cell;
+	const ListCell   *cell;
 
 	Assert(IsPointerList(list));
 	check_list_invariants(list);
@@ -462,9 +462,9 @@ list_member(List *list, void *datum)
  * determined by using simple pointer comparison.
  */
 bool
-list_member_ptr(List *list, void *datum)
+list_member_ptr(const List *list, const void *datum)
 {
-	ListCell   *cell;
+	const ListCell   *cell;
 
 	Assert(IsPointerList(list));
 	check_list_invariants(list);
@@ -482,9 +482,9 @@ list_member_ptr(List *list, void *datum)
  * Return true iff the integer 'datum' is a member of the list.
  */
 bool
-list_member_int(List *list, int datum)
+list_member_int(const List *list, int datum)
 {
-	ListCell   *cell;
+	const ListCell   *cell;
 
 	Assert(IsIntegerList(list));
 	check_list_invariants(list);
@@ -502,9 +502,9 @@ list_member_int(List *list, int datum)
  * Return true iff the OID 'datum' is a member of the list.
  */
 bool
-list_member_oid(List *list, Oid datum)
+list_member_oid(const List *list, Oid datum)
 {
-	ListCell   *cell;
+	const ListCell   *cell;
 
 	Assert(IsOidList(list));
 	check_list_invariants(list);
@@ -694,10 +694,10 @@ list_delete_first(List *list)
  * performance bottleneck.
  */
 List *
-list_union(List *list1, List *list2)
+list_union(const List *list1, const List *list2)
 {
 	List	   *result;
-	ListCell   *cell;
+	const ListCell   *cell;
 
 	Assert(IsPointerList(list1));
 	Assert(IsPointerList(list2));
@@ -718,10 +718,10 @@ list_union(List *list1, List *list2)
  * pointer comparison.
  */
 List *
-list_union_ptr(List *list1, List *list2)
+list_union_ptr(const List *list1, const List *list2)
 {
 	List	   *result;
-	ListCell   *cell;
+	const ListCell   *cell;
 
 	Assert(IsPointerList(list1));
 	Assert(IsPointerList(list2));
@@ -741,10 +741,10 @@ list_union_ptr(List *list1, List *list2)
  * This variant of list_union() operates upon lists of integers.
  */
 List *
-list_union_int(List *list1, List *list2)
+list_union_int(const List *list1, const List *list2)
 {
 	List	   *result;
-	ListCell   *cell;
+	const ListCell   *cell;
 
 	Assert(IsIntegerList(list1));
 	Assert(IsIntegerList(list2));
@@ -764,10 +764,10 @@ list_union_int(List *list1, List *list2)
  * This variant of list_union() operates upon lists of OIDs.
  */
 List *
-list_union_oid(List *list1, List *list2)
+list_union_oid(const List *list1, const List *list2)
 {
 	List	   *result;
-	ListCell   *cell;
+	const ListCell   *cell;
 
 	Assert(IsOidList(list1));
 	Assert(IsOidList(list2));
@@ -797,10 +797,10 @@ list_union_oid(List *list1, List *list2)
  * to in the result.
  */
 List *
-list_intersection(List *list1, List *list2)
+list_intersection(const List *list1, const List *list2)
 {
 	List	   *result;
-	ListCell   *cell;
+	const ListCell   *cell;
 
 	if (list1 == NIL || list2 == NIL)
 		return NIL;
@@ -829,9 +829,9 @@ list_intersection(List *list1, List *list2)
  * membership via equal()
  */
 List *
-list_difference(List *list1, List *list2)
+list_difference(const List *list1, const List *list2)
 {
-	ListCell   *cell;
+	const ListCell   *cell;
 	List	   *result = NIL;
 
 	Assert(IsPointerList(list1));
@@ -855,9 +855,9 @@ list_difference(List *list1, List *list2)
  * simple pointer equality.
  */
 List *
-list_difference_ptr(List *list1, List *list2)
+list_difference_ptr(const List *list1, const List *list2)
 {
-	ListCell   *cell;
+	const ListCell   *cell;
 	List	   *result = NIL;
 
 	Assert(IsPointerList(list1));
@@ -880,9 +880,9 @@ list_difference_ptr(List *list1, List *list2)
  * This variant of list_difference() operates upon lists of integers.
  */
 List *
-list_difference_int(List *list1, List *list2)
+list_difference_int(const List *list1, const List *list2)
 {
-	ListCell   *cell;
+	const ListCell   *cell;
 	List	   *result = NIL;
 
 	Assert(IsIntegerList(list1));
@@ -905,9 +905,9 @@ list_difference_int(List *list1, List *list2)
  * This variant of list_difference() operates upon lists of OIDs.
  */
 List *
-list_difference_oid(List *list1, List *list2)
+list_difference_oid(const List *list1, const List *list2)
 {
-	ListCell   *cell;
+	const ListCell   *cell;
 	List	   *result = NIL;
 
 	Assert(IsOidList(list1));
@@ -1131,7 +1131,7 @@ list_free_deep(List *list)
  * Return a shallow copy of the specified list.
  */
 List *
-list_copy(List *oldlist)
+list_copy(const List *oldlist)
 {
 	List	   *newlist;
 	ListCell   *newlist_prev;
@@ -1174,7 +1174,7 @@ list_copy(List *oldlist)
  * Return a shallow copy of the specified list, without the first N elements.
  */
 List *
-list_copy_tail(List *oldlist, int nskip)
+list_copy_tail(const List *oldlist, int nskip)
 {
 	List	   *newlist;
 	ListCell   *newlist_prev;
@@ -1230,7 +1230,7 @@ list_copy_tail(List *oldlist, int nskip)
 #ifndef USE_INLINE
 
 ListCell *
-list_head(List *l)
+list_head(const List *l)
 {
 	return l ? l->head : NULL;
 }
@@ -1242,7 +1242,7 @@ list_tail(List *l)
 }
 
 int
-list_length(List *l)
+list_length(const List *l)
 {
 	return l ? l->length : 0;
 }
@@ -1264,10 +1264,10 @@ list_length(List *l)
  * list_length() macro in order to avoid the overhead of a function
  * call.
  */
-int			length(List *list);
+int			length(const List *list);
 
 int
-length(List *list)
+length(const List *list)
 {
 	return list_length(list);
 }
diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c
index 0e57f6c6d7d..48b05902152 100644
--- a/src/backend/nodes/nodeFuncs.c
+++ b/src/backend/nodes/nodeFuncs.c
@@ -32,7 +32,7 @@ static int	leftmostLoc(int loc1, int loc2);
  *	  returns the Oid of the type of the expression's result.
  */
 Oid
-exprType(Node *expr)
+exprType(const Node *expr)
 {
 	Oid			type;
 
@@ -42,23 +42,23 @@ exprType(Node *expr)
 	switch (nodeTag(expr))
 	{
 		case T_Var:
-			type = ((Var *) expr)->vartype;
+			type = ((const Var *) expr)->vartype;
 			break;
 		case T_Const:
-			type = ((Const *) expr)->consttype;
+			type = ((const Const *) expr)->consttype;
 			break;
 		case T_Param:
-			type = ((Param *) expr)->paramtype;
+			type = ((const Param *) expr)->paramtype;
 			break;
 		case T_Aggref:
-			type = ((Aggref *) expr)->aggtype;
+			type = ((const Aggref *) expr)->aggtype;
 			break;
 		case T_WindowFunc:
-			type = ((WindowFunc *) expr)->wintype;
+			type = ((const WindowFunc *) expr)->wintype;
 			break;
 		case T_ArrayRef:
 			{
-				ArrayRef   *arrayref = (ArrayRef *) expr;
+				const ArrayRef   *arrayref = (const ArrayRef *) expr;
 
 				/* slice and/or store operations yield the array type */
 				if (arrayref->reflowerindexpr || arrayref->refassgnexpr)
@@ -68,19 +68,19 @@ exprType(Node *expr)
 			}
 			break;
 		case T_FuncExpr:
-			type = ((FuncExpr *) expr)->funcresulttype;
+			type = ((const FuncExpr *) expr)->funcresulttype;
 			break;
 		case T_NamedArgExpr:
-			type = exprType((Node *) ((NamedArgExpr *) expr)->arg);
+			type = exprType((Node *) ((const NamedArgExpr *) expr)->arg);
 			break;
 		case T_OpExpr:
-			type = ((OpExpr *) expr)->opresulttype;
+			type = ((const OpExpr *) expr)->opresulttype;
 			break;
 		case T_DistinctExpr:
-			type = ((DistinctExpr *) expr)->opresulttype;
+			type = ((const DistinctExpr *) expr)->opresulttype;
 			break;
 		case T_NullIfExpr:
-			type = ((NullIfExpr *) expr)->opresulttype;
+			type = ((const NullIfExpr *) expr)->opresulttype;
 			break;
 		case T_ScalarArrayOpExpr:
 			type = BOOLOID;
@@ -90,7 +90,7 @@ exprType(Node *expr)
 			break;
 		case T_SubLink:
 			{
-				SubLink    *sublink = (SubLink *) expr;
+				const SubLink    *sublink = (const SubLink *) expr;
 
 				if (sublink->subLinkType == EXPR_SUBLINK ||
 					sublink->subLinkType == ARRAY_SUBLINK)
@@ -124,7 +124,7 @@ exprType(Node *expr)
 			break;
 		case T_SubPlan:
 			{
-				SubPlan    *subplan = (SubPlan *) expr;
+				const SubPlan    *subplan = (const SubPlan *) expr;
 
 				if (subplan->subLinkType == EXPR_SUBLINK ||
 					subplan->subLinkType == ARRAY_SUBLINK)
@@ -150,58 +150,58 @@ exprType(Node *expr)
 			break;
 		case T_AlternativeSubPlan:
 			{
-				AlternativeSubPlan *asplan = (AlternativeSubPlan *) expr;
+				const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
 
 				/* subplans should all return the same thing */
 				type = exprType((Node *) linitial(asplan->subplans));
 			}
 			break;
 		case T_FieldSelect:
-			type = ((FieldSelect *) expr)->resulttype;
+			type = ((const FieldSelect *) expr)->resulttype;
 			break;
 		case T_FieldStore:
-			type = ((FieldStore *) expr)->resulttype;
+			type = ((const FieldStore *) expr)->resulttype;
 			break;
 		case T_RelabelType:
-			type = ((RelabelType *) expr)->resulttype;
+			type = ((const RelabelType *) expr)->resulttype;
 			break;
 		case T_CoerceViaIO:
-			type = ((CoerceViaIO *) expr)->resulttype;
+			type = ((const CoerceViaIO *) expr)->resulttype;
 			break;
 		case T_ArrayCoerceExpr:
-			type = ((ArrayCoerceExpr *) expr)->resulttype;
+			type = ((const ArrayCoerceExpr *) expr)->resulttype;
 			break;
 		case T_ConvertRowtypeExpr:
-			type = ((ConvertRowtypeExpr *) expr)->resulttype;
+			type = ((const ConvertRowtypeExpr *) expr)->resulttype;
 			break;
 		case T_CollateExpr:
-			type = exprType((Node *) ((CollateExpr *) expr)->arg);
+			type = exprType((Node *) ((const CollateExpr *) expr)->arg);
 			break;
 		case T_CaseExpr:
-			type = ((CaseExpr *) expr)->casetype;
+			type = ((const CaseExpr *) expr)->casetype;
 			break;
 		case T_CaseTestExpr:
-			type = ((CaseTestExpr *) expr)->typeId;
+			type = ((const CaseTestExpr *) expr)->typeId;
 			break;
 		case T_ArrayExpr:
-			type = ((ArrayExpr *) expr)->array_typeid;
+			type = ((const ArrayExpr *) expr)->array_typeid;
 			break;
 		case T_RowExpr:
-			type = ((RowExpr *) expr)->row_typeid;
+			type = ((const RowExpr *) expr)->row_typeid;
 			break;
 		case T_RowCompareExpr:
 			type = BOOLOID;
 			break;
 		case T_CoalesceExpr:
-			type = ((CoalesceExpr *) expr)->coalescetype;
+			type = ((const CoalesceExpr *) expr)->coalescetype;
 			break;
 		case T_MinMaxExpr:
-			type = ((MinMaxExpr *) expr)->minmaxtype;
+			type = ((const MinMaxExpr *) expr)->minmaxtype;
 			break;
 		case T_XmlExpr:
-			if (((XmlExpr *) expr)->op == IS_DOCUMENT)
+			if (((const XmlExpr *) expr)->op == IS_DOCUMENT)
 				type = BOOLOID;
-			else if (((XmlExpr *) expr)->op == IS_XMLSERIALIZE)
+			else if (((const XmlExpr *) expr)->op == IS_XMLSERIALIZE)
 				type = TEXTOID;
 			else
 				type = XMLOID;
@@ -213,19 +213,19 @@ exprType(Node *expr)
 			type = BOOLOID;
 			break;
 		case T_CoerceToDomain:
-			type = ((CoerceToDomain *) expr)->resulttype;
+			type = ((const CoerceToDomain *) expr)->resulttype;
 			break;
 		case T_CoerceToDomainValue:
-			type = ((CoerceToDomainValue *) expr)->typeId;
+			type = ((const CoerceToDomainValue *) expr)->typeId;
 			break;
 		case T_SetToDefault:
-			type = ((SetToDefault *) expr)->typeId;
+			type = ((const SetToDefault *) expr)->typeId;
 			break;
 		case T_CurrentOfExpr:
 			type = BOOLOID;
 			break;
 		case T_PlaceHolderVar:
-			type = exprType((Node *) ((PlaceHolderVar *) expr)->phexpr);
+			type = exprType((Node *) ((const PlaceHolderVar *) expr)->phexpr);
 			break;
 		default:
 			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
@@ -241,7 +241,7 @@ exprType(Node *expr)
  *	  if it can be determined.	In many cases, it can't and we return -1.
  */
 int32
-exprTypmod(Node *expr)
+exprTypmod(const Node *expr)
 {
 	if (!expr)
 		return -1;
@@ -249,14 +249,14 @@ exprTypmod(Node *expr)
 	switch (nodeTag(expr))
 	{
 		case T_Var:
-			return ((Var *) expr)->vartypmod;
+			return ((const Var *) expr)->vartypmod;
 		case T_Const:
-			return ((Const *) expr)->consttypmod;
+			return ((const Const *) expr)->consttypmod;
 		case T_Param:
-			return ((Param *) expr)->paramtypmod;
+			return ((const Param *) expr)->paramtypmod;
 		case T_ArrayRef:
 			/* typmod is the same for array or element */
-			return ((ArrayRef *) expr)->reftypmod;
+			return ((const ArrayRef *) expr)->reftypmod;
 		case T_FuncExpr:
 			{
 				int32		coercedTypmod;
@@ -267,21 +267,21 @@ exprTypmod(Node *expr)
 			}
 			break;
 		case T_NamedArgExpr:
-			return exprTypmod((Node *) ((NamedArgExpr *) expr)->arg);
+			return exprTypmod((Node *) ((const NamedArgExpr *) expr)->arg);
 		case T_NullIfExpr:
 			{
 				/*
 				 * Result is either first argument or NULL, so we can report
 				 * first argument's typmod if known.
 				 */
-				NullIfExpr *nexpr = (NullIfExpr *) expr;
+				const NullIfExpr *nexpr = (const NullIfExpr *) expr;
 
 				return exprTypmod((Node *) linitial(nexpr->args));
 			}
 			break;
 		case T_SubLink:
 			{
-				SubLink    *sublink = (SubLink *) expr;
+				const SubLink    *sublink = (const SubLink *) expr;
 
 				if (sublink->subLinkType == EXPR_SUBLINK ||
 					sublink->subLinkType == ARRAY_SUBLINK)
@@ -302,7 +302,7 @@ exprTypmod(Node *expr)
 			break;
 		case T_SubPlan:
 			{
-				SubPlan    *subplan = (SubPlan *) expr;
+				const SubPlan    *subplan = (const SubPlan *) expr;
 
 				if (subplan->subLinkType == EXPR_SUBLINK ||
 					subplan->subLinkType == ARRAY_SUBLINK)
@@ -320,27 +320,27 @@ exprTypmod(Node *expr)
 			break;
 		case T_AlternativeSubPlan:
 			{
-				AlternativeSubPlan *asplan = (AlternativeSubPlan *) expr;
+				const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
 
 				/* subplans should all return the same thing */
 				return exprTypmod((Node *) linitial(asplan->subplans));
 			}
 			break;
 		case T_FieldSelect:
-			return ((FieldSelect *) expr)->resulttypmod;
+			return ((const FieldSelect *) expr)->resulttypmod;
 		case T_RelabelType:
-			return ((RelabelType *) expr)->resulttypmod;
+			return ((const RelabelType *) expr)->resulttypmod;
 		case T_ArrayCoerceExpr:
-			return ((ArrayCoerceExpr *) expr)->resulttypmod;
+			return ((const ArrayCoerceExpr *) expr)->resulttypmod;
 		case T_CollateExpr:
-			return exprTypmod((Node *) ((CollateExpr *) expr)->arg);
+			return exprTypmod((Node *) ((const CollateExpr *) expr)->arg);
 		case T_CaseExpr:
 			{
 				/*
 				 * If all the alternatives agree on type/typmod, return that
 				 * typmod, else use -1
 				 */
-				CaseExpr   *cexpr = (CaseExpr *) expr;
+				const CaseExpr   *cexpr = (const CaseExpr *) expr;
 				Oid			casetype = cexpr->casetype;
 				int32		typmod;
 				ListCell   *arg;
@@ -366,14 +366,14 @@ exprTypmod(Node *expr)
 			}
 			break;
 		case T_CaseTestExpr:
-			return ((CaseTestExpr *) expr)->typeMod;
+			return ((const CaseTestExpr *) expr)->typeMod;
 		case T_ArrayExpr:
 			{
 				/*
 				 * If all the elements agree on type/typmod, return that
 				 * typmod, else use -1
 				 */
-				ArrayExpr  *arrayexpr = (ArrayExpr *) expr;
+				const ArrayExpr  *arrayexpr = (const ArrayExpr *) expr;
 				Oid			commontype;
 				int32		typmod;
 				ListCell   *elem;
@@ -405,7 +405,7 @@ exprTypmod(Node *expr)
 				 * If all the alternatives agree on type/typmod, return that
 				 * typmod, else use -1
 				 */
-				CoalesceExpr *cexpr = (CoalesceExpr *) expr;
+				const CoalesceExpr *cexpr = (const CoalesceExpr *) expr;
 				Oid			coalescetype = cexpr->coalescetype;
 				int32		typmod;
 				ListCell   *arg;
@@ -433,7 +433,7 @@ exprTypmod(Node *expr)
 				 * If all the alternatives agree on type/typmod, return that
 				 * typmod, else use -1
 				 */
-				MinMaxExpr *mexpr = (MinMaxExpr *) expr;
+				const MinMaxExpr *mexpr = (const MinMaxExpr *) expr;
 				Oid			minmaxtype = mexpr->minmaxtype;
 				int32		typmod;
 				ListCell   *arg;
@@ -456,13 +456,13 @@ exprTypmod(Node *expr)
 			}
 			break;
 		case T_CoerceToDomain:
-			return ((CoerceToDomain *) expr)->resulttypmod;
+			return ((const CoerceToDomain *) expr)->resulttypmod;
 		case T_CoerceToDomainValue:
-			return ((CoerceToDomainValue *) expr)->typeMod;
+			return ((const CoerceToDomainValue *) expr)->typeMod;
 		case T_SetToDefault:
-			return ((SetToDefault *) expr)->typeMod;
+			return ((const SetToDefault *) expr)->typeMod;
 		case T_PlaceHolderVar:
-			return exprTypmod((Node *) ((PlaceHolderVar *) expr)->phexpr);
+			return exprTypmod((Node *) ((const PlaceHolderVar *) expr)->phexpr);
 		default:
 			break;
 	}
@@ -481,7 +481,7 @@ exprTypmod(Node *expr)
  * length coercion by this routine.
  */
 bool
-exprIsLengthCoercion(Node *expr, int32 *coercedTypmod)
+exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod)
 {
 	if (coercedTypmod != NULL)
 		*coercedTypmod = -1;	/* default result on failure */
@@ -492,7 +492,7 @@ exprIsLengthCoercion(Node *expr, int32 *coercedTypmod)
 	 */
 	if (expr && IsA(expr, FuncExpr))
 	{
-		FuncExpr   *func = (FuncExpr *) expr;
+		const FuncExpr   *func = (const FuncExpr *) expr;
 		int			nargs;
 		Const	   *second_arg;
 
@@ -529,7 +529,7 @@ exprIsLengthCoercion(Node *expr, int32 *coercedTypmod)
 
 	if (expr && IsA(expr, ArrayCoerceExpr))
 	{
-		ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) expr;
+		const ArrayCoerceExpr *acoerce = (const ArrayCoerceExpr *) expr;
 
 		/* It's not a length coercion unless there's a nondefault typmod */
 		if (acoerce->resulttypmod < 0)
@@ -632,7 +632,7 @@ expression_returns_set_walker(Node *node, void *context)
  * or vice versa, the two are different.
  */
 Oid
-exprCollation(Node *expr)
+exprCollation(const Node *expr)
 {
 	Oid			coll;
 
@@ -642,37 +642,37 @@ exprCollation(Node *expr)
 	switch (nodeTag(expr))
 	{
 		case T_Var:
-			coll = ((Var *) expr)->varcollid;
+			coll = ((const Var *) expr)->varcollid;
 			break;
 		case T_Const:
-			coll = ((Const *) expr)->constcollid;
+			coll = ((const Const *) expr)->constcollid;
 			break;
 		case T_Param:
-			coll = ((Param *) expr)->paramcollid;
+			coll = ((const Param *) expr)->paramcollid;
 			break;
 		case T_Aggref:
-			coll = ((Aggref *) expr)->aggcollid;
+			coll = ((const Aggref *) expr)->aggcollid;
 			break;
 		case T_WindowFunc:
-			coll = ((WindowFunc *) expr)->wincollid;
+			coll = ((const WindowFunc *) expr)->wincollid;
 			break;
 		case T_ArrayRef:
-			coll = ((ArrayRef *) expr)->refcollid;
+			coll = ((const ArrayRef *) expr)->refcollid;
 			break;
 		case T_FuncExpr:
-			coll = ((FuncExpr *) expr)->funccollid;
+			coll = ((const FuncExpr *) expr)->funccollid;
 			break;
 		case T_NamedArgExpr:
-			coll = exprCollation((Node *) ((NamedArgExpr *) expr)->arg);
+			coll = exprCollation((Node *) ((const NamedArgExpr *) expr)->arg);
 			break;
 		case T_OpExpr:
-			coll = ((OpExpr *) expr)->opcollid;
+			coll = ((const OpExpr *) expr)->opcollid;
 			break;
 		case T_DistinctExpr:
-			coll = ((DistinctExpr *) expr)->opcollid;
+			coll = ((const DistinctExpr *) expr)->opcollid;
 			break;
 		case T_NullIfExpr:
-			coll = ((NullIfExpr *) expr)->opcollid;
+			coll = ((const NullIfExpr *) expr)->opcollid;
 			break;
 		case T_ScalarArrayOpExpr:
 			coll = InvalidOid;	/* result is always boolean */
@@ -682,7 +682,7 @@ exprCollation(Node *expr)
 			break;
 		case T_SubLink:
 			{
-				SubLink    *sublink = (SubLink *) expr;
+				const SubLink    *sublink = (const SubLink *) expr;
 
 				if (sublink->subLinkType == EXPR_SUBLINK ||
 					sublink->subLinkType == ARRAY_SUBLINK)
@@ -708,7 +708,7 @@ exprCollation(Node *expr)
 			break;
 		case T_SubPlan:
 			{
-				SubPlan    *subplan = (SubPlan *) expr;
+				const SubPlan    *subplan = (const SubPlan *) expr;
 
 				if (subplan->subLinkType == EXPR_SUBLINK ||
 					subplan->subLinkType == ARRAY_SUBLINK)
@@ -726,41 +726,41 @@ exprCollation(Node *expr)
 			break;
 		case T_AlternativeSubPlan:
 			{
-				AlternativeSubPlan *asplan = (AlternativeSubPlan *) expr;
+				const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
 
 				/* subplans should all return the same thing */
 				coll = exprCollation((Node *) linitial(asplan->subplans));
 			}
 			break;
 		case T_FieldSelect:
-			coll = ((FieldSelect *) expr)->resultcollid;
+			coll = ((const FieldSelect *) expr)->resultcollid;
 			break;
 		case T_FieldStore:
 			coll = InvalidOid;	/* result is always composite */
 			break;
 		case T_RelabelType:
-			coll = ((RelabelType *) expr)->resultcollid;
+			coll = ((const RelabelType *) expr)->resultcollid;
 			break;
 		case T_CoerceViaIO:
-			coll = ((CoerceViaIO *) expr)->resultcollid;
+			coll = ((const CoerceViaIO *) expr)->resultcollid;
 			break;
 		case T_ArrayCoerceExpr:
-			coll = ((ArrayCoerceExpr *) expr)->resultcollid;
+			coll = ((const ArrayCoerceExpr *) expr)->resultcollid;
 			break;
 		case T_ConvertRowtypeExpr:
 			coll = InvalidOid;	/* result is always composite */
 			break;
 		case T_CollateExpr:
-			coll = ((CollateExpr *) expr)->collOid;
+			coll = ((const CollateExpr *) expr)->collOid;
 			break;
 		case T_CaseExpr:
-			coll = ((CaseExpr *) expr)->casecollid;
+			coll = ((const CaseExpr *) expr)->casecollid;
 			break;
 		case T_CaseTestExpr:
-			coll = ((CaseTestExpr *) expr)->collation;
+			coll = ((const CaseTestExpr *) expr)->collation;
 			break;
 		case T_ArrayExpr:
-			coll = ((ArrayExpr *) expr)->array_collid;
+			coll = ((const ArrayExpr *) expr)->array_collid;
 			break;
 		case T_RowExpr:
 			coll = InvalidOid;	/* result is always composite */
@@ -769,10 +769,10 @@ exprCollation(Node *expr)
 			coll = InvalidOid;	/* result is always boolean */
 			break;
 		case T_CoalesceExpr:
-			coll = ((CoalesceExpr *) expr)->coalescecollid;
+			coll = ((const CoalesceExpr *) expr)->coalescecollid;
 			break;
 		case T_MinMaxExpr:
-			coll = ((MinMaxExpr *) expr)->minmaxcollid;
+			coll = ((const MinMaxExpr *) expr)->minmaxcollid;
 			break;
 		case T_XmlExpr:
 
@@ -781,7 +781,7 @@ exprCollation(Node *expr)
 			 * collation is always default.  The other cases return boolean or
 			 * XML, which are non-collatable.
 			 */
-			if (((XmlExpr *) expr)->op == IS_XMLSERIALIZE)
+			if (((const XmlExpr *) expr)->op == IS_XMLSERIALIZE)
 				coll = DEFAULT_COLLATION_OID;
 			else
 				coll = InvalidOid;
@@ -793,19 +793,19 @@ exprCollation(Node *expr)
 			coll = InvalidOid;	/* result is always boolean */
 			break;
 		case T_CoerceToDomain:
-			coll = ((CoerceToDomain *) expr)->resultcollid;
+			coll = ((const CoerceToDomain *) expr)->resultcollid;
 			break;
 		case T_CoerceToDomainValue:
-			coll = ((CoerceToDomainValue *) expr)->collation;
+			coll = ((const CoerceToDomainValue *) expr)->collation;
 			break;
 		case T_SetToDefault:
-			coll = ((SetToDefault *) expr)->collation;
+			coll = ((const SetToDefault *) expr)->collation;
 			break;
 		case T_CurrentOfExpr:
 			coll = InvalidOid;	/* result is always boolean */
 			break;
 		case T_PlaceHolderVar:
-			coll = exprCollation((Node *) ((PlaceHolderVar *) expr)->phexpr);
+			coll = exprCollation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
 			break;
 		default:
 			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
@@ -822,7 +822,7 @@ exprCollation(Node *expr)
  * Result is InvalidOid if the node type doesn't store this information.
  */
 Oid
-exprInputCollation(Node *expr)
+exprInputCollation(const Node *expr)
 {
 	Oid			coll;
 
@@ -832,28 +832,28 @@ exprInputCollation(Node *expr)
 	switch (nodeTag(expr))
 	{
 		case T_Aggref:
-			coll = ((Aggref *) expr)->inputcollid;
+			coll = ((const Aggref *) expr)->inputcollid;
 			break;
 		case T_WindowFunc:
-			coll = ((WindowFunc *) expr)->inputcollid;
+			coll = ((const WindowFunc *) expr)->inputcollid;
 			break;
 		case T_FuncExpr:
-			coll = ((FuncExpr *) expr)->inputcollid;
+			coll = ((const FuncExpr *) expr)->inputcollid;
 			break;
 		case T_OpExpr:
-			coll = ((OpExpr *) expr)->inputcollid;
+			coll = ((const OpExpr *) expr)->inputcollid;
 			break;
 		case T_DistinctExpr:
-			coll = ((DistinctExpr *) expr)->inputcollid;
+			coll = ((const DistinctExpr *) expr)->inputcollid;
 			break;
 		case T_NullIfExpr:
-			coll = ((NullIfExpr *) expr)->inputcollid;
+			coll = ((const NullIfExpr *) expr)->inputcollid;
 			break;
 		case T_ScalarArrayOpExpr:
-			coll = ((ScalarArrayOpExpr *) expr)->inputcollid;
+			coll = ((const ScalarArrayOpExpr *) expr)->inputcollid;
 			break;
 		case T_MinMaxExpr:
-			coll = ((MinMaxExpr *) expr)->inputcollid;
+			coll = ((const MinMaxExpr *) expr)->inputcollid;
 			break;
 		default:
 			coll = InvalidOid;
@@ -1078,7 +1078,7 @@ exprSetInputCollation(Node *expr, Oid inputcollation)
  * known and unknown locations in a tree.
  */
 int
-exprLocation(Node *expr)
+exprLocation(const Node *expr)
 {
 	int			loc;
 
@@ -1087,32 +1087,32 @@ exprLocation(Node *expr)
 	switch (nodeTag(expr))
 	{
 		case T_RangeVar:
-			loc = ((RangeVar *) expr)->location;
+			loc = ((const RangeVar *) expr)->location;
 			break;
 		case T_Var:
-			loc = ((Var *) expr)->location;
+			loc = ((const Var *) expr)->location;
 			break;
 		case T_Const:
-			loc = ((Const *) expr)->location;
+			loc = ((const Const *) expr)->location;
 			break;
 		case T_Param:
-			loc = ((Param *) expr)->location;
+			loc = ((const Param *) expr)->location;
 			break;
 		case T_Aggref:
 			/* function name should always be the first thing */
-			loc = ((Aggref *) expr)->location;
+			loc = ((const Aggref *) expr)->location;
 			break;
 		case T_WindowFunc:
 			/* function name should always be the first thing */
-			loc = ((WindowFunc *) expr)->location;
+			loc = ((const WindowFunc *) expr)->location;
 			break;
 		case T_ArrayRef:
 			/* just use array argument's location */
-			loc = exprLocation((Node *) ((ArrayRef *) expr)->refexpr);
+			loc = exprLocation((Node *) ((const ArrayRef *) expr)->refexpr);
 			break;
 		case T_FuncExpr:
 			{
-				FuncExpr   *fexpr = (FuncExpr *) expr;
+				const FuncExpr   *fexpr = (const FuncExpr *) expr;
 
 				/* consider both function name and leftmost arg */
 				loc = leftmostLoc(fexpr->location,
@@ -1121,7 +1121,7 @@ exprLocation(Node *expr)
 			break;
 		case T_NamedArgExpr:
 			{
-				NamedArgExpr *na = (NamedArgExpr *) expr;
+				const NamedArgExpr *na = (const NamedArgExpr *) expr;
 
 				/* consider both argument name and value */
 				loc = leftmostLoc(na->location,
@@ -1132,7 +1132,7 @@ exprLocation(Node *expr)
 		case T_DistinctExpr:	/* struct-equivalent to OpExpr */
 		case T_NullIfExpr:		/* struct-equivalent to OpExpr */
 			{
-				OpExpr	   *opexpr = (OpExpr *) expr;
+				const OpExpr	   *opexpr = (const OpExpr *) expr;
 
 				/* consider both operator name and leftmost arg */
 				loc = leftmostLoc(opexpr->location,
@@ -1141,7 +1141,7 @@ exprLocation(Node *expr)
 			break;
 		case T_ScalarArrayOpExpr:
 			{
-				ScalarArrayOpExpr *saopexpr = (ScalarArrayOpExpr *) expr;
+				const ScalarArrayOpExpr *saopexpr = (const ScalarArrayOpExpr *) expr;
 
 				/* consider both operator name and leftmost arg */
 				loc = leftmostLoc(saopexpr->location,
@@ -1150,7 +1150,7 @@ exprLocation(Node *expr)
 			break;
 		case T_BoolExpr:
 			{
-				BoolExpr   *bexpr = (BoolExpr *) expr;
+				const BoolExpr   *bexpr = (const BoolExpr *) expr;
 
 				/*
 				 * Same as above, to handle either NOT or AND/OR.  We can't
@@ -1163,7 +1163,7 @@ exprLocation(Node *expr)
 			break;
 		case T_SubLink:
 			{
-				SubLink    *sublink = (SubLink *) expr;
+				const SubLink    *sublink = (const SubLink *) expr;
 
 				/* check the testexpr, if any, and the operator/keyword */
 				loc = leftmostLoc(exprLocation(sublink->testexpr),
@@ -1172,15 +1172,15 @@ exprLocation(Node *expr)
 			break;
 		case T_FieldSelect:
 			/* just use argument's location */
-			loc = exprLocation((Node *) ((FieldSelect *) expr)->arg);
+			loc = exprLocation((Node *) ((const FieldSelect *) expr)->arg);
 			break;
 		case T_FieldStore:
 			/* just use argument's location */
-			loc = exprLocation((Node *) ((FieldStore *) expr)->arg);
+			loc = exprLocation((Node *) ((const FieldStore *) expr)->arg);
 			break;
 		case T_RelabelType:
 			{
-				RelabelType *rexpr = (RelabelType *) expr;
+				const RelabelType *rexpr = (const RelabelType *) expr;
 
 				/* Much as above */
 				loc = leftmostLoc(rexpr->location,
@@ -1189,7 +1189,7 @@ exprLocation(Node *expr)
 			break;
 		case T_CoerceViaIO:
 			{
-				CoerceViaIO *cexpr = (CoerceViaIO *) expr;
+				const CoerceViaIO *cexpr = (const CoerceViaIO *) expr;
 
 				/* Much as above */
 				loc = leftmostLoc(cexpr->location,
@@ -1198,7 +1198,7 @@ exprLocation(Node *expr)
 			break;
 		case T_ArrayCoerceExpr:
 			{
-				ArrayCoerceExpr *cexpr = (ArrayCoerceExpr *) expr;
+				const ArrayCoerceExpr *cexpr = (const ArrayCoerceExpr *) expr;
 
 				/* Much as above */
 				loc = leftmostLoc(cexpr->location,
@@ -1207,7 +1207,7 @@ exprLocation(Node *expr)
 			break;
 		case T_ConvertRowtypeExpr:
 			{
-				ConvertRowtypeExpr *cexpr = (ConvertRowtypeExpr *) expr;
+				const ConvertRowtypeExpr *cexpr = (const ConvertRowtypeExpr *) expr;
 
 				/* Much as above */
 				loc = leftmostLoc(cexpr->location,
@@ -1216,39 +1216,39 @@ exprLocation(Node *expr)
 			break;
 		case T_CollateExpr:
 			/* just use argument's location */
-			loc = exprLocation((Node *) ((CollateExpr *) expr)->arg);
+			loc = exprLocation((Node *) ((const CollateExpr *) expr)->arg);
 			break;
 		case T_CaseExpr:
 			/* CASE keyword should always be the first thing */
-			loc = ((CaseExpr *) expr)->location;
+			loc = ((const CaseExpr *) expr)->location;
 			break;
 		case T_CaseWhen:
 			/* WHEN keyword should always be the first thing */
-			loc = ((CaseWhen *) expr)->location;
+			loc = ((const CaseWhen *) expr)->location;
 			break;
 		case T_ArrayExpr:
 			/* the location points at ARRAY or [, which must be leftmost */
-			loc = ((ArrayExpr *) expr)->location;
+			loc = ((const ArrayExpr *) expr)->location;
 			break;
 		case T_RowExpr:
 			/* the location points at ROW or (, which must be leftmost */
-			loc = ((RowExpr *) expr)->location;
+			loc = ((const RowExpr *) expr)->location;
 			break;
 		case T_RowCompareExpr:
 			/* just use leftmost argument's location */
-			loc = exprLocation((Node *) ((RowCompareExpr *) expr)->largs);
+			loc = exprLocation((Node *) ((const RowCompareExpr *) expr)->largs);
 			break;
 		case T_CoalesceExpr:
 			/* COALESCE keyword should always be the first thing */
-			loc = ((CoalesceExpr *) expr)->location;
+			loc = ((const CoalesceExpr *) expr)->location;
 			break;
 		case T_MinMaxExpr:
 			/* GREATEST/LEAST keyword should always be the first thing */
-			loc = ((MinMaxExpr *) expr)->location;
+			loc = ((const MinMaxExpr *) expr)->location;
 			break;
 		case T_XmlExpr:
 			{
-				XmlExpr    *xexpr = (XmlExpr *) expr;
+				const XmlExpr    *xexpr = (const XmlExpr *) expr;
 
 				/* consider both function name and leftmost arg */
 				loc = leftmostLoc(xexpr->location,
@@ -1257,15 +1257,15 @@ exprLocation(Node *expr)
 			break;
 		case T_NullTest:
 			/* just use argument's location */
-			loc = exprLocation((Node *) ((NullTest *) expr)->arg);
+			loc = exprLocation((Node *) ((const NullTest *) expr)->arg);
 			break;
 		case T_BooleanTest:
 			/* just use argument's location */
-			loc = exprLocation((Node *) ((BooleanTest *) expr)->arg);
+			loc = exprLocation((Node *) ((const BooleanTest *) expr)->arg);
 			break;
 		case T_CoerceToDomain:
 			{
-				CoerceToDomain *cexpr = (CoerceToDomain *) expr;
+				const CoerceToDomain *cexpr = (const CoerceToDomain *) expr;
 
 				/* Much as above */
 				loc = leftmostLoc(cexpr->location,
@@ -1273,18 +1273,18 @@ exprLocation(Node *expr)
 			}
 			break;
 		case T_CoerceToDomainValue:
-			loc = ((CoerceToDomainValue *) expr)->location;
+			loc = ((const CoerceToDomainValue *) expr)->location;
 			break;
 		case T_SetToDefault:
-			loc = ((SetToDefault *) expr)->location;
+			loc = ((const SetToDefault *) expr)->location;
 			break;
 		case T_TargetEntry:
 			/* just use argument's location */
-			loc = exprLocation((Node *) ((TargetEntry *) expr)->expr);
+			loc = exprLocation((Node *) ((const TargetEntry *) expr)->expr);
 			break;
 		case T_IntoClause:
 			/* use the contained RangeVar's location --- close enough */
-			loc = exprLocation((Node *) ((IntoClause *) expr)->rel);
+			loc = exprLocation((Node *) ((const IntoClause *) expr)->rel);
 			break;
 		case T_List:
 			{
@@ -1292,7 +1292,7 @@ exprLocation(Node *expr)
 				ListCell   *lc;
 
 				loc = -1;		/* just to suppress compiler warning */
-				foreach(lc, (List *) expr)
+				foreach(lc, (const List *) expr)
 				{
 					loc = exprLocation((Node *) lfirst(lc));
 					if (loc >= 0)
@@ -1302,7 +1302,7 @@ exprLocation(Node *expr)
 			break;
 		case T_A_Expr:
 			{
-				A_Expr	   *aexpr = (A_Expr *) expr;
+				const A_Expr	   *aexpr = (const A_Expr *) expr;
 
 				/* use leftmost of operator or left operand (if any) */
 				/* we assume right operand can't be to left of operator */
@@ -1311,17 +1311,17 @@ exprLocation(Node *expr)
 			}
 			break;
 		case T_ColumnRef:
-			loc = ((ColumnRef *) expr)->location;
+			loc = ((const ColumnRef *) expr)->location;
 			break;
 		case T_ParamRef:
-			loc = ((ParamRef *) expr)->location;
+			loc = ((const ParamRef *) expr)->location;
 			break;
 		case T_A_Const:
-			loc = ((A_Const *) expr)->location;
+			loc = ((const A_Const *) expr)->location;
 			break;
 		case T_FuncCall:
 			{
-				FuncCall   *fc = (FuncCall *) expr;
+				const FuncCall   *fc = (const FuncCall *) expr;
 
 				/* consider both function name and leftmost arg */
 				/* (we assume any ORDER BY nodes must be to right of name) */
@@ -1331,15 +1331,15 @@ exprLocation(Node *expr)
 			break;
 		case T_A_ArrayExpr:
 			/* the location points at ARRAY or [, which must be leftmost */
-			loc = ((A_ArrayExpr *) expr)->location;
+			loc = ((const A_ArrayExpr *) expr)->location;
 			break;
 		case T_ResTarget:
 			/* we need not examine the contained expression (if any) */
-			loc = ((ResTarget *) expr)->location;
+			loc = ((const ResTarget *) expr)->location;
 			break;
 		case T_TypeCast:
 			{
-				TypeCast   *tc = (TypeCast *) expr;
+				const TypeCast   *tc = (const TypeCast *) expr;
 
 				/*
 				 * This could represent CAST(), ::, or TypeName 'literal', so
@@ -1352,34 +1352,34 @@ exprLocation(Node *expr)
 			break;
 		case T_CollateClause:
 			/* just use argument's location */
-			loc = exprLocation(((CollateClause *) expr)->arg);
+			loc = exprLocation(((const CollateClause *) expr)->arg);
 			break;
 		case T_SortBy:
 			/* just use argument's location (ignore operator, if any) */
-			loc = exprLocation(((SortBy *) expr)->node);
+			loc = exprLocation(((const SortBy *) expr)->node);
 			break;
 		case T_WindowDef:
-			loc = ((WindowDef *) expr)->location;
+			loc = ((const WindowDef *) expr)->location;
 			break;
 		case T_TypeName:
-			loc = ((TypeName *) expr)->location;
+			loc = ((const TypeName *) expr)->location;
 			break;
 		case T_Constraint:
-			loc = ((Constraint *) expr)->location;
+			loc = ((const Constraint *) expr)->location;
 			break;
 		case T_XmlSerialize:
 			/* XMLSERIALIZE keyword should always be the first thing */
-			loc = ((XmlSerialize *) expr)->location;
+			loc = ((const XmlSerialize *) expr)->location;
 			break;
 		case T_WithClause:
-			loc = ((WithClause *) expr)->location;
+			loc = ((const WithClause *) expr)->location;
 			break;
 		case T_CommonTableExpr:
-			loc = ((CommonTableExpr *) expr)->location;
+			loc = ((const CommonTableExpr *) expr)->location;
 			break;
 		case T_PlaceHolderVar:
 			/* just use argument's location */
-			loc = exprLocation((Node *) ((PlaceHolderVar *) expr)->phexpr);
+			loc = exprLocation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
 			break;
 		default:
 			/* for any other node type it's just unknown... */
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index 31af47fdd2a..bef1e78f5a2 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -94,7 +94,7 @@
 
 #define booltostr(x)  ((x) ? "true" : "false")
 
-static void _outNode(StringInfo str, void *obj);
+static void _outNode(StringInfo str, const void *obj);
 
 
 /*
@@ -105,7 +105,7 @@ static void _outNode(StringInfo str, void *obj);
  *	  If a null or empty string is given, it is encoded as "<>".
  */
 static void
-_outToken(StringInfo str, char *s)
+_outToken(StringInfo str, const char *s)
 {
 	if (s == NULL || *s == '\0')
 	{
@@ -137,9 +137,9 @@ _outToken(StringInfo str, char *s)
 }
 
 static void
-_outList(StringInfo str, List *node)
+_outList(StringInfo str, const List *node)
 {
-	ListCell   *lc;
+	const ListCell   *lc;
 
 	appendStringInfoChar(str, '(');
 
@@ -180,7 +180,7 @@ _outList(StringInfo str, List *node)
  * Note: the output format is "(b int int ...)", similar to an integer List.
  */
 static void
-_outBitmapset(StringInfo str, Bitmapset *bms)
+_outBitmapset(StringInfo str, const Bitmapset *bms)
 {
 	Bitmapset  *tmpset;
 	int			x;
@@ -235,7 +235,7 @@ _outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
  */
 
 static void
-_outPlannedStmt(StringInfo str, PlannedStmt *node)
+_outPlannedStmt(StringInfo str, const PlannedStmt *node)
 {
 	WRITE_NODE_TYPE("PLANNEDSTMT");
 
@@ -261,7 +261,7 @@ _outPlannedStmt(StringInfo str, PlannedStmt *node)
  * print the basic stuff of all nodes that inherit from Plan
  */
 static void
-_outPlanInfo(StringInfo str, Plan *node)
+_outPlanInfo(StringInfo str, const Plan *node)
 {
 	WRITE_FLOAT_FIELD(startup_cost, "%.2f");
 	WRITE_FLOAT_FIELD(total_cost, "%.2f");
@@ -280,9 +280,9 @@ _outPlanInfo(StringInfo str, Plan *node)
  * print the basic stuff of all nodes that inherit from Scan
  */
 static void
-_outScanInfo(StringInfo str, Scan *node)
+_outScanInfo(StringInfo str, const Scan *node)
 {
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_UINT_FIELD(scanrelid);
 }
@@ -291,9 +291,9 @@ _outScanInfo(StringInfo str, Scan *node)
  * print the basic stuff of all nodes that inherit from Join
  */
 static void
-_outJoinPlanInfo(StringInfo str, Join *node)
+_outJoinPlanInfo(StringInfo str, const Join *node)
 {
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_ENUM_FIELD(jointype, JoinType);
 	WRITE_NODE_FIELD(joinqual);
@@ -301,29 +301,29 @@ _outJoinPlanInfo(StringInfo str, Join *node)
 
 
 static void
-_outPlan(StringInfo str, Plan *node)
+_outPlan(StringInfo str, const Plan *node)
 {
 	WRITE_NODE_TYPE("PLAN");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 }
 
 static void
-_outResult(StringInfo str, Result *node)
+_outResult(StringInfo str, const Result *node)
 {
 	WRITE_NODE_TYPE("RESULT");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_NODE_FIELD(resconstantqual);
 }
 
 static void
-_outModifyTable(StringInfo str, ModifyTable *node)
+_outModifyTable(StringInfo str, const ModifyTable *node)
 {
 	WRITE_NODE_TYPE("MODIFYTABLE");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_ENUM_FIELD(operation, CmdType);
 	WRITE_BOOL_FIELD(canSetTag);
@@ -336,23 +336,23 @@ _outModifyTable(StringInfo str, ModifyTable *node)
 }
 
 static void
-_outAppend(StringInfo str, Append *node)
+_outAppend(StringInfo str, const Append *node)
 {
 	WRITE_NODE_TYPE("APPEND");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_NODE_FIELD(appendplans);
 }
 
 static void
-_outMergeAppend(StringInfo str, MergeAppend *node)
+_outMergeAppend(StringInfo str, const MergeAppend *node)
 {
 	int			i;
 
 	WRITE_NODE_TYPE("MERGEAPPEND");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_NODE_FIELD(mergeplans);
 
@@ -376,13 +376,13 @@ _outMergeAppend(StringInfo str, MergeAppend *node)
 }
 
 static void
-_outRecursiveUnion(StringInfo str, RecursiveUnion *node)
+_outRecursiveUnion(StringInfo str, const RecursiveUnion *node)
 {
 	int			i;
 
 	WRITE_NODE_TYPE("RECURSIVEUNION");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_INT_FIELD(wtParam);
 	WRITE_INT_FIELD(numCols);
@@ -399,47 +399,47 @@ _outRecursiveUnion(StringInfo str, RecursiveUnion *node)
 }
 
 static void
-_outBitmapAnd(StringInfo str, BitmapAnd *node)
+_outBitmapAnd(StringInfo str, const BitmapAnd *node)
 {
 	WRITE_NODE_TYPE("BITMAPAND");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_NODE_FIELD(bitmapplans);
 }
 
 static void
-_outBitmapOr(StringInfo str, BitmapOr *node)
+_outBitmapOr(StringInfo str, const BitmapOr *node)
 {
 	WRITE_NODE_TYPE("BITMAPOR");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_NODE_FIELD(bitmapplans);
 }
 
 static void
-_outScan(StringInfo str, Scan *node)
+_outScan(StringInfo str, const Scan *node)
 {
 	WRITE_NODE_TYPE("SCAN");
 
-	_outScanInfo(str, (Scan *) node);
+	_outScanInfo(str, node);
 }
 
 static void
-_outSeqScan(StringInfo str, SeqScan *node)
+_outSeqScan(StringInfo str, const SeqScan *node)
 {
 	WRITE_NODE_TYPE("SEQSCAN");
 
-	_outScanInfo(str, (Scan *) node);
+	_outScanInfo(str, (const Scan *) node);
 }
 
 static void
-_outIndexScan(StringInfo str, IndexScan *node)
+_outIndexScan(StringInfo str, const IndexScan *node)
 {
 	WRITE_NODE_TYPE("INDEXSCAN");
 
-	_outScanInfo(str, (Scan *) node);
+	_outScanInfo(str, (const Scan *) node);
 
 	WRITE_OID_FIELD(indexid);
 	WRITE_NODE_FIELD(indexqual);
@@ -450,11 +450,11 @@ _outIndexScan(StringInfo str, IndexScan *node)
 }
 
 static void
-_outIndexOnlyScan(StringInfo str, IndexOnlyScan *node)
+_outIndexOnlyScan(StringInfo str, const IndexOnlyScan *node)
 {
 	WRITE_NODE_TYPE("INDEXONLYSCAN");
 
-	_outScanInfo(str, (Scan *) node);
+	_outScanInfo(str, (const Scan *) node);
 
 	WRITE_OID_FIELD(indexid);
 	WRITE_NODE_FIELD(indexqual);
@@ -464,11 +464,11 @@ _outIndexOnlyScan(StringInfo str, IndexOnlyScan *node)
 }
 
 static void
-_outBitmapIndexScan(StringInfo str, BitmapIndexScan *node)
+_outBitmapIndexScan(StringInfo str, const BitmapIndexScan *node)
 {
 	WRITE_NODE_TYPE("BITMAPINDEXSCAN");
 
-	_outScanInfo(str, (Scan *) node);
+	_outScanInfo(str, (const Scan *) node);
 
 	WRITE_OID_FIELD(indexid);
 	WRITE_NODE_FIELD(indexqual);
@@ -476,41 +476,41 @@ _outBitmapIndexScan(StringInfo str, BitmapIndexScan *node)
 }
 
 static void
-_outBitmapHeapScan(StringInfo str, BitmapHeapScan *node)
+_outBitmapHeapScan(StringInfo str, const BitmapHeapScan *node)
 {
 	WRITE_NODE_TYPE("BITMAPHEAPSCAN");
 
-	_outScanInfo(str, (Scan *) node);
+	_outScanInfo(str, (const Scan *) node);
 
 	WRITE_NODE_FIELD(bitmapqualorig);
 }
 
 static void
-_outTidScan(StringInfo str, TidScan *node)
+_outTidScan(StringInfo str, const TidScan *node)
 {
 	WRITE_NODE_TYPE("TIDSCAN");
 
-	_outScanInfo(str, (Scan *) node);
+	_outScanInfo(str, (const Scan *) node);
 
 	WRITE_NODE_FIELD(tidquals);
 }
 
 static void
-_outSubqueryScan(StringInfo str, SubqueryScan *node)
+_outSubqueryScan(StringInfo str, const SubqueryScan *node)
 {
 	WRITE_NODE_TYPE("SUBQUERYSCAN");
 
-	_outScanInfo(str, (Scan *) node);
+	_outScanInfo(str, (const Scan *) node);
 
 	WRITE_NODE_FIELD(subplan);
 }
 
 static void
-_outFunctionScan(StringInfo str, FunctionScan *node)
+_outFunctionScan(StringInfo str, const FunctionScan *node)
 {
 	WRITE_NODE_TYPE("FUNCTIONSCAN");
 
-	_outScanInfo(str, (Scan *) node);
+	_outScanInfo(str, (const Scan *) node);
 
 	WRITE_NODE_FIELD(funcexpr);
 	WRITE_NODE_FIELD(funccolnames);
@@ -520,49 +520,49 @@ _outFunctionScan(StringInfo str, FunctionScan *node)
 }
 
 static void
-_outValuesScan(StringInfo str, ValuesScan *node)
+_outValuesScan(StringInfo str, const ValuesScan *node)
 {
 	WRITE_NODE_TYPE("VALUESSCAN");
 
-	_outScanInfo(str, (Scan *) node);
+	_outScanInfo(str, (const Scan *) node);
 
 	WRITE_NODE_FIELD(values_lists);
 }
 
 static void
-_outCteScan(StringInfo str, CteScan *node)
+_outCteScan(StringInfo str, const CteScan *node)
 {
 	WRITE_NODE_TYPE("CTESCAN");
 
-	_outScanInfo(str, (Scan *) node);
+	_outScanInfo(str, (const Scan *) node);
 
 	WRITE_INT_FIELD(ctePlanId);
 	WRITE_INT_FIELD(cteParam);
 }
 
 static void
-_outWorkTableScan(StringInfo str, WorkTableScan *node)
+_outWorkTableScan(StringInfo str, const WorkTableScan *node)
 {
 	WRITE_NODE_TYPE("WORKTABLESCAN");
 
-	_outScanInfo(str, (Scan *) node);
+	_outScanInfo(str, (const Scan *) node);
 
 	WRITE_INT_FIELD(wtParam);
 }
 
 static void
-_outForeignScan(StringInfo str, ForeignScan *node)
+_outForeignScan(StringInfo str, const ForeignScan *node)
 {
 	WRITE_NODE_TYPE("FOREIGNSCAN");
 
-	_outScanInfo(str, (Scan *) node);
+	_outScanInfo(str, (const Scan *) node);
 
 	WRITE_BOOL_FIELD(fsSystemCol);
 	WRITE_NODE_FIELD(fdwplan);
 }
 
 static void
-_outFdwPlan(StringInfo str, FdwPlan *node)
+_outFdwPlan(StringInfo str, const FdwPlan *node)
 {
 	WRITE_NODE_TYPE("FDWPLAN");
 
@@ -572,32 +572,32 @@ _outFdwPlan(StringInfo str, FdwPlan *node)
 }
 
 static void
-_outJoin(StringInfo str, Join *node)
+_outJoin(StringInfo str, const Join *node)
 {
 	WRITE_NODE_TYPE("JOIN");
 
-	_outJoinPlanInfo(str, (Join *) node);
+	_outJoinPlanInfo(str, (const Join *) node);
 }
 
 static void
-_outNestLoop(StringInfo str, NestLoop *node)
+_outNestLoop(StringInfo str, const NestLoop *node)
 {
 	WRITE_NODE_TYPE("NESTLOOP");
 
-	_outJoinPlanInfo(str, (Join *) node);
+	_outJoinPlanInfo(str, (const Join *) node);
 
 	WRITE_NODE_FIELD(nestParams);
 }
 
 static void
-_outMergeJoin(StringInfo str, MergeJoin *node)
+_outMergeJoin(StringInfo str, const MergeJoin *node)
 {
 	int			numCols;
 	int			i;
 
 	WRITE_NODE_TYPE("MERGEJOIN");
 
-	_outJoinPlanInfo(str, (Join *) node);
+	_outJoinPlanInfo(str, (const Join *) node);
 
 	WRITE_NODE_FIELD(mergeclauses);
 
@@ -621,23 +621,23 @@ _outMergeJoin(StringInfo str, MergeJoin *node)
 }
 
 static void
-_outHashJoin(StringInfo str, HashJoin *node)
+_outHashJoin(StringInfo str, const HashJoin *node)
 {
 	WRITE_NODE_TYPE("HASHJOIN");
 
-	_outJoinPlanInfo(str, (Join *) node);
+	_outJoinPlanInfo(str, (const Join *) node);
 
 	WRITE_NODE_FIELD(hashclauses);
 }
 
 static void
-_outAgg(StringInfo str, Agg *node)
+_outAgg(StringInfo str, const Agg *node)
 {
 	int			i;
 
 	WRITE_NODE_TYPE("AGG");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
 	WRITE_INT_FIELD(numCols);
@@ -654,13 +654,13 @@ _outAgg(StringInfo str, Agg *node)
 }
 
 static void
-_outWindowAgg(StringInfo str, WindowAgg *node)
+_outWindowAgg(StringInfo str, const WindowAgg *node)
 {
 	int			i;
 
 	WRITE_NODE_TYPE("WINDOWAGG");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_UINT_FIELD(winref);
 	WRITE_INT_FIELD(partNumCols);
@@ -689,13 +689,13 @@ _outWindowAgg(StringInfo str, WindowAgg *node)
 }
 
 static void
-_outGroup(StringInfo str, Group *node)
+_outGroup(StringInfo str, const Group *node)
 {
 	int			i;
 
 	WRITE_NODE_TYPE("GROUP");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_INT_FIELD(numCols);
 
@@ -709,21 +709,21 @@ _outGroup(StringInfo str, Group *node)
 }
 
 static void
-_outMaterial(StringInfo str, Material *node)
+_outMaterial(StringInfo str, const Material *node)
 {
 	WRITE_NODE_TYPE("MATERIAL");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 }
 
 static void
-_outSort(StringInfo str, Sort *node)
+_outSort(StringInfo str, const Sort *node)
 {
 	int			i;
 
 	WRITE_NODE_TYPE("SORT");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_INT_FIELD(numCols);
 
@@ -745,13 +745,13 @@ _outSort(StringInfo str, Sort *node)
 }
 
 static void
-_outUnique(StringInfo str, Unique *node)
+_outUnique(StringInfo str, const Unique *node)
 {
 	int			i;
 
 	WRITE_NODE_TYPE("UNIQUE");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_INT_FIELD(numCols);
 
@@ -765,11 +765,11 @@ _outUnique(StringInfo str, Unique *node)
 }
 
 static void
-_outHash(StringInfo str, Hash *node)
+_outHash(StringInfo str, const Hash *node)
 {
 	WRITE_NODE_TYPE("HASH");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_OID_FIELD(skewTable);
 	WRITE_INT_FIELD(skewColumn);
@@ -779,13 +779,13 @@ _outHash(StringInfo str, Hash *node)
 }
 
 static void
-_outSetOp(StringInfo str, SetOp *node)
+_outSetOp(StringInfo str, const SetOp *node)
 {
 	int			i;
 
 	WRITE_NODE_TYPE("SETOP");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_ENUM_FIELD(cmd, SetOpCmd);
 	WRITE_ENUM_FIELD(strategy, SetOpStrategy);
@@ -805,29 +805,29 @@ _outSetOp(StringInfo str, SetOp *node)
 }
 
 static void
-_outLockRows(StringInfo str, LockRows *node)
+_outLockRows(StringInfo str, const LockRows *node)
 {
 	WRITE_NODE_TYPE("LOCKROWS");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_NODE_FIELD(rowMarks);
 	WRITE_INT_FIELD(epqParam);
 }
 
 static void
-_outLimit(StringInfo str, Limit *node)
+_outLimit(StringInfo str, const Limit *node)
 {
 	WRITE_NODE_TYPE("LIMIT");
 
-	_outPlanInfo(str, (Plan *) node);
+	_outPlanInfo(str, (const Plan *) node);
 
 	WRITE_NODE_FIELD(limitOffset);
 	WRITE_NODE_FIELD(limitCount);
 }
 
 static void
-_outNestLoopParam(StringInfo str, NestLoopParam *node)
+_outNestLoopParam(StringInfo str, const NestLoopParam *node)
 {
 	WRITE_NODE_TYPE("NESTLOOPPARAM");
 
@@ -836,7 +836,7 @@ _outNestLoopParam(StringInfo str, NestLoopParam *node)
 }
 
 static void
-_outPlanRowMark(StringInfo str, PlanRowMark *node)
+_outPlanRowMark(StringInfo str, const PlanRowMark *node)
 {
 	WRITE_NODE_TYPE("PLANROWMARK");
 
@@ -849,7 +849,7 @@ _outPlanRowMark(StringInfo str, PlanRowMark *node)
 }
 
 static void
-_outPlanInvalItem(StringInfo str, PlanInvalItem *node)
+_outPlanInvalItem(StringInfo str, const PlanInvalItem *node)
 {
 	WRITE_NODE_TYPE("PLANINVALITEM");
 
@@ -864,7 +864,7 @@ _outPlanInvalItem(StringInfo str, PlanInvalItem *node)
  *****************************************************************************/
 
 static void
-_outAlias(StringInfo str, Alias *node)
+_outAlias(StringInfo str, const Alias *node)
 {
 	WRITE_NODE_TYPE("ALIAS");
 
@@ -873,7 +873,7 @@ _outAlias(StringInfo str, Alias *node)
 }
 
 static void
-_outRangeVar(StringInfo str, RangeVar *node)
+_outRangeVar(StringInfo str, const RangeVar *node)
 {
 	WRITE_NODE_TYPE("RANGEVAR");
 
@@ -890,7 +890,7 @@ _outRangeVar(StringInfo str, RangeVar *node)
 }
 
 static void
-_outIntoClause(StringInfo str, IntoClause *node)
+_outIntoClause(StringInfo str, const IntoClause *node)
 {
 	WRITE_NODE_TYPE("INTOCLAUSE");
 
@@ -903,7 +903,7 @@ _outIntoClause(StringInfo str, IntoClause *node)
 }
 
 static void
-_outVar(StringInfo str, Var *node)
+_outVar(StringInfo str, const Var *node)
 {
 	WRITE_NODE_TYPE("VAR");
 
@@ -919,7 +919,7 @@ _outVar(StringInfo str, Var *node)
 }
 
 static void
-_outConst(StringInfo str, Const *node)
+_outConst(StringInfo str, const Const *node)
 {
 	WRITE_NODE_TYPE("CONST");
 
@@ -939,7 +939,7 @@ _outConst(StringInfo str, Const *node)
 }
 
 static void
-_outParam(StringInfo str, Param *node)
+_outParam(StringInfo str, const Param *node)
 {
 	WRITE_NODE_TYPE("PARAM");
 
@@ -952,7 +952,7 @@ _outParam(StringInfo str, Param *node)
 }
 
 static void
-_outAggref(StringInfo str, Aggref *node)
+_outAggref(StringInfo str, const Aggref *node)
 {
 	WRITE_NODE_TYPE("AGGREF");
 
@@ -969,7 +969,7 @@ _outAggref(StringInfo str, Aggref *node)
 }
 
 static void
-_outWindowFunc(StringInfo str, WindowFunc *node)
+_outWindowFunc(StringInfo str, const WindowFunc *node)
 {
 	WRITE_NODE_TYPE("WINDOWFUNC");
 
@@ -985,7 +985,7 @@ _outWindowFunc(StringInfo str, WindowFunc *node)
 }
 
 static void
-_outArrayRef(StringInfo str, ArrayRef *node)
+_outArrayRef(StringInfo str, const ArrayRef *node)
 {
 	WRITE_NODE_TYPE("ARRAYREF");
 
@@ -1000,7 +1000,7 @@ _outArrayRef(StringInfo str, ArrayRef *node)
 }
 
 static void
-_outFuncExpr(StringInfo str, FuncExpr *node)
+_outFuncExpr(StringInfo str, const FuncExpr *node)
 {
 	WRITE_NODE_TYPE("FUNCEXPR");
 
@@ -1015,7 +1015,7 @@ _outFuncExpr(StringInfo str, FuncExpr *node)
 }
 
 static void
-_outNamedArgExpr(StringInfo str, NamedArgExpr *node)
+_outNamedArgExpr(StringInfo str, const NamedArgExpr *node)
 {
 	WRITE_NODE_TYPE("NAMEDARGEXPR");
 
@@ -1026,7 +1026,7 @@ _outNamedArgExpr(StringInfo str, NamedArgExpr *node)
 }
 
 static void
-_outOpExpr(StringInfo str, OpExpr *node)
+_outOpExpr(StringInfo str, const OpExpr *node)
 {
 	WRITE_NODE_TYPE("OPEXPR");
 
@@ -1041,7 +1041,7 @@ _outOpExpr(StringInfo str, OpExpr *node)
 }
 
 static void
-_outDistinctExpr(StringInfo str, DistinctExpr *node)
+_outDistinctExpr(StringInfo str, const DistinctExpr *node)
 {
 	WRITE_NODE_TYPE("DISTINCTEXPR");
 
@@ -1056,7 +1056,7 @@ _outDistinctExpr(StringInfo str, DistinctExpr *node)
 }
 
 static void
-_outNullIfExpr(StringInfo str, NullIfExpr *node)
+_outNullIfExpr(StringInfo str, const NullIfExpr *node)
 {
 	WRITE_NODE_TYPE("NULLIFEXPR");
 
@@ -1071,7 +1071,7 @@ _outNullIfExpr(StringInfo str, NullIfExpr *node)
 }
 
 static void
-_outScalarArrayOpExpr(StringInfo str, ScalarArrayOpExpr *node)
+_outScalarArrayOpExpr(StringInfo str, const ScalarArrayOpExpr *node)
 {
 	WRITE_NODE_TYPE("SCALARARRAYOPEXPR");
 
@@ -1084,7 +1084,7 @@ _outScalarArrayOpExpr(StringInfo str, ScalarArrayOpExpr *node)
 }
 
 static void
-_outBoolExpr(StringInfo str, BoolExpr *node)
+_outBoolExpr(StringInfo str, const BoolExpr *node)
 {
 	char	   *opstr = NULL;
 
@@ -1111,7 +1111,7 @@ _outBoolExpr(StringInfo str, BoolExpr *node)
 }
 
 static void
-_outSubLink(StringInfo str, SubLink *node)
+_outSubLink(StringInfo str, const SubLink *node)
 {
 	WRITE_NODE_TYPE("SUBLINK");
 
@@ -1123,7 +1123,7 @@ _outSubLink(StringInfo str, SubLink *node)
 }
 
 static void
-_outSubPlan(StringInfo str, SubPlan *node)
+_outSubPlan(StringInfo str, const SubPlan *node)
 {
 	WRITE_NODE_TYPE("SUBPLAN");
 
@@ -1145,7 +1145,7 @@ _outSubPlan(StringInfo str, SubPlan *node)
 }
 
 static void
-_outAlternativeSubPlan(StringInfo str, AlternativeSubPlan *node)
+_outAlternativeSubPlan(StringInfo str, const AlternativeSubPlan *node)
 {
 	WRITE_NODE_TYPE("ALTERNATIVESUBPLAN");
 
@@ -1153,7 +1153,7 @@ _outAlternativeSubPlan(StringInfo str, AlternativeSubPlan *node)
 }
 
 static void
-_outFieldSelect(StringInfo str, FieldSelect *node)
+_outFieldSelect(StringInfo str, const FieldSelect *node)
 {
 	WRITE_NODE_TYPE("FIELDSELECT");
 
@@ -1165,7 +1165,7 @@ _outFieldSelect(StringInfo str, FieldSelect *node)
 }
 
 static void
-_outFieldStore(StringInfo str, FieldStore *node)
+_outFieldStore(StringInfo str, const FieldStore *node)
 {
 	WRITE_NODE_TYPE("FIELDSTORE");
 
@@ -1176,7 +1176,7 @@ _outFieldStore(StringInfo str, FieldStore *node)
 }
 
 static void
-_outRelabelType(StringInfo str, RelabelType *node)
+_outRelabelType(StringInfo str, const RelabelType *node)
 {
 	WRITE_NODE_TYPE("RELABELTYPE");
 
@@ -1189,7 +1189,7 @@ _outRelabelType(StringInfo str, RelabelType *node)
 }
 
 static void
-_outCoerceViaIO(StringInfo str, CoerceViaIO *node)
+_outCoerceViaIO(StringInfo str, const CoerceViaIO *node)
 {
 	WRITE_NODE_TYPE("COERCEVIAIO");
 
@@ -1201,7 +1201,7 @@ _outCoerceViaIO(StringInfo str, CoerceViaIO *node)
 }
 
 static void
-_outArrayCoerceExpr(StringInfo str, ArrayCoerceExpr *node)
+_outArrayCoerceExpr(StringInfo str, const ArrayCoerceExpr *node)
 {
 	WRITE_NODE_TYPE("ARRAYCOERCEEXPR");
 
@@ -1216,7 +1216,7 @@ _outArrayCoerceExpr(StringInfo str, ArrayCoerceExpr *node)
 }
 
 static void
-_outConvertRowtypeExpr(StringInfo str, ConvertRowtypeExpr *node)
+_outConvertRowtypeExpr(StringInfo str, const ConvertRowtypeExpr *node)
 {
 	WRITE_NODE_TYPE("CONVERTROWTYPEEXPR");
 
@@ -1227,7 +1227,7 @@ _outConvertRowtypeExpr(StringInfo str, ConvertRowtypeExpr *node)
 }
 
 static void
-_outCollateExpr(StringInfo str, CollateExpr *node)
+_outCollateExpr(StringInfo str, const CollateExpr *node)
 {
 	WRITE_NODE_TYPE("COLLATE");
 
@@ -1237,7 +1237,7 @@ _outCollateExpr(StringInfo str, CollateExpr *node)
 }
 
 static void
-_outCaseExpr(StringInfo str, CaseExpr *node)
+_outCaseExpr(StringInfo str, const CaseExpr *node)
 {
 	WRITE_NODE_TYPE("CASE");
 
@@ -1250,7 +1250,7 @@ _outCaseExpr(StringInfo str, CaseExpr *node)
 }
 
 static void
-_outCaseWhen(StringInfo str, CaseWhen *node)
+_outCaseWhen(StringInfo str, const CaseWhen *node)
 {
 	WRITE_NODE_TYPE("WHEN");
 
@@ -1260,7 +1260,7 @@ _outCaseWhen(StringInfo str, CaseWhen *node)
 }
 
 static void
-_outCaseTestExpr(StringInfo str, CaseTestExpr *node)
+_outCaseTestExpr(StringInfo str, const CaseTestExpr *node)
 {
 	WRITE_NODE_TYPE("CASETESTEXPR");
 
@@ -1270,7 +1270,7 @@ _outCaseTestExpr(StringInfo str, CaseTestExpr *node)
 }
 
 static void
-_outArrayExpr(StringInfo str, ArrayExpr *node)
+_outArrayExpr(StringInfo str, const ArrayExpr *node)
 {
 	WRITE_NODE_TYPE("ARRAY");
 
@@ -1283,7 +1283,7 @@ _outArrayExpr(StringInfo str, ArrayExpr *node)
 }
 
 static void
-_outRowExpr(StringInfo str, RowExpr *node)
+_outRowExpr(StringInfo str, const RowExpr *node)
 {
 	WRITE_NODE_TYPE("ROW");
 
@@ -1295,7 +1295,7 @@ _outRowExpr(StringInfo str, RowExpr *node)
 }
 
 static void
-_outRowCompareExpr(StringInfo str, RowCompareExpr *node)
+_outRowCompareExpr(StringInfo str, const RowCompareExpr *node)
 {
 	WRITE_NODE_TYPE("ROWCOMPARE");
 
@@ -1308,7 +1308,7 @@ _outRowCompareExpr(StringInfo str, RowCompareExpr *node)
 }
 
 static void
-_outCoalesceExpr(StringInfo str, CoalesceExpr *node)
+_outCoalesceExpr(StringInfo str, const CoalesceExpr *node)
 {
 	WRITE_NODE_TYPE("COALESCE");
 
@@ -1319,7 +1319,7 @@ _outCoalesceExpr(StringInfo str, CoalesceExpr *node)
 }
 
 static void
-_outMinMaxExpr(StringInfo str, MinMaxExpr *node)
+_outMinMaxExpr(StringInfo str, const MinMaxExpr *node)
 {
 	WRITE_NODE_TYPE("MINMAX");
 
@@ -1332,7 +1332,7 @@ _outMinMaxExpr(StringInfo str, MinMaxExpr *node)
 }
 
 static void
-_outXmlExpr(StringInfo str, XmlExpr *node)
+_outXmlExpr(StringInfo str, const XmlExpr *node)
 {
 	WRITE_NODE_TYPE("XMLEXPR");
 
@@ -1348,7 +1348,7 @@ _outXmlExpr(StringInfo str, XmlExpr *node)
 }
 
 static void
-_outNullTest(StringInfo str, NullTest *node)
+_outNullTest(StringInfo str, const NullTest *node)
 {
 	WRITE_NODE_TYPE("NULLTEST");
 
@@ -1358,7 +1358,7 @@ _outNullTest(StringInfo str, NullTest *node)
 }
 
 static void
-_outBooleanTest(StringInfo str, BooleanTest *node)
+_outBooleanTest(StringInfo str, const BooleanTest *node)
 {
 	WRITE_NODE_TYPE("BOOLEANTEST");
 
@@ -1367,7 +1367,7 @@ _outBooleanTest(StringInfo str, BooleanTest *node)
 }
 
 static void
-_outCoerceToDomain(StringInfo str, CoerceToDomain *node)
+_outCoerceToDomain(StringInfo str, const CoerceToDomain *node)
 {
 	WRITE_NODE_TYPE("COERCETODOMAIN");
 
@@ -1380,7 +1380,7 @@ _outCoerceToDomain(StringInfo str, CoerceToDomain *node)
 }
 
 static void
-_outCoerceToDomainValue(StringInfo str, CoerceToDomainValue *node)
+_outCoerceToDomainValue(StringInfo str, const CoerceToDomainValue *node)
 {
 	WRITE_NODE_TYPE("COERCETODOMAINVALUE");
 
@@ -1391,7 +1391,7 @@ _outCoerceToDomainValue(StringInfo str, CoerceToDomainValue *node)
 }
 
 static void
-_outSetToDefault(StringInfo str, SetToDefault *node)
+_outSetToDefault(StringInfo str, const SetToDefault *node)
 {
 	WRITE_NODE_TYPE("SETTODEFAULT");
 
@@ -1402,7 +1402,7 @@ _outSetToDefault(StringInfo str, SetToDefault *node)
 }
 
 static void
-_outCurrentOfExpr(StringInfo str, CurrentOfExpr *node)
+_outCurrentOfExpr(StringInfo str, const CurrentOfExpr *node)
 {
 	WRITE_NODE_TYPE("CURRENTOFEXPR");
 
@@ -1412,7 +1412,7 @@ _outCurrentOfExpr(StringInfo str, CurrentOfExpr *node)
 }
 
 static void
-_outTargetEntry(StringInfo str, TargetEntry *node)
+_outTargetEntry(StringInfo str, const TargetEntry *node)
 {
 	WRITE_NODE_TYPE("TARGETENTRY");
 
@@ -1426,7 +1426,7 @@ _outTargetEntry(StringInfo str, TargetEntry *node)
 }
 
 static void
-_outRangeTblRef(StringInfo str, RangeTblRef *node)
+_outRangeTblRef(StringInfo str, const RangeTblRef *node)
 {
 	WRITE_NODE_TYPE("RANGETBLREF");
 
@@ -1434,7 +1434,7 @@ _outRangeTblRef(StringInfo str, RangeTblRef *node)
 }
 
 static void
-_outJoinExpr(StringInfo str, JoinExpr *node)
+_outJoinExpr(StringInfo str, const JoinExpr *node)
 {
 	WRITE_NODE_TYPE("JOINEXPR");
 
@@ -1449,7 +1449,7 @@ _outJoinExpr(StringInfo str, JoinExpr *node)
 }
 
 static void
-_outFromExpr(StringInfo str, FromExpr *node)
+_outFromExpr(StringInfo str, const FromExpr *node)
 {
 	WRITE_NODE_TYPE("FROMEXPR");
 
@@ -1470,7 +1470,7 @@ _outFromExpr(StringInfo str, FromExpr *node)
  * We can print the parent's relids for identification purposes, though.
  */
 static void
-_outPathInfo(StringInfo str, Path *node)
+_outPathInfo(StringInfo str, const Path *node)
 {
 	WRITE_ENUM_FIELD(pathtype, NodeTag);
 	appendStringInfo(str, " :parent_relids ");
@@ -1484,9 +1484,9 @@ _outPathInfo(StringInfo str, Path *node)
  * print the basic stuff of all nodes that inherit from JoinPath
  */
 static void
-_outJoinPathInfo(StringInfo str, JoinPath *node)
+_outJoinPathInfo(StringInfo str, const JoinPath *node)
 {
-	_outPathInfo(str, (Path *) node);
+	_outPathInfo(str, (const Path *) node);
 
 	WRITE_ENUM_FIELD(jointype, JoinType);
 	WRITE_NODE_FIELD(outerjoinpath);
@@ -1495,19 +1495,19 @@ _outJoinPathInfo(StringInfo str, JoinPath *node)
 }
 
 static void
-_outPath(StringInfo str, Path *node)
+_outPath(StringInfo str, const Path *node)
 {
 	WRITE_NODE_TYPE("PATH");
 
-	_outPathInfo(str, (Path *) node);
+	_outPathInfo(str, (const Path *) node);
 }
 
 static void
-_outIndexPath(StringInfo str, IndexPath *node)
+_outIndexPath(StringInfo str, const IndexPath *node)
 {
 	WRITE_NODE_TYPE("INDEXPATH");
 
-	_outPathInfo(str, (Path *) node);
+	_outPathInfo(str, (const Path *) node);
 
 	WRITE_NODE_FIELD(indexinfo);
 	WRITE_NODE_FIELD(indexclauses);
@@ -1521,11 +1521,11 @@ _outIndexPath(StringInfo str, IndexPath *node)
 }
 
 static void
-_outBitmapHeapPath(StringInfo str, BitmapHeapPath *node)
+_outBitmapHeapPath(StringInfo str, const BitmapHeapPath *node)
 {
 	WRITE_NODE_TYPE("BITMAPHEAPPATH");
 
-	_outPathInfo(str, (Path *) node);
+	_outPathInfo(str, (const Path *) node);
 
 	WRITE_NODE_FIELD(bitmapqual);
 	WRITE_BOOL_FIELD(isjoininner);
@@ -1533,94 +1533,94 @@ _outBitmapHeapPath(StringInfo str, BitmapHeapPath *node)
 }
 
 static void
-_outBitmapAndPath(StringInfo str, BitmapAndPath *node)
+_outBitmapAndPath(StringInfo str, const BitmapAndPath *node)
 {
 	WRITE_NODE_TYPE("BITMAPANDPATH");
 
-	_outPathInfo(str, (Path *) node);
+	_outPathInfo(str, (const Path *) node);
 
 	WRITE_NODE_FIELD(bitmapquals);
 	WRITE_FLOAT_FIELD(bitmapselectivity, "%.4f");
 }
 
 static void
-_outBitmapOrPath(StringInfo str, BitmapOrPath *node)
+_outBitmapOrPath(StringInfo str, const BitmapOrPath *node)
 {
 	WRITE_NODE_TYPE("BITMAPORPATH");
 
-	_outPathInfo(str, (Path *) node);
+	_outPathInfo(str, (const Path *) node);
 
 	WRITE_NODE_FIELD(bitmapquals);
 	WRITE_FLOAT_FIELD(bitmapselectivity, "%.4f");
 }
 
 static void
-_outTidPath(StringInfo str, TidPath *node)
+_outTidPath(StringInfo str, const TidPath *node)
 {
 	WRITE_NODE_TYPE("TIDPATH");
 
-	_outPathInfo(str, (Path *) node);
+	_outPathInfo(str, (const Path *) node);
 
 	WRITE_NODE_FIELD(tidquals);
 }
 
 static void
-_outForeignPath(StringInfo str, ForeignPath *node)
+_outForeignPath(StringInfo str, const ForeignPath *node)
 {
 	WRITE_NODE_TYPE("FOREIGNPATH");
 
-	_outPathInfo(str, (Path *) node);
+	_outPathInfo(str, (const Path *) node);
 
 	WRITE_NODE_FIELD(fdwplan);
 }
 
 static void
-_outAppendPath(StringInfo str, AppendPath *node)
+_outAppendPath(StringInfo str, const AppendPath *node)
 {
 	WRITE_NODE_TYPE("APPENDPATH");
 
-	_outPathInfo(str, (Path *) node);
+	_outPathInfo(str, (const Path *) node);
 
 	WRITE_NODE_FIELD(subpaths);
 }
 
 static void
-_outMergeAppendPath(StringInfo str, MergeAppendPath *node)
+_outMergeAppendPath(StringInfo str, const MergeAppendPath *node)
 {
 	WRITE_NODE_TYPE("MERGEAPPENDPATH");
 
-	_outPathInfo(str, (Path *) node);
+	_outPathInfo(str, (const Path *) node);
 
 	WRITE_NODE_FIELD(subpaths);
 	WRITE_FLOAT_FIELD(limit_tuples, "%.0f");
 }
 
 static void
-_outResultPath(StringInfo str, ResultPath *node)
+_outResultPath(StringInfo str, const ResultPath *node)
 {
 	WRITE_NODE_TYPE("RESULTPATH");
 
-	_outPathInfo(str, (Path *) node);
+	_outPathInfo(str, (const Path *) node);
 
 	WRITE_NODE_FIELD(quals);
 }
 
 static void
-_outMaterialPath(StringInfo str, MaterialPath *node)
+_outMaterialPath(StringInfo str, const MaterialPath *node)
 {
 	WRITE_NODE_TYPE("MATERIALPATH");
 
-	_outPathInfo(str, (Path *) node);
+	_outPathInfo(str, (const Path *) node);
 
 	WRITE_NODE_FIELD(subpath);
 }
 
 static void
-_outUniquePath(StringInfo str, UniquePath *node)
+_outUniquePath(StringInfo str, const UniquePath *node)
 {
 	WRITE_NODE_TYPE("UNIQUEPATH");
 
-	_outPathInfo(str, (Path *) node);
+	_outPathInfo(str, (const Path *) node);
 
 	WRITE_NODE_FIELD(subpath);
 	WRITE_ENUM_FIELD(umethod, UniquePathMethod);
@@ -1630,19 +1630,19 @@ _outUniquePath(StringInfo str, UniquePath *node)
 }
 
 static void
-_outNestPath(StringInfo str, NestPath *node)
+_outNestPath(StringInfo str, const NestPath *node)
 {
 	WRITE_NODE_TYPE("NESTPATH");
 
-	_outJoinPathInfo(str, (JoinPath *) node);
+	_outJoinPathInfo(str, (const JoinPath *) node);
 }
 
 static void
-_outMergePath(StringInfo str, MergePath *node)
+_outMergePath(StringInfo str, const MergePath *node)
 {
 	WRITE_NODE_TYPE("MERGEPATH");
 
-	_outJoinPathInfo(str, (JoinPath *) node);
+	_outJoinPathInfo(str, (const JoinPath *) node);
 
 	WRITE_NODE_FIELD(path_mergeclauses);
 	WRITE_NODE_FIELD(outersortkeys);
@@ -1651,18 +1651,18 @@ _outMergePath(StringInfo str, MergePath *node)
 }
 
 static void
-_outHashPath(StringInfo str, HashPath *node)
+_outHashPath(StringInfo str, const HashPath *node)
 {
 	WRITE_NODE_TYPE("HASHPATH");
 
-	_outJoinPathInfo(str, (JoinPath *) node);
+	_outJoinPathInfo(str, (const JoinPath *) node);
 
 	WRITE_NODE_FIELD(path_hashclauses);
 	WRITE_INT_FIELD(num_batches);
 }
 
 static void
-_outPlannerGlobal(StringInfo str, PlannerGlobal *node)
+_outPlannerGlobal(StringInfo str, const PlannerGlobal *node)
 {
 	WRITE_NODE_TYPE("PLANNERGLOBAL");
 
@@ -1681,7 +1681,7 @@ _outPlannerGlobal(StringInfo str, PlannerGlobal *node)
 }
 
 static void
-_outPlannerInfo(StringInfo str, PlannerInfo *node)
+_outPlannerInfo(StringInfo str, const PlannerInfo *node)
 {
 	WRITE_NODE_TYPE("PLANNERINFO");
 
@@ -1722,7 +1722,7 @@ _outPlannerInfo(StringInfo str, PlannerInfo *node)
 }
 
 static void
-_outRelOptInfo(StringInfo str, RelOptInfo *node)
+_outRelOptInfo(StringInfo str, const RelOptInfo *node)
 {
 	WRITE_NODE_TYPE("RELOPTINFO");
 
@@ -1755,7 +1755,7 @@ _outRelOptInfo(StringInfo str, RelOptInfo *node)
 }
 
 static void
-_outIndexOptInfo(StringInfo str, IndexOptInfo *node)
+_outIndexOptInfo(StringInfo str, const IndexOptInfo *node)
 {
 	WRITE_NODE_TYPE("INDEXOPTINFO");
 
@@ -1776,7 +1776,7 @@ _outIndexOptInfo(StringInfo str, IndexOptInfo *node)
 }
 
 static void
-_outEquivalenceClass(StringInfo str, EquivalenceClass *node)
+_outEquivalenceClass(StringInfo str, const EquivalenceClass *node)
 {
 	/*
 	 * To simplify reading, we just chase up to the topmost merged EC and
@@ -1801,7 +1801,7 @@ _outEquivalenceClass(StringInfo str, EquivalenceClass *node)
 }
 
 static void
-_outEquivalenceMember(StringInfo str, EquivalenceMember *node)
+_outEquivalenceMember(StringInfo str, const EquivalenceMember *node)
 {
 	WRITE_NODE_TYPE("EQUIVALENCEMEMBER");
 
@@ -1813,7 +1813,7 @@ _outEquivalenceMember(StringInfo str, EquivalenceMember *node)
 }
 
 static void
-_outPathKey(StringInfo str, PathKey *node)
+_outPathKey(StringInfo str, const PathKey *node)
 {
 	WRITE_NODE_TYPE("PATHKEY");
 
@@ -1824,7 +1824,7 @@ _outPathKey(StringInfo str, PathKey *node)
 }
 
 static void
-_outRestrictInfo(StringInfo str, RestrictInfo *node)
+_outRestrictInfo(StringInfo str, const RestrictInfo *node)
 {
 	WRITE_NODE_TYPE("RESTRICTINFO");
 
@@ -1853,7 +1853,7 @@ _outRestrictInfo(StringInfo str, RestrictInfo *node)
 }
 
 static void
-_outInnerIndexscanInfo(StringInfo str, InnerIndexscanInfo *node)
+_outInnerIndexscanInfo(StringInfo str, const InnerIndexscanInfo *node)
 {
 	WRITE_NODE_TYPE("INNERINDEXSCANINFO");
 	WRITE_BITMAPSET_FIELD(other_relids);
@@ -1863,7 +1863,7 @@ _outInnerIndexscanInfo(StringInfo str, InnerIndexscanInfo *node)
 }
 
 static void
-_outPlaceHolderVar(StringInfo str, PlaceHolderVar *node)
+_outPlaceHolderVar(StringInfo str, const PlaceHolderVar *node)
 {
 	WRITE_NODE_TYPE("PLACEHOLDERVAR");
 
@@ -1874,7 +1874,7 @@ _outPlaceHolderVar(StringInfo str, PlaceHolderVar *node)
 }
 
 static void
-_outSpecialJoinInfo(StringInfo str, SpecialJoinInfo *node)
+_outSpecialJoinInfo(StringInfo str, const SpecialJoinInfo *node)
 {
 	WRITE_NODE_TYPE("SPECIALJOININFO");
 
@@ -1889,7 +1889,7 @@ _outSpecialJoinInfo(StringInfo str, SpecialJoinInfo *node)
 }
 
 static void
-_outAppendRelInfo(StringInfo str, AppendRelInfo *node)
+_outAppendRelInfo(StringInfo str, const AppendRelInfo *node)
 {
 	WRITE_NODE_TYPE("APPENDRELINFO");
 
@@ -1902,7 +1902,7 @@ _outAppendRelInfo(StringInfo str, AppendRelInfo *node)
 }
 
 static void
-_outPlaceHolderInfo(StringInfo str, PlaceHolderInfo *node)
+_outPlaceHolderInfo(StringInfo str, const PlaceHolderInfo *node)
 {
 	WRITE_NODE_TYPE("PLACEHOLDERINFO");
 
@@ -1915,7 +1915,7 @@ _outPlaceHolderInfo(StringInfo str, PlaceHolderInfo *node)
 }
 
 static void
-_outMinMaxAggInfo(StringInfo str, MinMaxAggInfo *node)
+_outMinMaxAggInfo(StringInfo str, const MinMaxAggInfo *node)
 {
 	WRITE_NODE_TYPE("MINMAXAGGINFO");
 
@@ -1929,7 +1929,7 @@ _outMinMaxAggInfo(StringInfo str, MinMaxAggInfo *node)
 }
 
 static void
-_outPlannerParamItem(StringInfo str, PlannerParamItem *node)
+_outPlannerParamItem(StringInfo str, const PlannerParamItem *node)
 {
 	WRITE_NODE_TYPE("PLANNERPARAMITEM");
 
@@ -1944,7 +1944,7 @@ _outPlannerParamItem(StringInfo str, PlannerParamItem *node)
  *****************************************************************************/
 
 static void
-_outCreateStmt(StringInfo str, CreateStmt *node)
+_outCreateStmt(StringInfo str, const CreateStmt *node)
 {
 	WRITE_NODE_TYPE("CREATESTMT");
 
@@ -1960,18 +1960,18 @@ _outCreateStmt(StringInfo str, CreateStmt *node)
 }
 
 static void
-_outCreateForeignTableStmt(StringInfo str, CreateForeignTableStmt *node)
+_outCreateForeignTableStmt(StringInfo str, const CreateForeignTableStmt *node)
 {
 	WRITE_NODE_TYPE("CREATEFOREIGNTABLESTMT");
 
-	_outCreateStmt(str, (CreateStmt *) &node->base);
+	_outCreateStmt(str, (const CreateStmt *) &node->base);
 
 	WRITE_STRING_FIELD(servername);
 	WRITE_NODE_FIELD(options);
 }
 
 static void
-_outIndexStmt(StringInfo str, IndexStmt *node)
+_outIndexStmt(StringInfo str, const IndexStmt *node)
 {
 	WRITE_NODE_TYPE("INDEXSTMT");
 
@@ -1994,7 +1994,7 @@ _outIndexStmt(StringInfo str, IndexStmt *node)
 }
 
 static void
-_outNotifyStmt(StringInfo str, NotifyStmt *node)
+_outNotifyStmt(StringInfo str, const NotifyStmt *node)
 {
 	WRITE_NODE_TYPE("NOTIFY");
 
@@ -2003,7 +2003,7 @@ _outNotifyStmt(StringInfo str, NotifyStmt *node)
 }
 
 static void
-_outDeclareCursorStmt(StringInfo str, DeclareCursorStmt *node)
+_outDeclareCursorStmt(StringInfo str, const DeclareCursorStmt *node)
 {
 	WRITE_NODE_TYPE("DECLARECURSOR");
 
@@ -2013,7 +2013,7 @@ _outDeclareCursorStmt(StringInfo str, DeclareCursorStmt *node)
 }
 
 static void
-_outSelectStmt(StringInfo str, SelectStmt *node)
+_outSelectStmt(StringInfo str, const SelectStmt *node)
 {
 	WRITE_NODE_TYPE("SELECT");
 
@@ -2038,7 +2038,7 @@ _outSelectStmt(StringInfo str, SelectStmt *node)
 }
 
 static void
-_outFuncCall(StringInfo str, FuncCall *node)
+_outFuncCall(StringInfo str, const FuncCall *node)
 {
 	WRITE_NODE_TYPE("FUNCCALL");
 
@@ -2053,7 +2053,7 @@ _outFuncCall(StringInfo str, FuncCall *node)
 }
 
 static void
-_outDefElem(StringInfo str, DefElem *node)
+_outDefElem(StringInfo str, const DefElem *node)
 {
 	WRITE_NODE_TYPE("DEFELEM");
 
@@ -2064,7 +2064,7 @@ _outDefElem(StringInfo str, DefElem *node)
 }
 
 static void
-_outInhRelation(StringInfo str, InhRelation *node)
+_outInhRelation(StringInfo str, const InhRelation *node)
 {
 	WRITE_NODE_TYPE("INHRELATION");
 
@@ -2073,7 +2073,7 @@ _outInhRelation(StringInfo str, InhRelation *node)
 }
 
 static void
-_outLockingClause(StringInfo str, LockingClause *node)
+_outLockingClause(StringInfo str, const LockingClause *node)
 {
 	WRITE_NODE_TYPE("LOCKINGCLAUSE");
 
@@ -2083,7 +2083,7 @@ _outLockingClause(StringInfo str, LockingClause *node)
 }
 
 static void
-_outXmlSerialize(StringInfo str, XmlSerialize *node)
+_outXmlSerialize(StringInfo str, const XmlSerialize *node)
 {
 	WRITE_NODE_TYPE("XMLSERIALIZE");
 
@@ -2094,7 +2094,7 @@ _outXmlSerialize(StringInfo str, XmlSerialize *node)
 }
 
 static void
-_outColumnDef(StringInfo str, ColumnDef *node)
+_outColumnDef(StringInfo str, const ColumnDef *node)
 {
 	WRITE_NODE_TYPE("COLUMNDEF");
 
@@ -2114,7 +2114,7 @@ _outColumnDef(StringInfo str, ColumnDef *node)
 }
 
 static void
-_outTypeName(StringInfo str, TypeName *node)
+_outTypeName(StringInfo str, const TypeName *node)
 {
 	WRITE_NODE_TYPE("TYPENAME");
 
@@ -2129,7 +2129,7 @@ _outTypeName(StringInfo str, TypeName *node)
 }
 
 static void
-_outTypeCast(StringInfo str, TypeCast *node)
+_outTypeCast(StringInfo str, const TypeCast *node)
 {
 	WRITE_NODE_TYPE("TYPECAST");
 
@@ -2139,7 +2139,7 @@ _outTypeCast(StringInfo str, TypeCast *node)
 }
 
 static void
-_outCollateClause(StringInfo str, CollateClause *node)
+_outCollateClause(StringInfo str, const CollateClause *node)
 {
 	WRITE_NODE_TYPE("COLLATECLAUSE");
 
@@ -2149,7 +2149,7 @@ _outCollateClause(StringInfo str, CollateClause *node)
 }
 
 static void
-_outIndexElem(StringInfo str, IndexElem *node)
+_outIndexElem(StringInfo str, const IndexElem *node)
 {
 	WRITE_NODE_TYPE("INDEXELEM");
 
@@ -2163,7 +2163,7 @@ _outIndexElem(StringInfo str, IndexElem *node)
 }
 
 static void
-_outQuery(StringInfo str, Query *node)
+_outQuery(StringInfo str, const Query *node)
 {
 	WRITE_NODE_TYPE("QUERY");
 
@@ -2223,7 +2223,7 @@ _outQuery(StringInfo str, Query *node)
 }
 
 static void
-_outSortGroupClause(StringInfo str, SortGroupClause *node)
+_outSortGroupClause(StringInfo str, const SortGroupClause *node)
 {
 	WRITE_NODE_TYPE("SORTGROUPCLAUSE");
 
@@ -2235,7 +2235,7 @@ _outSortGroupClause(StringInfo str, SortGroupClause *node)
 }
 
 static void
-_outWindowClause(StringInfo str, WindowClause *node)
+_outWindowClause(StringInfo str, const WindowClause *node)
 {
 	WRITE_NODE_TYPE("WINDOWCLAUSE");
 
@@ -2251,7 +2251,7 @@ _outWindowClause(StringInfo str, WindowClause *node)
 }
 
 static void
-_outRowMarkClause(StringInfo str, RowMarkClause *node)
+_outRowMarkClause(StringInfo str, const RowMarkClause *node)
 {
 	WRITE_NODE_TYPE("ROWMARKCLAUSE");
 
@@ -2262,7 +2262,7 @@ _outRowMarkClause(StringInfo str, RowMarkClause *node)
 }
 
 static void
-_outWithClause(StringInfo str, WithClause *node)
+_outWithClause(StringInfo str, const WithClause *node)
 {
 	WRITE_NODE_TYPE("WITHCLAUSE");
 
@@ -2272,7 +2272,7 @@ _outWithClause(StringInfo str, WithClause *node)
 }
 
 static void
-_outCommonTableExpr(StringInfo str, CommonTableExpr *node)
+_outCommonTableExpr(StringInfo str, const CommonTableExpr *node)
 {
 	WRITE_NODE_TYPE("COMMONTABLEEXPR");
 
@@ -2289,7 +2289,7 @@ _outCommonTableExpr(StringInfo str, CommonTableExpr *node)
 }
 
 static void
-_outSetOperationStmt(StringInfo str, SetOperationStmt *node)
+_outSetOperationStmt(StringInfo str, const SetOperationStmt *node)
 {
 	WRITE_NODE_TYPE("SETOPERATIONSTMT");
 
@@ -2304,7 +2304,7 @@ _outSetOperationStmt(StringInfo str, SetOperationStmt *node)
 }
 
 static void
-_outRangeTblEntry(StringInfo str, RangeTblEntry *node)
+_outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
 {
 	WRITE_NODE_TYPE("RTE");
 
@@ -2358,7 +2358,7 @@ _outRangeTblEntry(StringInfo str, RangeTblEntry *node)
 }
 
 static void
-_outAExpr(StringInfo str, A_Expr *node)
+_outAExpr(StringInfo str, const A_Expr *node)
 {
 	WRITE_NODE_TYPE("AEXPR");
 
@@ -2414,7 +2414,7 @@ _outAExpr(StringInfo str, A_Expr *node)
 }
 
 static void
-_outValue(StringInfo str, Value *value)
+_outValue(StringInfo str, const Value *value)
 {
 	switch (value->type)
 	{
@@ -2449,7 +2449,7 @@ _outValue(StringInfo str, Value *value)
 }
 
 static void
-_outColumnRef(StringInfo str, ColumnRef *node)
+_outColumnRef(StringInfo str, const ColumnRef *node)
 {
 	WRITE_NODE_TYPE("COLUMNREF");
 
@@ -2458,7 +2458,7 @@ _outColumnRef(StringInfo str, ColumnRef *node)
 }
 
 static void
-_outParamRef(StringInfo str, ParamRef *node)
+_outParamRef(StringInfo str, const ParamRef *node)
 {
 	WRITE_NODE_TYPE("PARAMREF");
 
@@ -2467,7 +2467,7 @@ _outParamRef(StringInfo str, ParamRef *node)
 }
 
 static void
-_outAConst(StringInfo str, A_Const *node)
+_outAConst(StringInfo str, const A_Const *node)
 {
 	WRITE_NODE_TYPE("A_CONST");
 
@@ -2477,13 +2477,13 @@ _outAConst(StringInfo str, A_Const *node)
 }
 
 static void
-_outA_Star(StringInfo str, A_Star *node)
+_outA_Star(StringInfo str, const A_Star *node)
 {
 	WRITE_NODE_TYPE("A_STAR");
 }
 
 static void
-_outA_Indices(StringInfo str, A_Indices *node)
+_outA_Indices(StringInfo str, const A_Indices *node)
 {
 	WRITE_NODE_TYPE("A_INDICES");
 
@@ -2492,7 +2492,7 @@ _outA_Indices(StringInfo str, A_Indices *node)
 }
 
 static void
-_outA_Indirection(StringInfo str, A_Indirection *node)
+_outA_Indirection(StringInfo str, const A_Indirection *node)
 {
 	WRITE_NODE_TYPE("A_INDIRECTION");
 
@@ -2501,7 +2501,7 @@ _outA_Indirection(StringInfo str, A_Indirection *node)
 }
 
 static void
-_outA_ArrayExpr(StringInfo str, A_ArrayExpr *node)
+_outA_ArrayExpr(StringInfo str, const A_ArrayExpr *node)
 {
 	WRITE_NODE_TYPE("A_ARRAYEXPR");
 
@@ -2510,7 +2510,7 @@ _outA_ArrayExpr(StringInfo str, A_ArrayExpr *node)
 }
 
 static void
-_outResTarget(StringInfo str, ResTarget *node)
+_outResTarget(StringInfo str, const ResTarget *node)
 {
 	WRITE_NODE_TYPE("RESTARGET");
 
@@ -2521,7 +2521,7 @@ _outResTarget(StringInfo str, ResTarget *node)
 }
 
 static void
-_outSortBy(StringInfo str, SortBy *node)
+_outSortBy(StringInfo str, const SortBy *node)
 {
 	WRITE_NODE_TYPE("SORTBY");
 
@@ -2533,7 +2533,7 @@ _outSortBy(StringInfo str, SortBy *node)
 }
 
 static void
-_outWindowDef(StringInfo str, WindowDef *node)
+_outWindowDef(StringInfo str, const WindowDef *node)
 {
 	WRITE_NODE_TYPE("WINDOWDEF");
 
@@ -2548,7 +2548,7 @@ _outWindowDef(StringInfo str, WindowDef *node)
 }
 
 static void
-_outRangeSubselect(StringInfo str, RangeSubselect *node)
+_outRangeSubselect(StringInfo str, const RangeSubselect *node)
 {
 	WRITE_NODE_TYPE("RANGESUBSELECT");
 
@@ -2557,7 +2557,7 @@ _outRangeSubselect(StringInfo str, RangeSubselect *node)
 }
 
 static void
-_outRangeFunction(StringInfo str, RangeFunction *node)
+_outRangeFunction(StringInfo str, const RangeFunction *node)
 {
 	WRITE_NODE_TYPE("RANGEFUNCTION");
 
@@ -2567,7 +2567,7 @@ _outRangeFunction(StringInfo str, RangeFunction *node)
 }
 
 static void
-_outConstraint(StringInfo str, Constraint *node)
+_outConstraint(StringInfo str, const Constraint *node)
 {
 	WRITE_NODE_TYPE("CONSTRAINT");
 
@@ -2668,7 +2668,7 @@ _outConstraint(StringInfo str, Constraint *node)
  *	  converts a Node into ascii string and append it to 'str'
  */
 static void
-_outNode(StringInfo str, void *obj)
+_outNode(StringInfo str, const void *obj)
 {
 	if (obj == NULL)
 		appendStringInfo(str, "<>");
@@ -3168,7 +3168,7 @@ _outNode(StringInfo str, void *obj)
  *	   returns the ascii representation of the Node as a palloc'd string
  */
 char *
-nodeToString(void *obj)
+nodeToString(const void *obj)
 {
 	StringInfoData str;
 
diff --git a/src/backend/nodes/print.c b/src/backend/nodes/print.c
index 5fe4fd5520c..2d607674100 100644
--- a/src/backend/nodes/print.c
+++ b/src/backend/nodes/print.c
@@ -31,7 +31,7 @@
  *	  print contents of Node to stdout
  */
 void
-print(void *obj)
+print(const void *obj)
 {
 	char	   *s;
 	char	   *f;
@@ -49,7 +49,7 @@ print(void *obj)
  *	  pretty-print contents of Node to stdout
  */
 void
-pprint(void *obj)
+pprint(const void *obj)
 {
 	char	   *s;
 	char	   *f;
@@ -67,7 +67,7 @@ pprint(void *obj)
  *	  send pretty-printed contents of Node to postmaster log
  */
 void
-elog_node_display(int lev, const char *title, void *obj, bool pretty)
+elog_node_display(int lev, const char *title, const void *obj, bool pretty)
 {
 	char	   *s;
 	char	   *f;
@@ -249,9 +249,9 @@ pretty_format_node_dump(const char *dump)
  *	  print contents of range table
  */
 void
-print_rt(List *rtable)
+print_rt(const List *rtable)
 {
-	ListCell   *l;
+	const ListCell   *l;
 	int			i = 1;
 
 	printf("resno\trefname  \trelid\tinFromCl\n");
@@ -304,7 +304,7 @@ print_rt(List *rtable)
  *	  print an expression
  */
 void
-print_expr(Node *expr, List *rtable)
+print_expr(const Node *expr, const List *rtable)
 {
 	if (expr == NULL)
 	{
@@ -314,7 +314,7 @@ print_expr(Node *expr, List *rtable)
 
 	if (IsA(expr, Var))
 	{
-		Var		   *var = (Var *) expr;
+		const Var		   *var = (const Var *) expr;
 		char	   *relname,
 				   *attname;
 
@@ -348,7 +348,7 @@ print_expr(Node *expr, List *rtable)
 	}
 	else if (IsA(expr, Const))
 	{
-		Const	   *c = (Const *) expr;
+		const Const	   *c = (const Const *) expr;
 		Oid			typoutput;
 		bool		typIsVarlena;
 		char	   *outputstr;
@@ -368,26 +368,26 @@ print_expr(Node *expr, List *rtable)
 	}
 	else if (IsA(expr, OpExpr))
 	{
-		OpExpr	   *e = (OpExpr *) expr;
+		const OpExpr	   *e = (const OpExpr *) expr;
 		char	   *opname;
 
 		opname = get_opname(e->opno);
 		if (list_length(e->args) > 1)
 		{
-			print_expr(get_leftop((Expr *) e), rtable);
+			print_expr(get_leftop((const Expr *) e), rtable);
 			printf(" %s ", ((opname != NULL) ? opname : "(invalid operator)"));
-			print_expr(get_rightop((Expr *) e), rtable);
+			print_expr(get_rightop((const Expr *) e), rtable);
 		}
 		else
 		{
 			/* we print prefix and postfix ops the same... */
 			printf("%s ", ((opname != NULL) ? opname : "(invalid operator)"));
-			print_expr(get_leftop((Expr *) e), rtable);
+			print_expr(get_leftop((const Expr *) e), rtable);
 		}
 	}
 	else if (IsA(expr, FuncExpr))
 	{
-		FuncExpr   *e = (FuncExpr *) expr;
+		const FuncExpr   *e = (const FuncExpr *) expr;
 		char	   *funcname;
 		ListCell   *l;
 
@@ -410,9 +410,9 @@ print_expr(Node *expr, List *rtable)
  *	  pathkeys list of PathKeys
  */
 void
-print_pathkeys(List *pathkeys, List *rtable)
+print_pathkeys(const List *pathkeys, const List *rtable)
 {
-	ListCell   *i;
+	const ListCell   *i;
 
 	printf("(");
 	foreach(i, pathkeys)
@@ -450,9 +450,9 @@ print_pathkeys(List *pathkeys, List *rtable)
  *	  print targetlist in a more legible way.
  */
 void
-print_tl(List *tlist, List *rtable)
+print_tl(const List *tlist, const List *rtable)
 {
-	ListCell   *tl;
+	const ListCell   *tl;
 
 	printf("(\n");
 	foreach(tl, tlist)
diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c
index ad029501d29..16137e01663 100644
--- a/src/backend/optimizer/util/clauses.c
+++ b/src/backend/optimizer/util/clauses.c
@@ -181,9 +181,9 @@ make_opclause(Oid opno, Oid opresulttype, bool opretset,
  *		or (op expr)
  */
 Node *
-get_leftop(Expr *clause)
+get_leftop(const Expr *clause)
 {
-	OpExpr	   *expr = (OpExpr *) clause;
+	const OpExpr	   *expr = (const OpExpr *) clause;
 
 	if (expr->args != NIL)
 		return linitial(expr->args);
@@ -198,9 +198,9 @@ get_leftop(Expr *clause)
  * NB: result will be NULL if applied to a unary op clause.
  */
 Node *
-get_rightop(Expr *clause)
+get_rightop(const Expr *clause)
 {
-	OpExpr	   *expr = (OpExpr *) clause;
+	const OpExpr	   *expr = (const OpExpr *) clause;
 
 	if (list_length(expr->args) >= 2)
 		return lsecond(expr->args);
diff --git a/src/include/nodes/nodeFuncs.h b/src/include/nodes/nodeFuncs.h
index 591f2a9ca03..4980dd8f12c 100644
--- a/src/include/nodes/nodeFuncs.h
+++ b/src/include/nodes/nodeFuncs.h
@@ -26,17 +26,17 @@
 #define QTW_DONT_COPY_QUERY			0x20		/* do not copy top Query */
 
 
-extern Oid	exprType(Node *expr);
-extern int32 exprTypmod(Node *expr);
-extern bool exprIsLengthCoercion(Node *expr, int32 *coercedTypmod);
+extern Oid	exprType(const Node *expr);
+extern int32 exprTypmod(const Node *expr);
+extern bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod);
 extern bool expression_returns_set(Node *clause);
 
-extern Oid	exprCollation(Node *expr);
-extern Oid	exprInputCollation(Node *expr);
+extern Oid	exprCollation(const Node *expr);
+extern Oid	exprInputCollation(const Node *expr);
 extern void exprSetCollation(Node *expr, Oid collation);
 extern void exprSetInputCollation(Node *expr, Oid inputcollation);
 
-extern int	exprLocation(Node *expr);
+extern int	exprLocation(const Node *expr);
 
 extern bool expression_tree_walker(Node *node, bool (*walker) (),
 											   void *context);
diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h
index 3a240897985..f0c6381d437 100644
--- a/src/include/nodes/nodes.h
+++ b/src/include/nodes/nodes.h
@@ -431,7 +431,7 @@ typedef struct Node
 	NodeTag		type;
 } Node;
 
-#define nodeTag(nodeptr)		(((Node*)(nodeptr))->type)
+#define nodeTag(nodeptr)		(((const Node*)(nodeptr))->type)
 
 /*
  * newNode -
@@ -487,7 +487,7 @@ extern PGDLLIMPORT Node *newNodeMacroHolder;
 /*
  * nodes/{outfuncs.c,print.c}
  */
-extern char *nodeToString(void *obj);
+extern char *nodeToString(const void *obj);
 
 /*
  * nodes/{readfuncs.c,read.c}
@@ -497,12 +497,12 @@ extern void *stringToNode(char *str);
 /*
  * nodes/copyfuncs.c
  */
-extern void *copyObject(void *obj);
+extern void *copyObject(const void *obj);
 
 /*
  * nodes/equalfuncs.c
  */
-extern bool equal(void *a, void *b);
+extern bool equal(const void *a, const void *b);
 
 
 /*
diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h
index 38b94aaa012..4d11eb741d9 100644
--- a/src/include/nodes/pg_list.h
+++ b/src/include/nodes/pg_list.h
@@ -77,7 +77,7 @@ struct ListCell
 #ifdef USE_INLINE
 
 static inline ListCell *
-list_head(List *l)
+list_head(const List *l)
 {
 	return l ? l->head : NULL;
 }
@@ -89,15 +89,15 @@ list_tail(List *l)
 }
 
 static inline int
-list_length(List *l)
+list_length(const List *l)
 {
 	return l ? l->length : 0;
 }
 #else
 
-extern ListCell *list_head(List *l);
+extern ListCell *list_head(const List *l);
 extern ListCell *list_tail(List *l);
-extern int	list_length(List *l);
+extern int	list_length(const List *l);
 #endif   /* USE_INLINE */
 
 /*
@@ -206,14 +206,14 @@ extern List *lcons_oid(Oid datum, List *list);
 extern List *list_concat(List *list1, List *list2);
 extern List *list_truncate(List *list, int new_size);
 
-extern void *list_nth(List *list, int n);
-extern int	list_nth_int(List *list, int n);
-extern Oid	list_nth_oid(List *list, int n);
+extern void *list_nth(const List *list, int n);
+extern int	list_nth_int(const List *list, int n);
+extern Oid	list_nth_oid(const List *list, int n);
 
-extern bool list_member(List *list, void *datum);
-extern bool list_member_ptr(List *list, void *datum);
-extern bool list_member_int(List *list, int datum);
-extern bool list_member_oid(List *list, Oid datum);
+extern bool list_member(const List *list, const void *datum);
+extern bool list_member_ptr(const List *list, const void *datum);
+extern bool list_member_int(const List *list, int datum);
+extern bool list_member_oid(const List *list, Oid datum);
 
 extern List *list_delete(List *list, void *datum);
 extern List *list_delete_ptr(List *list, void *datum);
@@ -222,19 +222,19 @@ extern List *list_delete_oid(List *list, Oid datum);
 extern List *list_delete_first(List *list);
 extern List *list_delete_cell(List *list, ListCell *cell, ListCell *prev);
 
-extern List *list_union(List *list1, List *list2);
-extern List *list_union_ptr(List *list1, List *list2);
-extern List *list_union_int(List *list1, List *list2);
-extern List *list_union_oid(List *list1, List *list2);
+extern List *list_union(const List *list1, const List *list2);
+extern List *list_union_ptr(const List *list1, const List *list2);
+extern List *list_union_int(const List *list1, const List *list2);
+extern List *list_union_oid(const List *list1, const List *list2);
 
-extern List *list_intersection(List *list1, List *list2);
+extern List *list_intersection(const List *list1, const List *list2);
 
 /* currently, there's no need for list_intersection_int etc */
 
-extern List *list_difference(List *list1, List *list2);
-extern List *list_difference_ptr(List *list1, List *list2);
-extern List *list_difference_int(List *list1, List *list2);
-extern List *list_difference_oid(List *list1, List *list2);
+extern List *list_difference(const List *list1, const List *list2);
+extern List *list_difference_ptr(const List *list1, const List *list2);
+extern List *list_difference_int(const List *list1, const List *list2);
+extern List *list_difference_oid(const List *list1, const List *list2);
 
 extern List *list_append_unique(List *list, void *datum);
 extern List *list_append_unique_ptr(List *list, void *datum);
@@ -249,8 +249,8 @@ extern List *list_concat_unique_oid(List *list1, List *list2);
 extern void list_free(List *list);
 extern void list_free_deep(List *list);
 
-extern List *list_copy(List *list);
-extern List *list_copy_tail(List *list, int nskip);
+extern List *list_copy(const List *list);
+extern List *list_copy_tail(const List *list, int nskip);
 
 /*
  * To ease migration to the new list API, a set of compatibility
diff --git a/src/include/nodes/print.h b/src/include/nodes/print.h
index 8bac7b024b9..f4e0ff3e743 100644
--- a/src/include/nodes/print.h
+++ b/src/include/nodes/print.h
@@ -19,16 +19,16 @@
 
 #define nodeDisplay(x)		pprint(x)
 
-extern void print(void *obj);
-extern void pprint(void *obj);
+extern void print(const void *obj);
+extern void pprint(const void *obj);
 extern void elog_node_display(int lev, const char *title,
-				  void *obj, bool pretty);
+				  const void *obj, bool pretty);
 extern char *format_node_dump(const char *dump);
 extern char *pretty_format_node_dump(const char *dump);
-extern void print_rt(List *rtable);
-extern void print_expr(Node *expr, List *rtable);
-extern void print_pathkeys(List *pathkeys, List *rtable);
-extern void print_tl(List *tlist, List *rtable);
+extern void print_rt(const List *rtable);
+extern void print_expr(const Node *expr, const List *rtable);
+extern void print_pathkeys(const List *pathkeys, const List *rtable);
+extern void print_tl(const List *tlist, const List *rtable);
 extern void print_slot(TupleTableSlot *slot);
 
 #endif   /* PRINT_H */
diff --git a/src/include/optimizer/clauses.h b/src/include/optimizer/clauses.h
index 4cef7fadb2a..7b8ee51cca7 100644
--- a/src/include/optimizer/clauses.h
+++ b/src/include/optimizer/clauses.h
@@ -31,8 +31,8 @@ typedef struct
 extern Expr *make_opclause(Oid opno, Oid opresulttype, bool opretset,
 			  Expr *leftop, Expr *rightop,
 			  Oid opcollid, Oid inputcollid);
-extern Node *get_leftop(Expr *clause);
-extern Node *get_rightop(Expr *clause);
+extern Node *get_leftop(const Expr *clause);
+extern Node *get_rightop(const Expr *clause);
 
 extern bool not_clause(Node *clause);
 extern Expr *make_notclause(Expr *notclause);
-- 
GitLab