outfuncs.c 33.6 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.189 2002/12/13 19:45:56 tgl Exp $
12 13
 *
 * NOTES
14 15 16
 *	  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
17
 *	  functions for nodes that appear in raw parsetrees, path, and plan trees.
18 19 20
 *	  These nodes however need not have input functions.
 *
 *-------------------------------------------------------------------------
21
 */
22
#include "postgres.h"
23

24 25
#include <ctype.h>

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

33

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
/*
 * 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))


100 101
#define booltostr(x)  ((x) ? "true" : "false")

102
static void _outNode(StringInfo str, void *obj);
103

104

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
/*
 * _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;
	}
120

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

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

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

160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
/*
 * _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, ')');
}

175 176 177
/*
 * Print the value of a Datum given its type.
 */
178
static void
179
_outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
180
{
181 182 183
	Size		length,
				i;
	char	   *s;
184

185
	length = datumGetSize(value, typbyval, typlen);
186

187
	if (typbyval)
188
	{
189 190 191 192 193 194 195 196 197 198 199 200
		s = (char *) (&value);
		appendStringInfo(str, "%u [ ", (unsigned int) length);
		for (i = 0; i < (Size) sizeof(Datum); i++)
			appendStringInfo(str, "%d ", (int) (s[i]));
		appendStringInfo(str, "]");
	}
	else
	{
		s = (char *) DatumGetPointer(value);
		if (!PointerIsValid(s))
			appendStringInfo(str, "0 [ ]");
		else
201
		{
202 203 204 205
			appendStringInfo(str, "%u [ ", (unsigned int) length);
			for (i = 0; i < length; i++)
				appendStringInfo(str, "%d ", (int) (s[i]));
			appendStringInfo(str, "]");
206 207
		}
	}
208 209
}

210

211 212 213 214
/*
 *	Stuff from plannodes.h
 */

215 216 217 218
/*
 * print the basic stuff of all nodes that inherit from Plan
 */
static void
219
_outPlanInfo(StringInfo str, Plan *node)
220
{
221 222 223 224 225 226 227 228
	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);
229
	WRITE_NODE_FIELD(initPlan);
230 231 232 233
	WRITE_INTLIST_FIELD(extParam);
	WRITE_INTLIST_FIELD(locParam);
	WRITE_INT_FIELD(nParamExec);
}
M
 
Marc G. Fournier 已提交
234

235 236 237 238 239 240 241
/*
 * 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 已提交
242

243
	WRITE_UINT_FIELD(scanrelid);
244 245 246
}

/*
247
 * print the basic stuff of all nodes that inherit from Join
248
 */
