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