outfuncs.c 33.4 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * outfuncs.c
4
 *	  Output functions for Postgres tree nodes.
5
 *
B
Bruce Momjian 已提交
6
 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
7
 * Portions Copyright (c) 1994, Regents of the University of California
8
 *
9 10
 *
 * IDENTIFICATION
11
 *	  $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.183 2002/11/25 21:29:36 tgl Exp $
12 13
 *
 * NOTES
14 15 16 17 18 19 20
 *	  Every node type that can appear in stored rules' parsetrees *must*
 *	  have an output function defined here (as well as an input function
 *	  in readfuncs.c).  For use in debugging, we also provide output
 *	  functions for nodes that appear in raw parsetrees and plan trees.
 *	  These nodes however need not have input functions.
 *
 *-------------------------------------------------------------------------
21
 */
22
#include "postgres.h"
23

24 25
#include <ctype.h>

B
Bruce Momjian 已提交
26 27 28
#include "lib/stringinfo.h"
#include "nodes/nodes.h"
#include "nodes/parsenodes.h"
29 30 31
#include "nodes/plannodes.h"
#include "nodes/primnodes.h"
#include "nodes/relation.h"
32
#include "parser/parse.h"
B
Bruce Momjian 已提交
33
#include "utils/datum.h"
34

35

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
/*
 * Macros to simplify output of different kinds of fields.  Use these
 * wherever possible to reduce the chance for silly typos.  Note that these
 * hard-wire conventions about the names of the local variables in an Out
 * routine.
 */

/* Write the label for the node type */
#define WRITE_NODE_TYPE(nodelabel) \
	appendStringInfo(str, nodelabel)

/* Write an integer field (anything written as ":fldname %d") */
#define WRITE_INT_FIELD(fldname) \
	appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)

/* Write an unsigned integer field (anything written as ":fldname %u") */
#define WRITE_UINT_FIELD(fldname) \
	appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)

/* Write an OID field (don't hard-wire assumption that OID is same as uint) */
#define WRITE_OID_FIELD(fldname) \
	appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)

/* Write a long-integer field */
#define WRITE_LONG_FIELD(fldname) \
	appendStringInfo(str, " :" CppAsString(fldname) " %ld", node->fldname)

/* Write a char field (ie, one ascii character) */
#define WRITE_CHAR_FIELD(fldname) \
	appendStringInfo(str, " :" CppAsString(fldname) " %c", node->fldname)

/* Write an enumerated-type field as an integer code */
#define WRITE_ENUM_FIELD(fldname, enumtype) \
	appendStringInfo(str, " :" CppAsString(fldname) " %d", \
					 (int) node->fldname)

/* Write a float field --- caller must give format to define precision */
#define WRITE_FLOAT_FIELD(fldname,format) \
	appendStringInfo(str, " :" CppAsString(fldname) " " format, node->fldname)

/* Write a boolean field */
#define WRITE_BOOL_FIELD(fldname) \
	appendStringInfo(str, " :" CppAsString(fldname) " %s", \
					 booltostr(node->fldname))

/* Write a character-string (possibly NULL) field */
#define WRITE_STRING_FIELD(fldname) \
	(appendStringInfo(str, " :" CppAsString(fldname) " "), \
	 _outToken(str, node->fldname))

/* Write a Node field */
#define WRITE_NODE_FIELD(fldname) \
	(appendStringInfo(str, " :" CppAsString(fldname) " "), \
	 _outNode(str, node->fldname))

/* Write an integer-list field */
#define WRITE_INTLIST_FIELD(fldname) \
	(appendStringInfo(str, " :" CppAsString(fldname) " "), \
	 _outIntList(str, node->fldname))

/* Write an OID-list field */
#define WRITE_OIDLIST_FIELD(fldname) \
	(appendStringInfo(str, " :" CppAsString(fldname) " "), \
	 _outOidList(str, node->fldname))


102 103
#define booltostr(x)  ((x) ? "true" : "false")

104
static void _outDatum(StringInfo str, Datum value, int typlen, bool typbyval);
105
static void _outNode(StringInfo str, void *obj);
106

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
/*
 * _outToken
 *	  Convert an ordinary string (eg, an identifier) into a form that
 *	  will be decoded back to a plain token by read.c's functions.
 *
 *	  If a null or empty string is given, it is encoded as "<>".
 */
static void
_outToken(StringInfo str, char *s)
{
	if (s == NULL || *s == '\0')
	{
		appendStringInfo(str, "<>");
		return;
	}
122

123 124
	/*
	 * Look for characters or patterns that are treated specially by
125 126
	 * read.c (either in pg_strtok() or in nodeRead()), and therefore need
	 * a protective backslash.
127 128 129 130 131
	 */
	/* These characters only need to be quoted at the start of the string */
	if (*s == '<' ||
		*s == '\"' ||
		*s == '@' ||
132
		isdigit((unsigned char) *s) ||
133 134
		((*s == '+' || *s == '-') &&
		 (isdigit((unsigned char) s[1]) || s[1] == '.')))
135 136 137 138 139 140 141 142 143 144 145
		appendStringInfoChar(str, '\\');
	while (*s)
	{
		/* These chars must be backslashed anywhere in the string */
		if (*s == ' ' || *s == '\n' || *s == '\t' ||
			*s == '(' || *s == ')' || *s == '{' || *s == '}' ||
			*s == '\\')
			appendStringInfoChar(str, '\\');
		appendStringInfoChar(str, *s++);
	}
}
146

147 148
/*
 * _outIntList -
149
 *	   converts a List of integers
150
 */
151
static void
152
_outIntList(StringInfo str, List *list)
153
{
B
Bruce Momjian 已提交
154
	List	   *l;
155

156
	appendStringInfoChar(str, '(');
157
	foreach(l, list)
158 159
		appendStringInfo(str, " %d", lfirsti(l));
	appendStringInfoChar(str, ')');
160 161
}

162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
/*
 * _outOidList -
 *	   converts a List of OIDs
 */
static void
_outOidList(StringInfo str, List *list)
{
	List	   *l;

	appendStringInfoChar(str, '(');
	foreach(l, list)
		appendStringInfo(str, " %u", (Oid) lfirsti(l));
	appendStringInfoChar(str, ')');
}

177 178 179
static void
_outCreateStmt(StringInfo str, CreateStmt *node)
{
180
	WRITE_NODE_TYPE("CREATE");
181

182 183 184 185 186 187
	WRITE_NODE_FIELD(relation);
	WRITE_NODE_FIELD(tableElts);
	WRITE_NODE_FIELD(inhRelations);
	WRITE_NODE_FIELD(constraints);
	WRITE_BOOL_FIELD(hasoids);
	WRITE_ENUM_FIELD(oncommit, OnCommitAction);
188
}
189 190 191 192

static void
_outIndexStmt(StringInfo str, IndexStmt *node)
{
193 194 195 196 197 198 199 200 201 202 203
	WRITE_NODE_TYPE("INDEX");

	WRITE_STRING_FIELD(idxname);
	WRITE_NODE_FIELD(relation);
	WRITE_STRING_FIELD(accessMethod);
	WRITE_NODE_FIELD(indexParams);
	WRITE_NODE_FIELD(whereClause);
	WRITE_NODE_FIELD(rangetable);
	WRITE_BOOL_FIELD(unique);
	WRITE_BOOL_FIELD(primary);
	WRITE_BOOL_FIELD(isconstraint);
204
}
205