249 250 251 252 253 254 255 256 257 258
static void
_outJoinPlanInfo(StringInfo str, Join *node)
{
	_outPlanInfo(str, (Plan *) node);

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


259
static void
260
_outPlan(StringInfo str, Plan *node)
261
{
262 263
	WRITE_NODE_TYPE("PLAN");

264
	_outPlanInfo(str, (Plan *) node);
265 266 267
}

static void
268
_outResult(StringInfo str, Result *node)
269
{
270
	WRITE_NODE_TYPE("RESULT");
271

272
	_outPlanInfo(str, (Plan *) node);
273

274
	WRITE_NODE_FIELD(resconstantqual);
275 276 277
}

static void
B
Bruce Momjian 已提交
278
_outAppend(StringInfo str, Append *node)
279
{
280
	WRITE_NODE_TYPE("APPEND");
281

282
	_outPlanInfo(str, (Plan *) node);
283

284 285
	WRITE_NODE_FIELD(appendplans);
	WRITE_BOOL_FIELD(isTarget);
286 287 288
}

static void
289
_outScan(StringInfo str, Scan *node)
290
{
291 292 293
	WRITE_NODE_TYPE("SCAN");

	_outScanInfo(str, (Scan *) node);
294 295 296
}

static void
297
_outSeqScan(StringInfo str, SeqScan *node)
298
{
299 300 301
	WRITE_NODE_TYPE("SEQSCAN");

	_outScanInfo(str, (Scan *) node);
302 303 304
}

static void
305
_outIndexScan(StringInfo str, IndexScan *node)
306
{
307
	WRITE_NODE_TYPE("INDEXSCAN");
308

309 310 311 312 313 314
	_outScanInfo(str, (Scan *) node);

	WRITE_OIDLIST_FIELD(indxid);
	WRITE_NODE_FIELD(indxqual);
	WRITE_NODE_FIELD(indxqualorig);
	WRITE_ENUM_FIELD(indxorderdir, ScanDirection);
315 316 317
}

static void
318
_outTidScan(StringInfo str, TidScan *node)
319
{
320 321 322
	WRITE_NODE_TYPE("TIDSCAN");

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

324
	WRITE_NODE_FIELD(tideval);
325 326
}

V
Vadim B. Mikheev 已提交
327
static void
328
_outSubqueryScan(StringInfo str, SubqueryScan *node)
V
Vadim B. Mikheev 已提交
329
{
330
	WRITE_NODE_TYPE("SUBQUERYSCAN");
M
 
Marc G. Fournier 已提交
331

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

334
	WRITE_NODE_FIELD(subplan);
V
Vadim B. Mikheev 已提交
335 336
}

337
static void
338
_outFunctionScan(StringInfo str, FunctionScan *node)
339
{
340
	WRITE_NODE_TYPE("FUNCTIONSCAN");
341

342
	_outScanInfo(str, (Scan *) node);
343 344 345
}

static void
346
_outJoin(StringInfo str, Join *node)
347
{
348
	WRITE_NODE_TYPE("JOIN");
349

350
	_outJoinPlanInfo(str, (Join *) node);
351 352 353
}

static void
354
_outNestLoop(StringInfo str, NestLoop *node)
355
{
356
	WRITE_NODE_TYPE("NESTLOOP");
357

358 359
	_outJoinPlanInfo(str, (Join *) node);
}
360

361 362 363 364
static void
_outMergeJoin(StringInfo str, MergeJoin *node)
{
	WRITE_NODE_TYPE("MERGEJOIN");
365

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

368
	WRITE_NODE_FIELD(mergeclauses);
369 370
}

371
static void
372
_outHashJoin(StringInfo str, HashJoin *node)
373
{
374
	WRITE_NODE_TYPE("HASHJOIN");
375

376
	_outJoinPlanInfo(str, (Join *) node);
377

378
	WRITE_NODE_FIELD(hashclauses);
379 380
}

381
static void
382
_outAgg(StringInfo str, Agg *node)
383
{
384 385
	WRITE_NODE_TYPE("AGG");

386 387
	_outPlanInfo(str, (Plan *) node);

388 389 390
	WRITE_ENUM_FIELD(aggstrategy, AggStrategy);
	WRITE_INT_FIELD(numCols);
	WRITE_LONG_FIELD(numGroups);
391 392
}

393
static void
394
_outGroup(StringInfo str, Group *node)
395
{
396 397
	WRITE_NODE_TYPE("GRP");

398 399
	_outPlanInfo(str, (Plan *) node);

400
	WRITE_INT_FIELD(numCols);
401 402
}

403 404 405
static void
_outMaterial(StringInfo str, Material *node)
{
406 407
	WRITE_NODE_TYPE("MATERIAL");

408 409 410
	_outPlanInfo(str, (Plan *) node);
}

411
static void
412
_outSort(StringInfo str, Sort *node)
413
{
414
	WRITE_NODE_TYPE("SORT");
415

416
	_outPlanInfo(str, (Plan *) node);
417

418
	WRITE_INT_FIELD(keycount);
419
}
420

421
static void
422
_outUnique(StringInfo str, Unique *node)
423
{
B
Bruce Momjian 已提交
424
	int			i;
425

426 427
	WRITE_NODE_TYPE("UNIQUE");

428 429
	_outPlanInfo(str, (Plan *) node);

430 431 432
	WRITE_INT_FIELD(numCols);

	appendStringInfo(str, " :uniqColIdx");
433
	for (i = 0; i < node->numCols; i++)
434
		appendStringInfo(str, " %d", node->uniqColIdx[i]);
435
}
436

437 438 439
static void
_outSetOp(StringInfo str, SetOp *node)
{
B
Bruce Momjian 已提交
440
	int			i;
441

442 443
	WRITE_NODE_TYPE("SETOP");

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

446 447 448 449
	WRITE_ENUM_FIELD(cmd, SetOpCmd);
	WRITE_INT_FIELD(numCols);

	appendStringInfo(str, " :dupColIdx");
450
	for (i = 0; i < node->numCols; i++)
451 452 453
		appendStringInfo(str, " %d", node->dupColIdx[i]);

	WRITE_INT_FIELD(flagColIdx);
454 455
}

456 457 458
static void
_outLimit(StringInfo str, Limit *node)
{
459 460
	WRITE_NODE_TYPE("LIMIT");

461 462
	_outPlanInfo(str, (Plan *) node);

463 464
	WRITE_NODE_FIELD(limitOffset);
	WRITE_NODE_FIELD(limitCount);
465 466
}

467
static void
468
_outHash(StringInfo str, Hash *node)
469
{
470 471
	WRITE_NODE_TYPE("HASH");

472 473
	_outPlanInfo(str, (Plan *) node);

474
	WRITE_NODE_FIELD(hashkeys);
475 476
}

477 478
/*****************************************************************************
 *
479
 *	Stuff from primnodes.h.
480 481 482 483
 *
 *****************************************************************************/

static void
484
_outResdom(StringInfo str, Resdom *node)
485
{
486
	WRITE_NODE_TYPE("RESDOM");
487

488 489 490 491 492 493 494 495
	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);
496 497 498
}

static void
499
_outAlias(StringInfo str, Alias *node)
500
{
501
	WRITE_NODE_TYPE("ALIAS");
M
 
Marc G. Fournier 已提交
502

503 504
	WRITE_STRING_FIELD(aliasname);
	WRITE_NODE_FIELD(colnames);
505 506 507
}

