outfuncs.c 35.8 KB
Newer Older
1 2 3
/*-------------------------------------------------------------------------
 *
 * outfuncs.c--
4
 *	  routines to convert a node to ascii representation
5 6 7 8 9
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
10
 *	  $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.8 1997/09/08 02:23:41 momjian Exp $
11 12
 *
 * NOTES
13 14 15 16 17
 *	  Every (plan) node in POSTGRES has an associated "out" routine which
 *	  knows how to create its ascii representation. These functions are
 *	  useful for debugging as well as for storing plans in the system
 *	  catalogs (eg. indexes). This is also the plan string sent out in
 *	  Mariposa.
18
 *
19 20 21
 *	  These functions update the in/out argument of type StringInfo
 *	  passed to them. This argument contains the string holding the ASCII
 *	  representation plus some other information (string length, etc.)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
 *
 *-------------------------------------------------------------------------
 */
#include <stdio.h>
#include "postgres.h"

#include "access/heapam.h"
#include "access/htup.h"
#include "utils/syscache.h"
#include "utils/lsyscache.h"
#include "fmgr.h"
#include "utils/elog.h"
#include "utils/datum.h"
#include "utils/palloc.h"

#include "nodes/nodes.h"
#include "nodes/execnodes.h"
#include "nodes/pg_list.h"
#include "nodes/plannodes.h"
#include "nodes/parsenodes.h"
#include "nodes/primnodes.h"
#include "nodes/relation.h"

#include "catalog/pg_type.h"
#include "lib/stringinfo.h"

48 49
static void _outDatum(StringInfo str, Datum value, Oid type);
static void _outNode(StringInfo str, void *obj);
50 51 52

/*
 * _outIntList -
53
 *	   converts a List of integers
54
 */
55
static void
56
_outIntList(StringInfo str, List * list)
57
{
58 59
	List	   *l;
	char		buf[500];
60

61 62 63 64 65 66 67
	appendStringInfo(str, "(");
	foreach(l, list)
	{
		sprintf(buf, "%d ", (int) lfirst(l));
		appendStringInfo(str, buf);
	}
	appendStringInfo(str, ")");
68 69 70
}

static void
71
_outQuery(StringInfo str, Query * node)
72
{
73
	char		buf[500];
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 102 103 104 105 106

	sprintf(buf, "QUERY");
	appendStringInfo(str, buf);

	sprintf(buf, " :command %d", node->commandType);
	appendStringInfo(str, buf);
	if (node->utilityStmt &&
		nodeTag(node->utilityStmt) == T_NotifyStmt)
		sprintf(buf, " :utility %s",
				((NotifyStmt *) (node->utilityStmt))->relname);
	else
/* use "" to designate	*/
		sprintf(buf, " :utility \"\"");
	appendStringInfo(str, buf);

	sprintf(buf, " :resrel %d", node->resultRelation);
	appendStringInfo(str, buf);
	sprintf(buf, " :rtable ");
	appendStringInfo(str, buf);
	_outNode(str, node->rtable);
	if (node->uniqueFlag)
		sprintf(buf, " :unique %s", node->uniqueFlag);
	else
/* use "" to designate non-unique */
		sprintf(buf, " :unique \"\"");
	appendStringInfo(str, buf);
	sprintf(buf, " :targetlist ");
	appendStringInfo(str, buf);
	_outNode(str, node->targetList);
	sprintf(buf, " :qual ");
	appendStringInfo(str, buf);
	_outNode(str, node->qual);

107 108 109 110 111 112
}

/*
 * print the basic stuff of all nodes that inherit from Plan
 */
static void
113
_outPlanInfo(StringInfo str, Plan * node)
114
{
115
	char		buf[500];
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

	sprintf(buf, " :cost %g", node->cost);
	appendStringInfo(str, buf);
	sprintf(buf, " :size %d", node->plan_size);
	appendStringInfo(str, buf);
	sprintf(buf, " :width %d", node->plan_width);
	appendStringInfo(str, buf);
	sprintf(buf, " :state %s", (node->state == (EState *) NULL ?
								"nil" : "non-NIL"));
	appendStringInfo(str, buf);
	sprintf(buf, " :qptargetlist ");
	appendStringInfo(str, buf);
	_outNode(str, node->targetlist);
	sprintf(buf, " :qpqual ");
	appendStringInfo(str, buf);
	_outNode(str, node->qual);
	sprintf(buf, " :lefttree ");
	appendStringInfo(str, buf);
	_outNode(str, node->lefttree);
	sprintf(buf, " :righttree ");
	appendStringInfo(str, buf);
	_outNode(str, node->righttree);

139 140 141
}

/*
142
 *	Stuff from plannodes.h
143 144
 */
static void
145
_outPlan(StringInfo str, Plan * node)
146
{
147
	char		buf[500];
148 149 150 151 152

	sprintf(buf, "PLAN");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

153 154 155
}

static void
156
_outResult(StringInfo str, Result * node)
157
{
158
	char		buf[500];
159 160 161 162 163 164 165 166 167

	sprintf(buf, "RESULT");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

	sprintf(buf, " :resconstantqual ");
	appendStringInfo(str, buf);
	_outNode(str, node->resconstantqual);

168 169 170
}

/*
171
 *	Existential is a subclass of Plan.
172 173
 */
static void
174
_outExistential(StringInfo str, Existential * node)
175
{
176
	char		buf[500];
177 178 179 180 181 182

	sprintf(buf, "EXISTENTIAL");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);


183 184 185
}

/*
186
 *	Append is a subclass of Plan.
187 188
 */
static void
189
_outAppend(StringInfo str, Append * node)
190
{
191
	char		buf[500];
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207

	sprintf(buf, "APPEND");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

	sprintf(buf, " :unionplans ");
	appendStringInfo(str, buf);
	_outNode(str, node->unionplans);

	sprintf(buf, " :unionrelid %d", node->unionrelid);
	appendStringInfo(str, buf);

	sprintf(buf, " :unionrtentries ");
	appendStringInfo(str, buf);
	_outNode(str, node->unionrtentries);

208 209 210
}

/*
211
 *	Join is a subclass of Plan
212 213
 */