206 207 208
static void
_outNotifyStmt(StringInfo str, NotifyStmt *node)
{
209 210 211
	WRITE_NODE_TYPE("NOTIFY");

	WRITE_NODE_FIELD(relation);
212 213
}

214 215 216
static void
_outSelectStmt(StringInfo str, SelectStmt *node)
{
217 218
	WRITE_NODE_TYPE("SELECT");

219
	/* XXX this is pretty durn incomplete */
220
	WRITE_NODE_FIELD(whereClause);
221 222 223 224 225
}

static void
_outFuncCall(StringInfo str, FuncCall *node)
{
226 227 228 229 230 231
	WRITE_NODE_TYPE("FUNCCALL");

	WRITE_NODE_FIELD(funcname);
	WRITE_NODE_FIELD(args);
	WRITE_BOOL_FIELD(agg_star);
	WRITE_BOOL_FIELD(agg_distinct);
232
}
233

234 235 236
static void
_outColumnDef(StringInfo str, ColumnDef *node)
{
237 238 239 240 241 242 243 244 245 246 247
	WRITE_NODE_TYPE("COLUMNDEF");

	WRITE_STRING_FIELD(colname);
	WRITE_NODE_FIELD(typename);
	WRITE_INT_FIELD(inhcount);
	WRITE_BOOL_FIELD(is_local);
	WRITE_BOOL_FIELD(is_not_null);
	WRITE_NODE_FIELD(raw_default);
	WRITE_STRING_FIELD(cooked_default);
	WRITE_NODE_FIELD(constraints);
	WRITE_NODE_FIELD(support);
248 249 250 251 252
}

static void
_outTypeName(StringInfo str, TypeName *node)
{
253 254 255 256 257 258 259 260 261
	WRITE_NODE_TYPE("TYPENAME");

	WRITE_NODE_FIELD(names);
	WRITE_OID_FIELD(typeid);
	WRITE_BOOL_FIELD(timezone);
	WRITE_BOOL_FIELD(setof);
	WRITE_BOOL_FIELD(pct_type);
	WRITE_INT_FIELD(typmod);
	WRITE_NODE_FIELD(arrayBounds);
262
}
263

264 265 266
static void
_outTypeCast(StringInfo str, TypeCast *node)
{
267 268 269 270
	WRITE_NODE_TYPE("TYPECAST");

	WRITE_NODE_FIELD(arg);
	WRITE_NODE_FIELD(typename);
271 272
}

273 274 275
static void
_outIndexElem(StringInfo str, IndexElem *node)
{
276 277 278 279 280 281
	WRITE_NODE_TYPE("INDEXELEM");

	WRITE_STRING_FIELD(name);
	WRITE_NODE_FIELD(funcname);
	WRITE_NODE_FIELD(args);
	WRITE_NODE_FIELD(opclass);
282
}
283

284
static void
285
_outQuery(StringInfo str, Query *node)
286
{
287 288 289 290
	WRITE_NODE_TYPE("QUERY");

	WRITE_ENUM_FIELD(commandType, CmdType);
	WRITE_ENUM_FIELD(querySource, QuerySource);
291

292 293
	/*
	 * Hack to work around missing outfuncs routines for a lot of the
B
Bruce Momjian 已提交
294 295 296 297
	 * utility-statement node types.  (The only one we actually *need* for
	 * rules support is NotifyStmt.)  Someday we ought to support 'em all,
	 * but for the meantime do this to avoid getting lots of warnings when
	 * running with debug_print_parse on.
298
	 */
299 300 301 302 303 304 305
	if (node->utilityStmt)
	{
		switch (nodeTag(node->utilityStmt))
		{
			case T_CreateStmt:
			case T_IndexStmt:
			case T_NotifyStmt:
306
				WRITE_NODE_FIELD(utilityStmt);
307 308
				break;
			default:
309
				appendStringInfo(str, " :utilityStmt ?");
310
				break;
311 312
		}
	}
313
	else
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
		appendStringInfo(str, " :utilityStmt <>");

	WRITE_INT_FIELD(resultRelation);
	WRITE_NODE_FIELD(into);
	WRITE_BOOL_FIELD(isPortal);
	WRITE_BOOL_FIELD(isBinary);
	WRITE_BOOL_FIELD(hasAggs);
	WRITE_BOOL_FIELD(hasSubLinks);
	WRITE_NODE_FIELD(rtable);
	WRITE_NODE_FIELD(jointree);
	WRITE_INTLIST_FIELD(rowMarks);
	WRITE_NODE_FIELD(targetList);
	WRITE_NODE_FIELD(groupClause);
	WRITE_NODE_FIELD(havingQual);
	WRITE_NODE_FIELD(distinctClause);
	WRITE_NODE_FIELD(sortClause);
	WRITE_NODE_FIELD(limitOffset);
	WRITE_NODE_FIELD(limitCount);
	WRITE_NODE_FIELD(setOperations);
	WRITE_INTLIST_FIELD(resultRelations);
334 335

	/* planner-internal fields are not written out */
336 337 338
}

static void
339
_outSortClause(StringInfo str, SortClause *node)
340
{
341 342 343 344
	WRITE_NODE_TYPE("SORTCLAUSE");

	WRITE_UINT_FIELD(tleSortGroupRef);
	WRITE_OID_FIELD(sortop);
345 346 347 348 349
}

static void
_outGroupClause(StringInfo str, GroupClause *node)
{
350 351 352 353
	WRITE_NODE_TYPE("GROUPCLAUSE");

	WRITE_UINT_FIELD(tleSortGroupRef);
	WRITE_OID_FIELD(sortop);
354 355
}

356 357 358
static void
_outSetOperationStmt(StringInfo str, SetOperationStmt *node)
{
359 360 361 362 363 364 365
	WRITE_NODE_TYPE("SETOPERATIONSTMT");

	WRITE_ENUM_FIELD(op, SetOperation);
	WRITE_BOOL_FIELD(all);
	WRITE_NODE_FIELD(larg);
	WRITE_NODE_FIELD(rarg);
	WRITE_OIDLIST_FIELD(colTypes);
366 367
}

368 369 370 371
/*
 *	Stuff from plannodes.h
 */

372 373
/*
 * print the basic stuff of all nodes that inherit from Plan
374 375
 *
 * NOTE: we deliberately omit the execution state (EState)
376 377
 */
static void
378
_outPlanInfo(StringInfo str, Plan *node)
379
{
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
	WRITE_FLOAT_FIELD(startup_cost, "%.2f");
	WRITE_FLOAT_FIELD(total_cost, "%.2f");
	WRITE_FLOAT_FIELD(plan_rows, "%.0f");
	WRITE_INT_FIELD(plan_width);
	WRITE_NODE_FIELD(targetlist);
	WRITE_NODE_FIELD(qual);
	WRITE_NODE_FIELD(lefttree);
	WRITE_NODE_FIELD(righttree);
	WRITE_INTLIST_FIELD(extParam);
	WRITE_INTLIST_FIELD(locParam);
	/* chgParam is execution state too */
	WRITE_NODE_FIELD(initPlan);
	/* we don't write subPlan; reader must reconstruct list */
	WRITE_INT_FIELD(nParamExec);
}
M
 