static void
508
_outRangeVar(StringInfo str, RangeVar *node)
509
{
510
	WRITE_NODE_TYPE("RANGEVAR");
M
 
Marc G. Fournier 已提交
511

512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
	/*
	 * we deliberately ignore catalogname here, since it is presently not
	 * semantically meaningful
	 */
	WRITE_STRING_FIELD(schemaname);
	WRITE_STRING_FIELD(relname);
	WRITE_ENUM_FIELD(inhOpt, InhOption);
	WRITE_BOOL_FIELD(istemp);
	WRITE_NODE_FIELD(alias);
}

static void
_outVar(StringInfo str, Var *node)
{
	WRITE_NODE_TYPE("VAR");

	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);
535 536 537
}

static void
538
_outConst(StringInfo str, Const *node)
539
{
540 541 542 543 544 545
	WRITE_NODE_TYPE("CONST");

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

547
	appendStringInfo(str, " :constvalue ");
548
	if (node->constisnull)
B
Bruce Momjian 已提交
549
		appendStringInfo(str, "<>");
550
	else
551
		_outDatum(str, node->constvalue, node->constlen, node->constbyval);
552 553
}

554 555 556 557 558 559 560 561 562 563 564
static void
_outParam(StringInfo str, Param *node)
{
	WRITE_NODE_TYPE("PARAM");

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

565
static void
566
_outAggref(StringInfo str, Aggref *node)
567
{
568
	WRITE_NODE_TYPE("AGGREF");
M
 
Marc G. Fournier 已提交
569

570 571 572 573 574
	WRITE_OID_FIELD(aggfnoid);
	WRITE_OID_FIELD(aggtype);
	WRITE_NODE_FIELD(target);
	WRITE_BOOL_FIELD(aggstar);
	WRITE_BOOL_FIELD(aggdistinct);
575 576
}

577
static void
B
Bruce Momjian 已提交
578
_outArrayRef(StringInfo str, ArrayRef *node)
579
{
580
	WRITE_NODE_TYPE("ARRAYREF");
M
 
Marc G. Fournier 已提交
581

582 583 584 585 586 587 588 589 590
	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);
591 592 593
}

static void
594
_outFuncExpr(StringInfo str, FuncExpr *node)
595
{
596
	WRITE_NODE_TYPE("FUNCEXPR");
597 598 599 600 601

	WRITE_OID_FIELD(funcid);
	WRITE_OID_FIELD(funcresulttype);
	WRITE_BOOL_FIELD(funcretset);
	WRITE_ENUM_FIELD(funcformat, CoercionForm);
602 603 604 605 606 607 608 609 610 611 612 613 614
	WRITE_NODE_FIELD(args);
}

static void
_outOpExpr(StringInfo str, OpExpr *node)
{
	WRITE_NODE_TYPE("OPEXPR");

	WRITE_OID_FIELD(opno);
	WRITE_OID_FIELD(opfuncid);
	WRITE_OID_FIELD(opresulttype);
	WRITE_BOOL_FIELD(opretset);
	WRITE_NODE_FIELD(args);
615 616 617
}

static void
618
_outDistinctExpr(StringInfo str, DistinctExpr *node)
619
{
620
	WRITE_NODE_TYPE("DISTINCTEXPR");
621 622

	WRITE_OID_FIELD(opno);
623
	WRITE_OID_FIELD(opfuncid);
624 625
	WRITE_OID_FIELD(opresulttype);
	WRITE_BOOL_FIELD(opretset);
626
	WRITE_NODE_FIELD(args);
627 628 629
}

static void
630
_outBoolExpr(StringInfo str, BoolExpr *node)
631
{
632
	char	   *opstr = NULL;
633

634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
	WRITE_NODE_TYPE("BOOLEXPR");

	/* do-it-yourself enum representation */
	switch (node->boolop)
	{
		case AND_EXPR:
			opstr = "and";
			break;
		case OR_EXPR:
			opstr = "or";
			break;
		case NOT_EXPR:
			opstr = "not";
			break;
	}
	appendStringInfo(str, " :boolop ");
	_outToken(str, opstr);

	WRITE_NODE_FIELD(args);
}

static void
_outSubLink(StringInfo str, SubLink *node)
{
	WRITE_NODE_TYPE("SUBLINK");

	WRITE_ENUM_FIELD(subLinkType, SubLinkType);
	WRITE_BOOL_FIELD(useor);
	WRITE_NODE_FIELD(lefthand);
	WRITE_NODE_FIELD(oper);
	WRITE_NODE_FIELD(subselect);
}

static void
_outSubPlanExpr(StringInfo str, SubPlanExpr *node)
{
	WRITE_NODE_TYPE("SUBPLANEXPR");

	WRITE_OID_FIELD(typeOid);
	WRITE_NODE_FIELD(plan);
	WRITE_INT_FIELD(plan_id);
	WRITE_NODE_FIELD(rtable);
	WRITE_INTLIST_FIELD(setParam);
	WRITE_INTLIST_FIELD(parParam);
	WRITE_NODE_FIELD(args);
	WRITE_NODE_FIELD(sublink);
680 681
}

682 683 684
static void
_outFieldSelect(StringInfo str, FieldSelect *node)
{
685
	WRITE_NODE_TYPE("FIELDSELECT");
686

687 688 689 690
	WRITE_NODE_FIELD(arg);
	WRITE_INT_FIELD(fieldnum);
	WRITE_OID_FIELD(resulttype);
	WRITE_INT_FIELD(resulttypmod);
691 692 693 694 695
}