static void
214
_outJoin(StringInfo str, Join * node)
215
{
216
	char		buf[500];
217 218 219 220 221

	sprintf(buf, "JOIN");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

222 223 224
}

/*
225
 *	NestLoop is a subclass of Join
226 227
 */
static void
228
_outNestLoop(StringInfo str, NestLoop * node)
229
{
230
	char		buf[500];
231 232 233 234

	sprintf(buf, "NESTLOOP");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);
235 236 237
}

/*
238
 *	MergeJoin is a subclass of Join
239 240
 */
static void
241
_outMergeJoin(StringInfo str, MergeJoin * node)
242
{
243
	char		buf[500];
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260

	sprintf(buf, "MERGEJOIN");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

	sprintf(buf, " :mergeclauses ");
	appendStringInfo(str, buf);
	_outNode(str, node->mergeclauses);

	sprintf(buf, " :mergesortop %u", node->mergesortop);
	appendStringInfo(str, buf);

	sprintf(buf, " :mergerightorder %u", node->mergerightorder[0]);
	appendStringInfo(str, buf);

	sprintf(buf, " :mergeleftorder %u", node->mergeleftorder[0]);
	appendStringInfo(str, buf);
261 262 263
}

/*
264
 *	HashJoin is a subclass of Join.
265 266
 */
static void
267
_outHashJoin(StringInfo str, HashJoin * node)
268
{
269
	char		buf[500];
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288

	sprintf(buf, "HASHJOIN");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

	sprintf(buf, " :hashclauses ");
	appendStringInfo(str, buf);
	_outNode(str, node->hashclauses);

	sprintf(buf, " :hashjoinop %u", node->hashjoinop);
	appendStringInfo(str, buf);
	sprintf(buf, " :hashjointable 0x%x", (int) node->hashjointable);
	appendStringInfo(str, buf);
	sprintf(buf, " :hashjointablekey %d", node->hashjointablekey);
	appendStringInfo(str, buf);
	sprintf(buf, " :hashjointablesize %d", node->hashjointablesize);
	appendStringInfo(str, buf);
	sprintf(buf, " :hashdone %d", node->hashdone);
	appendStringInfo(str, buf);
289 290 291
}

/*
292
 *	Scan is a subclass of Node
293 294
 */
static void
295
_outScan(StringInfo str, Scan * node)
296
{
297
	char		buf[500];
298 299 300 301 302 303 304 305

	sprintf(buf, "SCAN");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

	sprintf(buf, " :scanrelid %d", node->scanrelid);
	appendStringInfo(str, buf);

306 307 308
}

/*
309
 *	SeqScan is a subclass of Scan
310 311
 */
static void
312
_outSeqScan(StringInfo str, SeqScan * node)
313
{
314
	char		buf[500];
315 316 317 318 319 320 321 322 323

	sprintf(buf, "SEQSCAN");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

	sprintf(buf, " :scanrelid %d", node->scanrelid);
	appendStringInfo(str, buf);


324 325 326
}

/*
327
 *	IndexScan is a subclass of Scan
328 329
 */
static void
330
_outIndexScan(StringInfo str, IndexScan * node)
331
{
332
	char		buf[500];
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348

	sprintf(buf, "INDEXSCAN");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

	sprintf(buf, " :scanrelid %d", node->scan.scanrelid);
	appendStringInfo(str, buf);

	sprintf(buf, " :indxid ");
	appendStringInfo(str, buf);
	_outIntList(str, node->indxid);

	sprintf(buf, " :indxqual ");
	appendStringInfo(str, buf);
	_outNode(str, node->indxqual);

349 350 351
}

/*
352
 *	Temp is a subclass of Plan
353 354
 */
static void
355
_outTemp(StringInfo str, Temp * node)
356
{
357
	char		buf[500];
358 359 360 361 362 363 364 365 366 367

	sprintf(buf, "TEMP");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

	sprintf(buf, " :tempid %u", node->tempid);
	appendStringInfo(str, buf);
	sprintf(buf, " :keycount %d", node->keycount);
	appendStringInfo(str, buf);

368 369 370
}

/*
371
 *	Sort is a subclass of Temp
372 373
 */
static void
374
_outSort(StringInfo str, Sort * node)
375
{
376
	char		buf[500];
377 378 379 380 381 382 383 384 385 386

	sprintf(buf, "SORT");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

	sprintf(buf, " :tempid %u", node->tempid);
	appendStringInfo(str, buf);
	sprintf(buf, " :keycount %d", node->keycount);
	appendStringInfo(str, buf);

387 388 389
}

static void
390
_outAgg(StringInfo str, Agg * node)
391
{
392
	char		buf[500];
393 394 395 396 397 398 399 400

	sprintf(buf, "AGG");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

	/* the actual Agg fields */
	sprintf(buf, " :numagg %d ", node->numAgg);
	appendStringInfo(str, buf);
401 402 403
}

static void
404
_outGroup(StringInfo str, Group * node)
405
{
406
	char		buf[500];
407 408 409 410 411 412 413 414 415 416

	sprintf(buf, "GRP");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

	/* the actual Group fields */
	sprintf(buf, " :numCols %d ", node->numCols);
	appendStringInfo(str, buf);
	sprintf(buf, " :tuplePerGroup %s", node->tuplePerGroup ? "true" : "nil");
	appendStringInfo(str, buf);
417
}
418 419


420 421

/*
422
 *	For some reason, unique is a subclass of Temp.
423 424
 */
static void
425
_outUnique(StringInfo str, Unique * node)
426
{
427
	char		buf[500];
428 429 430 431 432 433 434 435 436 437

	sprintf(buf, "UNIQUE");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

	sprintf(buf, " :tempid %u", node->tempid);
	appendStringInfo(str, buf);
	sprintf(buf, " :keycount %d", node->keycount);
	appendStringInfo(str, buf);

438 439 440 441
}


/*
442
 *	Hash is a subclass of Temp
443 444
 */