Marc G. Fournier 已提交
395

396 397 398 399 400 401 402
/*
 * print the basic stuff of all nodes that inherit from Scan
 */
static void
_outScanInfo(StringInfo str, Scan *node)
{
	_outPlanInfo(str, (Plan *) node);
M
 
Marc G. Fournier 已提交
403

404
	WRITE_UINT_FIELD(scanrelid);
405 406 407
}

/*
408
 * print the basic stuff of all nodes that inherit from Join
409
 */
410 411 412 413 414 415 416 417 418 419
static void
_outJoinPlanInfo(StringInfo str, Join *node)
{
	_outPlanInfo(str, (Plan *) node);

	WRITE_ENUM_FIELD(jointype, JoinType);
	WRITE_NODE_FIELD(joinqual);
}


420
static void
421
_outPlan(StringInfo str, Plan *node)
422
{
423 424
	WRITE_NODE_TYPE("PLAN");

425
	_outPlanInfo(str, (Plan *) node);
426 427 428
}

static void
429
_outResult(StringInfo str, Result *node)
430
{
431
	WRITE_NODE_TYPE("RESULT");
432

433
	_outPlanInfo(str, (Plan *) node);
434

435
	WRITE_NODE_FIELD(resconstantqual);
436 437 438
}

static void
B
Bruce Momjian 已提交
439
_outAppend(StringInfo str, Append *node)
440
{
441
	WRITE_NODE_TYPE("APPEND");
442

443
	_outPlanInfo(str, (Plan *) node);
444

445 446
	WRITE_NODE_FIELD(appendplans);
	WRITE_BOOL_FIELD(isTarget);
447 448 449
}

static void
450
_outScan(StringInfo str, Scan *node)
451
{
452 453 454
	WRITE_NODE_TYPE("SCAN");

	_outScanInfo(str, (Scan *) node);
455 456 457
}

static void
458
_outSeqScan(StringInfo str, SeqScan *node)
459
{
460 461 462
	WRITE_NODE_TYPE("SEQSCAN");

	_outScanInfo(str, (Scan *) node);
463 464 465
}

static void
466
_outIndexScan(StringInfo str, IndexScan *node)
467
{
468
	WRITE_NODE_TYPE("INDEXSCAN");
469

470 471 472 473 474 475
	_outScanInfo(str, (Scan *) node);

	WRITE_OIDLIST_FIELD(indxid);
	WRITE_NODE_FIELD(indxqual);
	WRITE_NODE_FIELD(indxqualorig);
	WRITE_ENUM_FIELD(indxorderdir, ScanDirection);
476 477 478
}

static void
479
_outTidScan(StringInfo str, TidScan *node)
480
{
481 482 483
	WRITE_NODE_TYPE("TIDSCAN");

	_outScanInfo(str, (Scan *) node);
484

485 486
	WRITE_BOOL_FIELD(needRescan);
	WRITE_NODE_FIELD(tideval);
487 488
}

V
Vadim B. Mikheev 已提交
489
static void
490
_outSubqueryScan(StringInfo str, SubqueryScan *node)
V
Vadim B. Mikheev 已提交
491
{
492
	WRITE_NODE_TYPE("SUBQUERYSCAN");
M
 
Marc G. Fournier 已提交
493

494
	_outScanInfo(str, (Scan *) node);
M
 
Marc G. Fournier 已提交
495

496
	WRITE_NODE_FIELD(subplan);
V
Vadim B. Mikheev 已提交
497 498
}

499
static void
500
_outFunctionScan(StringInfo str, FunctionScan *node)
501
{
502
	WRITE_NODE_TYPE("FUNCTIONSCAN");
503

504
	_outScanInfo(str, (Scan *) node);
505 506 507
}

static void
508
_outJoin(StringInfo str, Join *node)
509
{
510
	WRITE_NODE_TYPE("JOIN");
511

512
	_outJoinPlanInfo(str, (Join *) node);
513 514 515
}

static void
516
_outNestLoop(StringInfo str, NestLoop *node)
517
{
518
	WRITE_NODE_TYPE("NESTLOOP");
519

520 521
	_outJoinPlanInfo(str, (Join *) node);
}
522

523 524 525 526
static void
_outMergeJoin(StringInfo str, MergeJoin *node)
{
	WRITE_NODE_TYPE("MERGEJOIN");
527

528
	_outJoinPlanInfo(str, (Join *) node);
V
Vadim B. Mikheev 已提交
529

530
	WRITE_NODE_FIELD(mergeclauses);
531 532
}

533
static void
534
_outHashJoin(StringInfo str, HashJoin *node)
535
{
536
	WRITE_NODE_TYPE("HASHJOIN");
537

538
	_outJoinPlanInfo(str, (Join *) node);
539

540 541
	WRITE_NODE_FIELD(hashclauses);
	WRITE_OID_FIELD(hashjoinop);
542 543
}

544
static void
545
_outAgg(StringInfo str, Agg *node)
546
{
547 548
	WRITE_NODE_TYPE("AGG");

549 550
	_outPlanInfo(str, (Plan *) node);

551 552 553
	WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
	WRITE_INT_FIELD(numCols);
	WRITE_LONG_FIELD(numGroups);
554 555
}

556
static void
557
_outGroup(StringInfo str, Group *node)
558
{
559 560
	WRITE_NODE_TYPE("GRP");

561 562
	_outPlanInfo(str, (Plan *) node);

563
	WRITE_INT_FIELD(numCols);
564 565
}

566 567 568
static void
_outMaterial(StringInfo str, Material *node)
{
569 570
	WRITE_NODE_TYPE("MATERIAL");

571 572 573
	_outPlanInfo(str, (Plan *) node);
}

574
static void
575
_outSort(StringInfo str, Sort *node)
576
{
577
	WRITE_NODE_TYPE("SORT");
578

579
	_outPlanInfo(str, (Plan *) node);
580

581
	WRITE_INT_FIELD(keycount);
582
}
583

584
static void
585
_outUnique(StringInfo str, Unique *node)
586
{
B
Bruce Momjian 已提交
587
	int			i;
588

589 590
	WRITE_NODE_TYPE("UNIQUE");

591 592
	_outPlanInfo(str, (Plan *) node);

593 594 595
	WRITE_INT_FIELD(numCols);

	appendStringInfo(str, " :uniqColIdx");
596
	for (i = 0; i < node->numCols; i++)
597
		appendStringInfo(str, " %d", node->uniqColIdx[i]);
598
}
599

600 601 602
static void
_outSetOp(StringInfo str, SetOp *node)
{
B
Bruce Momjian 已提交
603
	int			i;
604

605 606
	WRITE_NODE_TYPE("SETOP");

607 608
	_outPlanInfo(str, (Plan *) node);

609 610 611 612
	WRITE_ENUM_FIELD(cmd, SetOpCmd);
	WRITE_INT_FIELD(numCols);

	appendStringInfo(str, " :dupColIdx");
613
	for (i = 0; i < node->numCols; i++)
614 615 616
		appendStringInfo(str, " %d", node->dupColIdx[i]);

	WRITE_INT_FIELD(flagColIdx);
617 618
}