static void
_outRelabelType(StringInfo str, RelabelType *node)
{
696 697 698 699 700 701
	WRITE_NODE_TYPE("RELABELTYPE");

	WRITE_NODE_FIELD(arg);
	WRITE_OID_FIELD(resulttype);
	WRITE_INT_FIELD(resulttypmod);
	WRITE_ENUM_FIELD(relabelformat, CoercionForm);
702 703 704
}

static void
705
_outCaseExpr(StringInfo str, CaseExpr *node)
706
{
707
	WRITE_NODE_TYPE("CASE");
708

709 710 711 712
	WRITE_OID_FIELD(casetype);
	WRITE_NODE_FIELD(arg);
	WRITE_NODE_FIELD(args);
	WRITE_NODE_FIELD(defresult);
713 714
}

715
static void
716
_outCaseWhen(StringInfo str, CaseWhen *node)
717
{
718
	WRITE_NODE_TYPE("WHEN");
719

720 721
	WRITE_NODE_FIELD(expr);
	WRITE_NODE_FIELD(result);
722 723
}

724
static void
725
_outNullTest(StringInfo str, NullTest *node)
726
{
727
	WRITE_NODE_TYPE("NULLTEST");
728

729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
	WRITE_NODE_FIELD(arg);
	WRITE_ENUM_FIELD(nulltesttype, NullTestType);
}

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

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

static void
_outConstraintTest(StringInfo str, ConstraintTest *node)
{
	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);
}

static void
_outConstraintTestValue(StringInfo str, ConstraintTestValue *node)
{
	WRITE_NODE_TYPE("CONSTRAINTTESTVALUE");

	WRITE_OID_FIELD(typeId);
	WRITE_INT_FIELD(typeMod);
761 762
}

763
static void
764
_outTargetEntry(StringInfo str, TargetEntry *node)
765
{
766
	WRITE_NODE_TYPE("TARGETENTRY");
767

768 769
	WRITE_NODE_FIELD(resdom);
	WRITE_NODE_FIELD(expr);
770
}
771

772
static void
773
_outRangeTblRef(StringInfo str, RangeTblRef *node)
774
{
775
	WRITE_NODE_TYPE("RANGETBLREF");
776

777
	WRITE_INT_FIELD(rtindex);
778 779
}

780
static void
781
_outJoinExpr(StringInfo str, JoinExpr *node)
782
{
783
	WRITE_NODE_TYPE("JOINEXPR");
784

785 786 787 788 789 790
	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);
791
	WRITE_NODE_FIELD(alias);
792 793
	WRITE_INT_FIELD(rtindex);
}
794

795 796 797 798
static void
_outFromExpr(StringInfo str, FromExpr *node)
{
	WRITE_NODE_TYPE("FROMEXPR");
799

800 801
	WRITE_NODE_FIELD(fromlist);
	WRITE_NODE_FIELD(quals);
802 803
}

804 805 806 807 808 809
/*****************************************************************************
 *
 *	Stuff from relation.h.
 *
 *****************************************************************************/

810
/*
811
 * print the basic stuff of all nodes that inherit from Path
812 813
 *
 * Note we do NOT print the parent, else we'd be in infinite recursion
814 815
 */
static void
816
_outPathInfo(StringInfo str, Path *node)
817
{
818 819 820 821
	WRITE_ENUM_FIELD(pathtype, NodeTag);
	WRITE_FLOAT_FIELD(startup_cost, "%.2f");
	WRITE_FLOAT_FIELD(total_cost, "%.2f");
	WRITE_NODE_FIELD(pathkeys);
822 823 824
}

/*
825
 * print the basic stuff of all nodes that inherit from JoinPath
826 827
 */
static void
828
_outJoinPathInfo(StringInfo str, JoinPath *node)
829
{
830
	_outPathInfo(str, (Path *) node);
831

832 833 834 835 836
	WRITE_ENUM_FIELD(jointype, JoinType);
	WRITE_NODE_FIELD(outerjoinpath);
	WRITE_NODE_FIELD(innerjoinpath);
	WRITE_NODE_FIELD(joinrestrictinfo);
}
837

838 839 840 841
static void
_outPath(StringInfo str, Path *node)
{
	WRITE_NODE_TYPE("PATH");
842

843
	_outPathInfo(str, (Path *) node);
844 845
}

846
/*
847
 *	IndexPath is a subclass of Path.
848
 */
849 850 851 852 853 854 855 856 857 858 859 860 861
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");
}

862 863 864
static void
_outTidPath(StringInfo str, TidPath *node)
{
865
	WRITE_NODE_TYPE("TIDPATH");
866

867
	_outPathInfo(str, (Path *) node);
868

869
	WRITE_NODE_FIELD(tideval);
870 871
}

872 873 874
static void
_outAppendPath(StringInfo str, AppendPath *node)
{
875 876 877
	WRITE_NODE_TYPE("APPENDPATH");

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

879
	WRITE_NODE_FIELD(subpaths);
880 881
}