static void
445
_outHash(StringInfo str, Hash * node)
446
{
447
	char		buf[500];
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462

	sprintf(buf, "HASH");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

	sprintf(buf, " :hashkey ");
	appendStringInfo(str, buf);
	_outNode(str, node->hashkey);

	sprintf(buf, " :hashtable 0x%x", (int) (node->hashtable));
	appendStringInfo(str, buf);
	sprintf(buf, " :hashtablekey %d", node->hashtablekey);
	appendStringInfo(str, buf);
	sprintf(buf, " :hashtablesize %d", node->hashtablesize);
	appendStringInfo(str, buf);
463 464 465
}

static void
466
_outTee(StringInfo str, Tee * node)
467
{
468
	char		buf[500];
469 470 471 472 473 474 475 476 477 478 479 480 481

	sprintf(buf, "TEE");
	appendStringInfo(str, buf);
	_outPlanInfo(str, (Plan *) node);

	sprintf(buf, " :leftParent %X", (int) (node->leftParent));
	appendStringInfo(str, buf);
	sprintf(buf, " :rightParent %X", (int) (node->rightParent));
	appendStringInfo(str, buf);

	sprintf(buf, " :rtentries ");
	appendStringInfo(str, buf);
	_outNode(str, node->rtentries);
482 483 484 485 486 487
}



/*****************************************************************************
 *
488
 *	Stuff from primnodes.h.
489 490 491 492 493
 *
 *****************************************************************************/


/*
494
 *	Resdom is a subclass of Node
495 496
 */
static void
497
_outResdom(StringInfo str, Resdom * node)
498
{
499
	char		buf[500];
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518

	sprintf(buf, "RESDOM");
	appendStringInfo(str, buf);
	sprintf(buf, " :resno %hd", node->resno);
	appendStringInfo(str, buf);
	sprintf(buf, " :restype %u", node->restype);
	appendStringInfo(str, buf);
	sprintf(buf, " :reslen %d", node->reslen);
	appendStringInfo(str, buf);
	sprintf(buf, " :resname \"%s\"",
			((node->resname) ? ((char *) node->resname) : "null"));
	appendStringInfo(str, buf);
	sprintf(buf, " :reskey %d", node->reskey);
	appendStringInfo(str, buf);
	sprintf(buf, " :reskeyop %u", node->reskeyop);
	appendStringInfo(str, buf);
	sprintf(buf, " :resjunk %d", node->resjunk);
	appendStringInfo(str, buf);

519 520 521
}

static void
522
_outFjoin(StringInfo str, Fjoin * node)
523
{
524 525
	char		buf[500];
	int			i;
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542

	sprintf(buf, "FJOIN");
	appendStringInfo(str, buf);
	sprintf(buf, " :initialized %s", node->fj_initialized ? "true" : "nil");
	appendStringInfo(str, buf);
	sprintf(buf, " :nNodes %d", node->fj_nNodes);
	appendStringInfo(str, buf);

	appendStringInfo(str, " :innerNode ");
	appendStringInfo(str, buf);
	_outNode(str, node->fj_innerNode);

	sprintf(buf, " :results @  0x%x ", (int) (node->fj_results));
	appendStringInfo(str, buf);

	appendStringInfo(str, " :alwaysdone ");
	for (i = 0; i < node->fj_nNodes; i++)
543
	{
544 545
		sprintf(buf, " %s ", ((node->fj_alwaysDone[i]) ? "true" : "nil"));
		appendStringInfo(str, buf);
546 547 548 549
	}
}

/*
550
 *	Expr is a subclass of Node
551 552
 */
static void
553
_outExpr(StringInfo str, Expr * node)
554
{
555 556
	char		buf[500];
	char	   *opstr = NULL;
557 558 559 560 561 562 563 564

	sprintf(buf, "EXPR");
	appendStringInfo(str, buf);

	sprintf(buf, " :typeOid %u", node->typeOid);
	appendStringInfo(str, buf);
	switch (node->opType)
	{
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
		case OP_EXPR:
			opstr = "op";
			break;
		case FUNC_EXPR:
			opstr = "func";
			break;
		case OR_EXPR:
			opstr = "or";
			break;
		case AND_EXPR:
			opstr = "and";
			break;
		case NOT_EXPR:
			opstr = "not";
			break;
580 581 582 583 584 585 586 587 588
	}
	sprintf(buf, " :opType %s", opstr);
	appendStringInfo(str, buf);
	sprintf(buf, " :oper ");
	appendStringInfo(str, buf);
	_outNode(str, node->oper);
	sprintf(buf, " :args ");
	appendStringInfo(str, buf);
	_outNode(str, node->args);
589 590 591
}

/*
592
 *	Var is a subclass of Expr
593 594
 */
static void
595
_outVar(StringInfo str, Var * node)
596
{
597
	char		buf[500];
598 599 600 601 602 603 604 605 606 607 608 609 610

	sprintf(buf, "VAR");
	appendStringInfo(str, buf);
	sprintf(buf, " :varno %d", node->varno);
	appendStringInfo(str, buf);
	sprintf(buf, " :varattno %hd", node->varattno);
	appendStringInfo(str, buf);
	sprintf(buf, " :vartype %u", node->vartype);
	appendStringInfo(str, buf);
	sprintf(buf, " :varnoold %d", node->varnoold);
	appendStringInfo(str, buf);
	sprintf(buf, " :varoattno %d", node->varoattno);
	appendStringInfo(str, buf);
611 612 613
}

/*
614
 *	Const is a subclass of Expr
615 616
 */
static void
617
_outConst(StringInfo str, Const * node)
618
{
619
	char		buf[500];
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642

	sprintf(buf, "CONST");
	appendStringInfo(str, buf);
	sprintf(buf, " :consttype %u", node->consttype);
	appendStringInfo(str, buf);
	sprintf(buf, " :constlen %hd", node->constlen);
	appendStringInfo(str, buf);
	sprintf(buf, " :constisnull %s", (node->constisnull ? "true" : "nil"));
	appendStringInfo(str, buf);
	sprintf(buf, " :constvalue ");
	appendStringInfo(str, buf);
	if (node->constisnull)
	{
		sprintf(buf, "NIL ");
		appendStringInfo(str, buf);
	}
	else
	{
		_outDatum(str, node->constvalue, node->consttype);
	}
	sprintf(buf, " :constbyval %s", (node->constbyval ? "true" : "nil"));
	appendStringInfo(str, buf);

643 644 645
}