619 620 621
static void
_outLimit(StringInfo str, Limit *node)
{
622 623
	WRITE_NODE_TYPE("LIMIT");

624 625
	_outPlanInfo(str, (Plan *) node);

626 627
	WRITE_NODE_FIELD(limitOffset);
	WRITE_NODE_FIELD(limitCount);
628 629
}

630
static void
631
_outHash(StringInfo str, Hash *node)
632
{
633 634
	WRITE_NODE_TYPE("HASH");

635 636
	_outPlanInfo(str, (Plan *) node);

637 638 639 640 641 642 643 644 645 646 647 648 649 650
	WRITE_NODE_FIELD(hashkey);
}

static void
_outSubPlan(StringInfo str, SubPlan *node)
{
	WRITE_NODE_TYPE("SUBPLAN");

	WRITE_NODE_FIELD(plan);
	WRITE_INT_FIELD(plan_id);
	WRITE_NODE_FIELD(rtable);
	WRITE_INTLIST_FIELD(setParam);
	WRITE_INTLIST_FIELD(parParam);
	WRITE_NODE_FIELD(sublink);
651 652 653 654
}

/*****************************************************************************
 *
655
 *	Stuff from primnodes.h.
656 657 658 659
 *
 *****************************************************************************/

static void
660
_outResdom(StringInfo str, Resdom *node)
661
{
662
	WRITE_NODE_TYPE("RESDOM");
663

664 665 666 667 668 669 670 671
	WRITE_INT_FIELD(resno);
	WRITE_OID_FIELD(restype);
	WRITE_INT_FIELD(restypmod);
	WRITE_STRING_FIELD(resname);
	WRITE_UINT_FIELD(ressortgroupref);
	WRITE_UINT_FIELD(reskey);
	WRITE_OID_FIELD(reskeyop);
	WRITE_BOOL_FIELD(resjunk);
672 673 674
}

static void
675
_outExpr(StringInfo str, Expr *node)
676
{
677
	char	   *opstr = NULL;
678

679 680 681
	WRITE_NODE_TYPE("EXPR");

	WRITE_OID_FIELD(typeOid);
682

683
	/* do-it-yourself enum representation */
684 685
	switch (node->opType)
	{
686 687 688
		case OP_EXPR:
			opstr = "op";
			break;
689 690 691
		case DISTINCT_EXPR:
			opstr = "distinct";
			break;
692 693 694 695 696 697 698 699 700 701 702 703
		case FUNC_EXPR:
			opstr = "func";
			break;
		case OR_EXPR:
			opstr = "or";
			break;
		case AND_EXPR:
			opstr = "and";
			break;
		case NOT_EXPR:
			opstr = "not";
			break;
V
Vadim B. Mikheev 已提交
704 705 706
		case SUBPLAN_EXPR:
			opstr = "subp";
			break;
707
	}
708 709
	appendStringInfo(str, " :opType ");
	_outToken(str, opstr);
M
 
Marc G. Fournier 已提交
710

711 712
	WRITE_NODE_FIELD(oper);
	WRITE_NODE_FIELD(args);
713 714 715
}

static void
716
_outVar(StringInfo str, Var *node)
717
{
718
	WRITE_NODE_TYPE("VAR");
M
 
Marc G. Fournier 已提交
719

720 721 722 723 724 725 726
	WRITE_UINT_FIELD(varno);
	WRITE_INT_FIELD(varattno);
	WRITE_OID_FIELD(vartype);
	WRITE_INT_FIELD(vartypmod);
	WRITE_UINT_FIELD(varlevelsup);
	WRITE_UINT_FIELD(varnoold);
	WRITE_INT_FIELD(varoattno);
727 728 729
}

static void
730
_outConst(StringInfo str, Const *node)
731
{
732 733 734 735 736 737
	WRITE_NODE_TYPE("CONST");

	WRITE_OID_FIELD(consttype);
	WRITE_INT_FIELD(constlen);
	WRITE_BOOL_FIELD(constbyval);
	WRITE_BOOL_FIELD(constisnull);
M
 
Marc G. Fournier 已提交
738

739
	appendStringInfo(str, " :constvalue ");
740
	if (node->constisnull)
B
Bruce Momjian 已提交
741
		appendStringInfo(str, "<>");
742
	else
743
		_outDatum(str, node->constvalue, node->constlen, node->constbyval);
744 745 746
}

static void
747
_outAggref(StringInfo str, Aggref *node)
748
{
749
	WRITE_NODE_TYPE("AGGREF");
M
 
Marc G. Fournier 已提交
750

751 752 753 754 755 756
	WRITE_OID_FIELD(aggfnoid);
	WRITE_OID_FIELD(aggtype);
	WRITE_NODE_FIELD(target);
	WRITE_BOOL_FIELD(aggstar);
	WRITE_BOOL_FIELD(aggdistinct);
	/* aggno is not saved since it is just executor state */
757 758
}

759 760 761
static void
_outSubLink(StringInfo str, SubLink *node)
{
762
	WRITE_NODE_TYPE("SUBLINK");
M
 
Marc G. Fournier 已提交
763

764 765 766 767 768
	WRITE_ENUM_FIELD(subLinkType, SubLinkType);
	WRITE_BOOL_FIELD(useor);
	WRITE_NODE_FIELD(lefthand);
	WRITE_NODE_FIELD(oper);
	WRITE_NODE_FIELD(subselect);
769 770
}

771
static void
B
Bruce Momjian 已提交
772
_outArrayRef(StringInfo str, ArrayRef *node)
773
{
774
	WRITE_NODE_TYPE("ARRAYREF");
M
 
Marc G. Fournier 已提交
775

776 777 778 779 780 781 782 783 784
	WRITE_OID_FIELD(refrestype);
	WRITE_INT_FIELD(refattrlength);
	WRITE_INT_FIELD(refelemlength);
	WRITE_BOOL_FIELD(refelembyval);
	WRITE_CHAR_FIELD(refelemalign);
	WRITE_NODE_FIELD(refupperindexpr);
	WRITE_NODE_FIELD(reflowerindexpr);
	WRITE_NODE_FIELD(refexpr);
	WRITE_NODE_FIELD(refassgnexpr);
785 786 787
}

static void
788
_outFunc(StringInfo str, Func *node)
789
{
790 791 792 793 794 795
	WRITE_NODE_TYPE("FUNC");

	WRITE_OID_FIELD(funcid);
	WRITE_OID_FIELD(funcresulttype);
	WRITE_BOOL_FIELD(funcretset);
	WRITE_ENUM_FIELD(funcformat, CoercionForm);
796 797 798
}

static void
799
_outOper(StringInfo str, Oper *node)
800
{
801 802 803 804 805 806
	WRITE_NODE_TYPE("OPER");

	WRITE_OID_FIELD(opno);
	WRITE_OID_FIELD(opid);
	WRITE_OID_FIELD(opresulttype);
	WRITE_BOOL_FIELD(opretset);
807 808 809
}

static void
810
_outParam(StringInfo str, Param *node)
811
{
812 813 814 815 816 817
	WRITE_NODE_TYPE("PARAM");

	WRITE_INT_FIELD(paramkind);
	WRITE_INT_FIELD(paramid);
	WRITE_STRING_FIELD(paramname);
	WRITE_OID_FIELD(paramtype);
818 819
}