882 883 884
static void
_outResultPath(StringInfo str, ResultPath *node)
{
885
	WRITE_NODE_TYPE("RESULTPATH");
886

887
	_outPathInfo(str, (Path *) node);
888

889 890
	WRITE_NODE_FIELD(subpath);
	WRITE_NODE_FIELD(constantqual);
891 892
}

893 894 895 896 897 898 899 900 901 902
static void
_outMaterialPath(StringInfo str, MaterialPath *node)
{
	WRITE_NODE_TYPE("MATERIALPATH");

	_outPathInfo(str, (Path *) node);

	WRITE_NODE_FIELD(subpath);
}

903
static void
904
_outNestPath(StringInfo str, NestPath *node)
905
{
906 907 908
	WRITE_NODE_TYPE("NESTPATH");

	_outJoinPathInfo(str, (JoinPath *) node);
909 910 911
}

static void
912
_outMergePath(StringInfo str, MergePath *node)
913
{
914
	WRITE_NODE_TYPE("MERGEPATH");
915

916
	_outJoinPathInfo(str, (JoinPath *) node);
917

918 919 920
	WRITE_NODE_FIELD(path_mergeclauses);
	WRITE_NODE_FIELD(outersortkeys);
	WRITE_NODE_FIELD(innersortkeys);
921 922 923
}

static void
924
_outHashPath(StringInfo str, HashPath *node)
925
{
926 927 928
	WRITE_NODE_TYPE("HASHPATH");

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

930
	WRITE_NODE_FIELD(path_hashclauses);
931 932 933
}

static void
934
_outPathKeyItem(StringInfo str, PathKeyItem *node)
935
{
936 937 938 939
	WRITE_NODE_TYPE("PATHKEYITEM");

	WRITE_NODE_FIELD(key);
	WRITE_OID_FIELD(sortop);
940 941 942
}

static void
943
_outRestrictInfo(StringInfo str, RestrictInfo *node)
944
{
945
	WRITE_NODE_TYPE("RESTRICTINFO");
946

947 948 949 950 951 952 953
	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);
954 955 956
}

static void
957
_outJoinInfo(StringInfo str, JoinInfo *node)
958
{
959
	WRITE_NODE_TYPE("JOININFO");
960

961 962
	WRITE_INTLIST_FIELD(unjoined_relids);
	WRITE_NODE_FIELD(jinfo_restrictinfo);
963 964
}

965 966 967 968 969 970
/*****************************************************************************
 *
 *	Stuff from parsenodes.h.
 *
 *****************************************************************************/

971
static void
972
_outCreateStmt(StringInfo str, CreateStmt *node)
973
{
974
	WRITE_NODE_TYPE("CREATE");
975

976 977 978 979 980 981 982
	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);
}
983

984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
static void
_outIndexStmt(StringInfo str, IndexStmt *node)
{
	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);
}

static void
_outNotifyStmt(StringInfo str, NotifyStmt *node)
{
	WRITE_NODE_TYPE("NOTIFY");

	WRITE_NODE_FIELD(relation);
}

static void
_outSelectStmt(StringInfo str, SelectStmt *node)
{
	WRITE_NODE_TYPE("SELECT");

	/* XXX this is pretty durn incomplete */
	WRITE_NODE_FIELD(whereClause);
}

static void
_outFuncCall(StringInfo str, FuncCall *node)
{
	WRITE_NODE_TYPE("FUNCCALL");

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

static void
_outColumnDef(StringInfo str, ColumnDef *node)
{
	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);
}

static void
_outTypeName(StringInfo str, TypeName *node)
{
	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);
}

static void
_outTypeCast(StringInfo str, TypeCast *node)
{
	WRITE_NODE_TYPE("TYPECAST");

	WRITE_NODE_FIELD(arg);
	WRITE_NODE_FIELD(typename);
}

static void
_outIndexElem(StringInfo str, IndexElem *node)
{
	WRITE_NODE_TYPE("INDEXELEM");

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

static void
_outQuery(StringInfo str, Query *node)
{
	WRITE_NODE_TYPE("QUERY");

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

	/*
	 * Hack to work around missing outfuncs routines for a lot of the
	 * 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.
	 */
	if (node->utilityStmt)
1094
	{
1095
		switch (nodeTag(node->utilityStmt))
1096
		{
1097 1098 1099 1100 1101 1102 1103 1104
			case T_CreateStmt:
			case T_IndexStmt:
			case T_NotifyStmt:
				WRITE_NODE_FIELD(utilityStmt);
				break;
			default:
				appendStringInfo(str, " :utilityStmt ?");
				break;
1105
		}
1106
	}
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
	else
		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);

	/* planner-internal fields are not written out */
}

static void
_outSortClause(StringInfo str, SortClause *node)
{
	WRITE_NODE_TYPE("SORTCLAUSE");

	WRITE_UINT_FIELD(tleSortGroupRef);
	WRITE_OID_FIELD(sortop);
}

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

	WRITE_UINT_FIELD(tleSortGroupRef);
	WRITE_OID_FIELD(sortop);
}

static void
_outSetOperationStmt(StringInfo str, SetOperationStmt *node)
{
	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);
}