/*
646
 *	Aggreg
647 648
 */
static void
649
_outAggreg(StringInfo str, Aggreg * node)
650
{
651
	char		buf[500];
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666

	sprintf(buf, "AGGREG");
	appendStringInfo(str, buf);
	sprintf(buf, " :aggname \"%s\"", (char *) node->aggname);
	appendStringInfo(str, buf);
	sprintf(buf, " :basetype %u", node->basetype);
	appendStringInfo(str, buf);
	sprintf(buf, " :aggtype %u", node->aggtype);
	appendStringInfo(str, buf);
	sprintf(buf, " :aggno %d", node->aggno);
	appendStringInfo(str, buf);

	sprintf(buf, " :target ");
	appendStringInfo(str, buf);
	_outNode(str, node->target);
667 668 669
}

/*
670
 *	Array is a subclass of Expr
671 672
 */
static void
673
_outArray(StringInfo str, Array * node)
674
{
675 676
	char		buf[500];
	int			i;
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703

	sprintf(buf, "ARRAY");
	appendStringInfo(str, buf);
	sprintf(buf, " :arrayelemtype %u", node->arrayelemtype);
	appendStringInfo(str, buf);
	sprintf(buf, " :arrayelemlength %d", node->arrayelemlength);
	appendStringInfo(str, buf);
	sprintf(buf, " :arrayelembyval %c", (node->arrayelembyval) ? 't' : 'f');
	appendStringInfo(str, buf);
	sprintf(buf, " :arrayndim %d", node->arrayndim);
	appendStringInfo(str, buf);
	sprintf(buf, " :arraylow ");
	appendStringInfo(str, buf);
	for (i = 0; i < node->arrayndim; i++)
	{
		sprintf(buf, "  %d", node->arraylow.indx[i]);
		appendStringInfo(str, buf);
	}
	sprintf(buf, " :arrayhigh ");
	appendStringInfo(str, buf);
	for (i = 0; i < node->arrayndim; i++)
	{
		sprintf(buf, " %d", node->arrayhigh.indx[i]);
		appendStringInfo(str, buf);
	}
	sprintf(buf, " :arraylen %d", node->arraylen);
	appendStringInfo(str, buf);
704 705 706
}

/*
707
 *	ArrayRef is a subclass of Expr
708 709
 */
static void
710
_outArrayRef(StringInfo str, ArrayRef * node)
711
{
712
	char		buf[500];
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739

	sprintf(buf, "ARRAYREF");
	appendStringInfo(str, buf);
	sprintf(buf, " :refelemtype %u", node->refelemtype);
	appendStringInfo(str, buf);
	sprintf(buf, " :refattrlength %d", node->refattrlength);
	appendStringInfo(str, buf);
	sprintf(buf, " :refelemlength %d", node->refelemlength);
	appendStringInfo(str, buf);
	sprintf(buf, " :refelembyval %c", (node->refelembyval) ? 't' : 'f');
	appendStringInfo(str, buf);

	sprintf(buf, " :refupperindex ");
	appendStringInfo(str, buf);
	_outNode(str, node->refupperindexpr);

	sprintf(buf, " :reflowerindex ");
	appendStringInfo(str, buf);
	_outNode(str, node->reflowerindexpr);

	sprintf(buf, " :refexpr ");
	appendStringInfo(str, buf);
	_outNode(str, node->refexpr);

	sprintf(buf, " :refassgnexpr ");
	appendStringInfo(str, buf);
	_outNode(str, node->refassgnexpr);
740 741 742
}

/*
743
 *	Func is a subclass of Expr
744 745
 */
static void
746
_outFunc(StringInfo str, Func * node)
747
{
748
	char		buf[500];
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768

	sprintf(buf, "FUNC");
	appendStringInfo(str, buf);
	sprintf(buf, " :funcid %u", node->funcid);
	appendStringInfo(str, buf);
	sprintf(buf, " :functype %u", node->functype);
	appendStringInfo(str, buf);
	sprintf(buf, " :funcisindex %s",
			(node->funcisindex ? "true" : "nil"));
	appendStringInfo(str, buf);
	sprintf(buf, " :funcsize %d", node->funcsize);
	appendStringInfo(str, buf);
	sprintf(buf, " :func_fcache @ 0x%x", (int) (node->func_fcache));
	appendStringInfo(str, buf);

	appendStringInfo(str, " :func_tlist ");
	_outNode(str, node->func_tlist);

	appendStringInfo(str, " :func_planlist ");
	_outNode(str, node->func_planlist);
769 770 771
}

/*
772
 *	Oper is a subclass of Expr
773 774
 */
static void
775
_outOper(StringInfo str, Oper * node)
776
{
777
	char		buf[500];
778 779 780 781 782 783 784 785 786 787

	sprintf(buf, "OPER");
	appendStringInfo(str, buf);
	sprintf(buf, " :opno %u", node->opno);
	appendStringInfo(str, buf);
	sprintf(buf, " :opid %u", node->opid);
	appendStringInfo(str, buf);
	sprintf(buf, " :opresulttype %u", node->opresulttype);
	appendStringInfo(str, buf);

788 789 790
}

/*
791
 *	Param is a subclass of Expr
792 793
 */
static void
794
_outParam(StringInfo str, Param * node)
795
{
796
	char		buf[500];
797 798 799 800 801 802 803 804 805 806 807 808 809 810

	sprintf(buf, "PARAM");
	appendStringInfo(str, buf);
	sprintf(buf, " :paramkind %d", node->paramkind);
	appendStringInfo(str, buf);
	sprintf(buf, " :paramid %hd", node->paramid);
	appendStringInfo(str, buf);
	sprintf(buf, " :paramname \"%s\"", node->paramname);
	appendStringInfo(str, buf);
	sprintf(buf, " :paramtype %u", node->paramtype);
	appendStringInfo(str, buf);

	appendStringInfo(str, " :param_tlist ");
	_outNode(str, node->param_tlist);
811 812 813
}

/*
814
 *	Stuff from execnodes.h
815 816 817
 */

/*
818
 *	EState is a subclass of Node.
819 820
 */