820 821 822
static void
_outFieldSelect(StringInfo str, FieldSelect *node)
{
823
	WRITE_NODE_TYPE("FIELDSELECT");
824

825 826 827 828
	WRITE_NODE_FIELD(arg);
	WRITE_INT_FIELD(fieldnum);
	WRITE_OID_FIELD(resulttype);
	WRITE_INT_FIELD(resulttypmod);
829 830 831 832 833
}

static void
_outRelabelType(StringInfo str, RelabelType *node)
{
834 835 836 837 838 839
	WRITE_NODE_TYPE("RELABELTYPE");

	WRITE_NODE_FIELD(arg);
	WRITE_OID_FIELD(resulttype);
	WRITE_INT_FIELD(resulttypmod);
	WRITE_ENUM_FIELD(relabelformat, CoercionForm);
840 841 842 843 844
}

static void
_outRangeTblRef(StringInfo str, RangeTblRef *node)
{
845 846 847
	WRITE_NODE_TYPE("RANGETBLREF");

	WRITE_INT_FIELD(rtindex);
848 849
}

850
static void
851
_outJoinExpr(StringInfo str, JoinExpr *node)
852
{
853 854 855 856 857 858 859 860 861 862
	WRITE_NODE_TYPE("JOINEXPR");

	WRITE_ENUM_FIELD(jointype, JoinType);
	WRITE_BOOL_FIELD(isNatural);
	WRITE_NODE_FIELD(larg);
	WRITE_NODE_FIELD(rarg);
	WRITE_NODE_FIELD(using);
	WRITE_NODE_FIELD(quals);
	WRITE_NODE_FIELD(alias);
	WRITE_INT_FIELD(rtindex);
863 864
}

865
static void
866
_outFromExpr(StringInfo str, FromExpr *node)
867
{
868 869 870 871
	WRITE_NODE_TYPE("FROMEXPR");

	WRITE_NODE_FIELD(fromlist);
	WRITE_NODE_FIELD(quals);
872 873
}

874
static void
875
_outTargetEntry(StringInfo str, TargetEntry *node)
876
{
877
	WRITE_NODE_TYPE("TARGETENTRY");
878

879 880 881
	WRITE_NODE_FIELD(resdom);
	/* fjoin not supported ... */
	WRITE_NODE_FIELD(expr);
882
}
883

884 885 886
static void
_outAlias(StringInfo str, Alias *node)
{
887 888 889 890
	WRITE_NODE_TYPE("ALIAS");

	WRITE_STRING_FIELD(aliasname);
	WRITE_NODE_FIELD(colnames);
891 892
}

893
static void
894
_outRangeTblEntry(StringInfo str, RangeTblEntry *node)
895
{
896 897
	WRITE_NODE_TYPE("RTE");

898
	/* put alias + eref first to make dump more legible */
899 900 901 902
	WRITE_NODE_FIELD(alias);
	WRITE_NODE_FIELD(eref);
	WRITE_ENUM_FIELD(rtekind, RTEKind);

903 904 905 906
	switch (node->rtekind)
	{
		case RTE_RELATION:
		case RTE_SPECIAL:
907
			WRITE_OID_FIELD(relid);
908 909
			break;
		case RTE_SUBQUERY:
910
			WRITE_NODE_FIELD(subquery);
911
			break;
912
		case RTE_FUNCTION:
913 914
			WRITE_NODE_FIELD(funcexpr);
			WRITE_NODE_FIELD(coldeflist);
915
			break;
916
		case RTE_JOIN:
917 918
			WRITE_ENUM_FIELD(jointype, JoinType);
			WRITE_NODE_FIELD(joinaliasvars);
919 920 921 922 923
			break;
		default:
			elog(ERROR, "bogus rte kind %d", (int) node->rtekind);
			break;
	}
924 925 926 927 928 929

	WRITE_BOOL_FIELD(inh);
	WRITE_BOOL_FIELD(inFromCl);
	WRITE_BOOL_FIELD(checkForRead);
	WRITE_BOOL_FIELD(checkForWrite);
	WRITE_OID_FIELD(checkAsUser);
930 931
}

932
/*
933
 * print the basic stuff of all nodes that inherit from Path
934 935
 */
static void
936
_outPathInfo(StringInfo str, Path *node)
937
{
938 939 940 941
	WRITE_ENUM_FIELD(pathtype, NodeTag);
	WRITE_FLOAT_FIELD(startup_cost, "%.2f");
	WRITE_FLOAT_FIELD(total_cost, "%.2f");
	WRITE_NODE_FIELD(pathkeys);
942 943 944
}

/*
945
 * print the basic stuff of all nodes that inherit from JoinPath
946 947
 */
static void
948
_outJoinPathInfo(StringInfo str, JoinPath *node)
949
{
950
	_outPathInfo(str, (Path *) node);
951

952 953 954 955 956
	WRITE_ENUM_FIELD(jointype, JoinType);
	WRITE_NODE_FIELD(outerjoinpath);
	WRITE_NODE_FIELD(innerjoinpath);
	WRITE_NODE_FIELD(joinrestrictinfo);
}
957

958 959 960 961
static void
_outPath(StringInfo str, Path *node)
{
	WRITE_NODE_TYPE("PATH");
962

963
	_outPathInfo(str, (Path *) node);
964 965
}

966
/*
967
 *	IndexPath is a subclass of Path.
968
 */
969 970 971 972 973 974 975 976 977 978 979 980 981
static void
_outIndexPath(StringInfo str, IndexPath *node)
{
	WRITE_NODE_TYPE("INDEXPATH");

	_outPathInfo(str, (Path *) node);

	WRITE_NODE_FIELD(indexinfo);
	WRITE_NODE_FIELD(indexqual);
	WRITE_ENUM_FIELD(indexscandir, ScanDirection);
	WRITE_FLOAT_FIELD(rows, "%.2f");
}

982 983 984
static void
_outTidPath(StringInfo str, TidPath *node)
{
985
	WRITE_NODE_TYPE("TIDPATH");
986

987
	_outPathInfo(str, (Path *) node);
988

989 990
	WRITE_NODE_FIELD(tideval);
	WRITE_INTLIST_FIELD(unjoined_relids);
991 992
}

993 994 995
static void
_outAppendPath(StringInfo str, AppendPath *node)
{
996 997 998
	WRITE_NODE_TYPE("APPENDPATH");

	_outPathInfo(str, (Path *) node);
999

1000
	WRITE_NODE_FIELD(subpaths);
1001 1002
}

1003 1004 1005
static void
_outResultPath(StringInfo str, ResultPath *node)
{
1006
	WRITE_NODE_TYPE("RESULTPATH");
1007

1008
	_outPathInfo(str, (Path *) node);
1009

1010 1011
	WRITE_NODE_FIELD(subpath);
	WRITE_NODE_FIELD(constantqual);
1012 1013
}

1014
static void
1015
_outNestPath(StringInfo str, NestPath *node)
1016
{
1017 1018 1019
	WRITE_NODE_TYPE("NESTPATH");

	_outJoinPathInfo(str, (JoinPath *) node);
1020 1021 1022
}