static void
_outRangeTblEntry(StringInfo str, RangeTblEntry *node)
{
	WRITE_NODE_TYPE("RTE");

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

	switch (node->rtekind)
	{
		case RTE_RELATION:
		case RTE_SPECIAL:
			WRITE_OID_FIELD(relid);
			break;
		case RTE_SUBQUERY:
			WRITE_NODE_FIELD(subquery);
			break;
		case RTE_FUNCTION:
			WRITE_NODE_FIELD(funcexpr);
			WRITE_NODE_FIELD(coldeflist);
			break;
		case RTE_JOIN:
			WRITE_ENUM_FIELD(jointype, JoinType);
			WRITE_NODE_FIELD(joinaliasvars);
			break;
		default:
			elog(ERROR, "bogus rte kind %d", (int) node->rtekind);
			break;
	}

	WRITE_BOOL_FIELD(inh);
	WRITE_BOOL_FIELD(inFromCl);
	WRITE_BOOL_FIELD(checkForRead);
	WRITE_BOOL_FIELD(checkForWrite);
	WRITE_OID_FIELD(checkAsUser);
1199 1200
}

1201 1202 1203
static void
_outAExpr(StringInfo str, A_Expr *node)
{
1204 1205
	WRITE_NODE_TYPE("AEXPR");

1206 1207 1208
	switch (node->oper)
	{
		case AND:
1209
			appendStringInfo(str, " AND");
1210 1211
			break;
		case OR:
1212
			appendStringInfo(str, " OR");
1213 1214
			break;
		case NOT:
1215
			appendStringInfo(str, " NOT");
1216
			break;
1217
		case OP:
1218
			appendStringInfo(str, " ");
1219
			WRITE_NODE_FIELD(name);
1220
			break;
1221
		default:
1222
			appendStringInfo(str, " ??");
1223
			break;
1224
	}
1225 1226 1227

	WRITE_NODE_FIELD(lexpr);
	WRITE_NODE_FIELD(rexpr);
1228 1229
}

1230
static void
1231
_outValue(StringInfo str, Value *value)
1232
{
1233 1234
	switch (value->type)
	{
1235
		case T_Integer:
1236
			appendStringInfo(str, "%ld", value->val.ival);
1237 1238
			break;
		case T_Float:
1239 1240 1241 1242

			/*
			 * We assume the value is a valid numeric literal and so does
			 * not need quoting.
1243
			 */
1244
			appendStringInfo(str, "%s", value->val.str);
1245 1246
			break;
		case T_String:
1247
			appendStringInfoChar(str, '"');
1248
			_outToken(str, value->val.str);
1249
			appendStringInfoChar(str, '"');
1250
			break;
1251
		case T_BitString:
1252
			/* internal representation already has leading 'b' */
1253
			appendStringInfo(str, "%s", value->val.str);
1254
			break;
1255
		default:
1256
			elog(WARNING, "_outValue: don't know how to print type %d",
1257
				 value->type);
1258
			break;
1259
	}
1260 1261
}

1262
static void
1263
_outColumnRef(StringInfo str, ColumnRef *node)
1264
{
1265 1266 1267 1268
	WRITE_NODE_TYPE("COLUMNREF");

	WRITE_NODE_FIELD(fields);
	WRITE_NODE_FIELD(indirection);
1269 1270 1271 1272 1273
}

static void
_outParamRef(StringInfo str, ParamRef *node)
{
1274 1275 1276 1277 1278
	WRITE_NODE_TYPE("PARAMREF");

	WRITE_INT_FIELD(number);
	WRITE_NODE_FIELD(fields);
	WRITE_NODE_FIELD(indirection);
1279 1280
}

1281 1282 1283
static void
_outAConst(StringInfo str, A_Const *node)
{
1284 1285
	WRITE_NODE_TYPE("CONST ");

1286
	_outValue(str, &(node->val));
1287
	WRITE_NODE_FIELD(typename);
1288 1289
}

1290 1291 1292
static void
_outExprFieldSelect(StringInfo str, ExprFieldSelect *node)
{
1293 1294 1295 1296 1297
	WRITE_NODE_TYPE("EXPRFIELDSELECT");

	WRITE_NODE_FIELD(arg);
	WRITE_NODE_FIELD(fields);
	WRITE_NODE_FIELD(indirection);
1298 1299
}