static void
821
_outEState(StringInfo str, EState * node)
822
{
823
	char		buf[500];
824 825 826 827 828 829 830 831 832 833 834 835 836 837

	sprintf(buf, "ESTATE");
	appendStringInfo(str, buf);
	sprintf(buf, " :direction %d", node->es_direction);
	appendStringInfo(str, buf);

	sprintf(buf, " :range_table ");
	appendStringInfo(str, buf);
	_outNode(str, node->es_range_table);

	sprintf(buf, " :result_relation_info @ 0x%x",
			(int) (node->es_result_relation_info));
	appendStringInfo(str, buf);

838 839 840
}

/*
841
 *	Stuff from relation.h
842 843
 */
static void
844
_outRel(StringInfo str, Rel * node)
845
{
846
	char		buf[500];
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887

	sprintf(buf, "REL");
	appendStringInfo(str, buf);

	sprintf(buf, " :relids ");
	appendStringInfo(str, buf);
	_outIntList(str, node->relids);

	sprintf(buf, " :indexed %s", (node->indexed ? "true" : "nil"));
	appendStringInfo(str, buf);
	sprintf(buf, " :pages %u", node->pages);
	appendStringInfo(str, buf);
	sprintf(buf, " :tuples %u", node->tuples);
	appendStringInfo(str, buf);
	sprintf(buf, " :size %u", node->size);
	appendStringInfo(str, buf);
	sprintf(buf, " :width %u", node->width);
	appendStringInfo(str, buf);

	sprintf(buf, " :targetlist ");
	appendStringInfo(str, buf);
	_outNode(str, node->targetlist);

	sprintf(buf, " :pathlist ");
	appendStringInfo(str, buf);
	_outNode(str, node->pathlist);

	/*
	 * Not sure if these are nodes or not.	They're declared as struct
	 * Path *.	Since i don't know, i'll just print the addresses for now.
	 * This can be changed later, if necessary.
	 */

	sprintf(buf, " :unorderedpath @ 0x%x", (int) (node->unorderedpath));
	appendStringInfo(str, buf);
	sprintf(buf, " :cheapestpath @ 0x%x", (int) (node->cheapestpath));
	appendStringInfo(str, buf);

	sprintf(buf, " :pruneable %s", (node->pruneable ? "true" : "nil"));
	appendStringInfo(str, buf);

888
#if 0
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913
	sprintf(buf, " :classlist ");
	appendStringInfo(str, buf);
	_outNode(str, node->classlist);

	sprintf(buf, " :indexkeys ");
	appendStringInfo(str, buf);
	_outNode(str, node->indexkeys);

	sprintf(buf, " :ordering ");
	appendStringInfo(str, buf);
	_outNode(str, node->ordering);
#endif

	sprintf(buf, " :clauseinfo ");
	appendStringInfo(str, buf);
	_outNode(str, node->clauseinfo);

	sprintf(buf, " :joininfo ");
	appendStringInfo(str, buf);
	_outNode(str, node->joininfo);

	sprintf(buf, " :innerjoin ");
	appendStringInfo(str, buf);
	_outNode(str, node->innerjoin);

914 915 916
}

/*
917
 *	TargetEntry is a subclass of Node.
918 919
 */
static void
920
_outTargetEntry(StringInfo str, TargetEntry * node)
921
{
922
	char		buf[500];
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940

	sprintf(buf, "TLE");
	appendStringInfo(str, buf);
	sprintf(buf, " :resdom ");
	appendStringInfo(str, buf);
	_outNode(str, node->resdom);

	sprintf(buf, " :expr ");
	appendStringInfo(str, buf);
	if (node->expr)
	{
		_outNode(str, node->expr);
	}
	else
	{
		appendStringInfo(str, "nil");
	}
}
941 942

static void
943
_outRangeTblEntry(StringInfo str, RangeTblEntry * node)
944
{
945
	char		buf[500];
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963

	sprintf(buf, "RTE");
	appendStringInfo(str, buf);

	sprintf(buf, " :relname \"%s\"",
			((node->relname) ? ((char *) node->relname) : "null"));
	appendStringInfo(str, buf);

	sprintf(buf, " :inh %d ", node->inh);
	appendStringInfo(str, buf);

	sprintf(buf, " :refname \"%s\"",
			((node->refname) ? ((char *) node->refname) : "null"));
	appendStringInfo(str, buf);

	sprintf(buf, " :relid %u ", node->relid);
	appendStringInfo(str, buf);
}
964 965

/*
966
 *	Path is a subclass of Node.
967 968
 */
static void
969
_outPath(StringInfo str, Path * node)
970
{
971
	char		buf[500];
972 973 974 975 976 977 978 979 980 981 982 983 984 985

	sprintf(buf, "PATH");
	appendStringInfo(str, buf);

	sprintf(buf, " :pathtype %d", node->pathtype);
	appendStringInfo(str, buf);

	sprintf(buf, " :cost %f", node->path_cost);
	appendStringInfo(str, buf);

	sprintf(buf, " :keys ");
	appendStringInfo(str, buf);
	_outNode(str, node->keys);

986 987 988
}

/*
989
 *	IndexPath is a subclass of Path.
990 991
 */
static void
992
_outIndexPath(StringInfo str, IndexPath * node)
993
{
994
	char		buf[500];
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009

	sprintf(buf, "INDEXPATH");
	appendStringInfo(str, buf);

	sprintf(buf, " :pathtype %d", node->path.pathtype);
	appendStringInfo(str, buf);

	/*
	 * sprintf(buf, " :parent "); appendStringInfo(str,buf); _outNode(str,
	 * node->parent);
	 */

	sprintf(buf, " :cost %f", node->path.path_cost);
	appendStringInfo(str, buf);

1010
#if 0
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
	sprintf(buf, " :p_ordering ");
	appendStringInfo(str, buf);
	_outNode(str, node->path.p_ordering);
#endif
	sprintf(buf, " :keys ");
	appendStringInfo(str, buf);
	_outNode(str, node->path.keys);

	sprintf(buf, " :indexid ");
	appendStringInfo(str, buf);
	_outIntList(str, node->indexid);

	sprintf(buf, " :indexqual ");
	appendStringInfo(str, buf);
	_outNode(str, node->indexqual);

1027 1028 1029
}