static void
1023
_outMergePath(StringInfo str, MergePath *node)
1024
{
1025
	WRITE_NODE_TYPE("MERGEPATH");
1026

1027
	_outJoinPathInfo(str, (JoinPath *) node);
1028

1029 1030 1031
	WRITE_NODE_FIELD(path_mergeclauses);
	WRITE_NODE_FIELD(outersortkeys);
	WRITE_NODE_FIELD(innersortkeys);
1032 1033 1034
}

static void
1035
_outHashPath(StringInfo str, HashPath *node)
1036
{
1037 1038 1039
	WRITE_NODE_TYPE("HASHPATH");

	_outJoinPathInfo(str, (JoinPath *) node);
1040

1041
	WRITE_NODE_FIELD(path_hashclauses);
1042 1043 1044
}

static void
1045
_outPathKeyItem(StringInfo str, PathKeyItem *node)
1046
{
1047 1048 1049 1050
	WRITE_NODE_TYPE("PATHKEYITEM");

	WRITE_NODE_FIELD(key);
	WRITE_OID_FIELD(sortop);
1051 1052 1053
}

static void
1054
_outRestrictInfo(StringInfo str, RestrictInfo *node)
1055
{
1056
	WRITE_NODE_TYPE("RESTRICTINFO");
1057

1058 1059 1060 1061 1062 1063 1064
	WRITE_NODE_FIELD(clause);
	WRITE_BOOL_FIELD(ispusheddown);
	WRITE_NODE_FIELD(subclauseindices);
	WRITE_OID_FIELD(mergejoinoperator);
	WRITE_OID_FIELD(left_sortop);
	WRITE_OID_FIELD(right_sortop);
	WRITE_OID_FIELD(hashjoinoperator);
1065 1066 1067
}

static void
1068
_outJoinInfo(StringInfo str, JoinInfo *node)
1069
{
1070
	WRITE_NODE_TYPE("JOININFO");
1071

1072 1073
	WRITE_INTLIST_FIELD(unjoined_relids);
	WRITE_NODE_FIELD(jinfo_restrictinfo);
1074 1075 1076 1077 1078 1079
}

/*
 * Print the value of a Datum given its type.
 */
static void
1080
_outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
1081
{
1082 1083
	Size		length,
				i;
1084
	char	   *s;
1085

1086
	length = datumGetSize(value, typbyval, typlen);
1087

1088
	if (typbyval)
1089 1090
	{
		s = (char *) (&value);
1091
		appendStringInfo(str, "%u [ ", (unsigned int) length);
1092
		for (i = 0; i < (Size) sizeof(Datum); i++)
1093
			appendStringInfo(str, "%d ", (int) (s[i]));
1094
		appendStringInfo(str, "]");
1095
	}
1096
	else
1097
	{
1098 1099
		s = (char *) DatumGetPointer(value);
		if (!PointerIsValid(s))
1100
			appendStringInfo(str, "0 [ ]");
1101 1102
		else
		{
1103
			appendStringInfo(str, "%u [ ", (unsigned int) length);
1104
			for (i = 0; i < length; i++)
1105
				appendStringInfo(str, "%d ", (int) (s[i]));
1106
			appendStringInfo(str, "]");
1107
		}
1108 1109 1110
	}
}

1111 1112 1113
static void
_outAExpr(StringInfo str, A_Expr *node)
{
1114 1115
	WRITE_NODE_TYPE("AEXPR");

1116 1117 1118
	switch (node->oper)
	{
		case AND:
1119
			appendStringInfo(str, " AND");
1120 1121
			break;
		case OR:
1122
			appendStringInfo(str, " OR");
1123 1124
			break;
		case NOT:
1125
			appendStringInfo(str, " NOT");
1126
			break;
1127
		case OP:
1128
			appendStringInfo(str, " ");
1129
			WRITE_NODE_FIELD(name);
1130
			break;
1131
		default:
1132
			appendStringInfo(str, " ??");
1133
			break;
1134
	}
1135 1136 1137

	WRITE_NODE_FIELD(lexpr);
	WRITE_NODE_FIELD(rexpr);
1138 1139
}

1140
static void
1141
_outValue(StringInfo str, Value *value)
1142
{
1143 1144
	switch (value->type)
	{
1145
		case T_Integer:
1146
			appendStringInfo(str, "%ld", value->val.ival);
1147 1148
			break;
		case T_Float:
1149 1150 1151 1152

			/*
			 * We assume the value is a valid numeric literal and so does
			 * not need quoting.
1153
			 */
1154
			appendStringInfo(str, "%s", value->val.str);
1155 1156
			break;
		case T_String:
1157
			appendStringInfoChar(str, '"');
1158
			_outToken(str, value->val.str);
1159
			appendStringInfoChar(str, '"');
1160
			break;
1161
		case T_BitString:
1162
			/* internal representation already has leading 'b' */
1163
			appendStringInfo(str, "%s", value->val.str);
1164
			break;
1165
		default:
1166
			elog(WARNING, "_outValue: don't know how to print type %d",
1167
				 value->type);
1168
			break;
1169
	}
1170 1171
}

1172
static void
1173
_outRangeVar(StringInfo str, RangeVar *node)
1174
{
1175
	WRITE_NODE_TYPE("RANGEVAR");
B
Bruce Momjian 已提交
1176

1177 1178 1179 1180
	/*
	 * we deliberately ignore catalogname here, since it is presently not
	 * semantically meaningful
	 */
1181 1182 1183 1184 1185
	WRITE_STRING_FIELD(schemaname);
	WRITE_STRING_FIELD(relname);
	WRITE_ENUM_FIELD(inhOpt, InhOption);
	WRITE_BOOL_FIELD(istemp);
	WRITE_NODE_FIELD(alias);
1186 1187
}

1188
static void
1189
_outColumnRef(StringInfo str, ColumnRef *node)
1190
{
1191 1192 1193 1194
	WRITE_NODE_TYPE("COLUMNREF");

	WRITE_NODE_FIELD(fields);
	WRITE_NODE_FIELD(indirection);
1195 1196 1197 1198 1199
}

static void
_outParamRef(StringInfo str, ParamRef *node)
{
1200 1201 1202 1203 1204
	WRITE_NODE_TYPE("PARAMREF");

	WRITE_INT_FIELD(number);
	WRITE_NODE_FIELD(fields);
	WRITE_NODE_FIELD(indirection);
1205 1206
}

1207 1208 1209
static void
_outAConst(StringInfo str, A_Const *node)
{
1210 1211
	WRITE_NODE_TYPE("CONST ");

1212
	_outValue(str, &(node->val));
1213
	WRITE_NODE_FIELD(typename);
1214 1215
}

1216 1217 1218
static void
_outExprFieldSelect(StringInfo str, ExprFieldSelect *node)
{
1219 1220 1221 1222 1223
	WRITE_NODE_TYPE("EXPRFIELDSELECT");

	WRITE_NODE_FIELD(arg);
	WRITE_NODE_FIELD(fields);
	WRITE_NODE_FIELD(indirection);
1224 1225
}