T
Thomas G. Lockhart 已提交
1300 1301 1302
static void
_outConstraint(StringInfo str, Constraint *node)
{
1303 1304 1305
	WRITE_NODE_TYPE("CONSTRAINT");

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

1307
	appendStringInfo(str, " :contype ");
T
Thomas G. Lockhart 已提交
1308 1309 1310
	switch (node->contype)
	{
		case CONSTR_PRIMARY:
1311 1312
			appendStringInfo(str, "PRIMARY_KEY");
			WRITE_NODE_FIELD(keys);
T
Thomas G. Lockhart 已提交
1313 1314 1315
			break;

		case CONSTR_CHECK:
1316 1317 1318
			appendStringInfo(str, "CHECK");
			WRITE_NODE_FIELD(raw_expr);
			WRITE_STRING_FIELD(cooked_expr);
T
Thomas G. Lockhart 已提交
1319 1320 1321
			break;

		case CONSTR_DEFAULT:
1322 1323 1324
			appendStringInfo(str, "DEFAULT");
			WRITE_NODE_FIELD(raw_expr);
			WRITE_STRING_FIELD(cooked_expr);
T
Thomas G. Lockhart 已提交
1325 1326 1327
			break;

		case CONSTR_NOTNULL:
1328
			appendStringInfo(str, "NOT_NULL");
T
Thomas G. Lockhart 已提交
1329 1330 1331
			break;

		case CONSTR_UNIQUE:
1332 1333
			appendStringInfo(str, "UNIQUE");
			WRITE_NODE_FIELD(keys);
T
Thomas G. Lockhart 已提交
1334 1335 1336
			break;

		default:
1337
			appendStringInfo(str, "<unrecognized_constraint>");
T
Thomas G. Lockhart 已提交
1338 1339 1340 1341
			break;
	}
}

1342 1343 1344
static void
_outFkConstraint(StringInfo str, FkConstraint *node)
{
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
	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);
1357 1358
}

1359

1360 1361
/*
 * _outNode -
1362
 *	  converts a Node into ascii string and append it to 'str'
1363 1364 1365 1366
 */