/*
1030
 *	JoinPath is a subclass of Path
1031 1032
 */
static void
1033
_outJoinPath(StringInfo str, JoinPath * node)
1034
{
1035
	char		buf[500];
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050

	sprintf(buf, "JOINPATH");
	appendStringInfo(str, buf);

	sprintf(buf, " :pathtype %d", node->path.pathtype);
	appendStringInfo(str, buf);

	/*
	 * sprintf(buf, " :parent "); appendStringInfo(str,buf); _outNode(str,
	 * node->parent);
	 */

	sprintf(buf, " :cost %f", node->path.path_cost);
	appendStringInfo(str, buf);

1051
#if 0
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
	sprintf(buf, " :p_ordering ");
	appendStringInfo(str, buf);
	_outNode(str, node->path.p_ordering);
#endif
	sprintf(buf, " :keys ");
	appendStringInfo(str, buf);
	_outNode(str, node->path.keys);

	sprintf(buf, " :pathclauseinfo ");
	appendStringInfo(str, buf);
	_outNode(str, node->pathclauseinfo);

	/*
	 * Not sure if these are nodes; they're declared as "struct path *".
	 * For now, i'll just print the addresses.
	 */

	sprintf(buf, " :outerjoinpath @ 0x%x", (int) (node->outerjoinpath));
	appendStringInfo(str, buf);
	sprintf(buf, " :innerjoinpath @ 0x%x", (int) (node->innerjoinpath));
	appendStringInfo(str, buf);

	sprintf(buf, " :outerjoincost %f", node->path.outerjoincost);
	appendStringInfo(str, buf);

	sprintf(buf, " :joinid ");
	appendStringInfo(str, buf);
	_outIntList(str, node->path.joinid);

1081 1082 1083
}

/*
1084
 *	MergePath is a subclass of JoinPath.
1085 1086
 */
static void
1087
_outMergePath(StringInfo str, MergePath * node)
1088
{
1089
	char		buf[500];
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 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

	sprintf(buf, "MERGEPATH");
	appendStringInfo(str, buf);

	sprintf(buf, " :pathtype %d", node->jpath.path.pathtype);
	appendStringInfo(str, buf);

	sprintf(buf, " :cost %f", node->jpath.path.path_cost);
	appendStringInfo(str, buf);

	sprintf(buf, " :keys ");
	appendStringInfo(str, buf);
	_outNode(str, node->jpath.path.keys);

	sprintf(buf, " :pathclauseinfo ");
	appendStringInfo(str, buf);
	_outNode(str, node->jpath.pathclauseinfo);

	/*
	 * Not sure if these are nodes; they're declared as "struct path *".
	 * For now, i'll just print the addresses.
	 */

	sprintf(buf, " :outerjoinpath @ 0x%x", (int) (node->jpath.outerjoinpath));
	appendStringInfo(str, buf);
	sprintf(buf, " :innerjoinpath @ 0x%x", (int) (node->jpath.innerjoinpath));
	appendStringInfo(str, buf);

	sprintf(buf, " :outerjoincost %f", node->jpath.path.outerjoincost);
	appendStringInfo(str, buf);

	sprintf(buf, " :joinid ");
	appendStringInfo(str, buf);
	_outIntList(str, node->jpath.path.joinid);

	sprintf(buf, " :path_mergeclauses ");
	appendStringInfo(str, buf);
	_outNode(str, node->path_mergeclauses);

	sprintf(buf, " :outersortkeys ");
	appendStringInfo(str, buf);
	_outNode(str, node->outersortkeys);

	sprintf(buf, " :innersortkeys ");
	appendStringInfo(str, buf);
	_outNode(str, node->innersortkeys);

1137 1138 1139
}

/*
1140
 *	HashPath is a subclass of JoinPath.
1141 1142
 */
static void
1143
_outHashPath(StringInfo str, HashPath * node)
1144
{
1145
	char		buf[500];
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

	sprintf(buf, "HASHPATH");
	appendStringInfo(str, buf);

	sprintf(buf, " :pathtype %d", node->jpath.path.pathtype);
	appendStringInfo(str, buf);

	sprintf(buf, " :cost %f", node->jpath.path.path_cost);
	appendStringInfo(str, buf);

	sprintf(buf, " :keys ");
	appendStringInfo(str, buf);
	_outNode(str, node->jpath.path.keys);

	sprintf(buf, " :pathclauseinfo ");
	appendStringInfo(str, buf);
	_outNode(str, node->jpath.pathclauseinfo);

	/*
	 * Not sure if these are nodes; they're declared as "struct path *".
	 * For now, i'll just print the addresses.
	 */

	sprintf(buf, " :outerjoinpath @ 0x%x", (int) (node->jpath.outerjoinpath));
	appendStringInfo(str, buf);
	sprintf(buf, " :innerjoinpath @ 0x%x", (int) (node->jpath.innerjoinpath));
	appendStringInfo(str, buf);

	sprintf(buf, " :outerjoincost %f", node->jpath.path.outerjoincost);
	appendStringInfo(str, buf);

	sprintf(buf, " :joinid ");
	appendStringInfo(str, buf);
	_outIntList(str, node->jpath.path.joinid);

	sprintf(buf, " :path_hashclauses ");
	appendStringInfo(str, buf);
	_outNode(str, node->path_hashclauses);

	sprintf(buf, " :outerhashkeys ");
	appendStringInfo(str, buf);
	_outNode(str, node->outerhashkeys);

	sprintf(buf, " :innerhashkeys ");
	appendStringInfo(str, buf);
	_outNode(str, node->innerhashkeys);

1193 1194 1195
}

/*
1196
 *	OrderKey is a subclass of Node.
1197 1198
 */
static void
1199
_outOrderKey(StringInfo str, OrderKey * node)
1200
{
1201
	char		buf[500];
1202 1203 1204 1205 1206 1207 1208 1209

	sprintf(buf, "ORDERKEY");
	appendStringInfo(str, buf);
	sprintf(buf, " :attribute_number %d", node->attribute_number);
	appendStringInfo(str, buf);
	sprintf(buf, " :array_index %d", node->array_index);
	appendStringInfo(str, buf);

1210 1211 1212
}

