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.191 2003/01/09 20:50:50 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
	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);
661 662
	WRITE_BOOL_FIELD(operIsEquals);
	WRITE_BOOL_FIELD(useOr);
663 664 665 666 667 668
	WRITE_NODE_FIELD(lefthand);
	WRITE_NODE_FIELD(oper);
	WRITE_NODE_FIELD(subselect);
}

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

673
	WRITE_ENUM_FIELD(subLinkType, SubLinkType);
674
	WRITE_BOOL_FIELD(useOr);
675
	WRITE_NODE_FIELD(oper);
676 677 678 679 680 681
	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);
682 683
}

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

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

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

	WRITE_NODE_FIELD(arg);
	WRITE_OID_FIELD(resulttype);
	WRITE_INT_FIELD(resulttypmod);
	WRITE_ENUM_FIELD(relabelformat, CoercionForm);
704 705 706
}

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

711 712 713 714
	WRITE_OID_FIELD(casetype);
	WRITE_NODE_FIELD(arg);
	WRITE_NODE_FIELD(args);
	WRITE_NODE_FIELD(defresult);
715 716
}

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

722 723
	WRITE_NODE_FIELD(expr);
	WRITE_NODE_FIELD(result);
724 725
}

726
static void
727
_outNullTest(StringInfo str, NullTest *node)
728
{
729
	WRITE_NODE_TYPE("NULLTEST");
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 761 762
	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);
763 764
}

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

770 771
	WRITE_NODE_FIELD(resdom);
	WRITE_NODE_FIELD(expr);
772
}
773

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

779
	WRITE_INT_FIELD(rtindex);
780 781
}

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

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

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

802 803
	WRITE_NODE_FIELD(fromlist);
	WRITE_NODE_FIELD(quals);
804 805
}

806 807 808 809 810 811
/*****************************************************************************
 *
 *	Stuff from relation.h.
 *
 *****************************************************************************/

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

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

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

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

845
	_outPathInfo(str, (Path *) node);
846 847
}

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

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

869
	_outPathInfo(str, (Path *) node);
870

871
	WRITE_NODE_FIELD(tideval);
872 873
}

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

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

881
	WRITE_NODE_FIELD(subpaths);
882 883
}

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

889
	_outPathInfo(str, (Path *) node);
890

891 892
	WRITE_NODE_FIELD(subpath);
	WRITE_NODE_FIELD(constantqual);
893 894
}

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

	_outPathInfo(str, (Path *) node);

	WRITE_NODE_FIELD(subpath);
}

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

	_outJoinPathInfo(str, (JoinPath *) node);
911 912 913
}

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

918
	_outJoinPathInfo(str, (JoinPath *) node);
919

920 921 922
	WRITE_NODE_FIELD(path_mergeclauses);
	WRITE_NODE_FIELD(outersortkeys);
	WRITE_NODE_FIELD(innersortkeys);
923 924 925
}

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

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

932
	WRITE_NODE_FIELD(path_hashclauses);
933 934 935
}

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

	WRITE_NODE_FIELD(key);
	WRITE_OID_FIELD(sortop);
942 943 944
}

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

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

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

963 964
	WRITE_INTLIST_FIELD(unjoined_relids);
	WRITE_NODE_FIELD(jinfo_restrictinfo);
965 966
}

967 968 969 970 971 972
/*****************************************************************************
 *
 *	Stuff from parsenodes.h.
 *
 *****************************************************************************/

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

978 979 980 981 982 983 984
	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);
}
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 1094 1095
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)
1096
	{
1097
		switch (nodeTag(node->utilityStmt))
1098
		{
1099 1100 1101 1102 1103 1104 1105 1106
			case T_CreateStmt:
			case T_IndexStmt:
			case T_NotifyStmt:
				WRITE_NODE_FIELD(utilityStmt);
				break;
			default:
				appendStringInfo(str, " :utilityStmt ?");
				break;
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 1199 1200
	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);
1201 1202
}

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

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

	WRITE_NODE_FIELD(lexpr);
	WRITE_NODE_FIELD(rexpr);
1230 1231
}

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

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

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

	WRITE_NODE_FIELD(fields);
	WRITE_NODE_FIELD(indirection);
1271 1272 1273 1274 1275
}

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

	WRITE_INT_FIELD(number);
	WRITE_NODE_FIELD(fields);
	WRITE_NODE_FIELD(indirection);
1281 1282
}

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

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

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

	WRITE_NODE_FIELD(arg);
	WRITE_NODE_FIELD(fields);
	WRITE_NODE_FIELD(indirection);
1300 1301
}

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

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

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

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

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

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

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

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

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

1361

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

1375
	if (IsA(obj, List))
1376
	{
1377
		List	   *l;
1378

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

1543 1544 1545 1546 1547 1548
			case T_Path:
				_outPath(str, obj);
				break;
			case T_IndexPath:
				_outIndexPath(str, obj);
				break;
1549 1550 1551
			case T_TidPath:
				_outTidPath(str, obj);
				break;
1552 1553 1554
			case T_AppendPath:
				_outAppendPath(str, obj);
				break;
1555 1556 1557
			case T_ResultPath:
				_outResultPath(str, obj);
				break;
1558 1559 1560
			case T_MaterialPath:
				_outMaterialPath(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 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 1617 1618

			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;
1619 1620 1621
			case T_A_Expr:
				_outAExpr(str, obj);
				break;
1622 1623 1624 1625 1626 1627
			case T_ColumnRef:
				_outColumnRef(str, obj);
				break;
			case T_ParamRef:
				_outParamRef(str, obj);
				break;
1628 1629 1630
			case T_A_Const:
				_outAConst(str, obj);
				break;
1631 1632 1633
			case T_ExprFieldSelect:
				_outExprFieldSelect(str, obj);
				break;
T
Thomas G. Lockhart 已提交
1634 1635 1636
			case T_Constraint:
				_outConstraint(str, obj);
				break;
1637 1638 1639
			case T_FkConstraint:
				_outFkConstraint(str, obj);
				break;
1640 1641 1642 1643
			case T_FuncCall:
				_outFuncCall(str, obj);
				break;

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

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

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