T
Thomas G. Lockhart 已提交
1226 1227 1228
static void
_outConstraint(StringInfo str, Constraint *node)
{
1229 1230 1231
	WRITE_NODE_TYPE("CONSTRAINT");

	WRITE_STRING_FIELD(name);
T
Thomas G. Lockhart 已提交
1232

1233
	appendStringInfo(str, " :contype ");
T
Thomas G. Lockhart 已提交
1234 1235 1236
	switch (node->contype)
	{
		case CONSTR_PRIMARY:
1237 1238
			appendStringInfo(str, "PRIMARY_KEY");
			WRITE_NODE_FIELD(keys);
T
Thomas G. Lockhart 已提交
1239 1240 1241
			break;

		case CONSTR_CHECK:
1242 1243 1244
			appendStringInfo(str, "CHECK");
			WRITE_NODE_FIELD(raw_expr);
			WRITE_STRING_FIELD(cooked_expr);
T
Thomas G. Lockhart 已提交
1245 1246 1247
			break;

		case CONSTR_DEFAULT:
1248 1249 1250
			appendStringInfo(str, "DEFAULT");
			WRITE_NODE_FIELD(raw_expr);
			WRITE_STRING_FIELD(cooked_expr);
T
Thomas G. Lockhart 已提交
1251 1252 1253
			break;

		case CONSTR_NOTNULL:
1254
			appendStringInfo(str, "NOT_NULL");
T
Thomas G. Lockhart 已提交
1255 1256 1257
			break;

		case CONSTR_UNIQUE:
1258 1259
			appendStringInfo(str, "UNIQUE");
			WRITE_NODE_FIELD(keys);
T
Thomas G. Lockhart 已提交
1260 1261 1262
			break;

		default:
1263
			appendStringInfo(str, "<unrecognized_constraint>");
T
Thomas G. Lockhart 已提交
1264 1265 1266 1267
			break;
	}
}

1268 1269 1270
static void
_outFkConstraint(StringInfo str, FkConstraint *node)
{
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
	WRITE_NODE_TYPE("FKCONSTRAINT");

	WRITE_STRING_FIELD(constr_name);
	WRITE_NODE_FIELD(pktable);
	WRITE_NODE_FIELD(fk_attrs);
	WRITE_NODE_FIELD(pk_attrs);
	WRITE_CHAR_FIELD(fk_matchtype);
	WRITE_CHAR_FIELD(fk_upd_action);
	WRITE_CHAR_FIELD(fk_del_action);
	WRITE_BOOL_FIELD(deferrable);
	WRITE_BOOL_FIELD(initdeferred);
	WRITE_BOOL_FIELD(skip_validation);
1283 1284
}

T
Thomas G. Lockhart 已提交
1285
static void
1286
_outCaseExpr(StringInfo str, CaseExpr *node)
T
Thomas G. Lockhart 已提交
1287
{
1288
	WRITE_NODE_TYPE("CASE");
M
 
Marc G. Fournier 已提交
1289

1290 1291 1292 1293
	WRITE_OID_FIELD(casetype);
	WRITE_NODE_FIELD(arg);
	WRITE_NODE_FIELD(args);
	WRITE_NODE_FIELD(defresult);
T
Thomas G. Lockhart 已提交
1294 1295 1296
}

static void
1297
_outCaseWhen(StringInfo str, CaseWhen *node)
T
Thomas G. Lockhart 已提交
1298
{
1299
	WRITE_NODE_TYPE("WHEN");
M
 
Marc G. Fournier 已提交
1300

1301 1302
	WRITE_NODE_FIELD(expr);
	WRITE_NODE_FIELD(result);
T
Thomas G. Lockhart 已提交
1303 1304
}

1305 1306 1307
static void
_outNullTest(StringInfo str, NullTest *node)
{
1308 1309 1310 1311
	WRITE_NODE_TYPE("NULLTEST");

	WRITE_NODE_FIELD(arg);
	WRITE_ENUM_FIELD(nulltesttype, NullTestType);
1312 1313 1314 1315 1316
}

static void
_outBooleanTest(StringInfo str, BooleanTest *node)
{
1317 1318 1319 1320
	WRITE_NODE_TYPE("BOOLEANTEST");

	WRITE_NODE_FIELD(arg);
	WRITE_ENUM_FIELD(booltesttype, BoolTestType);
1321 1322
}

1323 1324 1325
static void
_outConstraintTest(StringInfo str, ConstraintTest *node)
{
1326 1327 1328 1329 1330 1331 1332
	WRITE_NODE_TYPE("CONSTRAINTTEST");

	WRITE_NODE_FIELD(arg);
	WRITE_ENUM_FIELD(testtype, ConstraintTestType);
	WRITE_STRING_FIELD(name);
	WRITE_STRING_FIELD(domname);
	WRITE_NODE_FIELD(check_expr);
1333 1334
}

B
Bruce Momjian 已提交
1335
static void
1336
_outDomainConstraintValue(StringInfo str, DomainConstraintValue *node)
B
Bruce Momjian 已提交
1337
{
1338
	WRITE_NODE_TYPE("DOMAINCONSTRAINTVALUE");
B
Bruce Momjian 已提交
1339 1340 1341
}

static void
1342
_outConstraintTestValue(StringInfo str, ConstraintTestValue *node)
B
Bruce Momjian 已提交
1343
{
1344 1345 1346 1347
	WRITE_NODE_TYPE("CONSTRAINTTESTVALUE");

	WRITE_OID_FIELD(typeId);
	WRITE_INT_FIELD(typeMod);
B
Bruce Momjian 已提交
1348 1349
}

1350

1351 1352
/*
 * _outNode -
1353
 *	  converts a Node into ascii string and append it to 'str'
1354 1355 1356 1357
 */