/*
1213
 *	JoinKey is a subclass of Node.
1214 1215
 */
static void
1216
_outJoinKey(StringInfo str, JoinKey * node)
1217
{
1218
	char		buf[500];
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230

	sprintf(buf, "JOINKEY");
	appendStringInfo(str, buf);

	sprintf(buf, " :outer ");
	appendStringInfo(str, buf);
	_outNode(str, node->outer);

	sprintf(buf, " :inner ");
	appendStringInfo(str, buf);
	_outNode(str, node->inner);

1231 1232 1233
}

/*
1234
 *	MergeOrder is a subclass of Node.
1235 1236
 */
static void
1237
_outMergeOrder(StringInfo str, MergeOrder * node)
1238
{
1239
	char		buf[500];
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254

	sprintf(buf, "MERGEORDER");
	appendStringInfo(str, buf);

	sprintf(buf, " :join_operator %d", node->join_operator);
	appendStringInfo(str, buf);
	sprintf(buf, " :left_operator %d", node->left_operator);
	appendStringInfo(str, buf);
	sprintf(buf, " :right_operator %d", node->right_operator);
	appendStringInfo(str, buf);
	sprintf(buf, " :left_type %d", node->left_type);
	appendStringInfo(str, buf);
	sprintf(buf, " :right_type %d", node->right_type);
	appendStringInfo(str, buf);

1255 1256 1257
}

/*
1258
 *	CInfo is a subclass of Node.
1259 1260
 */
static void
1261
_outCInfo(StringInfo str, CInfo * node)
1262
{
1263
	char		buf[500];
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287

	sprintf(buf, "CINFO");
	appendStringInfo(str, buf);

	sprintf(buf, " :clause ");
	appendStringInfo(str, buf);
	_outNode(str, node->clause);

	sprintf(buf, " :selectivity %f", node->selectivity);
	appendStringInfo(str, buf);
	sprintf(buf, " :notclause %s", (node->notclause ? "true" : "nil"));
	appendStringInfo(str, buf);

	sprintf(buf, " :indexids ");
	appendStringInfo(str, buf);
	_outNode(str, node->indexids);

	sprintf(buf, " :mergesortorder ");
	appendStringInfo(str, buf);
	_outNode(str, node->mergesortorder);

	sprintf(buf, " :hashjoinoperator %u", node->hashjoinoperator);
	appendStringInfo(str, buf);

1288 1289 1290
}

/*
1291
 *	JoinMethod is a subclass of Node.
1292 1293
 */
static void
1294
_outJoinMethod(StringInfo str, JoinMethod * node)
1295
{
1296
	char		buf[500];
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309

	sprintf(buf, "JOINMETHOD");
	appendStringInfo(str, buf);

	sprintf(buf, " :jmkeys ");
	appendStringInfo(str, buf);
	_outNode(str, node->jmkeys);

	sprintf(buf, " :clauses ");
	appendStringInfo(str, buf);
	_outNode(str, node->clauses);


1310 1311 1312 1313 1314 1315
}

/*
 * HInfo is a subclass of JoinMethod.
 */
static void
1316
_outHInfo(StringInfo str, HInfo * node)
1317
{
1318
	char		buf[500];
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335

	sprintf(buf, "HASHINFO");
	appendStringInfo(str, buf);

	sprintf(buf, " :hashop ");
	appendStringInfo(str, buf);
	sprintf(buf, "%u", node->hashop);
	appendStringInfo(str, buf);

	sprintf(buf, " :jmkeys ");
	appendStringInfo(str, buf);
	_outNode(str, node->jmethod.jmkeys);

	sprintf(buf, " :clauses ");
	appendStringInfo(str, buf);
	_outNode(str, node->jmethod.clauses);

1336 1337 1338
}

/*
1339
 *	JInfo is a subclass of Node.
1340 1341
 */
static void
1342
_outJInfo(StringInfo str, JInfo * node)
1343
{
1344
	char		buf[500];
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363

	sprintf(buf, "JINFO");
	appendStringInfo(str, buf);

	sprintf(buf, " :otherrels ");
	appendStringInfo(str, buf);
	_outIntList(str, node->otherrels);

	sprintf(buf, " :jinfoclauseinfo ");
	appendStringInfo(str, buf);
	_outNode(str, node->jinfoclauseinfo);

	sprintf(buf, " :mergesortable %s",
			(node->mergesortable ? "true" : "nil"));
	appendStringInfo(str, buf);
	sprintf(buf, " :hashjoinable %s",
			(node->hashjoinable ? "true" : "nil"));
	appendStringInfo(str, buf);

1364 1365 1366 1367 1368 1369 1370 1371
}

/*
 * Print the value of a Datum given its type.
 */
static void
_outDatum(StringInfo str, Datum value, Oid type)
{
1372 1373 1374 1375 1376 1377
	char		buf[500];
	Size		length,
				typeLength;
	bool		byValue;
	int			i;
	char	   *s;
1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398

	/*
	 * find some information about the type and the "real" length of the
	 * datum.
	 */
	byValue = get_typbyval(type);
	typeLength = get_typlen(type);
	length = datumGetSize(value, type, byValue, typeLength);

	if (byValue)
	{
		s = (char *) (&value);
		sprintf(buf, " %d [ ", length);
		appendStringInfo(str, buf);
		for (i = 0; i < sizeof(Datum); i++)
		{
			sprintf(buf, "%d ", (int) (s[i]));
			appendStringInfo(str, buf);
		}
		sprintf(buf, "] ");
		appendStringInfo(str, buf);
1399
	}
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428
	else
	{							/* !byValue */
		s = (char *) DatumGetPointer(value);
		if (!PointerIsValid(s))
		{
			sprintf(buf, " 0 [ ] ");
			appendStringInfo(str, buf);
		}
		else
		{

			/*
			 * length is unsigned - very bad to do < comparison to -1
			 * without casting it to int first!! -mer 8 Jan 1991
			 */
			if (((int) length) <= -1)
			{
				length = VARSIZE(s);
			}
			sprintf(buf, " %d [ ", length);
			appendStringInfo(str, buf);
			for (i = 0; i < length; i++)
			{
				sprintf(buf, "%d ", (int) (s[i]));
				appendStringInfo(str, buf);
			}
			sprintf(buf, "] ");
			appendStringInfo(str, buf);
		}
1429
	}
1430

1431 1432 1433
}