static void
_outNode(StringInfo str, void *obj)
{
1367 1368
	if (obj == NULL)
	{
B
Bruce Momjian 已提交
1369
		appendStringInfo(str, "<>");
1370 1371
		return;
	}
1372

1373
	if (IsA(obj, List))
1374
	{
1375
		List	   *l;
1376

1377
		appendStringInfoChar(str, '(');
1378 1379 1380 1381
		foreach(l, (List *) obj)
		{
			_outNode(str, lfirst(l));
			if (lnext(l))
1382
				appendStringInfoChar(str, ' ');
1383
		}
1384
		appendStringInfoChar(str, ')');
1385
	}
1386 1387 1388 1389
	else if (IsA(obj, Integer) ||
			 IsA(obj, Float) ||
			 IsA(obj, String) ||
			 IsA(obj, BitString))
1390 1391 1392 1393
	{
		/* nodeRead does not want to see { } around these! */
		_outValue(str, obj);
	}
1394 1395
	else
	{
1396
		appendStringInfoChar(str, '{');
1397 1398
		switch (nodeTag(obj))
		{
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416
			case T_Plan:
				_outPlan(str, obj);
				break;
			case T_Result:
				_outResult(str, obj);
				break;
			case T_Append:
				_outAppend(str, obj);
				break;
			case T_Scan:
				_outScan(str, obj);
				break;
			case T_SeqScan:
				_outSeqScan(str, obj);
				break;
			case T_IndexScan:
				_outIndexScan(str, obj);
				break;
1417 1418 1419
			case T_TidScan:
				_outTidScan(str, obj);
				break;
1420 1421 1422
			case T_SubqueryScan:
				_outSubqueryScan(str, obj);
				break;
1423 1424 1425
			case T_FunctionScan:
				_outFunctionScan(str, obj);
				break;
1426 1427
			case T_Join:
				_outJoin(str, obj);
1428
				break;
1429 1430 1431 1432 1433 1434 1435 1436
			case T_NestLoop:
				_outNestLoop(str, obj);
				break;
			case T_MergeJoin:
				_outMergeJoin(str, obj);
				break;
			case T_HashJoin:
				_outHashJoin(str, obj);
1437 1438 1439 1440 1441 1442 1443
				break;
			case T_Agg:
				_outAgg(str, obj);
				break;
			case T_Group:
				_outGroup(str, obj);
				break;
1444 1445 1446 1447 1448 1449
			case T_Material:
				_outMaterial(str, obj);
				break;
			case T_Sort:
				_outSort(str, obj);
				break;
1450 1451 1452
			case T_Unique:
				_outUnique(str, obj);
				break;
1453 1454 1455
			case T_SetOp:
				_outSetOp(str, obj);
				break;
1456 1457 1458
			case T_Limit:
				_outLimit(str, obj);
				break;
1459 1460 1461 1462 1463 1464
			case T_Hash:
				_outHash(str, obj);
				break;
			case T_Resdom:
				_outResdom(str, obj);
				break;
1465 1466 1467 1468 1469
			case T_Alias:
				_outAlias(str, obj);
				break;
			case T_RangeVar:
				_outRangeVar(str, obj);
1470 1471 1472 1473 1474 1475 1476
				break;
			case T_Var:
				_outVar(str, obj);
				break;
			case T_Const:
				_outConst(str, obj);
				break;
1477 1478 1479
			case T_Param:
				_outParam(str, obj);
				break;
B
Bruce Momjian 已提交
1480 1481
			case T_Aggref:
				_outAggref(str, obj);
1482 1483 1484 1485
				break;
			case T_ArrayRef:
				_outArrayRef(str, obj);
				break;
1486 1487
			case T_FuncExpr:
				_outFuncExpr(str, obj);
1488
				break;
1489 1490
			case T_OpExpr:
				_outOpExpr(str, obj);
1491
				break;
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502
			case T_DistinctExpr:
				_outDistinctExpr(str, obj);
				break;
			case T_BoolExpr:
				_outBoolExpr(str, obj);
				break;
			case T_SubLink:
				_outSubLink(str, obj);
				break;
			case T_SubPlanExpr:
				_outSubPlanExpr(str, obj);
1503
				break;
1504 1505 1506 1507 1508 1509
			case T_FieldSelect:
				_outFieldSelect(str, obj);
				break;
			case T_RelabelType:
				_outRelabelType(str, obj);
				break;
1510 1511
			case T_CaseExpr:
				_outCaseExpr(str, obj);
1512
				break;
1513 1514
			case T_CaseWhen:
				_outCaseWhen(str, obj);
1515
				break;
1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526
			case T_NullTest:
				_outNullTest(str, obj);
				break;
			case T_BooleanTest:
				_outBooleanTest(str, obj);
				break;
			case T_ConstraintTest:
				_outConstraintTest(str, obj);
				break;
			case T_ConstraintTestValue:
				_outConstraintTestValue(str, obj);
1527
				break;
1528 1529 1530
			case T_TargetEntry:
				_outTargetEntry(str, obj);
				break;
1531 1532
			case T_RangeTblRef:
				_outRangeTblRef(str, obj);
1533
				break;
1534 1535 1536 1537 1538
			case T_JoinExpr:
				_outJoinExpr(str, obj);
				break;
			case T_FromExpr:
				_outFromExpr(str, obj);
1539
				break;
1540

1541 1542 1543 1544 1545 1546
			case T_Path:
				_outPath(str, obj);
				break;
			case T_IndexPath:
				_outIndexPath(str, obj);
				break;
1547 1548 1549
			case T_TidPath:
				_outTidPath(str, obj);
				break;
1550 1551 1552
			case T_AppendPath:
				_outAppendPath(str, obj);
				break;
1553 1554 1555
			case T_ResultPath:
				_outResultPath(str, obj);
				break;
1556 1557 1558
			case T_MaterialPath:
				_outMaterialPath(str, obj);
				break;
1559 1560
			case T_NestPath:
				_outNestPath(str, obj);
1561 1562 1563 1564 1565 1566 1567
				break;
			case T_MergePath:
				_outMergePath(str, obj);
				break;
			case T_HashPath:
				_outHashPath(str, obj);
				break;
1568 1569
			case T_PathKeyItem:
				_outPathKeyItem(str, obj);
1570
				break;
1571 1572
			case T_RestrictInfo:
				_outRestrictInfo(str, obj);
1573
				break;
1574 1575
			case T_JoinInfo:
				_outJoinInfo(str, obj);
1576
				break;
1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616

			case T_CreateStmt:
				_outCreateStmt(str, obj);
				break;
			case T_IndexStmt:
				_outIndexStmt(str, obj);
				break;
			case T_NotifyStmt:
				_outNotifyStmt(str, obj);
				break;
			case T_SelectStmt:
				_outSelectStmt(str, obj);
				break;
			case T_ColumnDef:
				_outColumnDef(str, obj);
				break;
			case T_TypeName:
				_outTypeName(str, obj);
				break;
			case T_TypeCast:
				_outTypeCast(str, obj);
				break;
			case T_IndexElem:
				_outIndexElem(str, obj);
				break;
			case T_Query:
				_outQuery(str, obj);
				break;
			case T_SortClause:
				_outSortClause(str, obj);
				break;
			case T_GroupClause:
				_outGroupClause(str, obj);
				break;
			case T_SetOperationStmt:
				_outSetOperationStmt(str, obj);
				break;
			case T_RangeTblEntry:
				_outRangeTblEntry(str, obj);
				break;
1617 1618 1619
			case T_A_Expr:
				_outAExpr(str, obj);
				break;
1620 1621 1622 1623 1624 1625
			case T_ColumnRef:
				_outColumnRef(str, obj);
				break;
			case T_ParamRef:
				_outParamRef(str, obj);
				break;
1626 1627 1628
			case T_A_Const:
				_outAConst(str, obj);
				break;
1629 1630 1631
			case T_ExprFieldSelect:
				_outExprFieldSelect(str, obj);
				break;
T
Thomas G. Lockhart 已提交
1632 1633 1634
			case T_Constraint:
				_outConstraint(str, obj);
				break;
1635 1636 1637
			case T_FkConstraint:
				_outFkConstraint(str, obj);
				break;
1638 1639 1640 1641
			case T_FuncCall:
				_outFuncCall(str, obj);
				break;

1642
			default:
1643
				elog(WARNING, "_outNode: don't know how to print type %d",
1644 1645
					 nodeTag(obj));
				break;
1646
		}
1647
		appendStringInfoChar(str, '}');
1648 1649 1650 1651 1652
	}
}

/*
 * nodeToString -
1653
 *	   returns the ascii representation of the Node as a palloc'd string
1654
 */
1655
char *
1656 1657
nodeToString(void *obj)
{
B
Bruce Momjian 已提交
1658
	StringInfoData str;
1659

1660 1661 1662 1663
	/* see stringinfo.h for an explanation of this maneuver */
	initStringInfo(&str);
	_outNode(&str, obj);
	return str.data;
1664
}