static void
_outNode(StringInfo str, void *obj)
{
1358 1359
	if (obj == NULL)
	{
B
Bruce Momjian 已提交
1360
		appendStringInfo(str, "<>");
1361 1362
		return;
	}
1363

1364
	if (IsA(obj, List))
1365
	{
1366
		List	   *l;
1367

1368
		appendStringInfoChar(str, '(');
1369 1370 1371 1372
		foreach(l, (List *) obj)
		{
			_outNode(str, lfirst(l));
			if (lnext(l))
1373
				appendStringInfoChar(str, ' ');
1374
		}
1375
		appendStringInfoChar(str, ')');
1376
	}
1377 1378 1379 1380
	else if (IsA(obj, Integer) ||
			 IsA(obj, Float) ||
			 IsA(obj, String) ||
			 IsA(obj, BitString))
1381 1382 1383 1384
	{
		/* nodeRead does not want to see { } around these! */
		_outValue(str, obj);
	}
1385 1386
	else
	{
1387
		appendStringInfoChar(str, '{');
1388 1389
		switch (nodeTag(obj))
		{
1390 1391 1392 1393 1394 1395
			case T_CreateStmt:
				_outCreateStmt(str, obj);
				break;
			case T_IndexStmt:
				_outIndexStmt(str, obj);
				break;
1396 1397 1398 1399 1400 1401
			case T_NotifyStmt:
				_outNotifyStmt(str, obj);
				break;
			case T_SelectStmt:
				_outSelectStmt(str, obj);
				break;
1402 1403 1404
			case T_ColumnDef:
				_outColumnDef(str, obj);
				break;
1405 1406 1407
			case T_TypeName:
				_outTypeName(str, obj);
				break;
1408 1409 1410
			case T_TypeCast:
				_outTypeCast(str, obj);
				break;
1411 1412 1413
			case T_IndexElem:
				_outIndexElem(str, obj);
				break;
1414 1415 1416
			case T_Query:
				_outQuery(str, obj);
				break;
1417 1418 1419 1420 1421
			case T_SortClause:
				_outSortClause(str, obj);
				break;
			case T_GroupClause:
				_outGroupClause(str, obj);
1422
				break;
1423 1424 1425
			case T_SetOperationStmt:
				_outSetOperationStmt(str, obj);
				break;
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455
			case T_Plan:
				_outPlan(str, obj);
				break;
			case T_Result:
				_outResult(str, obj);
				break;
			case T_Append:
				_outAppend(str, obj);
				break;
			case T_Join:
				_outJoin(str, obj);
				break;
			case T_NestLoop:
				_outNestLoop(str, obj);
				break;
			case T_MergeJoin:
				_outMergeJoin(str, obj);
				break;
			case T_HashJoin:
				_outHashJoin(str, obj);
				break;
			case T_Scan:
				_outScan(str, obj);
				break;
			case T_SeqScan:
				_outSeqScan(str, obj);
				break;
			case T_IndexScan:
				_outIndexScan(str, obj);
				break;
1456 1457 1458
			case T_TidScan:
				_outTidScan(str, obj);
				break;
1459 1460 1461
			case T_SubqueryScan:
				_outSubqueryScan(str, obj);
				break;
1462 1463 1464
			case T_FunctionScan:
				_outFunctionScan(str, obj);
				break;
1465 1466 1467
			case T_Material:
				_outMaterial(str, obj);
				break;
1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479
			case T_Sort:
				_outSort(str, obj);
				break;
			case T_Agg:
				_outAgg(str, obj);
				break;
			case T_Group:
				_outGroup(str, obj);
				break;
			case T_Unique:
				_outUnique(str, obj);
				break;
1480 1481 1482
			case T_SetOp:
				_outSetOp(str, obj);
				break;
1483 1484 1485
			case T_Limit:
				_outLimit(str, obj);
				break;
1486 1487 1488
			case T_Hash:
				_outHash(str, obj);
				break;
V
Vadim B. Mikheev 已提交
1489 1490 1491
			case T_SubPlan:
				_outSubPlan(str, obj);
				break;
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503
			case T_Resdom:
				_outResdom(str, obj);
				break;
			case T_Expr:
				_outExpr(str, obj);
				break;
			case T_Var:
				_outVar(str, obj);
				break;
			case T_Const:
				_outConst(str, obj);
				break;
B
Bruce Momjian 已提交
1504 1505
			case T_Aggref:
				_outAggref(str, obj);
1506
				break;
1507 1508 1509
			case T_SubLink:
				_outSubLink(str, obj);
				break;
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521
			case T_ArrayRef:
				_outArrayRef(str, obj);
				break;
			case T_Func:
				_outFunc(str, obj);
				break;
			case T_Oper:
				_outOper(str, obj);
				break;
			case T_Param:
				_outParam(str, obj);
				break;
1522 1523 1524 1525 1526 1527 1528 1529 1530
			case T_FieldSelect:
				_outFieldSelect(str, obj);
				break;
			case T_RelabelType:
				_outRelabelType(str, obj);
				break;
			case T_RangeTblRef:
				_outRangeTblRef(str, obj);
				break;
1531 1532 1533
			case T_FromExpr:
				_outFromExpr(str, obj);
				break;
1534 1535 1536
			case T_JoinExpr:
				_outJoinExpr(str, obj);
				break;
1537 1538 1539
			case T_TargetEntry:
				_outTargetEntry(str, obj);
				break;
1540 1541 1542
			case T_Alias:
				_outAlias(str, obj);
				break;
1543 1544 1545 1546 1547 1548 1549 1550 1551
			case T_RangeTblEntry:
				_outRangeTblEntry(str, obj);
				break;
			case T_Path:
				_outPath(str, obj);
				break;
			case T_IndexPath:
				_outIndexPath(str, obj);
				break;
1552 1553 1554
			case T_TidPath:
				_outTidPath(str, obj);
				break;
1555 1556 1557
			case T_AppendPath:
				_outAppendPath(str, obj);
				break;
1558 1559 1560
			case T_ResultPath:
				_outResultPath(str, obj);
				break;
1561 1562
			case T_NestPath:
				_outNestPath(str, obj);
1563 1564 1565 1566 1567 1568 1569
				break;
			case T_MergePath:
				_outMergePath(str, obj);
				break;
			case T_HashPath:
				_outHashPath(str, obj);
				break;
1570 1571
			case T_PathKeyItem:
				_outPathKeyItem(str, obj);
1572
				break;
1573 1574
			case T_RestrictInfo:
				_outRestrictInfo(str, obj);
1575
				break;
1576 1577
			case T_JoinInfo:
				_outJoinInfo(str, obj);
1578
				break;
1579 1580 1581
			case T_A_Expr:
				_outAExpr(str, obj);
				break;
1582 1583 1584 1585 1586 1587 1588 1589 1590
			case T_RangeVar:
				_outRangeVar(str, obj);
				break;
			case T_ColumnRef:
				_outColumnRef(str, obj);
				break;
			case T_ParamRef:
				_outParamRef(str, obj);
				break;
1591 1592 1593
			case T_A_Const:
				_outAConst(str, obj);
				break;
1594 1595 1596
			case T_ExprFieldSelect:
				_outExprFieldSelect(str, obj);
				break;
T
Thomas G. Lockhart 已提交
1597 1598 1599
			case T_Constraint:
				_outConstraint(str, obj);
				break;
1600 1601 1602
			case T_FkConstraint:
				_outFkConstraint(str, obj);
				break;
T
Thomas G. Lockhart 已提交
1603 1604 1605 1606 1607 1608
			case T_CaseExpr:
				_outCaseExpr(str, obj);
				break;
			case T_CaseWhen:
				_outCaseWhen(str, obj);
				break;
1609 1610 1611 1612 1613 1614
			case T_NullTest:
				_outNullTest(str, obj);
				break;
			case T_BooleanTest:
				_outBooleanTest(str, obj);
				break;
1615 1616 1617
			case T_ConstraintTest:
				_outConstraintTest(str, obj);
				break;
B
Bruce Momjian 已提交
1618 1619 1620
			case T_ConstraintTestValue:
				_outConstraintTestValue(str, obj);
				break;
1621 1622 1623
			case T_FuncCall:
				_outFuncCall(str, obj);
				break;
B
Bruce Momjian 已提交
1624 1625 1626
			case T_DomainConstraintValue:
				_outDomainConstraintValue(str, obj);
				break;
1627

1628
			default:
1629
				elog(WARNING, "_outNode: don't know how to print type %d",
1630 1631
					 nodeTag(obj));
				break;
1632
		}
1633
		appendStringInfoChar(str, '}');
1634 1635 1636 1637 1638
	}
}

/*
 * nodeToString -
1639
 *	   returns the ascii representation of the Node as a palloc'd string
1640
 */
1641
char *
1642 1643
nodeToString(void *obj)
{
B
Bruce Momjian 已提交
1644
	StringInfoData str;
1645

1646 1647 1648 1649
	/* see stringinfo.h for an explanation of this maneuver */
	initStringInfo(&str);
	_outNode(&str, obj);
	return str.data;
1650
}