static void
1434
_outIter(StringInfo str, Iter * node)
1435
{
1436 1437 1438 1439
	appendStringInfo(str, "ITER");

	appendStringInfo(str, " :iterexpr ");
	_outNode(str, node->iterexpr);
1440 1441 1442
}

static void
1443
_outStream(StringInfo str, Stream * node)
1444
{
1445
	char		buf[500];
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472

	appendStringInfo(str, "STREAM");

	sprintf(buf, " :pathptr @ 0x%x", (int) (node->pathptr));
	appendStringInfo(str, buf);

	sprintf(buf, " :cinfo @ 0x%x", (int) (node->cinfo));
	appendStringInfo(str, buf);

	sprintf(buf, " :clausetype %d", (int) (node->clausetype));
	appendStringInfo(str, buf);

	sprintf(buf, " :upstream @ 0x%x", (int) (node->upstream));
	appendStringInfo(str, buf);

	sprintf(buf, " :downstream @ 0x%x", (int) (node->downstream));
	appendStringInfo(str, buf);

	sprintf(buf, " :groupup %d", node->groupup);
	appendStringInfo(str, buf);

	sprintf(buf, " :groupcost %f", node->groupcost);
	appendStringInfo(str, buf);

	sprintf(buf, " :groupsel %f", node->groupsel);
	appendStringInfo(str, buf);
}
1473 1474

static void
1475
_outValue(StringInfo str, Value * value)
1476
{
1477
	char		buf[500];
1478 1479 1480

	switch (value->type)
	{
1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494
		case T_String:
			sprintf(buf, "\"%s\"", value->val.str);
			appendStringInfo(str, buf);
			break;
		case T_Integer:
			sprintf(buf, "%ld", value->val.ival);
			appendStringInfo(str, buf);
			break;
		case T_Float:
			sprintf(buf, "%f", value->val.dval);
			appendStringInfo(str, buf);
			break;
		default:
			break;
1495 1496
	}
	return;
1497 1498 1499 1500
}

/*
 * _outNode -
1501
 *	  converts a Node into ascii string and append it to 'str'
1502 1503 1504 1505
 */
static void
_outNode(StringInfo str, void *obj)
{
1506 1507 1508 1509 1510
	if (obj == NULL)
	{
		appendStringInfo(str, "nil");
		return;
	}
1511

1512 1513
	if (nodeTag(obj) == T_List)
	{
1514
		List	   *l;
1515 1516 1517 1518 1519 1520 1521 1522 1523

		appendStringInfo(str, "(");
		foreach(l, (List *) obj)
		{
			_outNode(str, lfirst(l));
			if (lnext(l))
				appendStringInfo(str, " ");
		}
		appendStringInfo(str, ")");
1524
	}
1525 1526 1527 1528 1529
	else
	{
		appendStringInfo(str, "{");
		switch (nodeTag(obj))
		{
1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 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 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682
			case T_Query:
				_outQuery(str, obj);
				break;
			case T_Plan:
				_outPlan(str, obj);
				break;
			case T_Result:
				_outResult(str, obj);
				break;
			case T_Existential:
				_outExistential(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;
			case T_Temp:
				_outTemp(str, obj);
				break;
			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;
			case T_Hash:
				_outHash(str, obj);
				break;
			case T_Tee:
				_outTee(str, obj);
				break;
			case T_Resdom:
				_outResdom(str, obj);
				break;
			case T_Fjoin:
				_outFjoin(str, obj);
				break;
			case T_Expr:
				_outExpr(str, obj);
				break;
			case T_Var:
				_outVar(str, obj);
				break;
			case T_Const:
				_outConst(str, obj);
				break;
			case T_Aggreg:
				_outAggreg(str, obj);
				break;
			case T_Array:
				_outArray(str, obj);
				break;
			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;
			case T_EState:
				_outEState(str, obj);
				break;
			case T_Rel:
				_outRel(str, obj);
				break;
			case T_TargetEntry:
				_outTargetEntry(str, obj);
				break;
			case T_RangeTblEntry:
				_outRangeTblEntry(str, obj);
				break;
			case T_Path:
				_outPath(str, obj);
				break;
			case T_IndexPath:
				_outIndexPath(str, obj);
				break;
			case T_JoinPath:
				_outJoinPath(str, obj);
				break;
			case T_MergePath:
				_outMergePath(str, obj);
				break;
			case T_HashPath:
				_outHashPath(str, obj);
				break;
			case T_OrderKey:
				_outOrderKey(str, obj);
				break;
			case T_JoinKey:
				_outJoinKey(str, obj);
				break;
			case T_MergeOrder:
				_outMergeOrder(str, obj);
				break;
			case T_CInfo:
				_outCInfo(str, obj);
				break;
			case T_JoinMethod:
				_outJoinMethod(str, obj);
				break;
			case T_HInfo:
				_outHInfo(str, obj);
				break;
			case T_JInfo:
				_outJInfo(str, obj);
				break;
			case T_Iter:
				_outIter(str, obj);
				break;
			case T_Stream:
				_outStream(str, obj);
				break;
			case T_Integer:
			case T_String:
			case T_Float:
				_outValue(str, obj);
				break;
			default:
				elog(NOTICE, "_outNode: don't know how to print type %d",
					 nodeTag(obj));
				break;
1683 1684
		}
		appendStringInfo(str, "}");
1685
	}
1686
	return;
1687 1688 1689 1690
}

/*
 * nodeToString -
1691
 *	   returns the ascii representation of the Node
1692
 */
1693
char	   *
1694 1695
nodeToString(void *obj)
{
1696 1697
	StringInfo	str;
	char	   *s;
1698 1699 1700 1701 1702 1703 1704 1705 1706 1707

	if (obj == NULL)
		return "";
	Assert(obj != NULL);
	str = makeStringInfo();
	_outNode(str, obj);
	s = str->data;
	pfree(str);

	return s;
1708
}