1 /*-------------------------------------------------------------------------
2  *
3  * outfuncs.c
4  *	  Output functions for Postgres tree nodes.
5  *
6  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  *	  src/backend/nodes/outfuncs.c
12  *
13  * NOTES
14  *	  Every node type that can appear in stored rules' parsetrees *must*
15  *	  have an output function defined here (as well as an input function
16  *	  in readfuncs.c).  In addition, plan nodes should have input and
17  *	  output functions so that they can be sent to parallel workers.
18  *
19  *	  For use in debugging, we also provide output functions for nodes
20  *	  that appear in raw parsetrees and planner Paths.  These node types
21  *	  need not have input functions.  Output support for raw parsetrees
22  *	  is somewhat incomplete, too; in particular, utility statements are
23  *	  almost entirely unsupported.  We try to support everything that can
24  *	  appear in a raw SELECT, though.
25  *
26  *-------------------------------------------------------------------------
27  */
28 #include "postgres.h"
29 
30 #include <ctype.h>
31 
32 #include "lib/stringinfo.h"
33 #include "miscadmin.h"
34 #include "nodes/extensible.h"
35 #include "nodes/pathnodes.h"
36 #include "nodes/plannodes.h"
37 #include "utils/datum.h"
38 #include "utils/rel.h"
39 
40 static void outChar(StringInfo str, char c);
41 
42 
43 /*
44  * Macros to simplify output of different kinds of fields.  Use these
45  * wherever possible to reduce the chance for silly typos.  Note that these
46  * hard-wire conventions about the names of the local variables in an Out
47  * routine.
48  */
49 
50 /* Write the label for the node type */
51 #define WRITE_NODE_TYPE(nodelabel) \
52 	appendStringInfoString(str, nodelabel)
53 
54 /* Write an integer field (anything written as ":fldname %d") */
55 #define WRITE_INT_FIELD(fldname) \
56 	appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)
57 
58 /* Write an unsigned integer field (anything written as ":fldname %u") */
59 #define WRITE_UINT_FIELD(fldname) \
60 	appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
61 
62 /* Write an unsigned integer field (anything written with UINT64_FORMAT) */
63 #define WRITE_UINT64_FIELD(fldname) \
64 	appendStringInfo(str, " :" CppAsString(fldname) " " UINT64_FORMAT, \
65 					 node->fldname)
66 
67 /* Write an OID field (don't hard-wire assumption that OID is same as uint) */
68 #define WRITE_OID_FIELD(fldname) \
69 	appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
70 
71 /* Write a long-integer field */
72 #define WRITE_LONG_FIELD(fldname) \
73 	appendStringInfo(str, " :" CppAsString(fldname) " %ld", node->fldname)
74 
75 /* Write a char field (ie, one ascii character) */
76 #define WRITE_CHAR_FIELD(fldname) \
77 	(appendStringInfo(str, " :" CppAsString(fldname) " "), \
78 	 outChar(str, node->fldname))
79 
80 /* Write an enumerated-type field as an integer code */
81 #define WRITE_ENUM_FIELD(fldname, enumtype) \
82 	appendStringInfo(str, " :" CppAsString(fldname) " %d", \
83 					 (int) node->fldname)
84 
85 /* Write a float field --- caller must give format to define precision */
86 #define WRITE_FLOAT_FIELD(fldname,format) \
87 	appendStringInfo(str, " :" CppAsString(fldname) " " format, node->fldname)
88 
89 /* Write a boolean field */
90 #define WRITE_BOOL_FIELD(fldname) \
91 	appendStringInfo(str, " :" CppAsString(fldname) " %s", \
92 					 booltostr(node->fldname))
93 
94 /* Write a character-string (possibly NULL) field */
95 #define WRITE_STRING_FIELD(fldname) \
96 	(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
97 	 outToken(str, node->fldname))
98 
99 /* Write a parse location field (actually same as INT case) */
100 #define WRITE_LOCATION_FIELD(fldname) \
101 	appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)
102 
103 /* Write a Node field */
104 #define WRITE_NODE_FIELD(fldname) \
105 	(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
106 	 outNode(str, node->fldname))
107 
108 /* Write a bitmapset field */
109 #define WRITE_BITMAPSET_FIELD(fldname) \
110 	(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
111 	 outBitmapset(str, node->fldname))
112 
113 #define WRITE_ATTRNUMBER_ARRAY(fldname, len) \
114 	do { \
115 		appendStringInfoString(str, " :" CppAsString(fldname) " "); \
116 		for (int i = 0; i < len; i++) \
117 			appendStringInfo(str, " %d", node->fldname[i]); \
118 	} while(0)
119 
120 #define WRITE_OID_ARRAY(fldname, len) \
121 	do { \
122 		appendStringInfoString(str, " :" CppAsString(fldname) " "); \
123 		for (int i = 0; i < len; i++) \
124 			appendStringInfo(str, " %u", node->fldname[i]); \
125 	} while(0)
126 
127 #define WRITE_INT_ARRAY(fldname, len) \
128 	do { \
129 		appendStringInfoString(str, " :" CppAsString(fldname) " "); \
130 		for (int i = 0; i < len; i++) \
131 			appendStringInfo(str, " %d", node->fldname[i]); \
132 	} while(0)
133 
134 #define WRITE_BOOL_ARRAY(fldname, len) \
135 	do { \
136 		appendStringInfoString(str, " :" CppAsString(fldname) " "); \
137 		for (int i = 0; i < len; i++) \
138 			appendStringInfo(str, " %s", booltostr(node->fldname[i])); \
139 	} while(0)
140 
141 
142 #define booltostr(x)  ((x) ? "true" : "false")
143 
144 
145 /*
146  * outToken
147  *	  Convert an ordinary string (eg, an identifier) into a form that
148  *	  will be decoded back to a plain token by read.c's functions.
149  *
150  *	  If a null or empty string is given, it is encoded as "<>".
151  */
152 void
outToken(StringInfo str,const char * s)153 outToken(StringInfo str, const char *s)
154 {
155 	if (s == NULL || *s == '\0')
156 	{
157 		appendStringInfoString(str, "<>");
158 		return;
159 	}
160 
161 	/*
162 	 * Look for characters or patterns that are treated specially by read.c
163 	 * (either in pg_strtok() or in nodeRead()), and therefore need a
164 	 * protective backslash.
165 	 */
166 	/* These characters only need to be quoted at the start of the string */
167 	if (*s == '<' ||
168 		*s == '"' ||
169 		isdigit((unsigned char) *s) ||
170 		((*s == '+' || *s == '-') &&
171 		 (isdigit((unsigned char) s[1]) || s[1] == '.')))
172 		appendStringInfoChar(str, '\\');
173 	while (*s)
174 	{
175 		/* These chars must be backslashed anywhere in the string */
176 		if (*s == ' ' || *s == '\n' || *s == '\t' ||
177 			*s == '(' || *s == ')' || *s == '{' || *s == '}' ||
178 			*s == '\\')
179 			appendStringInfoChar(str, '\\');
180 		appendStringInfoChar(str, *s++);
181 	}
182 }
183 
184 /*
185  * Convert one char.  Goes through outToken() so that special characters are
186  * escaped.
187  */
188 static void
outChar(StringInfo str,char c)189 outChar(StringInfo str, char c)
190 {
191 	char		in[2];
192 
193 	in[0] = c;
194 	in[1] = '\0';
195 
196 	outToken(str, in);
197 }
198 
199 static void
_outList(StringInfo str,const List * node)200 _outList(StringInfo str, const List *node)
201 {
202 	const ListCell *lc;
203 
204 	appendStringInfoChar(str, '(');
205 
206 	if (IsA(node, IntList))
207 		appendStringInfoChar(str, 'i');
208 	else if (IsA(node, OidList))
209 		appendStringInfoChar(str, 'o');
210 
211 	foreach(lc, node)
212 	{
213 		/*
214 		 * For the sake of backward compatibility, we emit a slightly
215 		 * different whitespace format for lists of nodes vs. other types of
216 		 * lists. XXX: is this necessary?
217 		 */
218 		if (IsA(node, List))
219 		{
220 			outNode(str, lfirst(lc));
221 			if (lnext(node, lc))
222 				appendStringInfoChar(str, ' ');
223 		}
224 		else if (IsA(node, IntList))
225 			appendStringInfo(str, " %d", lfirst_int(lc));
226 		else if (IsA(node, OidList))
227 			appendStringInfo(str, " %u", lfirst_oid(lc));
228 		else
229 			elog(ERROR, "unrecognized list node type: %d",
230 				 (int) node->type);
231 	}
232 
233 	appendStringInfoChar(str, ')');
234 }
235 
236 /*
237  * outBitmapset -
238  *	   converts a bitmap set of integers
239  *
240  * Note: the output format is "(b int int ...)", similar to an integer List.
241  */
242 void
outBitmapset(StringInfo str,const Bitmapset * bms)243 outBitmapset(StringInfo str, const Bitmapset *bms)
244 {
245 	int			x;
246 
247 	appendStringInfoChar(str, '(');
248 	appendStringInfoChar(str, 'b');
249 	x = -1;
250 	while ((x = bms_next_member(bms, x)) >= 0)
251 		appendStringInfo(str, " %d", x);
252 	appendStringInfoChar(str, ')');
253 }
254 
255 /*
256  * Print the value of a Datum given its type.
257  */
258 void
outDatum(StringInfo str,Datum value,int typlen,bool typbyval)259 outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
260 {
261 	Size		length,
262 				i;
263 	char	   *s;
264 
265 	length = datumGetSize(value, typbyval, typlen);
266 
267 	if (typbyval)
268 	{
269 		s = (char *) (&value);
270 		appendStringInfo(str, "%u [ ", (unsigned int) length);
271 		for (i = 0; i < (Size) sizeof(Datum); i++)
272 			appendStringInfo(str, "%d ", (int) (s[i]));
273 		appendStringInfoChar(str, ']');
274 	}
275 	else
276 	{
277 		s = (char *) DatumGetPointer(value);
278 		if (!PointerIsValid(s))
279 			appendStringInfoString(str, "0 [ ]");
280 		else
281 		{
282 			appendStringInfo(str, "%u [ ", (unsigned int) length);
283 			for (i = 0; i < length; i++)
284 				appendStringInfo(str, "%d ", (int) (s[i]));
285 			appendStringInfoChar(str, ']');
286 		}
287 	}
288 }
289 
290 
291 /*
292  *	Stuff from plannodes.h
293  */
294 
295 static void
_outPlannedStmt(StringInfo str,const PlannedStmt * node)296 _outPlannedStmt(StringInfo str, const PlannedStmt *node)
297 {
298 	WRITE_NODE_TYPE("PLANNEDSTMT");
299 
300 	WRITE_ENUM_FIELD(commandType, CmdType);
301 	WRITE_UINT64_FIELD(queryId);
302 	WRITE_BOOL_FIELD(hasReturning);
303 	WRITE_BOOL_FIELD(hasModifyingCTE);
304 	WRITE_BOOL_FIELD(canSetTag);
305 	WRITE_BOOL_FIELD(transientPlan);
306 	WRITE_BOOL_FIELD(dependsOnRole);
307 	WRITE_BOOL_FIELD(parallelModeNeeded);
308 	WRITE_INT_FIELD(jitFlags);
309 	WRITE_NODE_FIELD(planTree);
310 	WRITE_NODE_FIELD(rtable);
311 	WRITE_NODE_FIELD(resultRelations);
312 	WRITE_NODE_FIELD(appendRelations);
313 	WRITE_NODE_FIELD(subplans);
314 	WRITE_BITMAPSET_FIELD(rewindPlanIDs);
315 	WRITE_NODE_FIELD(rowMarks);
316 	WRITE_NODE_FIELD(relationOids);
317 	WRITE_NODE_FIELD(invalItems);
318 	WRITE_NODE_FIELD(paramExecTypes);
319 	WRITE_NODE_FIELD(utilityStmt);
320 	WRITE_LOCATION_FIELD(stmt_location);
321 	WRITE_INT_FIELD(stmt_len);
322 }
323 
324 /*
325  * print the basic stuff of all nodes that inherit from Plan
326  */
327 static void
_outPlanInfo(StringInfo str,const Plan * node)328 _outPlanInfo(StringInfo str, const Plan *node)
329 {
330 	WRITE_FLOAT_FIELD(startup_cost, "%.2f");
331 	WRITE_FLOAT_FIELD(total_cost, "%.2f");
332 	WRITE_FLOAT_FIELD(plan_rows, "%.0f");
333 	WRITE_INT_FIELD(plan_width);
334 	WRITE_BOOL_FIELD(parallel_aware);
335 	WRITE_BOOL_FIELD(parallel_safe);
336 	WRITE_BOOL_FIELD(async_capable);
337 	WRITE_INT_FIELD(plan_node_id);
338 	WRITE_NODE_FIELD(targetlist);
339 	WRITE_NODE_FIELD(qual);
340 	WRITE_NODE_FIELD(lefttree);
341 	WRITE_NODE_FIELD(righttree);
342 	WRITE_NODE_FIELD(initPlan);
343 	WRITE_BITMAPSET_FIELD(extParam);
344 	WRITE_BITMAPSET_FIELD(allParam);
345 }
346 
347 /*
348  * print the basic stuff of all nodes that inherit from Scan
349  */
350 static void
_outScanInfo(StringInfo str,const Scan * node)351 _outScanInfo(StringInfo str, const Scan *node)
352 {
353 	_outPlanInfo(str, (const Plan *) node);
354 
355 	WRITE_UINT_FIELD(scanrelid);
356 }
357 
358 /*
359  * print the basic stuff of all nodes that inherit from Join
360  */
361 static void
_outJoinPlanInfo(StringInfo str,const Join * node)362 _outJoinPlanInfo(StringInfo str, const Join *node)
363 {
364 	_outPlanInfo(str, (const Plan *) node);
365 
366 	WRITE_ENUM_FIELD(jointype, JoinType);
367 	WRITE_BOOL_FIELD(inner_unique);
368 	WRITE_NODE_FIELD(joinqual);
369 }
370 
371 
372 static void
_outPlan(StringInfo str,const Plan * node)373 _outPlan(StringInfo str, const Plan *node)
374 {
375 	WRITE_NODE_TYPE("PLAN");
376 
377 	_outPlanInfo(str, (const Plan *) node);
378 }
379 
380 static void
_outResult(StringInfo str,const Result * node)381 _outResult(StringInfo str, const Result *node)
382 {
383 	WRITE_NODE_TYPE("RESULT");
384 
385 	_outPlanInfo(str, (const Plan *) node);
386 
387 	WRITE_NODE_FIELD(resconstantqual);
388 }
389 
390 static void
_outProjectSet(StringInfo str,const ProjectSet * node)391 _outProjectSet(StringInfo str, const ProjectSet *node)
392 {
393 	WRITE_NODE_TYPE("PROJECTSET");
394 
395 	_outPlanInfo(str, (const Plan *) node);
396 }
397 
398 static void
_outModifyTable(StringInfo str,const ModifyTable * node)399 _outModifyTable(StringInfo str, const ModifyTable *node)
400 {
401 	WRITE_NODE_TYPE("MODIFYTABLE");
402 
403 	_outPlanInfo(str, (const Plan *) node);
404 
405 	WRITE_ENUM_FIELD(operation, CmdType);
406 	WRITE_BOOL_FIELD(canSetTag);
407 	WRITE_UINT_FIELD(nominalRelation);
408 	WRITE_UINT_FIELD(rootRelation);
409 	WRITE_BOOL_FIELD(partColsUpdated);
410 	WRITE_NODE_FIELD(resultRelations);
411 	WRITE_NODE_FIELD(updateColnosLists);
412 	WRITE_NODE_FIELD(withCheckOptionLists);
413 	WRITE_NODE_FIELD(returningLists);
414 	WRITE_NODE_FIELD(fdwPrivLists);
415 	WRITE_BITMAPSET_FIELD(fdwDirectModifyPlans);
416 	WRITE_NODE_FIELD(rowMarks);
417 	WRITE_INT_FIELD(epqParam);
418 	WRITE_ENUM_FIELD(onConflictAction, OnConflictAction);
419 	WRITE_NODE_FIELD(arbiterIndexes);
420 	WRITE_NODE_FIELD(onConflictSet);
421 	WRITE_NODE_FIELD(onConflictCols);
422 	WRITE_NODE_FIELD(onConflictWhere);
423 	WRITE_UINT_FIELD(exclRelRTI);
424 	WRITE_NODE_FIELD(exclRelTlist);
425 }
426 
427 static void
_outAppend(StringInfo str,const Append * node)428 _outAppend(StringInfo str, const Append *node)
429 {
430 	WRITE_NODE_TYPE("APPEND");
431 
432 	_outPlanInfo(str, (const Plan *) node);
433 
434 	WRITE_BITMAPSET_FIELD(apprelids);
435 	WRITE_NODE_FIELD(appendplans);
436 	WRITE_INT_FIELD(nasyncplans);
437 	WRITE_INT_FIELD(first_partial_plan);
438 	WRITE_NODE_FIELD(part_prune_info);
439 }
440 
441 static void
_outMergeAppend(StringInfo str,const MergeAppend * node)442 _outMergeAppend(StringInfo str, const MergeAppend *node)
443 {
444 	WRITE_NODE_TYPE("MERGEAPPEND");
445 
446 	_outPlanInfo(str, (const Plan *) node);
447 
448 	WRITE_BITMAPSET_FIELD(apprelids);
449 	WRITE_NODE_FIELD(mergeplans);
450 	WRITE_INT_FIELD(numCols);
451 	WRITE_ATTRNUMBER_ARRAY(sortColIdx, node->numCols);
452 	WRITE_OID_ARRAY(sortOperators, node->numCols);
453 	WRITE_OID_ARRAY(collations, node->numCols);
454 	WRITE_BOOL_ARRAY(nullsFirst, node->numCols);
455 	WRITE_NODE_FIELD(part_prune_info);
456 }
457 
458 static void
_outRecursiveUnion(StringInfo str,const RecursiveUnion * node)459 _outRecursiveUnion(StringInfo str, const RecursiveUnion *node)
460 {
461 	WRITE_NODE_TYPE("RECURSIVEUNION");
462 
463 	_outPlanInfo(str, (const Plan *) node);
464 
465 	WRITE_INT_FIELD(wtParam);
466 	WRITE_INT_FIELD(numCols);
467 	WRITE_ATTRNUMBER_ARRAY(dupColIdx, node->numCols);
468 	WRITE_OID_ARRAY(dupOperators, node->numCols);
469 	WRITE_OID_ARRAY(dupCollations, node->numCols);
470 	WRITE_LONG_FIELD(numGroups);
471 }
472 
473 static void
_outBitmapAnd(StringInfo str,const BitmapAnd * node)474 _outBitmapAnd(StringInfo str, const BitmapAnd *node)
475 {
476 	WRITE_NODE_TYPE("BITMAPAND");
477 
478 	_outPlanInfo(str, (const Plan *) node);
479 
480 	WRITE_NODE_FIELD(bitmapplans);
481 }
482 
483 static void
_outBitmapOr(StringInfo str,const BitmapOr * node)484 _outBitmapOr(StringInfo str, const BitmapOr *node)
485 {
486 	WRITE_NODE_TYPE("BITMAPOR");
487 
488 	_outPlanInfo(str, (const Plan *) node);
489 
490 	WRITE_BOOL_FIELD(isshared);
491 	WRITE_NODE_FIELD(bitmapplans);
492 }
493 
494 static void
_outGather(StringInfo str,const Gather * node)495 _outGather(StringInfo str, const Gather *node)
496 {
497 	WRITE_NODE_TYPE("GATHER");
498 
499 	_outPlanInfo(str, (const Plan *) node);
500 
501 	WRITE_INT_FIELD(num_workers);
502 	WRITE_INT_FIELD(rescan_param);
503 	WRITE_BOOL_FIELD(single_copy);
504 	WRITE_BOOL_FIELD(invisible);
505 	WRITE_BITMAPSET_FIELD(initParam);
506 }
507 
508 static void
_outGatherMerge(StringInfo str,const GatherMerge * node)509 _outGatherMerge(StringInfo str, const GatherMerge *node)
510 {
511 	WRITE_NODE_TYPE("GATHERMERGE");
512 
513 	_outPlanInfo(str, (const Plan *) node);
514 
515 	WRITE_INT_FIELD(num_workers);
516 	WRITE_INT_FIELD(rescan_param);
517 	WRITE_INT_FIELD(numCols);
518 	WRITE_ATTRNUMBER_ARRAY(sortColIdx, node->numCols);
519 	WRITE_OID_ARRAY(sortOperators, node->numCols);
520 	WRITE_OID_ARRAY(collations, node->numCols);
521 	WRITE_BOOL_ARRAY(nullsFirst, node->numCols);
522 	WRITE_BITMAPSET_FIELD(initParam);
523 }
524 
525 static void
_outScan(StringInfo str,const Scan * node)526 _outScan(StringInfo str, const Scan *node)
527 {
528 	WRITE_NODE_TYPE("SCAN");
529 
530 	_outScanInfo(str, node);
531 }
532 
533 static void
_outSeqScan(StringInfo str,const SeqScan * node)534 _outSeqScan(StringInfo str, const SeqScan *node)
535 {
536 	WRITE_NODE_TYPE("SEQSCAN");
537 
538 	_outScanInfo(str, (const Scan *) node);
539 }
540 
541 static void
_outSampleScan(StringInfo str,const SampleScan * node)542 _outSampleScan(StringInfo str, const SampleScan *node)
543 {
544 	WRITE_NODE_TYPE("SAMPLESCAN");
545 
546 	_outScanInfo(str, (const Scan *) node);
547 
548 	WRITE_NODE_FIELD(tablesample);
549 }
550 
551 static void
_outIndexScan(StringInfo str,const IndexScan * node)552 _outIndexScan(StringInfo str, const IndexScan *node)
553 {
554 	WRITE_NODE_TYPE("INDEXSCAN");
555 
556 	_outScanInfo(str, (const Scan *) node);
557 
558 	WRITE_OID_FIELD(indexid);
559 	WRITE_NODE_FIELD(indexqual);
560 	WRITE_NODE_FIELD(indexqualorig);
561 	WRITE_NODE_FIELD(indexorderby);
562 	WRITE_NODE_FIELD(indexorderbyorig);
563 	WRITE_NODE_FIELD(indexorderbyops);
564 	WRITE_ENUM_FIELD(indexorderdir, ScanDirection);
565 }
566 
567 static void
_outIndexOnlyScan(StringInfo str,const IndexOnlyScan * node)568 _outIndexOnlyScan(StringInfo str, const IndexOnlyScan *node)
569 {
570 	WRITE_NODE_TYPE("INDEXONLYSCAN");
571 
572 	_outScanInfo(str, (const Scan *) node);
573 
574 	WRITE_OID_FIELD(indexid);
575 	WRITE_NODE_FIELD(indexqual);
576 	WRITE_NODE_FIELD(indexorderby);
577 	WRITE_NODE_FIELD(indextlist);
578 	WRITE_ENUM_FIELD(indexorderdir, ScanDirection);
579 }
580 
581 static void
_outBitmapIndexScan(StringInfo str,const BitmapIndexScan * node)582 _outBitmapIndexScan(StringInfo str, const BitmapIndexScan *node)
583 {
584 	WRITE_NODE_TYPE("BITMAPINDEXSCAN");
585 
586 	_outScanInfo(str, (const Scan *) node);
587 
588 	WRITE_OID_FIELD(indexid);
589 	WRITE_BOOL_FIELD(isshared);
590 	WRITE_NODE_FIELD(indexqual);
591 	WRITE_NODE_FIELD(indexqualorig);
592 }
593 
594 static void
_outBitmapHeapScan(StringInfo str,const BitmapHeapScan * node)595 _outBitmapHeapScan(StringInfo str, const BitmapHeapScan *node)
596 {
597 	WRITE_NODE_TYPE("BITMAPHEAPSCAN");
598 
599 	_outScanInfo(str, (const Scan *) node);
600 
601 	WRITE_NODE_FIELD(bitmapqualorig);
602 }
603 
604 static void
_outTidScan(StringInfo str,const TidScan * node)605 _outTidScan(StringInfo str, const TidScan *node)
606 {
607 	WRITE_NODE_TYPE("TIDSCAN");
608 
609 	_outScanInfo(str, (const Scan *) node);
610 
611 	WRITE_NODE_FIELD(tidquals);
612 }
613 
614 static void
_outTidRangeScan(StringInfo str,const TidRangeScan * node)615 _outTidRangeScan(StringInfo str, const TidRangeScan *node)
616 {
617 	WRITE_NODE_TYPE("TIDRANGESCAN");
618 
619 	_outScanInfo(str, (const Scan *) node);
620 
621 	WRITE_NODE_FIELD(tidrangequals);
622 }
623 
624 static void
_outSubqueryScan(StringInfo str,const SubqueryScan * node)625 _outSubqueryScan(StringInfo str, const SubqueryScan *node)
626 {
627 	WRITE_NODE_TYPE("SUBQUERYSCAN");
628 
629 	_outScanInfo(str, (const Scan *) node);
630 
631 	WRITE_NODE_FIELD(subplan);
632 }
633 
634 static void
_outFunctionScan(StringInfo str,const FunctionScan * node)635 _outFunctionScan(StringInfo str, const FunctionScan *node)
636 {
637 	WRITE_NODE_TYPE("FUNCTIONSCAN");
638 
639 	_outScanInfo(str, (const Scan *) node);
640 
641 	WRITE_NODE_FIELD(functions);
642 	WRITE_BOOL_FIELD(funcordinality);
643 }
644 
645 static void
_outTableFuncScan(StringInfo str,const TableFuncScan * node)646 _outTableFuncScan(StringInfo str, const TableFuncScan *node)
647 {
648 	WRITE_NODE_TYPE("TABLEFUNCSCAN");
649 
650 	_outScanInfo(str, (const Scan *) node);
651 
652 	WRITE_NODE_FIELD(tablefunc);
653 }
654 
655 static void
_outValuesScan(StringInfo str,const ValuesScan * node)656 _outValuesScan(StringInfo str, const ValuesScan *node)
657 {
658 	WRITE_NODE_TYPE("VALUESSCAN");
659 
660 	_outScanInfo(str, (const Scan *) node);
661 
662 	WRITE_NODE_FIELD(values_lists);
663 }
664 
665 static void
_outCteScan(StringInfo str,const CteScan * node)666 _outCteScan(StringInfo str, const CteScan *node)
667 {
668 	WRITE_NODE_TYPE("CTESCAN");
669 
670 	_outScanInfo(str, (const Scan *) node);
671 
672 	WRITE_INT_FIELD(ctePlanId);
673 	WRITE_INT_FIELD(cteParam);
674 }
675 
676 static void
_outNamedTuplestoreScan(StringInfo str,const NamedTuplestoreScan * node)677 _outNamedTuplestoreScan(StringInfo str, const NamedTuplestoreScan *node)
678 {
679 	WRITE_NODE_TYPE("NAMEDTUPLESTORESCAN");
680 
681 	_outScanInfo(str, (const Scan *) node);
682 
683 	WRITE_STRING_FIELD(enrname);
684 }
685 
686 static void
_outWorkTableScan(StringInfo str,const WorkTableScan * node)687 _outWorkTableScan(StringInfo str, const WorkTableScan *node)
688 {
689 	WRITE_NODE_TYPE("WORKTABLESCAN");
690 
691 	_outScanInfo(str, (const Scan *) node);
692 
693 	WRITE_INT_FIELD(wtParam);
694 }
695 
696 static void
_outForeignScan(StringInfo str,const ForeignScan * node)697 _outForeignScan(StringInfo str, const ForeignScan *node)
698 {
699 	WRITE_NODE_TYPE("FOREIGNSCAN");
700 
701 	_outScanInfo(str, (const Scan *) node);
702 
703 	WRITE_ENUM_FIELD(operation, CmdType);
704 	WRITE_UINT_FIELD(resultRelation);
705 	WRITE_OID_FIELD(fs_server);
706 	WRITE_NODE_FIELD(fdw_exprs);
707 	WRITE_NODE_FIELD(fdw_private);
708 	WRITE_NODE_FIELD(fdw_scan_tlist);
709 	WRITE_NODE_FIELD(fdw_recheck_quals);
710 	WRITE_BITMAPSET_FIELD(fs_relids);
711 	WRITE_BOOL_FIELD(fsSystemCol);
712 }
713 
714 static void
_outCustomScan(StringInfo str,const CustomScan * node)715 _outCustomScan(StringInfo str, const CustomScan *node)
716 {
717 	WRITE_NODE_TYPE("CUSTOMSCAN");
718 
719 	_outScanInfo(str, (const Scan *) node);
720 
721 	WRITE_UINT_FIELD(flags);
722 	WRITE_NODE_FIELD(custom_plans);
723 	WRITE_NODE_FIELD(custom_exprs);
724 	WRITE_NODE_FIELD(custom_private);
725 	WRITE_NODE_FIELD(custom_scan_tlist);
726 	WRITE_BITMAPSET_FIELD(custom_relids);
727 	/* CustomName is a key to lookup CustomScanMethods */
728 	appendStringInfoString(str, " :methods ");
729 	outToken(str, node->methods->CustomName);
730 }
731 
732 static void
_outJoin(StringInfo str,const Join * node)733 _outJoin(StringInfo str, const Join *node)
734 {
735 	WRITE_NODE_TYPE("JOIN");
736 
737 	_outJoinPlanInfo(str, (const Join *) node);
738 }
739 
740 static void
_outNestLoop(StringInfo str,const NestLoop * node)741 _outNestLoop(StringInfo str, const NestLoop *node)
742 {
743 	WRITE_NODE_TYPE("NESTLOOP");
744 
745 	_outJoinPlanInfo(str, (const Join *) node);
746 
747 	WRITE_NODE_FIELD(nestParams);
748 }
749 
750 static void
_outMergeJoin(StringInfo str,const MergeJoin * node)751 _outMergeJoin(StringInfo str, const MergeJoin *node)
752 {
753 	int			numCols;
754 
755 	WRITE_NODE_TYPE("MERGEJOIN");
756 
757 	_outJoinPlanInfo(str, (const Join *) node);
758 
759 	WRITE_BOOL_FIELD(skip_mark_restore);
760 	WRITE_NODE_FIELD(mergeclauses);
761 
762 	numCols = list_length(node->mergeclauses);
763 
764 	WRITE_OID_ARRAY(mergeFamilies, numCols);
765 	WRITE_OID_ARRAY(mergeCollations, numCols);
766 	WRITE_INT_ARRAY(mergeStrategies, numCols);
767 	WRITE_BOOL_ARRAY(mergeNullsFirst, numCols);
768 }
769 
770 static void
_outHashJoin(StringInfo str,const HashJoin * node)771 _outHashJoin(StringInfo str, const HashJoin *node)
772 {
773 	WRITE_NODE_TYPE("HASHJOIN");
774 
775 	_outJoinPlanInfo(str, (const Join *) node);
776 
777 	WRITE_NODE_FIELD(hashclauses);
778 	WRITE_NODE_FIELD(hashoperators);
779 	WRITE_NODE_FIELD(hashcollations);
780 	WRITE_NODE_FIELD(hashkeys);
781 }
782 
783 static void
_outAgg(StringInfo str,const Agg * node)784 _outAgg(StringInfo str, const Agg *node)
785 {
786 	WRITE_NODE_TYPE("AGG");
787 
788 	_outPlanInfo(str, (const Plan *) node);
789 
790 	WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
791 	WRITE_ENUM_FIELD(aggsplit, AggSplit);
792 	WRITE_INT_FIELD(numCols);
793 	WRITE_ATTRNUMBER_ARRAY(grpColIdx, node->numCols);
794 	WRITE_OID_ARRAY(grpOperators, node->numCols);
795 	WRITE_OID_ARRAY(grpCollations, node->numCols);
796 	WRITE_LONG_FIELD(numGroups);
797 	WRITE_UINT64_FIELD(transitionSpace);
798 	WRITE_BITMAPSET_FIELD(aggParams);
799 	WRITE_NODE_FIELD(groupingSets);
800 	WRITE_NODE_FIELD(chain);
801 }
802 
803 static void
_outWindowAgg(StringInfo str,const WindowAgg * node)804 _outWindowAgg(StringInfo str, const WindowAgg *node)
805 {
806 	WRITE_NODE_TYPE("WINDOWAGG");
807 
808 	_outPlanInfo(str, (const Plan *) node);
809 
810 	WRITE_UINT_FIELD(winref);
811 	WRITE_INT_FIELD(partNumCols);
812 	WRITE_ATTRNUMBER_ARRAY(partColIdx, node->partNumCols);
813 	WRITE_OID_ARRAY(partOperators, node->partNumCols);
814 	WRITE_OID_ARRAY(partCollations, node->partNumCols);
815 	WRITE_INT_FIELD(ordNumCols);
816 	WRITE_ATTRNUMBER_ARRAY(ordColIdx, node->ordNumCols);
817 	WRITE_OID_ARRAY(ordOperators, node->ordNumCols);
818 	WRITE_OID_ARRAY(ordCollations, node->ordNumCols);
819 	WRITE_INT_FIELD(frameOptions);
820 	WRITE_NODE_FIELD(startOffset);
821 	WRITE_NODE_FIELD(endOffset);
822 	WRITE_OID_FIELD(startInRangeFunc);
823 	WRITE_OID_FIELD(endInRangeFunc);
824 	WRITE_OID_FIELD(inRangeColl);
825 	WRITE_BOOL_FIELD(inRangeAsc);
826 	WRITE_BOOL_FIELD(inRangeNullsFirst);
827 }
828 
829 static void
_outGroup(StringInfo str,const Group * node)830 _outGroup(StringInfo str, const Group *node)
831 {
832 	WRITE_NODE_TYPE("GROUP");
833 
834 	_outPlanInfo(str, (const Plan *) node);
835 
836 	WRITE_INT_FIELD(numCols);
837 	WRITE_ATTRNUMBER_ARRAY(grpColIdx, node->numCols);
838 	WRITE_OID_ARRAY(grpOperators, node->numCols);
839 	WRITE_OID_ARRAY(grpCollations, node->numCols);
840 }
841 
842 static void
_outMaterial(StringInfo str,const Material * node)843 _outMaterial(StringInfo str, const Material *node)
844 {
845 	WRITE_NODE_TYPE("MATERIAL");
846 
847 	_outPlanInfo(str, (const Plan *) node);
848 }
849 
850 static void
_outMemoize(StringInfo str,const Memoize * node)851 _outMemoize(StringInfo str, const Memoize *node)
852 {
853 	WRITE_NODE_TYPE("MEMOIZE");
854 
855 	_outPlanInfo(str, (const Plan *) node);
856 
857 	WRITE_INT_FIELD(numKeys);
858 	WRITE_OID_ARRAY(hashOperators, node->numKeys);
859 	WRITE_OID_ARRAY(collations, node->numKeys);
860 	WRITE_NODE_FIELD(param_exprs);
861 	WRITE_BOOL_FIELD(singlerow);
862 	WRITE_UINT_FIELD(est_entries);
863 }
864 
865 static void
_outSortInfo(StringInfo str,const Sort * node)866 _outSortInfo(StringInfo str, const Sort *node)
867 {
868 	_outPlanInfo(str, (const Plan *) node);
869 
870 	WRITE_INT_FIELD(numCols);
871 	WRITE_ATTRNUMBER_ARRAY(sortColIdx, node->numCols);
872 	WRITE_OID_ARRAY(sortOperators, node->numCols);
873 	WRITE_OID_ARRAY(collations, node->numCols);
874 	WRITE_BOOL_ARRAY(nullsFirst, node->numCols);
875 }
876 
877 static void
_outSort(StringInfo str,const Sort * node)878 _outSort(StringInfo str, const Sort *node)
879 {
880 	WRITE_NODE_TYPE("SORT");
881 
882 	_outSortInfo(str, node);
883 }
884 
885 static void
_outIncrementalSort(StringInfo str,const IncrementalSort * node)886 _outIncrementalSort(StringInfo str, const IncrementalSort *node)
887 {
888 	WRITE_NODE_TYPE("INCREMENTALSORT");
889 
890 	_outSortInfo(str, (const Sort *) node);
891 
892 	WRITE_INT_FIELD(nPresortedCols);
893 }
894 
895 static void
_outUnique(StringInfo str,const Unique * node)896 _outUnique(StringInfo str, const Unique *node)
897 {
898 	WRITE_NODE_TYPE("UNIQUE");
899 
900 	_outPlanInfo(str, (const Plan *) node);
901 
902 	WRITE_INT_FIELD(numCols);
903 	WRITE_ATTRNUMBER_ARRAY(uniqColIdx, node->numCols);
904 	WRITE_OID_ARRAY(uniqOperators, node->numCols);
905 	WRITE_OID_ARRAY(uniqCollations, node->numCols);
906 }
907 
908 static void
_outHash(StringInfo str,const Hash * node)909 _outHash(StringInfo str, const Hash *node)
910 {
911 	WRITE_NODE_TYPE("HASH");
912 
913 	_outPlanInfo(str, (const Plan *) node);
914 
915 	WRITE_NODE_FIELD(hashkeys);
916 	WRITE_OID_FIELD(skewTable);
917 	WRITE_INT_FIELD(skewColumn);
918 	WRITE_BOOL_FIELD(skewInherit);
919 	WRITE_FLOAT_FIELD(rows_total, "%.0f");
920 }
921 
922 static void
_outSetOp(StringInfo str,const SetOp * node)923 _outSetOp(StringInfo str, const SetOp *node)
924 {
925 	WRITE_NODE_TYPE("SETOP");
926 
927 	_outPlanInfo(str, (const Plan *) node);
928 
929 	WRITE_ENUM_FIELD(cmd, SetOpCmd);
930 	WRITE_ENUM_FIELD(strategy, SetOpStrategy);
931 	WRITE_INT_FIELD(numCols);
932 	WRITE_ATTRNUMBER_ARRAY(dupColIdx, node->numCols);
933 	WRITE_OID_ARRAY(dupOperators, node->numCols);
934 	WRITE_OID_ARRAY(dupCollations, node->numCols);
935 	WRITE_INT_FIELD(flagColIdx);
936 	WRITE_INT_FIELD(firstFlag);
937 	WRITE_LONG_FIELD(numGroups);
938 }
939 
940 static void
_outLockRows(StringInfo str,const LockRows * node)941 _outLockRows(StringInfo str, const LockRows *node)
942 {
943 	WRITE_NODE_TYPE("LOCKROWS");
944 
945 	_outPlanInfo(str, (const Plan *) node);
946 
947 	WRITE_NODE_FIELD(rowMarks);
948 	WRITE_INT_FIELD(epqParam);
949 }
950 
951 static void
_outLimit(StringInfo str,const Limit * node)952 _outLimit(StringInfo str, const Limit *node)
953 {
954 	WRITE_NODE_TYPE("LIMIT");
955 
956 	_outPlanInfo(str, (const Plan *) node);
957 
958 	WRITE_NODE_FIELD(limitOffset);
959 	WRITE_NODE_FIELD(limitCount);
960 	WRITE_ENUM_FIELD(limitOption, LimitOption);
961 	WRITE_INT_FIELD(uniqNumCols);
962 	WRITE_ATTRNUMBER_ARRAY(uniqColIdx, node->uniqNumCols);
963 	WRITE_OID_ARRAY(uniqOperators, node->uniqNumCols);
964 	WRITE_OID_ARRAY(uniqCollations, node->uniqNumCols);
965 }
966 
967 static void
_outNestLoopParam(StringInfo str,const NestLoopParam * node)968 _outNestLoopParam(StringInfo str, const NestLoopParam *node)
969 {
970 	WRITE_NODE_TYPE("NESTLOOPPARAM");
971 
972 	WRITE_INT_FIELD(paramno);
973 	WRITE_NODE_FIELD(paramval);
974 }
975 
976 static void
_outPlanRowMark(StringInfo str,const PlanRowMark * node)977 _outPlanRowMark(StringInfo str, const PlanRowMark *node)
978 {
979 	WRITE_NODE_TYPE("PLANROWMARK");
980 
981 	WRITE_UINT_FIELD(rti);
982 	WRITE_UINT_FIELD(prti);
983 	WRITE_UINT_FIELD(rowmarkId);
984 	WRITE_ENUM_FIELD(markType, RowMarkType);
985 	WRITE_INT_FIELD(allMarkTypes);
986 	WRITE_ENUM_FIELD(strength, LockClauseStrength);
987 	WRITE_ENUM_FIELD(waitPolicy, LockWaitPolicy);
988 	WRITE_BOOL_FIELD(isParent);
989 }
990 
991 static void
_outPartitionPruneInfo(StringInfo str,const PartitionPruneInfo * node)992 _outPartitionPruneInfo(StringInfo str, const PartitionPruneInfo *node)
993 {
994 	WRITE_NODE_TYPE("PARTITIONPRUNEINFO");
995 
996 	WRITE_NODE_FIELD(prune_infos);
997 	WRITE_BITMAPSET_FIELD(other_subplans);
998 }
999 
1000 static void
_outPartitionedRelPruneInfo(StringInfo str,const PartitionedRelPruneInfo * node)1001 _outPartitionedRelPruneInfo(StringInfo str, const PartitionedRelPruneInfo *node)
1002 {
1003 	WRITE_NODE_TYPE("PARTITIONEDRELPRUNEINFO");
1004 
1005 	WRITE_UINT_FIELD(rtindex);
1006 	WRITE_BITMAPSET_FIELD(present_parts);
1007 	WRITE_INT_FIELD(nparts);
1008 	WRITE_INT_ARRAY(subplan_map, node->nparts);
1009 	WRITE_INT_ARRAY(subpart_map, node->nparts);
1010 	WRITE_OID_ARRAY(relid_map, node->nparts);
1011 	WRITE_NODE_FIELD(initial_pruning_steps);
1012 	WRITE_NODE_FIELD(exec_pruning_steps);
1013 	WRITE_BITMAPSET_FIELD(execparamids);
1014 }
1015 
1016 static void
_outPartitionPruneStepOp(StringInfo str,const PartitionPruneStepOp * node)1017 _outPartitionPruneStepOp(StringInfo str, const PartitionPruneStepOp *node)
1018 {
1019 	WRITE_NODE_TYPE("PARTITIONPRUNESTEPOP");
1020 
1021 	WRITE_INT_FIELD(step.step_id);
1022 	WRITE_INT_FIELD(opstrategy);
1023 	WRITE_NODE_FIELD(exprs);
1024 	WRITE_NODE_FIELD(cmpfns);
1025 	WRITE_BITMAPSET_FIELD(nullkeys);
1026 }
1027 
1028 static void
_outPartitionPruneStepCombine(StringInfo str,const PartitionPruneStepCombine * node)1029 _outPartitionPruneStepCombine(StringInfo str, const PartitionPruneStepCombine *node)
1030 {
1031 	WRITE_NODE_TYPE("PARTITIONPRUNESTEPCOMBINE");
1032 
1033 	WRITE_INT_FIELD(step.step_id);
1034 	WRITE_ENUM_FIELD(combineOp, PartitionPruneCombineOp);
1035 	WRITE_NODE_FIELD(source_stepids);
1036 }
1037 
1038 static void
_outPlanInvalItem(StringInfo str,const PlanInvalItem * node)1039 _outPlanInvalItem(StringInfo str, const PlanInvalItem *node)
1040 {
1041 	WRITE_NODE_TYPE("PLANINVALITEM");
1042 
1043 	WRITE_INT_FIELD(cacheId);
1044 	WRITE_UINT_FIELD(hashValue);
1045 }
1046 
1047 /*****************************************************************************
1048  *
1049  *	Stuff from primnodes.h.
1050  *
1051  *****************************************************************************/
1052 
1053 static void
_outAlias(StringInfo str,const Alias * node)1054 _outAlias(StringInfo str, const Alias *node)
1055 {
1056 	WRITE_NODE_TYPE("ALIAS");
1057 
1058 	WRITE_STRING_FIELD(aliasname);
1059 	WRITE_NODE_FIELD(colnames);
1060 }
1061 
1062 static void
_outRangeVar(StringInfo str,const RangeVar * node)1063 _outRangeVar(StringInfo str, const RangeVar *node)
1064 {
1065 	WRITE_NODE_TYPE("RANGEVAR");
1066 
1067 	/*
1068 	 * we deliberately ignore catalogname here, since it is presently not
1069 	 * semantically meaningful
1070 	 */
1071 	WRITE_STRING_FIELD(schemaname);
1072 	WRITE_STRING_FIELD(relname);
1073 	WRITE_BOOL_FIELD(inh);
1074 	WRITE_CHAR_FIELD(relpersistence);
1075 	WRITE_NODE_FIELD(alias);
1076 	WRITE_LOCATION_FIELD(location);
1077 }
1078 
1079 static void
_outTableFunc(StringInfo str,const TableFunc * node)1080 _outTableFunc(StringInfo str, const TableFunc *node)
1081 {
1082 	WRITE_NODE_TYPE("TABLEFUNC");
1083 
1084 	WRITE_NODE_FIELD(ns_uris);
1085 	WRITE_NODE_FIELD(ns_names);
1086 	WRITE_NODE_FIELD(docexpr);
1087 	WRITE_NODE_FIELD(rowexpr);
1088 	WRITE_NODE_FIELD(colnames);
1089 	WRITE_NODE_FIELD(coltypes);
1090 	WRITE_NODE_FIELD(coltypmods);
1091 	WRITE_NODE_FIELD(colcollations);
1092 	WRITE_NODE_FIELD(colexprs);
1093 	WRITE_NODE_FIELD(coldefexprs);
1094 	WRITE_BITMAPSET_FIELD(notnulls);
1095 	WRITE_INT_FIELD(ordinalitycol);
1096 	WRITE_LOCATION_FIELD(location);
1097 }
1098 
1099 static void
_outIntoClause(StringInfo str,const IntoClause * node)1100 _outIntoClause(StringInfo str, const IntoClause *node)
1101 {
1102 	WRITE_NODE_TYPE("INTOCLAUSE");
1103 
1104 	WRITE_NODE_FIELD(rel);
1105 	WRITE_NODE_FIELD(colNames);
1106 	WRITE_STRING_FIELD(accessMethod);
1107 	WRITE_NODE_FIELD(options);
1108 	WRITE_ENUM_FIELD(onCommit, OnCommitAction);
1109 	WRITE_STRING_FIELD(tableSpaceName);
1110 	WRITE_NODE_FIELD(viewQuery);
1111 	WRITE_BOOL_FIELD(skipData);
1112 }
1113 
1114 static void
_outVar(StringInfo str,const Var * node)1115 _outVar(StringInfo str, const Var *node)
1116 {
1117 	WRITE_NODE_TYPE("VAR");
1118 
1119 	WRITE_UINT_FIELD(varno);
1120 	WRITE_INT_FIELD(varattno);
1121 	WRITE_OID_FIELD(vartype);
1122 	WRITE_INT_FIELD(vartypmod);
1123 	WRITE_OID_FIELD(varcollid);
1124 	WRITE_UINT_FIELD(varlevelsup);
1125 	WRITE_UINT_FIELD(varnosyn);
1126 	WRITE_INT_FIELD(varattnosyn);
1127 	WRITE_LOCATION_FIELD(location);
1128 }
1129 
1130 static void
_outConst(StringInfo str,const Const * node)1131 _outConst(StringInfo str, const Const *node)
1132 {
1133 	WRITE_NODE_TYPE("CONST");
1134 
1135 	WRITE_OID_FIELD(consttype);
1136 	WRITE_INT_FIELD(consttypmod);
1137 	WRITE_OID_FIELD(constcollid);
1138 	WRITE_INT_FIELD(constlen);
1139 	WRITE_BOOL_FIELD(constbyval);
1140 	WRITE_BOOL_FIELD(constisnull);
1141 	WRITE_LOCATION_FIELD(location);
1142 
1143 	appendStringInfoString(str, " :constvalue ");
1144 	if (node->constisnull)
1145 		appendStringInfoString(str, "<>");
1146 	else
1147 		outDatum(str, node->constvalue, node->constlen, node->constbyval);
1148 }
1149 
1150 static void
_outParam(StringInfo str,const Param * node)1151 _outParam(StringInfo str, const Param *node)
1152 {
1153 	WRITE_NODE_TYPE("PARAM");
1154 
1155 	WRITE_ENUM_FIELD(paramkind, ParamKind);
1156 	WRITE_INT_FIELD(paramid);
1157 	WRITE_OID_FIELD(paramtype);
1158 	WRITE_INT_FIELD(paramtypmod);
1159 	WRITE_OID_FIELD(paramcollid);
1160 	WRITE_LOCATION_FIELD(location);
1161 }
1162 
1163 static void
_outAggref(StringInfo str,const Aggref * node)1164 _outAggref(StringInfo str, const Aggref *node)
1165 {
1166 	WRITE_NODE_TYPE("AGGREF");
1167 
1168 	WRITE_OID_FIELD(aggfnoid);
1169 	WRITE_OID_FIELD(aggtype);
1170 	WRITE_OID_FIELD(aggcollid);
1171 	WRITE_OID_FIELD(inputcollid);
1172 	WRITE_OID_FIELD(aggtranstype);
1173 	WRITE_NODE_FIELD(aggargtypes);
1174 	WRITE_NODE_FIELD(aggdirectargs);
1175 	WRITE_NODE_FIELD(args);
1176 	WRITE_NODE_FIELD(aggorder);
1177 	WRITE_NODE_FIELD(aggdistinct);
1178 	WRITE_NODE_FIELD(aggfilter);
1179 	WRITE_BOOL_FIELD(aggstar);
1180 	WRITE_BOOL_FIELD(aggvariadic);
1181 	WRITE_CHAR_FIELD(aggkind);
1182 	WRITE_UINT_FIELD(agglevelsup);
1183 	WRITE_ENUM_FIELD(aggsplit, AggSplit);
1184 	WRITE_INT_FIELD(aggno);
1185 	WRITE_INT_FIELD(aggtransno);
1186 	WRITE_LOCATION_FIELD(location);
1187 }
1188 
1189 static void
_outGroupingFunc(StringInfo str,const GroupingFunc * node)1190 _outGroupingFunc(StringInfo str, const GroupingFunc *node)
1191 {
1192 	WRITE_NODE_TYPE("GROUPINGFUNC");
1193 
1194 	WRITE_NODE_FIELD(args);
1195 	WRITE_NODE_FIELD(refs);
1196 	WRITE_NODE_FIELD(cols);
1197 	WRITE_UINT_FIELD(agglevelsup);
1198 	WRITE_LOCATION_FIELD(location);
1199 }
1200 
1201 static void
_outWindowFunc(StringInfo str,const WindowFunc * node)1202 _outWindowFunc(StringInfo str, const WindowFunc *node)
1203 {
1204 	WRITE_NODE_TYPE("WINDOWFUNC");
1205 
1206 	WRITE_OID_FIELD(winfnoid);
1207 	WRITE_OID_FIELD(wintype);
1208 	WRITE_OID_FIELD(wincollid);
1209 	WRITE_OID_FIELD(inputcollid);
1210 	WRITE_NODE_FIELD(args);
1211 	WRITE_NODE_FIELD(aggfilter);
1212 	WRITE_UINT_FIELD(winref);
1213 	WRITE_BOOL_FIELD(winstar);
1214 	WRITE_BOOL_FIELD(winagg);
1215 	WRITE_LOCATION_FIELD(location);
1216 }
1217 
1218 static void
_outSubscriptingRef(StringInfo str,const SubscriptingRef * node)1219 _outSubscriptingRef(StringInfo str, const SubscriptingRef *node)
1220 {
1221 	WRITE_NODE_TYPE("SUBSCRIPTINGREF");
1222 
1223 	WRITE_OID_FIELD(refcontainertype);
1224 	WRITE_OID_FIELD(refelemtype);
1225 	WRITE_OID_FIELD(refrestype);
1226 	WRITE_INT_FIELD(reftypmod);
1227 	WRITE_OID_FIELD(refcollid);
1228 	WRITE_NODE_FIELD(refupperindexpr);
1229 	WRITE_NODE_FIELD(reflowerindexpr);
1230 	WRITE_NODE_FIELD(refexpr);
1231 	WRITE_NODE_FIELD(refassgnexpr);
1232 }
1233 
1234 static void
_outFuncExpr(StringInfo str,const FuncExpr * node)1235 _outFuncExpr(StringInfo str, const FuncExpr *node)
1236 {
1237 	WRITE_NODE_TYPE("FUNCEXPR");
1238 
1239 	WRITE_OID_FIELD(funcid);
1240 	WRITE_OID_FIELD(funcresulttype);
1241 	WRITE_BOOL_FIELD(funcretset);
1242 	WRITE_BOOL_FIELD(funcvariadic);
1243 	WRITE_ENUM_FIELD(funcformat, CoercionForm);
1244 	WRITE_OID_FIELD(funccollid);
1245 	WRITE_OID_FIELD(inputcollid);
1246 	WRITE_NODE_FIELD(args);
1247 	WRITE_LOCATION_FIELD(location);
1248 }
1249 
1250 static void
_outNamedArgExpr(StringInfo str,const NamedArgExpr * node)1251 _outNamedArgExpr(StringInfo str, const NamedArgExpr *node)
1252 {
1253 	WRITE_NODE_TYPE("NAMEDARGEXPR");
1254 
1255 	WRITE_NODE_FIELD(arg);
1256 	WRITE_STRING_FIELD(name);
1257 	WRITE_INT_FIELD(argnumber);
1258 	WRITE_LOCATION_FIELD(location);
1259 }
1260 
1261 static void
_outOpExpr(StringInfo str,const OpExpr * node)1262 _outOpExpr(StringInfo str, const OpExpr *node)
1263 {
1264 	WRITE_NODE_TYPE("OPEXPR");
1265 
1266 	WRITE_OID_FIELD(opno);
1267 	WRITE_OID_FIELD(opfuncid);
1268 	WRITE_OID_FIELD(opresulttype);
1269 	WRITE_BOOL_FIELD(opretset);
1270 	WRITE_OID_FIELD(opcollid);
1271 	WRITE_OID_FIELD(inputcollid);
1272 	WRITE_NODE_FIELD(args);
1273 	WRITE_LOCATION_FIELD(location);
1274 }
1275 
1276 static void
_outDistinctExpr(StringInfo str,const DistinctExpr * node)1277 _outDistinctExpr(StringInfo str, const DistinctExpr *node)
1278 {
1279 	WRITE_NODE_TYPE("DISTINCTEXPR");
1280 
1281 	WRITE_OID_FIELD(opno);
1282 	WRITE_OID_FIELD(opfuncid);
1283 	WRITE_OID_FIELD(opresulttype);
1284 	WRITE_BOOL_FIELD(opretset);
1285 	WRITE_OID_FIELD(opcollid);
1286 	WRITE_OID_FIELD(inputcollid);
1287 	WRITE_NODE_FIELD(args);
1288 	WRITE_LOCATION_FIELD(location);
1289 }
1290 
1291 static void
_outNullIfExpr(StringInfo str,const NullIfExpr * node)1292 _outNullIfExpr(StringInfo str, const NullIfExpr *node)
1293 {
1294 	WRITE_NODE_TYPE("NULLIFEXPR");
1295 
1296 	WRITE_OID_FIELD(opno);
1297 	WRITE_OID_FIELD(opfuncid);
1298 	WRITE_OID_FIELD(opresulttype);
1299 	WRITE_BOOL_FIELD(opretset);
1300 	WRITE_OID_FIELD(opcollid);
1301 	WRITE_OID_FIELD(inputcollid);
1302 	WRITE_NODE_FIELD(args);
1303 	WRITE_LOCATION_FIELD(location);
1304 }
1305 
1306 static void
_outScalarArrayOpExpr(StringInfo str,const ScalarArrayOpExpr * node)1307 _outScalarArrayOpExpr(StringInfo str, const ScalarArrayOpExpr *node)
1308 {
1309 	WRITE_NODE_TYPE("SCALARARRAYOPEXPR");
1310 
1311 	WRITE_OID_FIELD(opno);
1312 	WRITE_OID_FIELD(opfuncid);
1313 	WRITE_OID_FIELD(hashfuncid);
1314 	WRITE_BOOL_FIELD(useOr);
1315 	WRITE_OID_FIELD(inputcollid);
1316 	WRITE_NODE_FIELD(args);
1317 	WRITE_LOCATION_FIELD(location);
1318 }
1319 
1320 static void
_outBoolExpr(StringInfo str,const BoolExpr * node)1321 _outBoolExpr(StringInfo str, const BoolExpr *node)
1322 {
1323 	char	   *opstr = NULL;
1324 
1325 	WRITE_NODE_TYPE("BOOLEXPR");
1326 
1327 	/* do-it-yourself enum representation */
1328 	switch (node->boolop)
1329 	{
1330 		case AND_EXPR:
1331 			opstr = "and";
1332 			break;
1333 		case OR_EXPR:
1334 			opstr = "or";
1335 			break;
1336 		case NOT_EXPR:
1337 			opstr = "not";
1338 			break;
1339 	}
1340 	appendStringInfoString(str, " :boolop ");
1341 	outToken(str, opstr);
1342 
1343 	WRITE_NODE_FIELD(args);
1344 	WRITE_LOCATION_FIELD(location);
1345 }
1346 
1347 static void
_outSubLink(StringInfo str,const SubLink * node)1348 _outSubLink(StringInfo str, const SubLink *node)
1349 {
1350 	WRITE_NODE_TYPE("SUBLINK");
1351 
1352 	WRITE_ENUM_FIELD(subLinkType, SubLinkType);
1353 	WRITE_INT_FIELD(subLinkId);
1354 	WRITE_NODE_FIELD(testexpr);
1355 	WRITE_NODE_FIELD(operName);
1356 	WRITE_NODE_FIELD(subselect);
1357 	WRITE_LOCATION_FIELD(location);
1358 }
1359 
1360 static void
_outSubPlan(StringInfo str,const SubPlan * node)1361 _outSubPlan(StringInfo str, const SubPlan *node)
1362 {
1363 	WRITE_NODE_TYPE("SUBPLAN");
1364 
1365 	WRITE_ENUM_FIELD(subLinkType, SubLinkType);
1366 	WRITE_NODE_FIELD(testexpr);
1367 	WRITE_NODE_FIELD(paramIds);
1368 	WRITE_INT_FIELD(plan_id);
1369 	WRITE_STRING_FIELD(plan_name);
1370 	WRITE_OID_FIELD(firstColType);
1371 	WRITE_INT_FIELD(firstColTypmod);
1372 	WRITE_OID_FIELD(firstColCollation);
1373 	WRITE_BOOL_FIELD(useHashTable);
1374 	WRITE_BOOL_FIELD(unknownEqFalse);
1375 	WRITE_BOOL_FIELD(parallel_safe);
1376 	WRITE_NODE_FIELD(setParam);
1377 	WRITE_NODE_FIELD(parParam);
1378 	WRITE_NODE_FIELD(args);
1379 	WRITE_FLOAT_FIELD(startup_cost, "%.2f");
1380 	WRITE_FLOAT_FIELD(per_call_cost, "%.2f");
1381 }
1382 
1383 static void
_outAlternativeSubPlan(StringInfo str,const AlternativeSubPlan * node)1384 _outAlternativeSubPlan(StringInfo str, const AlternativeSubPlan *node)
1385 {
1386 	WRITE_NODE_TYPE("ALTERNATIVESUBPLAN");
1387 
1388 	WRITE_NODE_FIELD(subplans);
1389 }
1390 
1391 static void
_outFieldSelect(StringInfo str,const FieldSelect * node)1392 _outFieldSelect(StringInfo str, const FieldSelect *node)
1393 {
1394 	WRITE_NODE_TYPE("FIELDSELECT");
1395 
1396 	WRITE_NODE_FIELD(arg);
1397 	WRITE_INT_FIELD(fieldnum);
1398 	WRITE_OID_FIELD(resulttype);
1399 	WRITE_INT_FIELD(resulttypmod);
1400 	WRITE_OID_FIELD(resultcollid);
1401 }
1402 
1403 static void
_outFieldStore(StringInfo str,const FieldStore * node)1404 _outFieldStore(StringInfo str, const FieldStore *node)
1405 {
1406 	WRITE_NODE_TYPE("FIELDSTORE");
1407 
1408 	WRITE_NODE_FIELD(arg);
1409 	WRITE_NODE_FIELD(newvals);
1410 	WRITE_NODE_FIELD(fieldnums);
1411 	WRITE_OID_FIELD(resulttype);
1412 }
1413 
1414 static void
_outRelabelType(StringInfo str,const RelabelType * node)1415 _outRelabelType(StringInfo str, const RelabelType *node)
1416 {
1417 	WRITE_NODE_TYPE("RELABELTYPE");
1418 
1419 	WRITE_NODE_FIELD(arg);
1420 	WRITE_OID_FIELD(resulttype);
1421 	WRITE_INT_FIELD(resulttypmod);
1422 	WRITE_OID_FIELD(resultcollid);
1423 	WRITE_ENUM_FIELD(relabelformat, CoercionForm);
1424 	WRITE_LOCATION_FIELD(location);
1425 }
1426 
1427 static void
_outCoerceViaIO(StringInfo str,const CoerceViaIO * node)1428 _outCoerceViaIO(StringInfo str, const CoerceViaIO *node)
1429 {
1430 	WRITE_NODE_TYPE("COERCEVIAIO");
1431 
1432 	WRITE_NODE_FIELD(arg);
1433 	WRITE_OID_FIELD(resulttype);
1434 	WRITE_OID_FIELD(resultcollid);
1435 	WRITE_ENUM_FIELD(coerceformat, CoercionForm);
1436 	WRITE_LOCATION_FIELD(location);
1437 }
1438 
1439 static void
_outArrayCoerceExpr(StringInfo str,const ArrayCoerceExpr * node)1440 _outArrayCoerceExpr(StringInfo str, const ArrayCoerceExpr *node)
1441 {
1442 	WRITE_NODE_TYPE("ARRAYCOERCEEXPR");
1443 
1444 	WRITE_NODE_FIELD(arg);
1445 	WRITE_NODE_FIELD(elemexpr);
1446 	WRITE_OID_FIELD(resulttype);
1447 	WRITE_INT_FIELD(resulttypmod);
1448 	WRITE_OID_FIELD(resultcollid);
1449 	WRITE_ENUM_FIELD(coerceformat, CoercionForm);
1450 	WRITE_LOCATION_FIELD(location);
1451 }
1452 
1453 static void
_outConvertRowtypeExpr(StringInfo str,const ConvertRowtypeExpr * node)1454 _outConvertRowtypeExpr(StringInfo str, const ConvertRowtypeExpr *node)
1455 {
1456 	WRITE_NODE_TYPE("CONVERTROWTYPEEXPR");
1457 
1458 	WRITE_NODE_FIELD(arg);
1459 	WRITE_OID_FIELD(resulttype);
1460 	WRITE_ENUM_FIELD(convertformat, CoercionForm);
1461 	WRITE_LOCATION_FIELD(location);
1462 }
1463 
1464 static void
_outCollateExpr(StringInfo str,const CollateExpr * node)1465 _outCollateExpr(StringInfo str, const CollateExpr *node)
1466 {
1467 	WRITE_NODE_TYPE("COLLATE");
1468 
1469 	WRITE_NODE_FIELD(arg);
1470 	WRITE_OID_FIELD(collOid);
1471 	WRITE_LOCATION_FIELD(location);
1472 }
1473 
1474 static void
_outCaseExpr(StringInfo str,const CaseExpr * node)1475 _outCaseExpr(StringInfo str, const CaseExpr *node)
1476 {
1477 	WRITE_NODE_TYPE("CASE");
1478 
1479 	WRITE_OID_FIELD(casetype);
1480 	WRITE_OID_FIELD(casecollid);
1481 	WRITE_NODE_FIELD(arg);
1482 	WRITE_NODE_FIELD(args);
1483 	WRITE_NODE_FIELD(defresult);
1484 	WRITE_LOCATION_FIELD(location);
1485 }
1486 
1487 static void
_outCaseWhen(StringInfo str,const CaseWhen * node)1488 _outCaseWhen(StringInfo str, const CaseWhen *node)
1489 {
1490 	WRITE_NODE_TYPE("WHEN");
1491 
1492 	WRITE_NODE_FIELD(expr);
1493 	WRITE_NODE_FIELD(result);
1494 	WRITE_LOCATION_FIELD(location);
1495 }
1496 
1497 static void
_outCaseTestExpr(StringInfo str,const CaseTestExpr * node)1498 _outCaseTestExpr(StringInfo str, const CaseTestExpr *node)
1499 {
1500 	WRITE_NODE_TYPE("CASETESTEXPR");
1501 
1502 	WRITE_OID_FIELD(typeId);
1503 	WRITE_INT_FIELD(typeMod);
1504 	WRITE_OID_FIELD(collation);
1505 }
1506 
1507 static void
_outArrayExpr(StringInfo str,const ArrayExpr * node)1508 _outArrayExpr(StringInfo str, const ArrayExpr *node)
1509 {
1510 	WRITE_NODE_TYPE("ARRAY");
1511 
1512 	WRITE_OID_FIELD(array_typeid);
1513 	WRITE_OID_FIELD(array_collid);
1514 	WRITE_OID_FIELD(element_typeid);
1515 	WRITE_NODE_FIELD(elements);
1516 	WRITE_BOOL_FIELD(multidims);
1517 	WRITE_LOCATION_FIELD(location);
1518 }
1519 
1520 static void
_outRowExpr(StringInfo str,const RowExpr * node)1521 _outRowExpr(StringInfo str, const RowExpr *node)
1522 {
1523 	WRITE_NODE_TYPE("ROW");
1524 
1525 	WRITE_NODE_FIELD(args);
1526 	WRITE_OID_FIELD(row_typeid);
1527 	WRITE_ENUM_FIELD(row_format, CoercionForm);
1528 	WRITE_NODE_FIELD(colnames);
1529 	WRITE_LOCATION_FIELD(location);
1530 }
1531 
1532 static void
_outRowCompareExpr(StringInfo str,const RowCompareExpr * node)1533 _outRowCompareExpr(StringInfo str, const RowCompareExpr *node)
1534 {
1535 	WRITE_NODE_TYPE("ROWCOMPARE");
1536 
1537 	WRITE_ENUM_FIELD(rctype, RowCompareType);
1538 	WRITE_NODE_FIELD(opnos);
1539 	WRITE_NODE_FIELD(opfamilies);
1540 	WRITE_NODE_FIELD(inputcollids);
1541 	WRITE_NODE_FIELD(largs);
1542 	WRITE_NODE_FIELD(rargs);
1543 }
1544 
1545 static void
_outCoalesceExpr(StringInfo str,const CoalesceExpr * node)1546 _outCoalesceExpr(StringInfo str, const CoalesceExpr *node)
1547 {
1548 	WRITE_NODE_TYPE("COALESCE");
1549 
1550 	WRITE_OID_FIELD(coalescetype);
1551 	WRITE_OID_FIELD(coalescecollid);
1552 	WRITE_NODE_FIELD(args);
1553 	WRITE_LOCATION_FIELD(location);
1554 }
1555 
1556 static void
_outMinMaxExpr(StringInfo str,const MinMaxExpr * node)1557 _outMinMaxExpr(StringInfo str, const MinMaxExpr *node)
1558 {
1559 	WRITE_NODE_TYPE("MINMAX");
1560 
1561 	WRITE_OID_FIELD(minmaxtype);
1562 	WRITE_OID_FIELD(minmaxcollid);
1563 	WRITE_OID_FIELD(inputcollid);
1564 	WRITE_ENUM_FIELD(op, MinMaxOp);
1565 	WRITE_NODE_FIELD(args);
1566 	WRITE_LOCATION_FIELD(location);
1567 }
1568 
1569 static void
_outSQLValueFunction(StringInfo str,const SQLValueFunction * node)1570 _outSQLValueFunction(StringInfo str, const SQLValueFunction *node)
1571 {
1572 	WRITE_NODE_TYPE("SQLVALUEFUNCTION");
1573 
1574 	WRITE_ENUM_FIELD(op, SQLValueFunctionOp);
1575 	WRITE_OID_FIELD(type);
1576 	WRITE_INT_FIELD(typmod);
1577 	WRITE_LOCATION_FIELD(location);
1578 }
1579 
1580 static void
_outXmlExpr(StringInfo str,const XmlExpr * node)1581 _outXmlExpr(StringInfo str, const XmlExpr *node)
1582 {
1583 	WRITE_NODE_TYPE("XMLEXPR");
1584 
1585 	WRITE_ENUM_FIELD(op, XmlExprOp);
1586 	WRITE_STRING_FIELD(name);
1587 	WRITE_NODE_FIELD(named_args);
1588 	WRITE_NODE_FIELD(arg_names);
1589 	WRITE_NODE_FIELD(args);
1590 	WRITE_ENUM_FIELD(xmloption, XmlOptionType);
1591 	WRITE_OID_FIELD(type);
1592 	WRITE_INT_FIELD(typmod);
1593 	WRITE_LOCATION_FIELD(location);
1594 }
1595 
1596 static void
_outNullTest(StringInfo str,const NullTest * node)1597 _outNullTest(StringInfo str, const NullTest *node)
1598 {
1599 	WRITE_NODE_TYPE("NULLTEST");
1600 
1601 	WRITE_NODE_FIELD(arg);
1602 	WRITE_ENUM_FIELD(nulltesttype, NullTestType);
1603 	WRITE_BOOL_FIELD(argisrow);
1604 	WRITE_LOCATION_FIELD(location);
1605 }
1606 
1607 static void
_outBooleanTest(StringInfo str,const BooleanTest * node)1608 _outBooleanTest(StringInfo str, const BooleanTest *node)
1609 {
1610 	WRITE_NODE_TYPE("BOOLEANTEST");
1611 
1612 	WRITE_NODE_FIELD(arg);
1613 	WRITE_ENUM_FIELD(booltesttype, BoolTestType);
1614 	WRITE_LOCATION_FIELD(location);
1615 }
1616 
1617 static void
_outCoerceToDomain(StringInfo str,const CoerceToDomain * node)1618 _outCoerceToDomain(StringInfo str, const CoerceToDomain *node)
1619 {
1620 	WRITE_NODE_TYPE("COERCETODOMAIN");
1621 
1622 	WRITE_NODE_FIELD(arg);
1623 	WRITE_OID_FIELD(resulttype);
1624 	WRITE_INT_FIELD(resulttypmod);
1625 	WRITE_OID_FIELD(resultcollid);
1626 	WRITE_ENUM_FIELD(coercionformat, CoercionForm);
1627 	WRITE_LOCATION_FIELD(location);
1628 }
1629 
1630 static void
_outCoerceToDomainValue(StringInfo str,const CoerceToDomainValue * node)1631 _outCoerceToDomainValue(StringInfo str, const CoerceToDomainValue *node)
1632 {
1633 	WRITE_NODE_TYPE("COERCETODOMAINVALUE");
1634 
1635 	WRITE_OID_FIELD(typeId);
1636 	WRITE_INT_FIELD(typeMod);
1637 	WRITE_OID_FIELD(collation);
1638 	WRITE_LOCATION_FIELD(location);
1639 }
1640 
1641 static void
_outSetToDefault(StringInfo str,const SetToDefault * node)1642 _outSetToDefault(StringInfo str, const SetToDefault *node)
1643 {
1644 	WRITE_NODE_TYPE("SETTODEFAULT");
1645 
1646 	WRITE_OID_FIELD(typeId);
1647 	WRITE_INT_FIELD(typeMod);
1648 	WRITE_OID_FIELD(collation);
1649 	WRITE_LOCATION_FIELD(location);
1650 }
1651 
1652 static void
_outCurrentOfExpr(StringInfo str,const CurrentOfExpr * node)1653 _outCurrentOfExpr(StringInfo str, const CurrentOfExpr *node)
1654 {
1655 	WRITE_NODE_TYPE("CURRENTOFEXPR");
1656 
1657 	WRITE_UINT_FIELD(cvarno);
1658 	WRITE_STRING_FIELD(cursor_name);
1659 	WRITE_INT_FIELD(cursor_param);
1660 }
1661 
1662 static void
_outNextValueExpr(StringInfo str,const NextValueExpr * node)1663 _outNextValueExpr(StringInfo str, const NextValueExpr *node)
1664 {
1665 	WRITE_NODE_TYPE("NEXTVALUEEXPR");
1666 
1667 	WRITE_OID_FIELD(seqid);
1668 	WRITE_OID_FIELD(typeId);
1669 }
1670 
1671 static void
_outInferenceElem(StringInfo str,const InferenceElem * node)1672 _outInferenceElem(StringInfo str, const InferenceElem *node)
1673 {
1674 	WRITE_NODE_TYPE("INFERENCEELEM");
1675 
1676 	WRITE_NODE_FIELD(expr);
1677 	WRITE_OID_FIELD(infercollid);
1678 	WRITE_OID_FIELD(inferopclass);
1679 }
1680 
1681 static void
_outTargetEntry(StringInfo str,const TargetEntry * node)1682 _outTargetEntry(StringInfo str, const TargetEntry *node)
1683 {
1684 	WRITE_NODE_TYPE("TARGETENTRY");
1685 
1686 	WRITE_NODE_FIELD(expr);
1687 	WRITE_INT_FIELD(resno);
1688 	WRITE_STRING_FIELD(resname);
1689 	WRITE_UINT_FIELD(ressortgroupref);
1690 	WRITE_OID_FIELD(resorigtbl);
1691 	WRITE_INT_FIELD(resorigcol);
1692 	WRITE_BOOL_FIELD(resjunk);
1693 }
1694 
1695 static void
_outRangeTblRef(StringInfo str,const RangeTblRef * node)1696 _outRangeTblRef(StringInfo str, const RangeTblRef *node)
1697 {
1698 	WRITE_NODE_TYPE("RANGETBLREF");
1699 
1700 	WRITE_INT_FIELD(rtindex);
1701 }
1702 
1703 static void
_outJoinExpr(StringInfo str,const JoinExpr * node)1704 _outJoinExpr(StringInfo str, const JoinExpr *node)
1705 {
1706 	WRITE_NODE_TYPE("JOINEXPR");
1707 
1708 	WRITE_ENUM_FIELD(jointype, JoinType);
1709 	WRITE_BOOL_FIELD(isNatural);
1710 	WRITE_NODE_FIELD(larg);
1711 	WRITE_NODE_FIELD(rarg);
1712 	WRITE_NODE_FIELD(usingClause);
1713 	WRITE_NODE_FIELD(join_using_alias);
1714 	WRITE_NODE_FIELD(quals);
1715 	WRITE_NODE_FIELD(alias);
1716 	WRITE_INT_FIELD(rtindex);
1717 }
1718 
1719 static void
_outFromExpr(StringInfo str,const FromExpr * node)1720 _outFromExpr(StringInfo str, const FromExpr *node)
1721 {
1722 	WRITE_NODE_TYPE("FROMEXPR");
1723 
1724 	WRITE_NODE_FIELD(fromlist);
1725 	WRITE_NODE_FIELD(quals);
1726 }
1727 
1728 static void
_outOnConflictExpr(StringInfo str,const OnConflictExpr * node)1729 _outOnConflictExpr(StringInfo str, const OnConflictExpr *node)
1730 {
1731 	WRITE_NODE_TYPE("ONCONFLICTEXPR");
1732 
1733 	WRITE_ENUM_FIELD(action, OnConflictAction);
1734 	WRITE_NODE_FIELD(arbiterElems);
1735 	WRITE_NODE_FIELD(arbiterWhere);
1736 	WRITE_OID_FIELD(constraint);
1737 	WRITE_NODE_FIELD(onConflictSet);
1738 	WRITE_NODE_FIELD(onConflictWhere);
1739 	WRITE_INT_FIELD(exclRelIndex);
1740 	WRITE_NODE_FIELD(exclRelTlist);
1741 }
1742 
1743 /*****************************************************************************
1744  *
1745  *	Stuff from pathnodes.h.
1746  *
1747  *****************************************************************************/
1748 
1749 /*
1750  * print the basic stuff of all nodes that inherit from Path
1751  *
1752  * Note we do NOT print the parent, else we'd be in infinite recursion.
1753  * We can print the parent's relids for identification purposes, though.
1754  * We print the pathtarget only if it's not the default one for the rel.
1755  * We also do not print the whole of param_info, since it's printed by
1756  * _outRelOptInfo; it's sufficient and less cluttering to print just the
1757  * required outer relids.
1758  */
1759 static void
_outPathInfo(StringInfo str,const Path * node)1760 _outPathInfo(StringInfo str, const Path *node)
1761 {
1762 	WRITE_ENUM_FIELD(pathtype, NodeTag);
1763 	appendStringInfoString(str, " :parent_relids ");
1764 	outBitmapset(str, node->parent->relids);
1765 	if (node->pathtarget != node->parent->reltarget)
1766 		WRITE_NODE_FIELD(pathtarget);
1767 	appendStringInfoString(str, " :required_outer ");
1768 	if (node->param_info)
1769 		outBitmapset(str, node->param_info->ppi_req_outer);
1770 	else
1771 		outBitmapset(str, NULL);
1772 	WRITE_BOOL_FIELD(parallel_aware);
1773 	WRITE_BOOL_FIELD(parallel_safe);
1774 	WRITE_INT_FIELD(parallel_workers);
1775 	WRITE_FLOAT_FIELD(rows, "%.0f");
1776 	WRITE_FLOAT_FIELD(startup_cost, "%.2f");
1777 	WRITE_FLOAT_FIELD(total_cost, "%.2f");
1778 	WRITE_NODE_FIELD(pathkeys);
1779 }
1780 
1781 /*
1782  * print the basic stuff of all nodes that inherit from JoinPath
1783  */
1784 static void
_outJoinPathInfo(StringInfo str,const JoinPath * node)1785 _outJoinPathInfo(StringInfo str, const JoinPath *node)
1786 {
1787 	_outPathInfo(str, (const Path *) node);
1788 
1789 	WRITE_ENUM_FIELD(jointype, JoinType);
1790 	WRITE_BOOL_FIELD(inner_unique);
1791 	WRITE_NODE_FIELD(outerjoinpath);
1792 	WRITE_NODE_FIELD(innerjoinpath);
1793 	WRITE_NODE_FIELD(joinrestrictinfo);
1794 }
1795 
1796 static void
_outPath(StringInfo str,const Path * node)1797 _outPath(StringInfo str, const Path *node)
1798 {
1799 	WRITE_NODE_TYPE("PATH");
1800 
1801 	_outPathInfo(str, (const Path *) node);
1802 }
1803 
1804 static void
_outIndexPath(StringInfo str,const IndexPath * node)1805 _outIndexPath(StringInfo str, const IndexPath *node)
1806 {
1807 	WRITE_NODE_TYPE("INDEXPATH");
1808 
1809 	_outPathInfo(str, (const Path *) node);
1810 
1811 	WRITE_NODE_FIELD(indexinfo);
1812 	WRITE_NODE_FIELD(indexclauses);
1813 	WRITE_NODE_FIELD(indexorderbys);
1814 	WRITE_NODE_FIELD(indexorderbycols);
1815 	WRITE_ENUM_FIELD(indexscandir, ScanDirection);
1816 	WRITE_FLOAT_FIELD(indextotalcost, "%.2f");
1817 	WRITE_FLOAT_FIELD(indexselectivity, "%.4f");
1818 }
1819 
1820 static void
_outBitmapHeapPath(StringInfo str,const BitmapHeapPath * node)1821 _outBitmapHeapPath(StringInfo str, const BitmapHeapPath *node)
1822 {
1823 	WRITE_NODE_TYPE("BITMAPHEAPPATH");
1824 
1825 	_outPathInfo(str, (const Path *) node);
1826 
1827 	WRITE_NODE_FIELD(bitmapqual);
1828 }
1829 
1830 static void
_outBitmapAndPath(StringInfo str,const BitmapAndPath * node)1831 _outBitmapAndPath(StringInfo str, const BitmapAndPath *node)
1832 {
1833 	WRITE_NODE_TYPE("BITMAPANDPATH");
1834 
1835 	_outPathInfo(str, (const Path *) node);
1836 
1837 	WRITE_NODE_FIELD(bitmapquals);
1838 	WRITE_FLOAT_FIELD(bitmapselectivity, "%.4f");
1839 }
1840 
1841 static void
_outBitmapOrPath(StringInfo str,const BitmapOrPath * node)1842 _outBitmapOrPath(StringInfo str, const BitmapOrPath *node)
1843 {
1844 	WRITE_NODE_TYPE("BITMAPORPATH");
1845 
1846 	_outPathInfo(str, (const Path *) node);
1847 
1848 	WRITE_NODE_FIELD(bitmapquals);
1849 	WRITE_FLOAT_FIELD(bitmapselectivity, "%.4f");
1850 }
1851 
1852 static void
_outTidPath(StringInfo str,const TidPath * node)1853 _outTidPath(StringInfo str, const TidPath *node)
1854 {
1855 	WRITE_NODE_TYPE("TIDPATH");
1856 
1857 	_outPathInfo(str, (const Path *) node);
1858 
1859 	WRITE_NODE_FIELD(tidquals);
1860 }
1861 
1862 static void
_outTidRangePath(StringInfo str,const TidRangePath * node)1863 _outTidRangePath(StringInfo str, const TidRangePath *node)
1864 {
1865 	WRITE_NODE_TYPE("TIDRANGEPATH");
1866 
1867 	_outPathInfo(str, (const Path *) node);
1868 
1869 	WRITE_NODE_FIELD(tidrangequals);
1870 }
1871 
1872 static void
_outSubqueryScanPath(StringInfo str,const SubqueryScanPath * node)1873 _outSubqueryScanPath(StringInfo str, const SubqueryScanPath *node)
1874 {
1875 	WRITE_NODE_TYPE("SUBQUERYSCANPATH");
1876 
1877 	_outPathInfo(str, (const Path *) node);
1878 
1879 	WRITE_NODE_FIELD(subpath);
1880 }
1881 
1882 static void
_outForeignPath(StringInfo str,const ForeignPath * node)1883 _outForeignPath(StringInfo str, const ForeignPath *node)
1884 {
1885 	WRITE_NODE_TYPE("FOREIGNPATH");
1886 
1887 	_outPathInfo(str, (const Path *) node);
1888 
1889 	WRITE_NODE_FIELD(fdw_outerpath);
1890 	WRITE_NODE_FIELD(fdw_private);
1891 }
1892 
1893 static void
_outCustomPath(StringInfo str,const CustomPath * node)1894 _outCustomPath(StringInfo str, const CustomPath *node)
1895 {
1896 	WRITE_NODE_TYPE("CUSTOMPATH");
1897 
1898 	_outPathInfo(str, (const Path *) node);
1899 
1900 	WRITE_UINT_FIELD(flags);
1901 	WRITE_NODE_FIELD(custom_paths);
1902 	WRITE_NODE_FIELD(custom_private);
1903 	appendStringInfoString(str, " :methods ");
1904 	outToken(str, node->methods->CustomName);
1905 }
1906 
1907 static void
_outAppendPath(StringInfo str,const AppendPath * node)1908 _outAppendPath(StringInfo str, const AppendPath *node)
1909 {
1910 	WRITE_NODE_TYPE("APPENDPATH");
1911 
1912 	_outPathInfo(str, (const Path *) node);
1913 
1914 	WRITE_NODE_FIELD(subpaths);
1915 	WRITE_INT_FIELD(first_partial_path);
1916 	WRITE_FLOAT_FIELD(limit_tuples, "%.0f");
1917 }
1918 
1919 static void
_outMergeAppendPath(StringInfo str,const MergeAppendPath * node)1920 _outMergeAppendPath(StringInfo str, const MergeAppendPath *node)
1921 {
1922 	WRITE_NODE_TYPE("MERGEAPPENDPATH");
1923 
1924 	_outPathInfo(str, (const Path *) node);
1925 
1926 	WRITE_NODE_FIELD(subpaths);
1927 	WRITE_FLOAT_FIELD(limit_tuples, "%.0f");
1928 }
1929 
1930 static void
_outGroupResultPath(StringInfo str,const GroupResultPath * node)1931 _outGroupResultPath(StringInfo str, const GroupResultPath *node)
1932 {
1933 	WRITE_NODE_TYPE("GROUPRESULTPATH");
1934 
1935 	_outPathInfo(str, (const Path *) node);
1936 
1937 	WRITE_NODE_FIELD(quals);
1938 }
1939 
1940 static void
_outMaterialPath(StringInfo str,const MaterialPath * node)1941 _outMaterialPath(StringInfo str, const MaterialPath *node)
1942 {
1943 	WRITE_NODE_TYPE("MATERIALPATH");
1944 
1945 	_outPathInfo(str, (const Path *) node);
1946 
1947 	WRITE_NODE_FIELD(subpath);
1948 }
1949 
1950 static void
_outMemoizePath(StringInfo str,const MemoizePath * node)1951 _outMemoizePath(StringInfo str, const MemoizePath *node)
1952 {
1953 	WRITE_NODE_TYPE("MEMOIZEPATH");
1954 
1955 	_outPathInfo(str, (const Path *) node);
1956 
1957 	WRITE_NODE_FIELD(subpath);
1958 	WRITE_NODE_FIELD(hash_operators);
1959 	WRITE_NODE_FIELD(param_exprs);
1960 	WRITE_BOOL_FIELD(singlerow);
1961 	WRITE_FLOAT_FIELD(calls, "%.0f");
1962 	WRITE_UINT_FIELD(est_entries);
1963 }
1964 
1965 static void
_outUniquePath(StringInfo str,const UniquePath * node)1966 _outUniquePath(StringInfo str, const UniquePath *node)
1967 {
1968 	WRITE_NODE_TYPE("UNIQUEPATH");
1969 
1970 	_outPathInfo(str, (const Path *) node);
1971 
1972 	WRITE_NODE_FIELD(subpath);
1973 	WRITE_ENUM_FIELD(umethod, UniquePathMethod);
1974 	WRITE_NODE_FIELD(in_operators);
1975 	WRITE_NODE_FIELD(uniq_exprs);
1976 }
1977 
1978 static void
_outGatherPath(StringInfo str,const GatherPath * node)1979 _outGatherPath(StringInfo str, const GatherPath *node)
1980 {
1981 	WRITE_NODE_TYPE("GATHERPATH");
1982 
1983 	_outPathInfo(str, (const Path *) node);
1984 
1985 	WRITE_NODE_FIELD(subpath);
1986 	WRITE_BOOL_FIELD(single_copy);
1987 	WRITE_INT_FIELD(num_workers);
1988 }
1989 
1990 static void
_outProjectionPath(StringInfo str,const ProjectionPath * node)1991 _outProjectionPath(StringInfo str, const ProjectionPath *node)
1992 {
1993 	WRITE_NODE_TYPE("PROJECTIONPATH");
1994 
1995 	_outPathInfo(str, (const Path *) node);
1996 
1997 	WRITE_NODE_FIELD(subpath);
1998 	WRITE_BOOL_FIELD(dummypp);
1999 }
2000 
2001 static void
_outProjectSetPath(StringInfo str,const ProjectSetPath * node)2002 _outProjectSetPath(StringInfo str, const ProjectSetPath *node)
2003 {
2004 	WRITE_NODE_TYPE("PROJECTSETPATH");
2005 
2006 	_outPathInfo(str, (const Path *) node);
2007 
2008 	WRITE_NODE_FIELD(subpath);
2009 }
2010 
2011 static void
_outSortPathInfo(StringInfo str,const SortPath * node)2012 _outSortPathInfo(StringInfo str, const SortPath *node)
2013 {
2014 	_outPathInfo(str, (const Path *) node);
2015 
2016 	WRITE_NODE_FIELD(subpath);
2017 }
2018 
2019 static void
_outSortPath(StringInfo str,const SortPath * node)2020 _outSortPath(StringInfo str, const SortPath *node)
2021 {
2022 	WRITE_NODE_TYPE("SORTPATH");
2023 
2024 	_outSortPathInfo(str, node);
2025 }
2026 
2027 static void
_outIncrementalSortPath(StringInfo str,const IncrementalSortPath * node)2028 _outIncrementalSortPath(StringInfo str, const IncrementalSortPath *node)
2029 {
2030 	WRITE_NODE_TYPE("INCREMENTALSORTPATH");
2031 
2032 	_outSortPathInfo(str, (const SortPath *) node);
2033 
2034 	WRITE_INT_FIELD(nPresortedCols);
2035 }
2036 
2037 static void
_outGroupPath(StringInfo str,const GroupPath * node)2038 _outGroupPath(StringInfo str, const GroupPath *node)
2039 {
2040 	WRITE_NODE_TYPE("GROUPPATH");
2041 
2042 	_outPathInfo(str, (const Path *) node);
2043 
2044 	WRITE_NODE_FIELD(subpath);
2045 	WRITE_NODE_FIELD(groupClause);
2046 	WRITE_NODE_FIELD(qual);
2047 }
2048 
2049 static void
_outUpperUniquePath(StringInfo str,const UpperUniquePath * node)2050 _outUpperUniquePath(StringInfo str, const UpperUniquePath *node)
2051 {
2052 	WRITE_NODE_TYPE("UPPERUNIQUEPATH");
2053 
2054 	_outPathInfo(str, (const Path *) node);
2055 
2056 	WRITE_NODE_FIELD(subpath);
2057 	WRITE_INT_FIELD(numkeys);
2058 }
2059 
2060 static void
_outAggPath(StringInfo str,const AggPath * node)2061 _outAggPath(StringInfo str, const AggPath *node)
2062 {
2063 	WRITE_NODE_TYPE("AGGPATH");
2064 
2065 	_outPathInfo(str, (const Path *) node);
2066 
2067 	WRITE_NODE_FIELD(subpath);
2068 	WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
2069 	WRITE_ENUM_FIELD(aggsplit, AggSplit);
2070 	WRITE_FLOAT_FIELD(numGroups, "%.0f");
2071 	WRITE_UINT64_FIELD(transitionSpace);
2072 	WRITE_NODE_FIELD(groupClause);
2073 	WRITE_NODE_FIELD(qual);
2074 }
2075 
2076 static void
_outRollupData(StringInfo str,const RollupData * node)2077 _outRollupData(StringInfo str, const RollupData *node)
2078 {
2079 	WRITE_NODE_TYPE("ROLLUP");
2080 
2081 	WRITE_NODE_FIELD(groupClause);
2082 	WRITE_NODE_FIELD(gsets);
2083 	WRITE_NODE_FIELD(gsets_data);
2084 	WRITE_FLOAT_FIELD(numGroups, "%.0f");
2085 	WRITE_BOOL_FIELD(hashable);
2086 	WRITE_BOOL_FIELD(is_hashed);
2087 }
2088 
2089 static void
_outGroupingSetData(StringInfo str,const GroupingSetData * node)2090 _outGroupingSetData(StringInfo str, const GroupingSetData *node)
2091 {
2092 	WRITE_NODE_TYPE("GSDATA");
2093 
2094 	WRITE_NODE_FIELD(set);
2095 	WRITE_FLOAT_FIELD(numGroups, "%.0f");
2096 }
2097 
2098 static void
_outGroupingSetsPath(StringInfo str,const GroupingSetsPath * node)2099 _outGroupingSetsPath(StringInfo str, const GroupingSetsPath *node)
2100 {
2101 	WRITE_NODE_TYPE("GROUPINGSETSPATH");
2102 
2103 	_outPathInfo(str, (const Path *) node);
2104 
2105 	WRITE_NODE_FIELD(subpath);
2106 	WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
2107 	WRITE_NODE_FIELD(rollups);
2108 	WRITE_NODE_FIELD(qual);
2109 	WRITE_UINT64_FIELD(transitionSpace);
2110 }
2111 
2112 static void
_outMinMaxAggPath(StringInfo str,const MinMaxAggPath * node)2113 _outMinMaxAggPath(StringInfo str, const MinMaxAggPath *node)
2114 {
2115 	WRITE_NODE_TYPE("MINMAXAGGPATH");
2116 
2117 	_outPathInfo(str, (const Path *) node);
2118 
2119 	WRITE_NODE_FIELD(mmaggregates);
2120 	WRITE_NODE_FIELD(quals);
2121 }
2122 
2123 static void
_outWindowAggPath(StringInfo str,const WindowAggPath * node)2124 _outWindowAggPath(StringInfo str, const WindowAggPath *node)
2125 {
2126 	WRITE_NODE_TYPE("WINDOWAGGPATH");
2127 
2128 	_outPathInfo(str, (const Path *) node);
2129 
2130 	WRITE_NODE_FIELD(subpath);
2131 	WRITE_NODE_FIELD(winclause);
2132 }
2133 
2134 static void
_outSetOpPath(StringInfo str,const SetOpPath * node)2135 _outSetOpPath(StringInfo str, const SetOpPath *node)
2136 {
2137 	WRITE_NODE_TYPE("SETOPPATH");
2138 
2139 	_outPathInfo(str, (const Path *) node);
2140 
2141 	WRITE_NODE_FIELD(subpath);
2142 	WRITE_ENUM_FIELD(cmd, SetOpCmd);
2143 	WRITE_ENUM_FIELD(strategy, SetOpStrategy);
2144 	WRITE_NODE_FIELD(distinctList);
2145 	WRITE_INT_FIELD(flagColIdx);
2146 	WRITE_INT_FIELD(firstFlag);
2147 	WRITE_FLOAT_FIELD(numGroups, "%.0f");
2148 }
2149 
2150 static void
_outRecursiveUnionPath(StringInfo str,const RecursiveUnionPath * node)2151 _outRecursiveUnionPath(StringInfo str, const RecursiveUnionPath *node)
2152 {
2153 	WRITE_NODE_TYPE("RECURSIVEUNIONPATH");
2154 
2155 	_outPathInfo(str, (const Path *) node);
2156 
2157 	WRITE_NODE_FIELD(leftpath);
2158 	WRITE_NODE_FIELD(rightpath);
2159 	WRITE_NODE_FIELD(distinctList);
2160 	WRITE_INT_FIELD(wtParam);
2161 	WRITE_FLOAT_FIELD(numGroups, "%.0f");
2162 }
2163 
2164 static void
_outLockRowsPath(StringInfo str,const LockRowsPath * node)2165 _outLockRowsPath(StringInfo str, const LockRowsPath *node)
2166 {
2167 	WRITE_NODE_TYPE("LOCKROWSPATH");
2168 
2169 	_outPathInfo(str, (const Path *) node);
2170 
2171 	WRITE_NODE_FIELD(subpath);
2172 	WRITE_NODE_FIELD(rowMarks);
2173 	WRITE_INT_FIELD(epqParam);
2174 }
2175 
2176 static void
_outModifyTablePath(StringInfo str,const ModifyTablePath * node)2177 _outModifyTablePath(StringInfo str, const ModifyTablePath *node)
2178 {
2179 	WRITE_NODE_TYPE("MODIFYTABLEPATH");
2180 
2181 	_outPathInfo(str, (const Path *) node);
2182 
2183 	WRITE_NODE_FIELD(subpath);
2184 	WRITE_ENUM_FIELD(operation, CmdType);
2185 	WRITE_BOOL_FIELD(canSetTag);
2186 	WRITE_UINT_FIELD(nominalRelation);
2187 	WRITE_UINT_FIELD(rootRelation);
2188 	WRITE_BOOL_FIELD(partColsUpdated);
2189 	WRITE_NODE_FIELD(resultRelations);
2190 	WRITE_NODE_FIELD(updateColnosLists);
2191 	WRITE_NODE_FIELD(withCheckOptionLists);
2192 	WRITE_NODE_FIELD(returningLists);
2193 	WRITE_NODE_FIELD(rowMarks);
2194 	WRITE_NODE_FIELD(onconflict);
2195 	WRITE_INT_FIELD(epqParam);
2196 }
2197 
2198 static void
_outLimitPath(StringInfo str,const LimitPath * node)2199 _outLimitPath(StringInfo str, const LimitPath *node)
2200 {
2201 	WRITE_NODE_TYPE("LIMITPATH");
2202 
2203 	_outPathInfo(str, (const Path *) node);
2204 
2205 	WRITE_NODE_FIELD(subpath);
2206 	WRITE_NODE_FIELD(limitOffset);
2207 	WRITE_NODE_FIELD(limitCount);
2208 	WRITE_ENUM_FIELD(limitOption, LimitOption);
2209 }
2210 
2211 static void
_outGatherMergePath(StringInfo str,const GatherMergePath * node)2212 _outGatherMergePath(StringInfo str, const GatherMergePath *node)
2213 {
2214 	WRITE_NODE_TYPE("GATHERMERGEPATH");
2215 
2216 	_outPathInfo(str, (const Path *) node);
2217 
2218 	WRITE_NODE_FIELD(subpath);
2219 	WRITE_INT_FIELD(num_workers);
2220 }
2221 
2222 static void
_outNestPath(StringInfo str,const NestPath * node)2223 _outNestPath(StringInfo str, const NestPath *node)
2224 {
2225 	WRITE_NODE_TYPE("NESTPATH");
2226 
2227 	_outJoinPathInfo(str, (const JoinPath *) node);
2228 }
2229 
2230 static void
_outMergePath(StringInfo str,const MergePath * node)2231 _outMergePath(StringInfo str, const MergePath *node)
2232 {
2233 	WRITE_NODE_TYPE("MERGEPATH");
2234 
2235 	_outJoinPathInfo(str, (const JoinPath *) node);
2236 
2237 	WRITE_NODE_FIELD(path_mergeclauses);
2238 	WRITE_NODE_FIELD(outersortkeys);
2239 	WRITE_NODE_FIELD(innersortkeys);
2240 	WRITE_BOOL_FIELD(skip_mark_restore);
2241 	WRITE_BOOL_FIELD(materialize_inner);
2242 }
2243 
2244 static void
_outHashPath(StringInfo str,const HashPath * node)2245 _outHashPath(StringInfo str, const HashPath *node)
2246 {
2247 	WRITE_NODE_TYPE("HASHPATH");
2248 
2249 	_outJoinPathInfo(str, (const JoinPath *) node);
2250 
2251 	WRITE_NODE_FIELD(path_hashclauses);
2252 	WRITE_INT_FIELD(num_batches);
2253 	WRITE_FLOAT_FIELD(inner_rows_total, "%.0f");
2254 }
2255 
2256 static void
_outPlannerGlobal(StringInfo str,const PlannerGlobal * node)2257 _outPlannerGlobal(StringInfo str, const PlannerGlobal *node)
2258 {
2259 	WRITE_NODE_TYPE("PLANNERGLOBAL");
2260 
2261 	/* NB: this isn't a complete set of fields */
2262 	WRITE_NODE_FIELD(subplans);
2263 	WRITE_BITMAPSET_FIELD(rewindPlanIDs);
2264 	WRITE_NODE_FIELD(finalrtable);
2265 	WRITE_NODE_FIELD(finalrowmarks);
2266 	WRITE_NODE_FIELD(resultRelations);
2267 	WRITE_NODE_FIELD(appendRelations);
2268 	WRITE_NODE_FIELD(relationOids);
2269 	WRITE_NODE_FIELD(invalItems);
2270 	WRITE_NODE_FIELD(paramExecTypes);
2271 	WRITE_UINT_FIELD(lastPHId);
2272 	WRITE_UINT_FIELD(lastRowMarkId);
2273 	WRITE_INT_FIELD(lastPlanNodeId);
2274 	WRITE_BOOL_FIELD(transientPlan);
2275 	WRITE_BOOL_FIELD(dependsOnRole);
2276 	WRITE_BOOL_FIELD(parallelModeOK);
2277 	WRITE_BOOL_FIELD(parallelModeNeeded);
2278 	WRITE_CHAR_FIELD(maxParallelHazard);
2279 }
2280 
2281 static void
_outPlannerInfo(StringInfo str,const PlannerInfo * node)2282 _outPlannerInfo(StringInfo str, const PlannerInfo *node)
2283 {
2284 	WRITE_NODE_TYPE("PLANNERINFO");
2285 
2286 	/* NB: this isn't a complete set of fields */
2287 	WRITE_NODE_FIELD(parse);
2288 	WRITE_NODE_FIELD(glob);
2289 	WRITE_UINT_FIELD(query_level);
2290 	WRITE_NODE_FIELD(plan_params);
2291 	WRITE_BITMAPSET_FIELD(outer_params);
2292 	WRITE_BITMAPSET_FIELD(all_baserels);
2293 	WRITE_BITMAPSET_FIELD(nullable_baserels);
2294 	WRITE_NODE_FIELD(join_rel_list);
2295 	WRITE_INT_FIELD(join_cur_level);
2296 	WRITE_NODE_FIELD(init_plans);
2297 	WRITE_NODE_FIELD(cte_plan_ids);
2298 	WRITE_NODE_FIELD(multiexpr_params);
2299 	WRITE_NODE_FIELD(eq_classes);
2300 	WRITE_BOOL_FIELD(ec_merging_done);
2301 	WRITE_NODE_FIELD(canon_pathkeys);
2302 	WRITE_NODE_FIELD(left_join_clauses);
2303 	WRITE_NODE_FIELD(right_join_clauses);
2304 	WRITE_NODE_FIELD(full_join_clauses);
2305 	WRITE_NODE_FIELD(join_info_list);
2306 	WRITE_BITMAPSET_FIELD(all_result_relids);
2307 	WRITE_BITMAPSET_FIELD(leaf_result_relids);
2308 	WRITE_NODE_FIELD(append_rel_list);
2309 	WRITE_NODE_FIELD(row_identity_vars);
2310 	WRITE_NODE_FIELD(rowMarks);
2311 	WRITE_NODE_FIELD(placeholder_list);
2312 	WRITE_NODE_FIELD(fkey_list);
2313 	WRITE_NODE_FIELD(query_pathkeys);
2314 	WRITE_NODE_FIELD(group_pathkeys);
2315 	WRITE_NODE_FIELD(window_pathkeys);
2316 	WRITE_NODE_FIELD(distinct_pathkeys);
2317 	WRITE_NODE_FIELD(sort_pathkeys);
2318 	WRITE_NODE_FIELD(processed_tlist);
2319 	WRITE_NODE_FIELD(update_colnos);
2320 	WRITE_NODE_FIELD(minmax_aggs);
2321 	WRITE_FLOAT_FIELD(total_table_pages, "%.0f");
2322 	WRITE_FLOAT_FIELD(tuple_fraction, "%.4f");
2323 	WRITE_FLOAT_FIELD(limit_tuples, "%.0f");
2324 	WRITE_UINT_FIELD(qual_security_level);
2325 	WRITE_BOOL_FIELD(hasJoinRTEs);
2326 	WRITE_BOOL_FIELD(hasLateralRTEs);
2327 	WRITE_BOOL_FIELD(hasHavingQual);
2328 	WRITE_BOOL_FIELD(hasPseudoConstantQuals);
2329 	WRITE_BOOL_FIELD(hasAlternativeSubPlans);
2330 	WRITE_BOOL_FIELD(hasRecursion);
2331 	WRITE_INT_FIELD(wt_param_id);
2332 	WRITE_BITMAPSET_FIELD(curOuterRels);
2333 	WRITE_NODE_FIELD(curOuterParams);
2334 	WRITE_BOOL_FIELD(partColsUpdated);
2335 }
2336 
2337 static void
_outRelOptInfo(StringInfo str,const RelOptInfo * node)2338 _outRelOptInfo(StringInfo str, const RelOptInfo *node)
2339 {
2340 	WRITE_NODE_TYPE("RELOPTINFO");
2341 
2342 	/* NB: this isn't a complete set of fields */
2343 	WRITE_ENUM_FIELD(reloptkind, RelOptKind);
2344 	WRITE_BITMAPSET_FIELD(relids);
2345 	WRITE_FLOAT_FIELD(rows, "%.0f");
2346 	WRITE_BOOL_FIELD(consider_startup);
2347 	WRITE_BOOL_FIELD(consider_param_startup);
2348 	WRITE_BOOL_FIELD(consider_parallel);
2349 	WRITE_NODE_FIELD(reltarget);
2350 	WRITE_NODE_FIELD(pathlist);
2351 	WRITE_NODE_FIELD(ppilist);
2352 	WRITE_NODE_FIELD(partial_pathlist);
2353 	WRITE_NODE_FIELD(cheapest_startup_path);
2354 	WRITE_NODE_FIELD(cheapest_total_path);
2355 	WRITE_NODE_FIELD(cheapest_unique_path);
2356 	WRITE_NODE_FIELD(cheapest_parameterized_paths);
2357 	WRITE_BITMAPSET_FIELD(direct_lateral_relids);
2358 	WRITE_BITMAPSET_FIELD(lateral_relids);
2359 	WRITE_UINT_FIELD(relid);
2360 	WRITE_OID_FIELD(reltablespace);
2361 	WRITE_ENUM_FIELD(rtekind, RTEKind);
2362 	WRITE_INT_FIELD(min_attr);
2363 	WRITE_INT_FIELD(max_attr);
2364 	WRITE_NODE_FIELD(lateral_vars);
2365 	WRITE_BITMAPSET_FIELD(lateral_referencers);
2366 	WRITE_NODE_FIELD(indexlist);
2367 	WRITE_NODE_FIELD(statlist);
2368 	WRITE_UINT_FIELD(pages);
2369 	WRITE_FLOAT_FIELD(tuples, "%.0f");
2370 	WRITE_FLOAT_FIELD(allvisfrac, "%.6f");
2371 	WRITE_BITMAPSET_FIELD(eclass_indexes);
2372 	WRITE_NODE_FIELD(subroot);
2373 	WRITE_NODE_FIELD(subplan_params);
2374 	WRITE_INT_FIELD(rel_parallel_workers);
2375 	WRITE_UINT_FIELD(amflags);
2376 	WRITE_OID_FIELD(serverid);
2377 	WRITE_OID_FIELD(userid);
2378 	WRITE_BOOL_FIELD(useridiscurrent);
2379 	/* we don't try to print fdwroutine or fdw_private */
2380 	/* can't print unique_for_rels/non_unique_for_rels; BMSes aren't Nodes */
2381 	WRITE_NODE_FIELD(baserestrictinfo);
2382 	WRITE_UINT_FIELD(baserestrict_min_security);
2383 	WRITE_NODE_FIELD(joininfo);
2384 	WRITE_BOOL_FIELD(has_eclass_joins);
2385 	WRITE_BOOL_FIELD(consider_partitionwise_join);
2386 	WRITE_BITMAPSET_FIELD(top_parent_relids);
2387 	WRITE_BOOL_FIELD(partbounds_merged);
2388 	WRITE_BITMAPSET_FIELD(all_partrels);
2389 }
2390 
2391 static void
_outIndexOptInfo(StringInfo str,const IndexOptInfo * node)2392 _outIndexOptInfo(StringInfo str, const IndexOptInfo *node)
2393 {
2394 	WRITE_NODE_TYPE("INDEXOPTINFO");
2395 
2396 	/* NB: this isn't a complete set of fields */
2397 	WRITE_OID_FIELD(indexoid);
2398 	/* Do NOT print rel field, else infinite recursion */
2399 	WRITE_UINT_FIELD(pages);
2400 	WRITE_FLOAT_FIELD(tuples, "%.0f");
2401 	WRITE_INT_FIELD(tree_height);
2402 	WRITE_INT_FIELD(ncolumns);
2403 	/* array fields aren't really worth the trouble to print */
2404 	WRITE_OID_FIELD(relam);
2405 	/* indexprs is redundant since we print indextlist */
2406 	WRITE_NODE_FIELD(indpred);
2407 	WRITE_NODE_FIELD(indextlist);
2408 	WRITE_NODE_FIELD(indrestrictinfo);
2409 	WRITE_BOOL_FIELD(predOK);
2410 	WRITE_BOOL_FIELD(unique);
2411 	WRITE_BOOL_FIELD(immediate);
2412 	WRITE_BOOL_FIELD(hypothetical);
2413 	/* we don't bother with fields copied from the index AM's API struct */
2414 }
2415 
2416 static void
_outForeignKeyOptInfo(StringInfo str,const ForeignKeyOptInfo * node)2417 _outForeignKeyOptInfo(StringInfo str, const ForeignKeyOptInfo *node)
2418 {
2419 	int			i;
2420 
2421 	WRITE_NODE_TYPE("FOREIGNKEYOPTINFO");
2422 
2423 	WRITE_UINT_FIELD(con_relid);
2424 	WRITE_UINT_FIELD(ref_relid);
2425 	WRITE_INT_FIELD(nkeys);
2426 	WRITE_ATTRNUMBER_ARRAY(conkey, node->nkeys);
2427 	WRITE_ATTRNUMBER_ARRAY(confkey, node->nkeys);
2428 	WRITE_OID_ARRAY(conpfeqop, node->nkeys);
2429 	WRITE_INT_FIELD(nmatched_ec);
2430 	WRITE_INT_FIELD(nconst_ec);
2431 	WRITE_INT_FIELD(nmatched_rcols);
2432 	WRITE_INT_FIELD(nmatched_ri);
2433 	/* for compactness, just print the number of matches per column: */
2434 	appendStringInfoString(str, " :eclass");
2435 	for (i = 0; i < node->nkeys; i++)
2436 		appendStringInfo(str, " %d", (node->eclass[i] != NULL));
2437 	appendStringInfoString(str, " :rinfos");
2438 	for (i = 0; i < node->nkeys; i++)
2439 		appendStringInfo(str, " %d", list_length(node->rinfos[i]));
2440 }
2441 
2442 static void
_outStatisticExtInfo(StringInfo str,const StatisticExtInfo * node)2443 _outStatisticExtInfo(StringInfo str, const StatisticExtInfo *node)
2444 {
2445 	WRITE_NODE_TYPE("STATISTICEXTINFO");
2446 
2447 	/* NB: this isn't a complete set of fields */
2448 	WRITE_OID_FIELD(statOid);
2449 	/* don't write rel, leads to infinite recursion in plan tree dump */
2450 	WRITE_CHAR_FIELD(kind);
2451 	WRITE_BITMAPSET_FIELD(keys);
2452 }
2453 
2454 static void
_outEquivalenceClass(StringInfo str,const EquivalenceClass * node)2455 _outEquivalenceClass(StringInfo str, const EquivalenceClass *node)
2456 {
2457 	/*
2458 	 * To simplify reading, we just chase up to the topmost merged EC and
2459 	 * print that, without bothering to show the merge-ees separately.
2460 	 */
2461 	while (node->ec_merged)
2462 		node = node->ec_merged;
2463 
2464 	WRITE_NODE_TYPE("EQUIVALENCECLASS");
2465 
2466 	WRITE_NODE_FIELD(ec_opfamilies);
2467 	WRITE_OID_FIELD(ec_collation);
2468 	WRITE_NODE_FIELD(ec_members);
2469 	WRITE_NODE_FIELD(ec_sources);
2470 	WRITE_NODE_FIELD(ec_derives);
2471 	WRITE_BITMAPSET_FIELD(ec_relids);
2472 	WRITE_BOOL_FIELD(ec_has_const);
2473 	WRITE_BOOL_FIELD(ec_has_volatile);
2474 	WRITE_BOOL_FIELD(ec_below_outer_join);
2475 	WRITE_BOOL_FIELD(ec_broken);
2476 	WRITE_UINT_FIELD(ec_sortref);
2477 	WRITE_UINT_FIELD(ec_min_security);
2478 	WRITE_UINT_FIELD(ec_max_security);
2479 }
2480 
2481 static void
_outEquivalenceMember(StringInfo str,const EquivalenceMember * node)2482 _outEquivalenceMember(StringInfo str, const EquivalenceMember *node)
2483 {
2484 	WRITE_NODE_TYPE("EQUIVALENCEMEMBER");
2485 
2486 	WRITE_NODE_FIELD(em_expr);
2487 	WRITE_BITMAPSET_FIELD(em_relids);
2488 	WRITE_BITMAPSET_FIELD(em_nullable_relids);
2489 	WRITE_BOOL_FIELD(em_is_const);
2490 	WRITE_BOOL_FIELD(em_is_child);
2491 	WRITE_OID_FIELD(em_datatype);
2492 }
2493 
2494 static void
_outPathKey(StringInfo str,const PathKey * node)2495 _outPathKey(StringInfo str, const PathKey *node)
2496 {
2497 	WRITE_NODE_TYPE("PATHKEY");
2498 
2499 	WRITE_NODE_FIELD(pk_eclass);
2500 	WRITE_OID_FIELD(pk_opfamily);
2501 	WRITE_INT_FIELD(pk_strategy);
2502 	WRITE_BOOL_FIELD(pk_nulls_first);
2503 }
2504 
2505 static void
_outPathTarget(StringInfo str,const PathTarget * node)2506 _outPathTarget(StringInfo str, const PathTarget *node)
2507 {
2508 	WRITE_NODE_TYPE("PATHTARGET");
2509 
2510 	WRITE_NODE_FIELD(exprs);
2511 	if (node->sortgrouprefs)
2512 	{
2513 		int			i;
2514 
2515 		appendStringInfoString(str, " :sortgrouprefs");
2516 		for (i = 0; i < list_length(node->exprs); i++)
2517 			appendStringInfo(str, " %u", node->sortgrouprefs[i]);
2518 	}
2519 	WRITE_FLOAT_FIELD(cost.startup, "%.2f");
2520 	WRITE_FLOAT_FIELD(cost.per_tuple, "%.2f");
2521 	WRITE_INT_FIELD(width);
2522 	WRITE_ENUM_FIELD(has_volatile_expr, VolatileFunctionStatus);
2523 }
2524 
2525 static void
_outParamPathInfo(StringInfo str,const ParamPathInfo * node)2526 _outParamPathInfo(StringInfo str, const ParamPathInfo *node)
2527 {
2528 	WRITE_NODE_TYPE("PARAMPATHINFO");
2529 
2530 	WRITE_BITMAPSET_FIELD(ppi_req_outer);
2531 	WRITE_FLOAT_FIELD(ppi_rows, "%.0f");
2532 	WRITE_NODE_FIELD(ppi_clauses);
2533 }
2534 
2535 static void
_outRestrictInfo(StringInfo str,const RestrictInfo * node)2536 _outRestrictInfo(StringInfo str, const RestrictInfo *node)
2537 {
2538 	WRITE_NODE_TYPE("RESTRICTINFO");
2539 
2540 	/* NB: this isn't a complete set of fields */
2541 	WRITE_NODE_FIELD(clause);
2542 	WRITE_BOOL_FIELD(is_pushed_down);
2543 	WRITE_BOOL_FIELD(outerjoin_delayed);
2544 	WRITE_BOOL_FIELD(can_join);
2545 	WRITE_BOOL_FIELD(pseudoconstant);
2546 	WRITE_BOOL_FIELD(leakproof);
2547 	WRITE_ENUM_FIELD(has_volatile, VolatileFunctionStatus);
2548 	WRITE_UINT_FIELD(security_level);
2549 	WRITE_BITMAPSET_FIELD(clause_relids);
2550 	WRITE_BITMAPSET_FIELD(required_relids);
2551 	WRITE_BITMAPSET_FIELD(outer_relids);
2552 	WRITE_BITMAPSET_FIELD(nullable_relids);
2553 	WRITE_BITMAPSET_FIELD(left_relids);
2554 	WRITE_BITMAPSET_FIELD(right_relids);
2555 	WRITE_NODE_FIELD(orclause);
2556 	/* don't write parent_ec, leads to infinite recursion in plan tree dump */
2557 	WRITE_FLOAT_FIELD(norm_selec, "%.4f");
2558 	WRITE_FLOAT_FIELD(outer_selec, "%.4f");
2559 	WRITE_NODE_FIELD(mergeopfamilies);
2560 	/* don't write left_ec, leads to infinite recursion in plan tree dump */
2561 	/* don't write right_ec, leads to infinite recursion in plan tree dump */
2562 	WRITE_NODE_FIELD(left_em);
2563 	WRITE_NODE_FIELD(right_em);
2564 	WRITE_BOOL_FIELD(outer_is_left);
2565 	WRITE_OID_FIELD(hashjoinoperator);
2566 	WRITE_OID_FIELD(hasheqoperator);
2567 }
2568 
2569 static void
_outIndexClause(StringInfo str,const IndexClause * node)2570 _outIndexClause(StringInfo str, const IndexClause *node)
2571 {
2572 	WRITE_NODE_TYPE("INDEXCLAUSE");
2573 
2574 	WRITE_NODE_FIELD(rinfo);
2575 	WRITE_NODE_FIELD(indexquals);
2576 	WRITE_BOOL_FIELD(lossy);
2577 	WRITE_INT_FIELD(indexcol);
2578 	WRITE_NODE_FIELD(indexcols);
2579 }
2580 
2581 static void
_outPlaceHolderVar(StringInfo str,const PlaceHolderVar * node)2582 _outPlaceHolderVar(StringInfo str, const PlaceHolderVar *node)
2583 {
2584 	WRITE_NODE_TYPE("PLACEHOLDERVAR");
2585 
2586 	WRITE_NODE_FIELD(phexpr);
2587 	WRITE_BITMAPSET_FIELD(phrels);
2588 	WRITE_UINT_FIELD(phid);
2589 	WRITE_UINT_FIELD(phlevelsup);
2590 }
2591 
2592 static void
_outSpecialJoinInfo(StringInfo str,const SpecialJoinInfo * node)2593 _outSpecialJoinInfo(StringInfo str, const SpecialJoinInfo *node)
2594 {
2595 	WRITE_NODE_TYPE("SPECIALJOININFO");
2596 
2597 	WRITE_BITMAPSET_FIELD(min_lefthand);
2598 	WRITE_BITMAPSET_FIELD(min_righthand);
2599 	WRITE_BITMAPSET_FIELD(syn_lefthand);
2600 	WRITE_BITMAPSET_FIELD(syn_righthand);
2601 	WRITE_ENUM_FIELD(jointype, JoinType);
2602 	WRITE_BOOL_FIELD(lhs_strict);
2603 	WRITE_BOOL_FIELD(delay_upper_joins);
2604 	WRITE_BOOL_FIELD(semi_can_btree);
2605 	WRITE_BOOL_FIELD(semi_can_hash);
2606 	WRITE_NODE_FIELD(semi_operators);
2607 	WRITE_NODE_FIELD(semi_rhs_exprs);
2608 }
2609 
2610 static void
_outAppendRelInfo(StringInfo str,const AppendRelInfo * node)2611 _outAppendRelInfo(StringInfo str, const AppendRelInfo *node)
2612 {
2613 	WRITE_NODE_TYPE("APPENDRELINFO");
2614 
2615 	WRITE_UINT_FIELD(parent_relid);
2616 	WRITE_UINT_FIELD(child_relid);
2617 	WRITE_OID_FIELD(parent_reltype);
2618 	WRITE_OID_FIELD(child_reltype);
2619 	WRITE_NODE_FIELD(translated_vars);
2620 	WRITE_INT_FIELD(num_child_cols);
2621 	WRITE_ATTRNUMBER_ARRAY(parent_colnos, node->num_child_cols);
2622 	WRITE_OID_FIELD(parent_reloid);
2623 }
2624 
2625 static void
_outRowIdentityVarInfo(StringInfo str,const RowIdentityVarInfo * node)2626 _outRowIdentityVarInfo(StringInfo str, const RowIdentityVarInfo *node)
2627 {
2628 	WRITE_NODE_TYPE("ROWIDENTITYVARINFO");
2629 
2630 	WRITE_NODE_FIELD(rowidvar);
2631 	WRITE_INT_FIELD(rowidwidth);
2632 	WRITE_STRING_FIELD(rowidname);
2633 	WRITE_BITMAPSET_FIELD(rowidrels);
2634 }
2635 
2636 static void
_outPlaceHolderInfo(StringInfo str,const PlaceHolderInfo * node)2637 _outPlaceHolderInfo(StringInfo str, const PlaceHolderInfo *node)
2638 {
2639 	WRITE_NODE_TYPE("PLACEHOLDERINFO");
2640 
2641 	WRITE_UINT_FIELD(phid);
2642 	WRITE_NODE_FIELD(ph_var);
2643 	WRITE_BITMAPSET_FIELD(ph_eval_at);
2644 	WRITE_BITMAPSET_FIELD(ph_lateral);
2645 	WRITE_BITMAPSET_FIELD(ph_needed);
2646 	WRITE_INT_FIELD(ph_width);
2647 }
2648 
2649 static void
_outMinMaxAggInfo(StringInfo str,const MinMaxAggInfo * node)2650 _outMinMaxAggInfo(StringInfo str, const MinMaxAggInfo *node)
2651 {
2652 	WRITE_NODE_TYPE("MINMAXAGGINFO");
2653 
2654 	WRITE_OID_FIELD(aggfnoid);
2655 	WRITE_OID_FIELD(aggsortop);
2656 	WRITE_NODE_FIELD(target);
2657 	/* We intentionally omit subroot --- too large, not interesting enough */
2658 	WRITE_NODE_FIELD(path);
2659 	WRITE_FLOAT_FIELD(pathcost, "%.2f");
2660 	WRITE_NODE_FIELD(param);
2661 }
2662 
2663 static void
_outPlannerParamItem(StringInfo str,const PlannerParamItem * node)2664 _outPlannerParamItem(StringInfo str, const PlannerParamItem *node)
2665 {
2666 	WRITE_NODE_TYPE("PLANNERPARAMITEM");
2667 
2668 	WRITE_NODE_FIELD(item);
2669 	WRITE_INT_FIELD(paramId);
2670 }
2671 
2672 /*****************************************************************************
2673  *
2674  *	Stuff from extensible.h
2675  *
2676  *****************************************************************************/
2677 
2678 static void
_outExtensibleNode(StringInfo str,const ExtensibleNode * node)2679 _outExtensibleNode(StringInfo str, const ExtensibleNode *node)
2680 {
2681 	const ExtensibleNodeMethods *methods;
2682 
2683 	methods = GetExtensibleNodeMethods(node->extnodename, false);
2684 
2685 	WRITE_NODE_TYPE("EXTENSIBLENODE");
2686 
2687 	WRITE_STRING_FIELD(extnodename);
2688 
2689 	/* serialize the private fields */
2690 	methods->nodeOut(str, node);
2691 }
2692 
2693 /*****************************************************************************
2694  *
2695  *	Stuff from parsenodes.h.
2696  *
2697  *****************************************************************************/
2698 
2699 /*
2700  * print the basic stuff of all nodes that inherit from CreateStmt
2701  */
2702 static void
_outCreateStmtInfo(StringInfo str,const CreateStmt * node)2703 _outCreateStmtInfo(StringInfo str, const CreateStmt *node)
2704 {
2705 	WRITE_NODE_FIELD(relation);
2706 	WRITE_NODE_FIELD(tableElts);
2707 	WRITE_NODE_FIELD(inhRelations);
2708 	WRITE_NODE_FIELD(partspec);
2709 	WRITE_NODE_FIELD(partbound);
2710 	WRITE_NODE_FIELD(ofTypename);
2711 	WRITE_NODE_FIELD(constraints);
2712 	WRITE_NODE_FIELD(options);
2713 	WRITE_ENUM_FIELD(oncommit, OnCommitAction);
2714 	WRITE_STRING_FIELD(tablespacename);
2715 	WRITE_STRING_FIELD(accessMethod);
2716 	WRITE_BOOL_FIELD(if_not_exists);
2717 }
2718 
2719 static void
_outCreateStmt(StringInfo str,const CreateStmt * node)2720 _outCreateStmt(StringInfo str, const CreateStmt *node)
2721 {
2722 	WRITE_NODE_TYPE("CREATESTMT");
2723 
2724 	_outCreateStmtInfo(str, (const CreateStmt *) node);
2725 }
2726 
2727 static void
_outCreateForeignTableStmt(StringInfo str,const CreateForeignTableStmt * node)2728 _outCreateForeignTableStmt(StringInfo str, const CreateForeignTableStmt *node)
2729 {
2730 	WRITE_NODE_TYPE("CREATEFOREIGNTABLESTMT");
2731 
2732 	_outCreateStmtInfo(str, (const CreateStmt *) node);
2733 
2734 	WRITE_STRING_FIELD(servername);
2735 	WRITE_NODE_FIELD(options);
2736 }
2737 
2738 static void
_outImportForeignSchemaStmt(StringInfo str,const ImportForeignSchemaStmt * node)2739 _outImportForeignSchemaStmt(StringInfo str, const ImportForeignSchemaStmt *node)
2740 {
2741 	WRITE_NODE_TYPE("IMPORTFOREIGNSCHEMASTMT");
2742 
2743 	WRITE_STRING_FIELD(server_name);
2744 	WRITE_STRING_FIELD(remote_schema);
2745 	WRITE_STRING_FIELD(local_schema);
2746 	WRITE_ENUM_FIELD(list_type, ImportForeignSchemaType);
2747 	WRITE_NODE_FIELD(table_list);
2748 	WRITE_NODE_FIELD(options);
2749 }
2750 
2751 static void
_outIndexStmt(StringInfo str,const IndexStmt * node)2752 _outIndexStmt(StringInfo str, const IndexStmt *node)
2753 {
2754 	WRITE_NODE_TYPE("INDEXSTMT");
2755 
2756 	WRITE_STRING_FIELD(idxname);
2757 	WRITE_NODE_FIELD(relation);
2758 	WRITE_STRING_FIELD(accessMethod);
2759 	WRITE_STRING_FIELD(tableSpace);
2760 	WRITE_NODE_FIELD(indexParams);
2761 	WRITE_NODE_FIELD(indexIncludingParams);
2762 	WRITE_NODE_FIELD(options);
2763 	WRITE_NODE_FIELD(whereClause);
2764 	WRITE_NODE_FIELD(excludeOpNames);
2765 	WRITE_STRING_FIELD(idxcomment);
2766 	WRITE_OID_FIELD(indexOid);
2767 	WRITE_OID_FIELD(oldNode);
2768 	WRITE_UINT_FIELD(oldCreateSubid);
2769 	WRITE_UINT_FIELD(oldFirstRelfilenodeSubid);
2770 	WRITE_BOOL_FIELD(unique);
2771 	WRITE_BOOL_FIELD(primary);
2772 	WRITE_BOOL_FIELD(isconstraint);
2773 	WRITE_BOOL_FIELD(deferrable);
2774 	WRITE_BOOL_FIELD(initdeferred);
2775 	WRITE_BOOL_FIELD(transformed);
2776 	WRITE_BOOL_FIELD(concurrent);
2777 	WRITE_BOOL_FIELD(if_not_exists);
2778 	WRITE_BOOL_FIELD(reset_default_tblspc);
2779 }
2780 
2781 static void
_outCreateStatsStmt(StringInfo str,const CreateStatsStmt * node)2782 _outCreateStatsStmt(StringInfo str, const CreateStatsStmt *node)
2783 {
2784 	WRITE_NODE_TYPE("CREATESTATSSTMT");
2785 
2786 	WRITE_NODE_FIELD(defnames);
2787 	WRITE_NODE_FIELD(stat_types);
2788 	WRITE_NODE_FIELD(exprs);
2789 	WRITE_NODE_FIELD(relations);
2790 	WRITE_STRING_FIELD(stxcomment);
2791 	WRITE_BOOL_FIELD(transformed);
2792 	WRITE_BOOL_FIELD(if_not_exists);
2793 }
2794 
2795 static void
_outAlterStatsStmt(StringInfo str,const AlterStatsStmt * node)2796 _outAlterStatsStmt(StringInfo str, const AlterStatsStmt *node)
2797 {
2798 	WRITE_NODE_TYPE("ALTERSTATSSTMT");
2799 
2800 	WRITE_NODE_FIELD(defnames);
2801 	WRITE_INT_FIELD(stxstattarget);
2802 	WRITE_BOOL_FIELD(missing_ok);
2803 }
2804 
2805 static void
_outNotifyStmt(StringInfo str,const NotifyStmt * node)2806 _outNotifyStmt(StringInfo str, const NotifyStmt *node)
2807 {
2808 	WRITE_NODE_TYPE("NOTIFY");
2809 
2810 	WRITE_STRING_FIELD(conditionname);
2811 	WRITE_STRING_FIELD(payload);
2812 }
2813 
2814 static void
_outDeclareCursorStmt(StringInfo str,const DeclareCursorStmt * node)2815 _outDeclareCursorStmt(StringInfo str, const DeclareCursorStmt *node)
2816 {
2817 	WRITE_NODE_TYPE("DECLARECURSOR");
2818 
2819 	WRITE_STRING_FIELD(portalname);
2820 	WRITE_INT_FIELD(options);
2821 	WRITE_NODE_FIELD(query);
2822 }
2823 
2824 static void
_outSelectStmt(StringInfo str,const SelectStmt * node)2825 _outSelectStmt(StringInfo str, const SelectStmt *node)
2826 {
2827 	WRITE_NODE_TYPE("SELECT");
2828 
2829 	WRITE_NODE_FIELD(distinctClause);
2830 	WRITE_NODE_FIELD(intoClause);
2831 	WRITE_NODE_FIELD(targetList);
2832 	WRITE_NODE_FIELD(fromClause);
2833 	WRITE_NODE_FIELD(whereClause);
2834 	WRITE_NODE_FIELD(groupClause);
2835 	WRITE_BOOL_FIELD(groupDistinct);
2836 	WRITE_NODE_FIELD(havingClause);
2837 	WRITE_NODE_FIELD(windowClause);
2838 	WRITE_NODE_FIELD(valuesLists);
2839 	WRITE_NODE_FIELD(sortClause);
2840 	WRITE_NODE_FIELD(limitOffset);
2841 	WRITE_NODE_FIELD(limitCount);
2842 	WRITE_ENUM_FIELD(limitOption, LimitOption);
2843 	WRITE_NODE_FIELD(lockingClause);
2844 	WRITE_NODE_FIELD(withClause);
2845 	WRITE_ENUM_FIELD(op, SetOperation);
2846 	WRITE_BOOL_FIELD(all);
2847 	WRITE_NODE_FIELD(larg);
2848 	WRITE_NODE_FIELD(rarg);
2849 }
2850 
2851 static void
_outReturnStmt(StringInfo str,const ReturnStmt * node)2852 _outReturnStmt(StringInfo str, const ReturnStmt *node)
2853 {
2854 	WRITE_NODE_TYPE("RETURN");
2855 
2856 	WRITE_NODE_FIELD(returnval);
2857 }
2858 
2859 static void
_outPLAssignStmt(StringInfo str,const PLAssignStmt * node)2860 _outPLAssignStmt(StringInfo str, const PLAssignStmt *node)
2861 {
2862 	WRITE_NODE_TYPE("PLASSIGN");
2863 
2864 	WRITE_STRING_FIELD(name);
2865 	WRITE_NODE_FIELD(indirection);
2866 	WRITE_INT_FIELD(nnames);
2867 	WRITE_NODE_FIELD(val);
2868 	WRITE_LOCATION_FIELD(location);
2869 }
2870 
2871 static void
_outFuncCall(StringInfo str,const FuncCall * node)2872 _outFuncCall(StringInfo str, const FuncCall *node)
2873 {
2874 	WRITE_NODE_TYPE("FUNCCALL");
2875 
2876 	WRITE_NODE_FIELD(funcname);
2877 	WRITE_NODE_FIELD(args);
2878 	WRITE_NODE_FIELD(agg_order);
2879 	WRITE_NODE_FIELD(agg_filter);
2880 	WRITE_NODE_FIELD(over);
2881 	WRITE_BOOL_FIELD(agg_within_group);
2882 	WRITE_BOOL_FIELD(agg_star);
2883 	WRITE_BOOL_FIELD(agg_distinct);
2884 	WRITE_BOOL_FIELD(func_variadic);
2885 	WRITE_ENUM_FIELD(funcformat, CoercionForm);
2886 	WRITE_LOCATION_FIELD(location);
2887 }
2888 
2889 static void
_outDefElem(StringInfo str,const DefElem * node)2890 _outDefElem(StringInfo str, const DefElem *node)
2891 {
2892 	WRITE_NODE_TYPE("DEFELEM");
2893 
2894 	WRITE_STRING_FIELD(defnamespace);
2895 	WRITE_STRING_FIELD(defname);
2896 	WRITE_NODE_FIELD(arg);
2897 	WRITE_ENUM_FIELD(defaction, DefElemAction);
2898 	WRITE_LOCATION_FIELD(location);
2899 }
2900 
2901 static void
_outTableLikeClause(StringInfo str,const TableLikeClause * node)2902 _outTableLikeClause(StringInfo str, const TableLikeClause *node)
2903 {
2904 	WRITE_NODE_TYPE("TABLELIKECLAUSE");
2905 
2906 	WRITE_NODE_FIELD(relation);
2907 	WRITE_UINT_FIELD(options);
2908 	WRITE_OID_FIELD(relationOid);
2909 }
2910 
2911 static void
_outLockingClause(StringInfo str,const LockingClause * node)2912 _outLockingClause(StringInfo str, const LockingClause *node)
2913 {
2914 	WRITE_NODE_TYPE("LOCKINGCLAUSE");
2915 
2916 	WRITE_NODE_FIELD(lockedRels);
2917 	WRITE_ENUM_FIELD(strength, LockClauseStrength);
2918 	WRITE_ENUM_FIELD(waitPolicy, LockWaitPolicy);
2919 }
2920 
2921 static void
_outXmlSerialize(StringInfo str,const XmlSerialize * node)2922 _outXmlSerialize(StringInfo str, const XmlSerialize *node)
2923 {
2924 	WRITE_NODE_TYPE("XMLSERIALIZE");
2925 
2926 	WRITE_ENUM_FIELD(xmloption, XmlOptionType);
2927 	WRITE_NODE_FIELD(expr);
2928 	WRITE_NODE_FIELD(typeName);
2929 	WRITE_LOCATION_FIELD(location);
2930 }
2931 
2932 static void
_outTriggerTransition(StringInfo str,const TriggerTransition * node)2933 _outTriggerTransition(StringInfo str, const TriggerTransition *node)
2934 {
2935 	WRITE_NODE_TYPE("TRIGGERTRANSITION");
2936 
2937 	WRITE_STRING_FIELD(name);
2938 	WRITE_BOOL_FIELD(isNew);
2939 	WRITE_BOOL_FIELD(isTable);
2940 }
2941 
2942 static void
_outColumnDef(StringInfo str,const ColumnDef * node)2943 _outColumnDef(StringInfo str, const ColumnDef *node)
2944 {
2945 	WRITE_NODE_TYPE("COLUMNDEF");
2946 
2947 	WRITE_STRING_FIELD(colname);
2948 	WRITE_NODE_FIELD(typeName);
2949 	WRITE_STRING_FIELD(compression);
2950 	WRITE_INT_FIELD(inhcount);
2951 	WRITE_BOOL_FIELD(is_local);
2952 	WRITE_BOOL_FIELD(is_not_null);
2953 	WRITE_BOOL_FIELD(is_from_type);
2954 	WRITE_CHAR_FIELD(storage);
2955 	WRITE_NODE_FIELD(raw_default);
2956 	WRITE_NODE_FIELD(cooked_default);
2957 	WRITE_CHAR_FIELD(identity);
2958 	WRITE_NODE_FIELD(identitySequence);
2959 	WRITE_CHAR_FIELD(generated);
2960 	WRITE_NODE_FIELD(collClause);
2961 	WRITE_OID_FIELD(collOid);
2962 	WRITE_NODE_FIELD(constraints);
2963 	WRITE_NODE_FIELD(fdwoptions);
2964 	WRITE_LOCATION_FIELD(location);
2965 }
2966 
2967 static void
_outTypeName(StringInfo str,const TypeName * node)2968 _outTypeName(StringInfo str, const TypeName *node)
2969 {
2970 	WRITE_NODE_TYPE("TYPENAME");
2971 
2972 	WRITE_NODE_FIELD(names);
2973 	WRITE_OID_FIELD(typeOid);
2974 	WRITE_BOOL_FIELD(setof);
2975 	WRITE_BOOL_FIELD(pct_type);
2976 	WRITE_NODE_FIELD(typmods);
2977 	WRITE_INT_FIELD(typemod);
2978 	WRITE_NODE_FIELD(arrayBounds);
2979 	WRITE_LOCATION_FIELD(location);
2980 }
2981 
2982 static void
_outTypeCast(StringInfo str,const TypeCast * node)2983 _outTypeCast(StringInfo str, const TypeCast *node)
2984 {
2985 	WRITE_NODE_TYPE("TYPECAST");
2986 
2987 	WRITE_NODE_FIELD(arg);
2988 	WRITE_NODE_FIELD(typeName);
2989 	WRITE_LOCATION_FIELD(location);
2990 }
2991 
2992 static void
_outCollateClause(StringInfo str,const CollateClause * node)2993 _outCollateClause(StringInfo str, const CollateClause *node)
2994 {
2995 	WRITE_NODE_TYPE("COLLATECLAUSE");
2996 
2997 	WRITE_NODE_FIELD(arg);
2998 	WRITE_NODE_FIELD(collname);
2999 	WRITE_LOCATION_FIELD(location);
3000 }
3001 
3002 static void
_outIndexElem(StringInfo str,const IndexElem * node)3003 _outIndexElem(StringInfo str, const IndexElem *node)
3004 {
3005 	WRITE_NODE_TYPE("INDEXELEM");
3006 
3007 	WRITE_STRING_FIELD(name);
3008 	WRITE_NODE_FIELD(expr);
3009 	WRITE_STRING_FIELD(indexcolname);
3010 	WRITE_NODE_FIELD(collation);
3011 	WRITE_NODE_FIELD(opclass);
3012 	WRITE_NODE_FIELD(opclassopts);
3013 	WRITE_ENUM_FIELD(ordering, SortByDir);
3014 	WRITE_ENUM_FIELD(nulls_ordering, SortByNulls);
3015 }
3016 
3017 static void
_outStatsElem(StringInfo str,const StatsElem * node)3018 _outStatsElem(StringInfo str, const StatsElem *node)
3019 {
3020 	WRITE_NODE_TYPE("STATSELEM");
3021 
3022 	WRITE_STRING_FIELD(name);
3023 	WRITE_NODE_FIELD(expr);
3024 }
3025 
3026 static void
_outQuery(StringInfo str,const Query * node)3027 _outQuery(StringInfo str, const Query *node)
3028 {
3029 	WRITE_NODE_TYPE("QUERY");
3030 
3031 	WRITE_ENUM_FIELD(commandType, CmdType);
3032 	WRITE_ENUM_FIELD(querySource, QuerySource);
3033 	/* we intentionally do not print the queryId field */
3034 	WRITE_BOOL_FIELD(canSetTag);
3035 
3036 	/*
3037 	 * Hack to work around missing outfuncs routines for a lot of the
3038 	 * utility-statement node types.  (The only one we actually *need* for
3039 	 * rules support is NotifyStmt.)  Someday we ought to support 'em all, but
3040 	 * for the meantime do this to avoid getting lots of warnings when running
3041 	 * with debug_print_parse on.
3042 	 */
3043 	if (node->utilityStmt)
3044 	{
3045 		switch (nodeTag(node->utilityStmt))
3046 		{
3047 			case T_CreateStmt:
3048 			case T_IndexStmt:
3049 			case T_NotifyStmt:
3050 			case T_DeclareCursorStmt:
3051 				WRITE_NODE_FIELD(utilityStmt);
3052 				break;
3053 			default:
3054 				appendStringInfoString(str, " :utilityStmt ?");
3055 				break;
3056 		}
3057 	}
3058 	else
3059 		appendStringInfoString(str, " :utilityStmt <>");
3060 
3061 	WRITE_INT_FIELD(resultRelation);
3062 	WRITE_BOOL_FIELD(hasAggs);
3063 	WRITE_BOOL_FIELD(hasWindowFuncs);
3064 	WRITE_BOOL_FIELD(hasTargetSRFs);
3065 	WRITE_BOOL_FIELD(hasSubLinks);
3066 	WRITE_BOOL_FIELD(hasDistinctOn);
3067 	WRITE_BOOL_FIELD(hasRecursive);
3068 	WRITE_BOOL_FIELD(hasModifyingCTE);
3069 	WRITE_BOOL_FIELD(hasForUpdate);
3070 	WRITE_BOOL_FIELD(hasRowSecurity);
3071 	WRITE_BOOL_FIELD(isReturn);
3072 	WRITE_NODE_FIELD(cteList);
3073 	WRITE_NODE_FIELD(rtable);
3074 	WRITE_NODE_FIELD(jointree);
3075 	WRITE_NODE_FIELD(targetList);
3076 	WRITE_ENUM_FIELD(override, OverridingKind);
3077 	WRITE_NODE_FIELD(onConflict);
3078 	WRITE_NODE_FIELD(returningList);
3079 	WRITE_NODE_FIELD(groupClause);
3080 	WRITE_BOOL_FIELD(groupDistinct);
3081 	WRITE_NODE_FIELD(groupingSets);
3082 	WRITE_NODE_FIELD(havingQual);
3083 	WRITE_NODE_FIELD(windowClause);
3084 	WRITE_NODE_FIELD(distinctClause);
3085 	WRITE_NODE_FIELD(sortClause);
3086 	WRITE_NODE_FIELD(limitOffset);
3087 	WRITE_NODE_FIELD(limitCount);
3088 	WRITE_ENUM_FIELD(limitOption, LimitOption);
3089 	WRITE_NODE_FIELD(rowMarks);
3090 	WRITE_NODE_FIELD(setOperations);
3091 	WRITE_NODE_FIELD(constraintDeps);
3092 	WRITE_NODE_FIELD(withCheckOptions);
3093 	WRITE_LOCATION_FIELD(stmt_location);
3094 	WRITE_INT_FIELD(stmt_len);
3095 }
3096 
3097 static void
_outWithCheckOption(StringInfo str,const WithCheckOption * node)3098 _outWithCheckOption(StringInfo str, const WithCheckOption *node)
3099 {
3100 	WRITE_NODE_TYPE("WITHCHECKOPTION");
3101 
3102 	WRITE_ENUM_FIELD(kind, WCOKind);
3103 	WRITE_STRING_FIELD(relname);
3104 	WRITE_STRING_FIELD(polname);
3105 	WRITE_NODE_FIELD(qual);
3106 	WRITE_BOOL_FIELD(cascaded);
3107 }
3108 
3109 static void
_outSortGroupClause(StringInfo str,const SortGroupClause * node)3110 _outSortGroupClause(StringInfo str, const SortGroupClause *node)
3111 {
3112 	WRITE_NODE_TYPE("SORTGROUPCLAUSE");
3113 
3114 	WRITE_UINT_FIELD(tleSortGroupRef);
3115 	WRITE_OID_FIELD(eqop);
3116 	WRITE_OID_FIELD(sortop);
3117 	WRITE_BOOL_FIELD(nulls_first);
3118 	WRITE_BOOL_FIELD(hashable);
3119 }
3120 
3121 static void
_outGroupingSet(StringInfo str,const GroupingSet * node)3122 _outGroupingSet(StringInfo str, const GroupingSet *node)
3123 {
3124 	WRITE_NODE_TYPE("GROUPINGSET");
3125 
3126 	WRITE_ENUM_FIELD(kind, GroupingSetKind);
3127 	WRITE_NODE_FIELD(content);
3128 	WRITE_LOCATION_FIELD(location);
3129 }
3130 
3131 static void
_outWindowClause(StringInfo str,const WindowClause * node)3132 _outWindowClause(StringInfo str, const WindowClause *node)
3133 {
3134 	WRITE_NODE_TYPE("WINDOWCLAUSE");
3135 
3136 	WRITE_STRING_FIELD(name);
3137 	WRITE_STRING_FIELD(refname);
3138 	WRITE_NODE_FIELD(partitionClause);
3139 	WRITE_NODE_FIELD(orderClause);
3140 	WRITE_INT_FIELD(frameOptions);
3141 	WRITE_NODE_FIELD(startOffset);
3142 	WRITE_NODE_FIELD(endOffset);
3143 	WRITE_OID_FIELD(startInRangeFunc);
3144 	WRITE_OID_FIELD(endInRangeFunc);
3145 	WRITE_OID_FIELD(inRangeColl);
3146 	WRITE_BOOL_FIELD(inRangeAsc);
3147 	WRITE_BOOL_FIELD(inRangeNullsFirst);
3148 	WRITE_UINT_FIELD(winref);
3149 	WRITE_BOOL_FIELD(copiedOrder);
3150 }
3151 
3152 static void
_outRowMarkClause(StringInfo str,const RowMarkClause * node)3153 _outRowMarkClause(StringInfo str, const RowMarkClause *node)
3154 {
3155 	WRITE_NODE_TYPE("ROWMARKCLAUSE");
3156 
3157 	WRITE_UINT_FIELD(rti);
3158 	WRITE_ENUM_FIELD(strength, LockClauseStrength);
3159 	WRITE_ENUM_FIELD(waitPolicy, LockWaitPolicy);
3160 	WRITE_BOOL_FIELD(pushedDown);
3161 }
3162 
3163 static void
_outWithClause(StringInfo str,const WithClause * node)3164 _outWithClause(StringInfo str, const WithClause *node)
3165 {
3166 	WRITE_NODE_TYPE("WITHCLAUSE");
3167 
3168 	WRITE_NODE_FIELD(ctes);
3169 	WRITE_BOOL_FIELD(recursive);
3170 	WRITE_LOCATION_FIELD(location);
3171 }
3172 
3173 static void
_outCTESearchClause(StringInfo str,const CTESearchClause * node)3174 _outCTESearchClause(StringInfo str, const CTESearchClause *node)
3175 {
3176 	WRITE_NODE_TYPE("CTESEARCHCLAUSE");
3177 
3178 	WRITE_NODE_FIELD(search_col_list);
3179 	WRITE_BOOL_FIELD(search_breadth_first);
3180 	WRITE_STRING_FIELD(search_seq_column);
3181 	WRITE_LOCATION_FIELD(location);
3182 }
3183 
3184 static void
_outCTECycleClause(StringInfo str,const CTECycleClause * node)3185 _outCTECycleClause(StringInfo str, const CTECycleClause *node)
3186 {
3187 	WRITE_NODE_TYPE("CTECYCLECLAUSE");
3188 
3189 	WRITE_NODE_FIELD(cycle_col_list);
3190 	WRITE_STRING_FIELD(cycle_mark_column);
3191 	WRITE_NODE_FIELD(cycle_mark_value);
3192 	WRITE_NODE_FIELD(cycle_mark_default);
3193 	WRITE_STRING_FIELD(cycle_path_column);
3194 	WRITE_LOCATION_FIELD(location);
3195 	WRITE_OID_FIELD(cycle_mark_type);
3196 	WRITE_INT_FIELD(cycle_mark_typmod);
3197 	WRITE_OID_FIELD(cycle_mark_collation);
3198 	WRITE_OID_FIELD(cycle_mark_neop);
3199 }
3200 
3201 static void
_outCommonTableExpr(StringInfo str,const CommonTableExpr * node)3202 _outCommonTableExpr(StringInfo str, const CommonTableExpr *node)
3203 {
3204 	WRITE_NODE_TYPE("COMMONTABLEEXPR");
3205 
3206 	WRITE_STRING_FIELD(ctename);
3207 	WRITE_NODE_FIELD(aliascolnames);
3208 	WRITE_ENUM_FIELD(ctematerialized, CTEMaterialize);
3209 	WRITE_NODE_FIELD(ctequery);
3210 	WRITE_NODE_FIELD(search_clause);
3211 	WRITE_NODE_FIELD(cycle_clause);
3212 	WRITE_LOCATION_FIELD(location);
3213 	WRITE_BOOL_FIELD(cterecursive);
3214 	WRITE_INT_FIELD(cterefcount);
3215 	WRITE_NODE_FIELD(ctecolnames);
3216 	WRITE_NODE_FIELD(ctecoltypes);
3217 	WRITE_NODE_FIELD(ctecoltypmods);
3218 	WRITE_NODE_FIELD(ctecolcollations);
3219 }
3220 
3221 static void
_outSetOperationStmt(StringInfo str,const SetOperationStmt * node)3222 _outSetOperationStmt(StringInfo str, const SetOperationStmt *node)
3223 {
3224 	WRITE_NODE_TYPE("SETOPERATIONSTMT");
3225 
3226 	WRITE_ENUM_FIELD(op, SetOperation);
3227 	WRITE_BOOL_FIELD(all);
3228 	WRITE_NODE_FIELD(larg);
3229 	WRITE_NODE_FIELD(rarg);
3230 	WRITE_NODE_FIELD(colTypes);
3231 	WRITE_NODE_FIELD(colTypmods);
3232 	WRITE_NODE_FIELD(colCollations);
3233 	WRITE_NODE_FIELD(groupClauses);
3234 }
3235 
3236 static void
_outRangeTblEntry(StringInfo str,const RangeTblEntry * node)3237 _outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
3238 {
3239 	WRITE_NODE_TYPE("RTE");
3240 
3241 	/* put alias + eref first to make dump more legible */
3242 	WRITE_NODE_FIELD(alias);
3243 	WRITE_NODE_FIELD(eref);
3244 	WRITE_ENUM_FIELD(rtekind, RTEKind);
3245 
3246 	switch (node->rtekind)
3247 	{
3248 		case RTE_RELATION:
3249 			WRITE_OID_FIELD(relid);
3250 			WRITE_CHAR_FIELD(relkind);
3251 			WRITE_INT_FIELD(rellockmode);
3252 			WRITE_NODE_FIELD(tablesample);
3253 			break;
3254 		case RTE_SUBQUERY:
3255 			WRITE_NODE_FIELD(subquery);
3256 			WRITE_BOOL_FIELD(security_barrier);
3257 			break;
3258 		case RTE_JOIN:
3259 			WRITE_ENUM_FIELD(jointype, JoinType);
3260 			WRITE_INT_FIELD(joinmergedcols);
3261 			WRITE_NODE_FIELD(joinaliasvars);
3262 			WRITE_NODE_FIELD(joinleftcols);
3263 			WRITE_NODE_FIELD(joinrightcols);
3264 			WRITE_NODE_FIELD(join_using_alias);
3265 			break;
3266 		case RTE_FUNCTION:
3267 			WRITE_NODE_FIELD(functions);
3268 			WRITE_BOOL_FIELD(funcordinality);
3269 			break;
3270 		case RTE_TABLEFUNC:
3271 			WRITE_NODE_FIELD(tablefunc);
3272 			break;
3273 		case RTE_VALUES:
3274 			WRITE_NODE_FIELD(values_lists);
3275 			WRITE_NODE_FIELD(coltypes);
3276 			WRITE_NODE_FIELD(coltypmods);
3277 			WRITE_NODE_FIELD(colcollations);
3278 			break;
3279 		case RTE_CTE:
3280 			WRITE_STRING_FIELD(ctename);
3281 			WRITE_UINT_FIELD(ctelevelsup);
3282 			WRITE_BOOL_FIELD(self_reference);
3283 			WRITE_NODE_FIELD(coltypes);
3284 			WRITE_NODE_FIELD(coltypmods);
3285 			WRITE_NODE_FIELD(colcollations);
3286 			break;
3287 		case RTE_NAMEDTUPLESTORE:
3288 			WRITE_STRING_FIELD(enrname);
3289 			WRITE_FLOAT_FIELD(enrtuples, "%.0f");
3290 			WRITE_OID_FIELD(relid);
3291 			WRITE_NODE_FIELD(coltypes);
3292 			WRITE_NODE_FIELD(coltypmods);
3293 			WRITE_NODE_FIELD(colcollations);
3294 			break;
3295 		case RTE_RESULT:
3296 			/* no extra fields */
3297 			break;
3298 		default:
3299 			elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
3300 			break;
3301 	}
3302 
3303 	WRITE_BOOL_FIELD(lateral);
3304 	WRITE_BOOL_FIELD(inh);
3305 	WRITE_BOOL_FIELD(inFromCl);
3306 	WRITE_UINT_FIELD(requiredPerms);
3307 	WRITE_OID_FIELD(checkAsUser);
3308 	WRITE_BITMAPSET_FIELD(selectedCols);
3309 	WRITE_BITMAPSET_FIELD(insertedCols);
3310 	WRITE_BITMAPSET_FIELD(updatedCols);
3311 	WRITE_BITMAPSET_FIELD(extraUpdatedCols);
3312 	WRITE_NODE_FIELD(securityQuals);
3313 }
3314 
3315 static void
_outRangeTblFunction(StringInfo str,const RangeTblFunction * node)3316 _outRangeTblFunction(StringInfo str, const RangeTblFunction *node)
3317 {
3318 	WRITE_NODE_TYPE("RANGETBLFUNCTION");
3319 
3320 	WRITE_NODE_FIELD(funcexpr);
3321 	WRITE_INT_FIELD(funccolcount);
3322 	WRITE_NODE_FIELD(funccolnames);
3323 	WRITE_NODE_FIELD(funccoltypes);
3324 	WRITE_NODE_FIELD(funccoltypmods);
3325 	WRITE_NODE_FIELD(funccolcollations);
3326 	WRITE_BITMAPSET_FIELD(funcparams);
3327 }
3328 
3329 static void
_outTableSampleClause(StringInfo str,const TableSampleClause * node)3330 _outTableSampleClause(StringInfo str, const TableSampleClause *node)
3331 {
3332 	WRITE_NODE_TYPE("TABLESAMPLECLAUSE");
3333 
3334 	WRITE_OID_FIELD(tsmhandler);
3335 	WRITE_NODE_FIELD(args);
3336 	WRITE_NODE_FIELD(repeatable);
3337 }
3338 
3339 static void
_outAExpr(StringInfo str,const A_Expr * node)3340 _outAExpr(StringInfo str, const A_Expr *node)
3341 {
3342 	WRITE_NODE_TYPE("AEXPR");
3343 
3344 	switch (node->kind)
3345 	{
3346 		case AEXPR_OP:
3347 			appendStringInfoChar(str, ' ');
3348 			WRITE_NODE_FIELD(name);
3349 			break;
3350 		case AEXPR_OP_ANY:
3351 			appendStringInfoChar(str, ' ');
3352 			WRITE_NODE_FIELD(name);
3353 			appendStringInfoString(str, " ANY ");
3354 			break;
3355 		case AEXPR_OP_ALL:
3356 			appendStringInfoChar(str, ' ');
3357 			WRITE_NODE_FIELD(name);
3358 			appendStringInfoString(str, " ALL ");
3359 			break;
3360 		case AEXPR_DISTINCT:
3361 			appendStringInfoString(str, " DISTINCT ");
3362 			WRITE_NODE_FIELD(name);
3363 			break;
3364 		case AEXPR_NOT_DISTINCT:
3365 			appendStringInfoString(str, " NOT_DISTINCT ");
3366 			WRITE_NODE_FIELD(name);
3367 			break;
3368 		case AEXPR_NULLIF:
3369 			appendStringInfoString(str, " NULLIF ");
3370 			WRITE_NODE_FIELD(name);
3371 			break;
3372 		case AEXPR_IN:
3373 			appendStringInfoString(str, " IN ");
3374 			WRITE_NODE_FIELD(name);
3375 			break;
3376 		case AEXPR_LIKE:
3377 			appendStringInfoString(str, " LIKE ");
3378 			WRITE_NODE_FIELD(name);
3379 			break;
3380 		case AEXPR_ILIKE:
3381 			appendStringInfoString(str, " ILIKE ");
3382 			WRITE_NODE_FIELD(name);
3383 			break;
3384 		case AEXPR_SIMILAR:
3385 			appendStringInfoString(str, " SIMILAR ");
3386 			WRITE_NODE_FIELD(name);
3387 			break;
3388 		case AEXPR_BETWEEN:
3389 			appendStringInfoString(str, " BETWEEN ");
3390 			WRITE_NODE_FIELD(name);
3391 			break;
3392 		case AEXPR_NOT_BETWEEN:
3393 			appendStringInfoString(str, " NOT_BETWEEN ");
3394 			WRITE_NODE_FIELD(name);
3395 			break;
3396 		case AEXPR_BETWEEN_SYM:
3397 			appendStringInfoString(str, " BETWEEN_SYM ");
3398 			WRITE_NODE_FIELD(name);
3399 			break;
3400 		case AEXPR_NOT_BETWEEN_SYM:
3401 			appendStringInfoString(str, " NOT_BETWEEN_SYM ");
3402 			WRITE_NODE_FIELD(name);
3403 			break;
3404 		default:
3405 			appendStringInfoString(str, " ??");
3406 			break;
3407 	}
3408 
3409 	WRITE_NODE_FIELD(lexpr);
3410 	WRITE_NODE_FIELD(rexpr);
3411 	WRITE_LOCATION_FIELD(location);
3412 }
3413 
3414 static void
_outValue(StringInfo str,const Value * value)3415 _outValue(StringInfo str, const Value *value)
3416 {
3417 	switch (value->type)
3418 	{
3419 		case T_Integer:
3420 			appendStringInfo(str, "%d", value->val.ival);
3421 			break;
3422 		case T_Float:
3423 
3424 			/*
3425 			 * We assume the value is a valid numeric literal and so does not
3426 			 * need quoting.
3427 			 */
3428 			appendStringInfoString(str, value->val.str);
3429 			break;
3430 		case T_String:
3431 
3432 			/*
3433 			 * We use outToken to provide escaping of the string's content,
3434 			 * but we don't want it to do anything with an empty string.
3435 			 */
3436 			appendStringInfoChar(str, '"');
3437 			if (value->val.str[0] != '\0')
3438 				outToken(str, value->val.str);
3439 			appendStringInfoChar(str, '"');
3440 			break;
3441 		case T_BitString:
3442 			/* internal representation already has leading 'b' */
3443 			appendStringInfoString(str, value->val.str);
3444 			break;
3445 		case T_Null:
3446 			/* this is seen only within A_Const, not in transformed trees */
3447 			appendStringInfoString(str, "NULL");
3448 			break;
3449 		default:
3450 			elog(ERROR, "unrecognized node type: %d", (int) value->type);
3451 			break;
3452 	}
3453 }
3454 
3455 static void
_outColumnRef(StringInfo str,const ColumnRef * node)3456 _outColumnRef(StringInfo str, const ColumnRef *node)
3457 {
3458 	WRITE_NODE_TYPE("COLUMNREF");
3459 
3460 	WRITE_NODE_FIELD(fields);
3461 	WRITE_LOCATION_FIELD(location);
3462 }
3463 
3464 static void
_outParamRef(StringInfo str,const ParamRef * node)3465 _outParamRef(StringInfo str, const ParamRef *node)
3466 {
3467 	WRITE_NODE_TYPE("PARAMREF");
3468 
3469 	WRITE_INT_FIELD(number);
3470 	WRITE_LOCATION_FIELD(location);
3471 }
3472 
3473 /*
3474  * Node types found in raw parse trees (supported for debug purposes)
3475  */
3476 
3477 static void
_outRawStmt(StringInfo str,const RawStmt * node)3478 _outRawStmt(StringInfo str, const RawStmt *node)
3479 {
3480 	WRITE_NODE_TYPE("RAWSTMT");
3481 
3482 	WRITE_NODE_FIELD(stmt);
3483 	WRITE_LOCATION_FIELD(stmt_location);
3484 	WRITE_INT_FIELD(stmt_len);
3485 }
3486 
3487 static void
_outAConst(StringInfo str,const A_Const * node)3488 _outAConst(StringInfo str, const A_Const *node)
3489 {
3490 	WRITE_NODE_TYPE("A_CONST");
3491 
3492 	appendStringInfoString(str, " :val ");
3493 	_outValue(str, &(node->val));
3494 	WRITE_LOCATION_FIELD(location);
3495 }
3496 
3497 static void
_outA_Star(StringInfo str,const A_Star * node)3498 _outA_Star(StringInfo str, const A_Star *node)
3499 {
3500 	WRITE_NODE_TYPE("A_STAR");
3501 }
3502 
3503 static void
_outA_Indices(StringInfo str,const A_Indices * node)3504 _outA_Indices(StringInfo str, const A_Indices *node)
3505 {
3506 	WRITE_NODE_TYPE("A_INDICES");
3507 
3508 	WRITE_BOOL_FIELD(is_slice);
3509 	WRITE_NODE_FIELD(lidx);
3510 	WRITE_NODE_FIELD(uidx);
3511 }
3512 
3513 static void
_outA_Indirection(StringInfo str,const A_Indirection * node)3514 _outA_Indirection(StringInfo str, const A_Indirection *node)
3515 {
3516 	WRITE_NODE_TYPE("A_INDIRECTION");
3517 
3518 	WRITE_NODE_FIELD(arg);
3519 	WRITE_NODE_FIELD(indirection);
3520 }
3521 
3522 static void
_outA_ArrayExpr(StringInfo str,const A_ArrayExpr * node)3523 _outA_ArrayExpr(StringInfo str, const A_ArrayExpr *node)
3524 {
3525 	WRITE_NODE_TYPE("A_ARRAYEXPR");
3526 
3527 	WRITE_NODE_FIELD(elements);
3528 	WRITE_LOCATION_FIELD(location);
3529 }
3530 
3531 static void
_outResTarget(StringInfo str,const ResTarget * node)3532 _outResTarget(StringInfo str, const ResTarget *node)
3533 {
3534 	WRITE_NODE_TYPE("RESTARGET");
3535 
3536 	WRITE_STRING_FIELD(name);
3537 	WRITE_NODE_FIELD(indirection);
3538 	WRITE_NODE_FIELD(val);
3539 	WRITE_LOCATION_FIELD(location);
3540 }
3541 
3542 static void
_outMultiAssignRef(StringInfo str,const MultiAssignRef * node)3543 _outMultiAssignRef(StringInfo str, const MultiAssignRef *node)
3544 {
3545 	WRITE_NODE_TYPE("MULTIASSIGNREF");
3546 
3547 	WRITE_NODE_FIELD(source);
3548 	WRITE_INT_FIELD(colno);
3549 	WRITE_INT_FIELD(ncolumns);
3550 }
3551 
3552 static void
_outSortBy(StringInfo str,const SortBy * node)3553 _outSortBy(StringInfo str, const SortBy *node)
3554 {
3555 	WRITE_NODE_TYPE("SORTBY");
3556 
3557 	WRITE_NODE_FIELD(node);
3558 	WRITE_ENUM_FIELD(sortby_dir, SortByDir);
3559 	WRITE_ENUM_FIELD(sortby_nulls, SortByNulls);
3560 	WRITE_NODE_FIELD(useOp);
3561 	WRITE_LOCATION_FIELD(location);
3562 }
3563 
3564 static void
_outWindowDef(StringInfo str,const WindowDef * node)3565 _outWindowDef(StringInfo str, const WindowDef *node)
3566 {
3567 	WRITE_NODE_TYPE("WINDOWDEF");
3568 
3569 	WRITE_STRING_FIELD(name);
3570 	WRITE_STRING_FIELD(refname);
3571 	WRITE_NODE_FIELD(partitionClause);
3572 	WRITE_NODE_FIELD(orderClause);
3573 	WRITE_INT_FIELD(frameOptions);
3574 	WRITE_NODE_FIELD(startOffset);
3575 	WRITE_NODE_FIELD(endOffset);
3576 	WRITE_LOCATION_FIELD(location);
3577 }
3578 
3579 static void
_outRangeSubselect(StringInfo str,const RangeSubselect * node)3580 _outRangeSubselect(StringInfo str, const RangeSubselect *node)
3581 {
3582 	WRITE_NODE_TYPE("RANGESUBSELECT");
3583 
3584 	WRITE_BOOL_FIELD(lateral);
3585 	WRITE_NODE_FIELD(subquery);
3586 	WRITE_NODE_FIELD(alias);
3587 }
3588 
3589 static void
_outRangeFunction(StringInfo str,const RangeFunction * node)3590 _outRangeFunction(StringInfo str, const RangeFunction *node)
3591 {
3592 	WRITE_NODE_TYPE("RANGEFUNCTION");
3593 
3594 	WRITE_BOOL_FIELD(lateral);
3595 	WRITE_BOOL_FIELD(ordinality);
3596 	WRITE_BOOL_FIELD(is_rowsfrom);
3597 	WRITE_NODE_FIELD(functions);
3598 	WRITE_NODE_FIELD(alias);
3599 	WRITE_NODE_FIELD(coldeflist);
3600 }
3601 
3602 static void
_outRangeTableSample(StringInfo str,const RangeTableSample * node)3603 _outRangeTableSample(StringInfo str, const RangeTableSample *node)
3604 {
3605 	WRITE_NODE_TYPE("RANGETABLESAMPLE");
3606 
3607 	WRITE_NODE_FIELD(relation);
3608 	WRITE_NODE_FIELD(method);
3609 	WRITE_NODE_FIELD(args);
3610 	WRITE_NODE_FIELD(repeatable);
3611 	WRITE_LOCATION_FIELD(location);
3612 }
3613 
3614 static void
_outRangeTableFunc(StringInfo str,const RangeTableFunc * node)3615 _outRangeTableFunc(StringInfo str, const RangeTableFunc *node)
3616 {
3617 	WRITE_NODE_TYPE("RANGETABLEFUNC");
3618 
3619 	WRITE_BOOL_FIELD(lateral);
3620 	WRITE_NODE_FIELD(docexpr);
3621 	WRITE_NODE_FIELD(rowexpr);
3622 	WRITE_NODE_FIELD(namespaces);
3623 	WRITE_NODE_FIELD(columns);
3624 	WRITE_NODE_FIELD(alias);
3625 	WRITE_LOCATION_FIELD(location);
3626 }
3627 
3628 static void
_outRangeTableFuncCol(StringInfo str,const RangeTableFuncCol * node)3629 _outRangeTableFuncCol(StringInfo str, const RangeTableFuncCol *node)
3630 {
3631 	WRITE_NODE_TYPE("RANGETABLEFUNCCOL");
3632 
3633 	WRITE_STRING_FIELD(colname);
3634 	WRITE_NODE_FIELD(typeName);
3635 	WRITE_BOOL_FIELD(for_ordinality);
3636 	WRITE_BOOL_FIELD(is_not_null);
3637 	WRITE_NODE_FIELD(colexpr);
3638 	WRITE_NODE_FIELD(coldefexpr);
3639 	WRITE_LOCATION_FIELD(location);
3640 }
3641 
3642 static void
_outConstraint(StringInfo str,const Constraint * node)3643 _outConstraint(StringInfo str, const Constraint *node)
3644 {
3645 	WRITE_NODE_TYPE("CONSTRAINT");
3646 
3647 	WRITE_STRING_FIELD(conname);
3648 	WRITE_BOOL_FIELD(deferrable);
3649 	WRITE_BOOL_FIELD(initdeferred);
3650 	WRITE_LOCATION_FIELD(location);
3651 
3652 	appendStringInfoString(str, " :contype ");
3653 	switch (node->contype)
3654 	{
3655 		case CONSTR_NULL:
3656 			appendStringInfoString(str, "NULL");
3657 			break;
3658 
3659 		case CONSTR_NOTNULL:
3660 			appendStringInfoString(str, "NOT_NULL");
3661 			break;
3662 
3663 		case CONSTR_DEFAULT:
3664 			appendStringInfoString(str, "DEFAULT");
3665 			WRITE_NODE_FIELD(raw_expr);
3666 			WRITE_STRING_FIELD(cooked_expr);
3667 			break;
3668 
3669 		case CONSTR_IDENTITY:
3670 			appendStringInfoString(str, "IDENTITY");
3671 			WRITE_NODE_FIELD(raw_expr);
3672 			WRITE_STRING_FIELD(cooked_expr);
3673 			WRITE_CHAR_FIELD(generated_when);
3674 			break;
3675 
3676 		case CONSTR_GENERATED:
3677 			appendStringInfoString(str, "GENERATED");
3678 			WRITE_NODE_FIELD(raw_expr);
3679 			WRITE_STRING_FIELD(cooked_expr);
3680 			WRITE_CHAR_FIELD(generated_when);
3681 			break;
3682 
3683 		case CONSTR_CHECK:
3684 			appendStringInfoString(str, "CHECK");
3685 			WRITE_BOOL_FIELD(is_no_inherit);
3686 			WRITE_NODE_FIELD(raw_expr);
3687 			WRITE_STRING_FIELD(cooked_expr);
3688 			break;
3689 
3690 		case CONSTR_PRIMARY:
3691 			appendStringInfoString(str, "PRIMARY_KEY");
3692 			WRITE_NODE_FIELD(keys);
3693 			WRITE_NODE_FIELD(including);
3694 			WRITE_NODE_FIELD(options);
3695 			WRITE_STRING_FIELD(indexname);
3696 			WRITE_STRING_FIELD(indexspace);
3697 			WRITE_BOOL_FIELD(reset_default_tblspc);
3698 			/* access_method and where_clause not currently used */
3699 			break;
3700 
3701 		case CONSTR_UNIQUE:
3702 			appendStringInfoString(str, "UNIQUE");
3703 			WRITE_NODE_FIELD(keys);
3704 			WRITE_NODE_FIELD(including);
3705 			WRITE_NODE_FIELD(options);
3706 			WRITE_STRING_FIELD(indexname);
3707 			WRITE_STRING_FIELD(indexspace);
3708 			WRITE_BOOL_FIELD(reset_default_tblspc);
3709 			/* access_method and where_clause not currently used */
3710 			break;
3711 
3712 		case CONSTR_EXCLUSION:
3713 			appendStringInfoString(str, "EXCLUSION");
3714 			WRITE_NODE_FIELD(exclusions);
3715 			WRITE_NODE_FIELD(including);
3716 			WRITE_NODE_FIELD(options);
3717 			WRITE_STRING_FIELD(indexname);
3718 			WRITE_STRING_FIELD(indexspace);
3719 			WRITE_BOOL_FIELD(reset_default_tblspc);
3720 			WRITE_STRING_FIELD(access_method);
3721 			WRITE_NODE_FIELD(where_clause);
3722 			break;
3723 
3724 		case CONSTR_FOREIGN:
3725 			appendStringInfoString(str, "FOREIGN_KEY");
3726 			WRITE_NODE_FIELD(pktable);
3727 			WRITE_NODE_FIELD(fk_attrs);
3728 			WRITE_NODE_FIELD(pk_attrs);
3729 			WRITE_CHAR_FIELD(fk_matchtype);
3730 			WRITE_CHAR_FIELD(fk_upd_action);
3731 			WRITE_CHAR_FIELD(fk_del_action);
3732 			WRITE_NODE_FIELD(old_conpfeqop);
3733 			WRITE_OID_FIELD(old_pktable_oid);
3734 			WRITE_BOOL_FIELD(skip_validation);
3735 			WRITE_BOOL_FIELD(initially_valid);
3736 			break;
3737 
3738 		case CONSTR_ATTR_DEFERRABLE:
3739 			appendStringInfoString(str, "ATTR_DEFERRABLE");
3740 			break;
3741 
3742 		case CONSTR_ATTR_NOT_DEFERRABLE:
3743 			appendStringInfoString(str, "ATTR_NOT_DEFERRABLE");
3744 			break;
3745 
3746 		case CONSTR_ATTR_DEFERRED:
3747 			appendStringInfoString(str, "ATTR_DEFERRED");
3748 			break;
3749 
3750 		case CONSTR_ATTR_IMMEDIATE:
3751 			appendStringInfoString(str, "ATTR_IMMEDIATE");
3752 			break;
3753 
3754 		default:
3755 			appendStringInfo(str, "<unrecognized_constraint %d>",
3756 							 (int) node->contype);
3757 			break;
3758 	}
3759 }
3760 
3761 static void
_outForeignKeyCacheInfo(StringInfo str,const ForeignKeyCacheInfo * node)3762 _outForeignKeyCacheInfo(StringInfo str, const ForeignKeyCacheInfo *node)
3763 {
3764 	WRITE_NODE_TYPE("FOREIGNKEYCACHEINFO");
3765 
3766 	WRITE_OID_FIELD(conoid);
3767 	WRITE_OID_FIELD(conrelid);
3768 	WRITE_OID_FIELD(confrelid);
3769 	WRITE_INT_FIELD(nkeys);
3770 	WRITE_ATTRNUMBER_ARRAY(conkey, node->nkeys);
3771 	WRITE_ATTRNUMBER_ARRAY(confkey, node->nkeys);
3772 	WRITE_OID_ARRAY(conpfeqop, node->nkeys);
3773 }
3774 
3775 static void
_outPartitionElem(StringInfo str,const PartitionElem * node)3776 _outPartitionElem(StringInfo str, const PartitionElem *node)
3777 {
3778 	WRITE_NODE_TYPE("PARTITIONELEM");
3779 
3780 	WRITE_STRING_FIELD(name);
3781 	WRITE_NODE_FIELD(expr);
3782 	WRITE_NODE_FIELD(collation);
3783 	WRITE_NODE_FIELD(opclass);
3784 	WRITE_LOCATION_FIELD(location);
3785 }
3786 
3787 static void
_outPartitionSpec(StringInfo str,const PartitionSpec * node)3788 _outPartitionSpec(StringInfo str, const PartitionSpec *node)
3789 {
3790 	WRITE_NODE_TYPE("PARTITIONSPEC");
3791 
3792 	WRITE_STRING_FIELD(strategy);
3793 	WRITE_NODE_FIELD(partParams);
3794 	WRITE_LOCATION_FIELD(location);
3795 }
3796 
3797 static void
_outPartitionBoundSpec(StringInfo str,const PartitionBoundSpec * node)3798 _outPartitionBoundSpec(StringInfo str, const PartitionBoundSpec *node)
3799 {
3800 	WRITE_NODE_TYPE("PARTITIONBOUNDSPEC");
3801 
3802 	WRITE_CHAR_FIELD(strategy);
3803 	WRITE_BOOL_FIELD(is_default);
3804 	WRITE_INT_FIELD(modulus);
3805 	WRITE_INT_FIELD(remainder);
3806 	WRITE_NODE_FIELD(listdatums);
3807 	WRITE_NODE_FIELD(lowerdatums);
3808 	WRITE_NODE_FIELD(upperdatums);
3809 	WRITE_LOCATION_FIELD(location);
3810 }
3811 
3812 static void
_outPartitionRangeDatum(StringInfo str,const PartitionRangeDatum * node)3813 _outPartitionRangeDatum(StringInfo str, const PartitionRangeDatum *node)
3814 {
3815 	WRITE_NODE_TYPE("PARTITIONRANGEDATUM");
3816 
3817 	WRITE_ENUM_FIELD(kind, PartitionRangeDatumKind);
3818 	WRITE_NODE_FIELD(value);
3819 	WRITE_LOCATION_FIELD(location);
3820 }
3821 
3822 /*
3823  * outNode -
3824  *	  converts a Node into ascii string and append it to 'str'
3825  */
3826 void
outNode(StringInfo str,const void * obj)3827 outNode(StringInfo str, const void *obj)
3828 {
3829 	/* Guard against stack overflow due to overly complex expressions */
3830 	check_stack_depth();
3831 
3832 	if (obj == NULL)
3833 		appendStringInfoString(str, "<>");
3834 	else if (IsA(obj, List) || IsA(obj, IntList) || IsA(obj, OidList))
3835 		_outList(str, obj);
3836 	else if (IsA(obj, Integer) ||
3837 			 IsA(obj, Float) ||
3838 			 IsA(obj, String) ||
3839 			 IsA(obj, BitString))
3840 	{
3841 		/* nodeRead does not want to see { } around these! */
3842 		_outValue(str, obj);
3843 	}
3844 	else
3845 	{
3846 		appendStringInfoChar(str, '{');
3847 		switch (nodeTag(obj))
3848 		{
3849 			case T_PlannedStmt:
3850 				_outPlannedStmt(str, obj);
3851 				break;
3852 			case T_Plan:
3853 				_outPlan(str, obj);
3854 				break;
3855 			case T_Result:
3856 				_outResult(str, obj);
3857 				break;
3858 			case T_ProjectSet:
3859 				_outProjectSet(str, obj);
3860 				break;
3861 			case T_ModifyTable:
3862 				_outModifyTable(str, obj);
3863 				break;
3864 			case T_Append:
3865 				_outAppend(str, obj);
3866 				break;
3867 			case T_MergeAppend:
3868 				_outMergeAppend(str, obj);
3869 				break;
3870 			case T_RecursiveUnion:
3871 				_outRecursiveUnion(str, obj);
3872 				break;
3873 			case T_BitmapAnd:
3874 				_outBitmapAnd(str, obj);
3875 				break;
3876 			case T_BitmapOr:
3877 				_outBitmapOr(str, obj);
3878 				break;
3879 			case T_Gather:
3880 				_outGather(str, obj);
3881 				break;
3882 			case T_GatherMerge:
3883 				_outGatherMerge(str, obj);
3884 				break;
3885 			case T_Scan:
3886 				_outScan(str, obj);
3887 				break;
3888 			case T_SeqScan:
3889 				_outSeqScan(str, obj);
3890 				break;
3891 			case T_SampleScan:
3892 				_outSampleScan(str, obj);
3893 				break;
3894 			case T_IndexScan:
3895 				_outIndexScan(str, obj);
3896 				break;
3897 			case T_IndexOnlyScan:
3898 				_outIndexOnlyScan(str, obj);
3899 				break;
3900 			case T_BitmapIndexScan:
3901 				_outBitmapIndexScan(str, obj);
3902 				break;
3903 			case T_BitmapHeapScan:
3904 				_outBitmapHeapScan(str, obj);
3905 				break;
3906 			case T_TidScan:
3907 				_outTidScan(str, obj);
3908 				break;
3909 			case T_TidRangeScan:
3910 				_outTidRangeScan(str, obj);
3911 				break;
3912 			case T_SubqueryScan:
3913 				_outSubqueryScan(str, obj);
3914 				break;
3915 			case T_FunctionScan:
3916 				_outFunctionScan(str, obj);
3917 				break;
3918 			case T_TableFuncScan:
3919 				_outTableFuncScan(str, obj);
3920 				break;
3921 			case T_ValuesScan:
3922 				_outValuesScan(str, obj);
3923 				break;
3924 			case T_CteScan:
3925 				_outCteScan(str, obj);
3926 				break;
3927 			case T_NamedTuplestoreScan:
3928 				_outNamedTuplestoreScan(str, obj);
3929 				break;
3930 			case T_WorkTableScan:
3931 				_outWorkTableScan(str, obj);
3932 				break;
3933 			case T_ForeignScan:
3934 				_outForeignScan(str, obj);
3935 				break;
3936 			case T_CustomScan:
3937 				_outCustomScan(str, obj);
3938 				break;
3939 			case T_Join:
3940 				_outJoin(str, obj);
3941 				break;
3942 			case T_NestLoop:
3943 				_outNestLoop(str, obj);
3944 				break;
3945 			case T_MergeJoin:
3946 				_outMergeJoin(str, obj);
3947 				break;
3948 			case T_HashJoin:
3949 				_outHashJoin(str, obj);
3950 				break;
3951 			case T_Agg:
3952 				_outAgg(str, obj);
3953 				break;
3954 			case T_WindowAgg:
3955 				_outWindowAgg(str, obj);
3956 				break;
3957 			case T_Group:
3958 				_outGroup(str, obj);
3959 				break;
3960 			case T_Material:
3961 				_outMaterial(str, obj);
3962 				break;
3963 			case T_Memoize:
3964 				_outMemoize(str, obj);
3965 				break;
3966 			case T_Sort:
3967 				_outSort(str, obj);
3968 				break;
3969 			case T_IncrementalSort:
3970 				_outIncrementalSort(str, obj);
3971 				break;
3972 			case T_Unique:
3973 				_outUnique(str, obj);
3974 				break;
3975 			case T_Hash:
3976 				_outHash(str, obj);
3977 				break;
3978 			case T_SetOp:
3979 				_outSetOp(str, obj);
3980 				break;
3981 			case T_LockRows:
3982 				_outLockRows(str, obj);
3983 				break;
3984 			case T_Limit:
3985 				_outLimit(str, obj);
3986 				break;
3987 			case T_NestLoopParam:
3988 				_outNestLoopParam(str, obj);
3989 				break;
3990 			case T_PlanRowMark:
3991 				_outPlanRowMark(str, obj);
3992 				break;
3993 			case T_PartitionPruneInfo:
3994 				_outPartitionPruneInfo(str, obj);
3995 				break;
3996 			case T_PartitionedRelPruneInfo:
3997 				_outPartitionedRelPruneInfo(str, obj);
3998 				break;
3999 			case T_PartitionPruneStepOp:
4000 				_outPartitionPruneStepOp(str, obj);
4001 				break;
4002 			case T_PartitionPruneStepCombine:
4003 				_outPartitionPruneStepCombine(str, obj);
4004 				break;
4005 			case T_PlanInvalItem:
4006 				_outPlanInvalItem(str, obj);
4007 				break;
4008 			case T_Alias:
4009 				_outAlias(str, obj);
4010 				break;
4011 			case T_RangeVar:
4012 				_outRangeVar(str, obj);
4013 				break;
4014 			case T_TableFunc:
4015 				_outTableFunc(str, obj);
4016 				break;
4017 			case T_IntoClause:
4018 				_outIntoClause(str, obj);
4019 				break;
4020 			case T_Var:
4021 				_outVar(str, obj);
4022 				break;
4023 			case T_Const:
4024 				_outConst(str, obj);
4025 				break;
4026 			case T_Param:
4027 				_outParam(str, obj);
4028 				break;
4029 			case T_Aggref:
4030 				_outAggref(str, obj);
4031 				break;
4032 			case T_GroupingFunc:
4033 				_outGroupingFunc(str, obj);
4034 				break;
4035 			case T_WindowFunc:
4036 				_outWindowFunc(str, obj);
4037 				break;
4038 			case T_SubscriptingRef:
4039 				_outSubscriptingRef(str, obj);
4040 				break;
4041 			case T_FuncExpr:
4042 				_outFuncExpr(str, obj);
4043 				break;
4044 			case T_NamedArgExpr:
4045 				_outNamedArgExpr(str, obj);
4046 				break;
4047 			case T_OpExpr:
4048 				_outOpExpr(str, obj);
4049 				break;
4050 			case T_DistinctExpr:
4051 				_outDistinctExpr(str, obj);
4052 				break;
4053 			case T_NullIfExpr:
4054 				_outNullIfExpr(str, obj);
4055 				break;
4056 			case T_ScalarArrayOpExpr:
4057 				_outScalarArrayOpExpr(str, obj);
4058 				break;
4059 			case T_BoolExpr:
4060 				_outBoolExpr(str, obj);
4061 				break;
4062 			case T_SubLink:
4063 				_outSubLink(str, obj);
4064 				break;
4065 			case T_SubPlan:
4066 				_outSubPlan(str, obj);
4067 				break;
4068 			case T_AlternativeSubPlan:
4069 				_outAlternativeSubPlan(str, obj);
4070 				break;
4071 			case T_FieldSelect:
4072 				_outFieldSelect(str, obj);
4073 				break;
4074 			case T_FieldStore:
4075 				_outFieldStore(str, obj);
4076 				break;
4077 			case T_RelabelType:
4078 				_outRelabelType(str, obj);
4079 				break;
4080 			case T_CoerceViaIO:
4081 				_outCoerceViaIO(str, obj);
4082 				break;
4083 			case T_ArrayCoerceExpr:
4084 				_outArrayCoerceExpr(str, obj);
4085 				break;
4086 			case T_ConvertRowtypeExpr:
4087 				_outConvertRowtypeExpr(str, obj);
4088 				break;
4089 			case T_CollateExpr:
4090 				_outCollateExpr(str, obj);
4091 				break;
4092 			case T_CaseExpr:
4093 				_outCaseExpr(str, obj);
4094 				break;
4095 			case T_CaseWhen:
4096 				_outCaseWhen(str, obj);
4097 				break;
4098 			case T_CaseTestExpr:
4099 				_outCaseTestExpr(str, obj);
4100 				break;
4101 			case T_ArrayExpr:
4102 				_outArrayExpr(str, obj);
4103 				break;
4104 			case T_RowExpr:
4105 				_outRowExpr(str, obj);
4106 				break;
4107 			case T_RowCompareExpr:
4108 				_outRowCompareExpr(str, obj);
4109 				break;
4110 			case T_CoalesceExpr:
4111 				_outCoalesceExpr(str, obj);
4112 				break;
4113 			case T_MinMaxExpr:
4114 				_outMinMaxExpr(str, obj);
4115 				break;
4116 			case T_SQLValueFunction:
4117 				_outSQLValueFunction(str, obj);
4118 				break;
4119 			case T_XmlExpr:
4120 				_outXmlExpr(str, obj);
4121 				break;
4122 			case T_NullTest:
4123 				_outNullTest(str, obj);
4124 				break;
4125 			case T_BooleanTest:
4126 				_outBooleanTest(str, obj);
4127 				break;
4128 			case T_CoerceToDomain:
4129 				_outCoerceToDomain(str, obj);
4130 				break;
4131 			case T_CoerceToDomainValue:
4132 				_outCoerceToDomainValue(str, obj);
4133 				break;
4134 			case T_SetToDefault:
4135 				_outSetToDefault(str, obj);
4136 				break;
4137 			case T_CurrentOfExpr:
4138 				_outCurrentOfExpr(str, obj);
4139 				break;
4140 			case T_NextValueExpr:
4141 				_outNextValueExpr(str, obj);
4142 				break;
4143 			case T_InferenceElem:
4144 				_outInferenceElem(str, obj);
4145 				break;
4146 			case T_TargetEntry:
4147 				_outTargetEntry(str, obj);
4148 				break;
4149 			case T_RangeTblRef:
4150 				_outRangeTblRef(str, obj);
4151 				break;
4152 			case T_JoinExpr:
4153 				_outJoinExpr(str, obj);
4154 				break;
4155 			case T_FromExpr:
4156 				_outFromExpr(str, obj);
4157 				break;
4158 			case T_OnConflictExpr:
4159 				_outOnConflictExpr(str, obj);
4160 				break;
4161 			case T_Path:
4162 				_outPath(str, obj);
4163 				break;
4164 			case T_IndexPath:
4165 				_outIndexPath(str, obj);
4166 				break;
4167 			case T_BitmapHeapPath:
4168 				_outBitmapHeapPath(str, obj);
4169 				break;
4170 			case T_BitmapAndPath:
4171 				_outBitmapAndPath(str, obj);
4172 				break;
4173 			case T_BitmapOrPath:
4174 				_outBitmapOrPath(str, obj);
4175 				break;
4176 			case T_TidPath:
4177 				_outTidPath(str, obj);
4178 				break;
4179 			case T_TidRangePath:
4180 				_outTidRangePath(str, obj);
4181 				break;
4182 			case T_SubqueryScanPath:
4183 				_outSubqueryScanPath(str, obj);
4184 				break;
4185 			case T_ForeignPath:
4186 				_outForeignPath(str, obj);
4187 				break;
4188 			case T_CustomPath:
4189 				_outCustomPath(str, obj);
4190 				break;
4191 			case T_AppendPath:
4192 				_outAppendPath(str, obj);
4193 				break;
4194 			case T_MergeAppendPath:
4195 				_outMergeAppendPath(str, obj);
4196 				break;
4197 			case T_GroupResultPath:
4198 				_outGroupResultPath(str, obj);
4199 				break;
4200 			case T_MaterialPath:
4201 				_outMaterialPath(str, obj);
4202 				break;
4203 			case T_MemoizePath:
4204 				_outMemoizePath(str, obj);
4205 				break;
4206 			case T_UniquePath:
4207 				_outUniquePath(str, obj);
4208 				break;
4209 			case T_GatherPath:
4210 				_outGatherPath(str, obj);
4211 				break;
4212 			case T_ProjectionPath:
4213 				_outProjectionPath(str, obj);
4214 				break;
4215 			case T_ProjectSetPath:
4216 				_outProjectSetPath(str, obj);
4217 				break;
4218 			case T_SortPath:
4219 				_outSortPath(str, obj);
4220 				break;
4221 			case T_IncrementalSortPath:
4222 				_outIncrementalSortPath(str, obj);
4223 				break;
4224 			case T_GroupPath:
4225 				_outGroupPath(str, obj);
4226 				break;
4227 			case T_UpperUniquePath:
4228 				_outUpperUniquePath(str, obj);
4229 				break;
4230 			case T_AggPath:
4231 				_outAggPath(str, obj);
4232 				break;
4233 			case T_GroupingSetsPath:
4234 				_outGroupingSetsPath(str, obj);
4235 				break;
4236 			case T_MinMaxAggPath:
4237 				_outMinMaxAggPath(str, obj);
4238 				break;
4239 			case T_WindowAggPath:
4240 				_outWindowAggPath(str, obj);
4241 				break;
4242 			case T_SetOpPath:
4243 				_outSetOpPath(str, obj);
4244 				break;
4245 			case T_RecursiveUnionPath:
4246 				_outRecursiveUnionPath(str, obj);
4247 				break;
4248 			case T_LockRowsPath:
4249 				_outLockRowsPath(str, obj);
4250 				break;
4251 			case T_ModifyTablePath:
4252 				_outModifyTablePath(str, obj);
4253 				break;
4254 			case T_LimitPath:
4255 				_outLimitPath(str, obj);
4256 				break;
4257 			case T_GatherMergePath:
4258 				_outGatherMergePath(str, obj);
4259 				break;
4260 			case T_NestPath:
4261 				_outNestPath(str, obj);
4262 				break;
4263 			case T_MergePath:
4264 				_outMergePath(str, obj);
4265 				break;
4266 			case T_HashPath:
4267 				_outHashPath(str, obj);
4268 				break;
4269 			case T_PlannerGlobal:
4270 				_outPlannerGlobal(str, obj);
4271 				break;
4272 			case T_PlannerInfo:
4273 				_outPlannerInfo(str, obj);
4274 				break;
4275 			case T_RelOptInfo:
4276 				_outRelOptInfo(str, obj);
4277 				break;
4278 			case T_IndexOptInfo:
4279 				_outIndexOptInfo(str, obj);
4280 				break;
4281 			case T_ForeignKeyOptInfo:
4282 				_outForeignKeyOptInfo(str, obj);
4283 				break;
4284 			case T_EquivalenceClass:
4285 				_outEquivalenceClass(str, obj);
4286 				break;
4287 			case T_EquivalenceMember:
4288 				_outEquivalenceMember(str, obj);
4289 				break;
4290 			case T_PathKey:
4291 				_outPathKey(str, obj);
4292 				break;
4293 			case T_PathTarget:
4294 				_outPathTarget(str, obj);
4295 				break;
4296 			case T_ParamPathInfo:
4297 				_outParamPathInfo(str, obj);
4298 				break;
4299 			case T_RestrictInfo:
4300 				_outRestrictInfo(str, obj);
4301 				break;
4302 			case T_IndexClause:
4303 				_outIndexClause(str, obj);
4304 				break;
4305 			case T_PlaceHolderVar:
4306 				_outPlaceHolderVar(str, obj);
4307 				break;
4308 			case T_SpecialJoinInfo:
4309 				_outSpecialJoinInfo(str, obj);
4310 				break;
4311 			case T_AppendRelInfo:
4312 				_outAppendRelInfo(str, obj);
4313 				break;
4314 			case T_RowIdentityVarInfo:
4315 				_outRowIdentityVarInfo(str, obj);
4316 				break;
4317 			case T_PlaceHolderInfo:
4318 				_outPlaceHolderInfo(str, obj);
4319 				break;
4320 			case T_MinMaxAggInfo:
4321 				_outMinMaxAggInfo(str, obj);
4322 				break;
4323 			case T_PlannerParamItem:
4324 				_outPlannerParamItem(str, obj);
4325 				break;
4326 			case T_RollupData:
4327 				_outRollupData(str, obj);
4328 				break;
4329 			case T_GroupingSetData:
4330 				_outGroupingSetData(str, obj);
4331 				break;
4332 			case T_StatisticExtInfo:
4333 				_outStatisticExtInfo(str, obj);
4334 				break;
4335 			case T_ExtensibleNode:
4336 				_outExtensibleNode(str, obj);
4337 				break;
4338 			case T_CreateStmt:
4339 				_outCreateStmt(str, obj);
4340 				break;
4341 			case T_CreateForeignTableStmt:
4342 				_outCreateForeignTableStmt(str, obj);
4343 				break;
4344 			case T_ImportForeignSchemaStmt:
4345 				_outImportForeignSchemaStmt(str, obj);
4346 				break;
4347 			case T_IndexStmt:
4348 				_outIndexStmt(str, obj);
4349 				break;
4350 			case T_CreateStatsStmt:
4351 				_outCreateStatsStmt(str, obj);
4352 				break;
4353 			case T_AlterStatsStmt:
4354 				_outAlterStatsStmt(str, obj);
4355 				break;
4356 			case T_NotifyStmt:
4357 				_outNotifyStmt(str, obj);
4358 				break;
4359 			case T_DeclareCursorStmt:
4360 				_outDeclareCursorStmt(str, obj);
4361 				break;
4362 			case T_SelectStmt:
4363 				_outSelectStmt(str, obj);
4364 				break;
4365 			case T_ReturnStmt:
4366 				_outReturnStmt(str, obj);
4367 				break;
4368 			case T_PLAssignStmt:
4369 				_outPLAssignStmt(str, obj);
4370 				break;
4371 			case T_ColumnDef:
4372 				_outColumnDef(str, obj);
4373 				break;
4374 			case T_TypeName:
4375 				_outTypeName(str, obj);
4376 				break;
4377 			case T_TypeCast:
4378 				_outTypeCast(str, obj);
4379 				break;
4380 			case T_CollateClause:
4381 				_outCollateClause(str, obj);
4382 				break;
4383 			case T_IndexElem:
4384 				_outIndexElem(str, obj);
4385 				break;
4386 			case T_StatsElem:
4387 				_outStatsElem(str, obj);
4388 				break;
4389 			case T_Query:
4390 				_outQuery(str, obj);
4391 				break;
4392 			case T_WithCheckOption:
4393 				_outWithCheckOption(str, obj);
4394 				break;
4395 			case T_SortGroupClause:
4396 				_outSortGroupClause(str, obj);
4397 				break;
4398 			case T_GroupingSet:
4399 				_outGroupingSet(str, obj);
4400 				break;
4401 			case T_WindowClause:
4402 				_outWindowClause(str, obj);
4403 				break;
4404 			case T_RowMarkClause:
4405 				_outRowMarkClause(str, obj);
4406 				break;
4407 			case T_WithClause:
4408 				_outWithClause(str, obj);
4409 				break;
4410 			case T_CTESearchClause:
4411 				_outCTESearchClause(str, obj);
4412 				break;
4413 			case T_CTECycleClause:
4414 				_outCTECycleClause(str, obj);
4415 				break;
4416 			case T_CommonTableExpr:
4417 				_outCommonTableExpr(str, obj);
4418 				break;
4419 			case T_SetOperationStmt:
4420 				_outSetOperationStmt(str, obj);
4421 				break;
4422 			case T_RangeTblEntry:
4423 				_outRangeTblEntry(str, obj);
4424 				break;
4425 			case T_RangeTblFunction:
4426 				_outRangeTblFunction(str, obj);
4427 				break;
4428 			case T_TableSampleClause:
4429 				_outTableSampleClause(str, obj);
4430 				break;
4431 			case T_A_Expr:
4432 				_outAExpr(str, obj);
4433 				break;
4434 			case T_ColumnRef:
4435 				_outColumnRef(str, obj);
4436 				break;
4437 			case T_ParamRef:
4438 				_outParamRef(str, obj);
4439 				break;
4440 			case T_RawStmt:
4441 				_outRawStmt(str, obj);
4442 				break;
4443 			case T_A_Const:
4444 				_outAConst(str, obj);
4445 				break;
4446 			case T_A_Star:
4447 				_outA_Star(str, obj);
4448 				break;
4449 			case T_A_Indices:
4450 				_outA_Indices(str, obj);
4451 				break;
4452 			case T_A_Indirection:
4453 				_outA_Indirection(str, obj);
4454 				break;
4455 			case T_A_ArrayExpr:
4456 				_outA_ArrayExpr(str, obj);
4457 				break;
4458 			case T_ResTarget:
4459 				_outResTarget(str, obj);
4460 				break;
4461 			case T_MultiAssignRef:
4462 				_outMultiAssignRef(str, obj);
4463 				break;
4464 			case T_SortBy:
4465 				_outSortBy(str, obj);
4466 				break;
4467 			case T_WindowDef:
4468 				_outWindowDef(str, obj);
4469 				break;
4470 			case T_RangeSubselect:
4471 				_outRangeSubselect(str, obj);
4472 				break;
4473 			case T_RangeFunction:
4474 				_outRangeFunction(str, obj);
4475 				break;
4476 			case T_RangeTableSample:
4477 				_outRangeTableSample(str, obj);
4478 				break;
4479 			case T_RangeTableFunc:
4480 				_outRangeTableFunc(str, obj);
4481 				break;
4482 			case T_RangeTableFuncCol:
4483 				_outRangeTableFuncCol(str, obj);
4484 				break;
4485 			case T_Constraint:
4486 				_outConstraint(str, obj);
4487 				break;
4488 			case T_FuncCall:
4489 				_outFuncCall(str, obj);
4490 				break;
4491 			case T_DefElem:
4492 				_outDefElem(str, obj);
4493 				break;
4494 			case T_TableLikeClause:
4495 				_outTableLikeClause(str, obj);
4496 				break;
4497 			case T_LockingClause:
4498 				_outLockingClause(str, obj);
4499 				break;
4500 			case T_XmlSerialize:
4501 				_outXmlSerialize(str, obj);
4502 				break;
4503 			case T_ForeignKeyCacheInfo:
4504 				_outForeignKeyCacheInfo(str, obj);
4505 				break;
4506 			case T_TriggerTransition:
4507 				_outTriggerTransition(str, obj);
4508 				break;
4509 			case T_PartitionElem:
4510 				_outPartitionElem(str, obj);
4511 				break;
4512 			case T_PartitionSpec:
4513 				_outPartitionSpec(str, obj);
4514 				break;
4515 			case T_PartitionBoundSpec:
4516 				_outPartitionBoundSpec(str, obj);
4517 				break;
4518 			case T_PartitionRangeDatum:
4519 				_outPartitionRangeDatum(str, obj);
4520 				break;
4521 
4522 			default:
4523 
4524 				/*
4525 				 * This should be an ERROR, but it's too useful to be able to
4526 				 * dump structures that outNode only understands part of.
4527 				 */
4528 				elog(WARNING, "could not dump unrecognized node type: %d",
4529 					 (int) nodeTag(obj));
4530 				break;
4531 		}
4532 		appendStringInfoChar(str, '}');
4533 	}
4534 }
4535 
4536 /*
4537  * nodeToString -
4538  *	   returns the ascii representation of the Node as a palloc'd string
4539  */
4540 char *
nodeToString(const void * obj)4541 nodeToString(const void *obj)
4542 {
4543 	StringInfoData str;
4544 
4545 	/* see stringinfo.h for an explanation of this maneuver */
4546 	initStringInfo(&str);
4547 	outNode(&str, obj);
4548 	return str.data;
4549 }
4550 
4551 /*
4552  * bmsToString -
4553  *	   returns the ascii representation of the Bitmapset as a palloc'd string
4554  */
4555 char *
bmsToString(const Bitmapset * bms)4556 bmsToString(const Bitmapset *bms)
4557 {
4558 	StringInfoData str;
4559 
4560 	/* see stringinfo.h for an explanation of this maneuver */
4561 	initStringInfo(&str);
4562 	outBitmapset(&str, bms);
4563 	return str.data;
4564 }
4565