outfuncs.c 34.1 KB
Newer Older
M
 
Marc G. Fournier 已提交
1
/*
2
 *
3
 * outfuncs.c
4
 *	  routines to convert a node to ascii representation
5 6 7
 *
 * Copyright (c) 1994, Regents of the University of California
 *
8
 *	$Id: outfuncs.c,v 1.101 2000/01/09 00:26:23 tgl Exp $
9 10
 *
 * NOTES
11 12 13 14 15
 *	  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.
16
 *
17 18 19
 *	  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.)
20 21 22
 *
 */

23
#include "postgres.h"
24 25
#include "access/heapam.h"
#include "access/htup.h"
B
Bruce Momjian 已提交
26
#include "catalog/pg_type.h"
27
#include "fmgr.h"
B
Bruce Momjian 已提交
28
#include "lib/stringinfo.h"
29
#include "nodes/execnodes.h"
B
Bruce Momjian 已提交
30 31
#include "nodes/nodes.h"
#include "nodes/parsenodes.h"
32 33 34 35
#include "nodes/pg_list.h"
#include "nodes/plannodes.h"
#include "nodes/primnodes.h"
#include "nodes/relation.h"
B
Bruce Momjian 已提交
36 37 38
#include "utils/datum.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
39

40 41
#include "../parse.h"

42 43
static void _outDatum(StringInfo str, Datum value, Oid type);
static void _outNode(StringInfo str, void *obj);
44

45 46 47 48
/* Convert a null string pointer into "<>" */
#define stringStringInfo(s) (((s) == NULL) ? "<>" : (s))


49 50
/*
 * _outIntList -
51
 *	   converts a List of integers
52
 */
53
static void
54
_outIntList(StringInfo str, List *list)
55
{
B
Bruce Momjian 已提交
56
	List	   *l;
57

58 59
	appendStringInfo(str, "(");
	foreach(l, list)
B
Bruce Momjian 已提交
60
		appendStringInfo(str, " %d ", lfirsti(l));
61
	appendStringInfo(str, ")");
62 63
}

64 65 66
static void
_outCreateStmt(StringInfo str, CreateStmt *node)
{
B
Bruce Momjian 已提交
67 68
	appendStringInfo(str, " CREATE :relname %s ",
					 stringStringInfo(node->relname));
69 70

	appendStringInfo(str, " :istemp %s ",
B
Bruce Momjian 已提交
71
					 node->istemp ? "true" : "false");
72 73

	appendStringInfo(str, "	:columns ");
74
	_outNode(str, node->tableElts);
M
 
Marc G. Fournier 已提交
75

76
	appendStringInfo(str, " :inhRelnames ");
77
	_outNode(str, node->inhRelnames);
M
 
Marc G. Fournier 已提交
78

79
	appendStringInfo(str, " :constraints ");
80
	_outNode(str, node->constraints);
81
}
82 83 84 85

static void
_outIndexStmt(StringInfo str, IndexStmt *node)
{
B
Bruce Momjian 已提交
86 87 88 89 90
	appendStringInfo(str,
		 " INDEX :idxname %s :relname %s :accessMethod %s :indexParams ",
					 stringStringInfo(node->idxname),
					 stringStringInfo(node->relname),
					 stringStringInfo(node->accessMethod));
91
	_outNode(str, node->indexParams);
M
 
Marc G. Fournier 已提交
92

93 94
	appendStringInfo(str, " :withClause ");
	_outNode(str, node->withClause);
M
 
Marc G. Fournier 已提交
95

96 97
	appendStringInfo(str, " :whereClause ");
	_outNode(str, node->whereClause);
M
 
Marc G. Fournier 已提交
98

99 100
	appendStringInfo(str, " :rangetable ");
	_outNode(str, node->rangetable);
M
 
Marc G. Fournier 已提交
101 102

	appendStringInfo(str, " :lossy %s :unique %s ",
B
Bruce Momjian 已提交
103 104
					 node->lossy ? "true" : "false",
					 node->unique ? "true" : "false");
105
}
106

107 108 109
static void
_outSelectStmt(StringInfo str, SelectStmt *node)
{
M
 
Marc G. Fournier 已提交
110
	appendStringInfo(str, "SELECT :where ");
111 112 113 114 115 116
	_outNode(str, node->whereClause);
}

static void
_outFuncCall(StringInfo str, FuncCall *node)
{
117 118
	appendStringInfo(str, "FUNCTION %s :args ",
					 stringStringInfo(node->funcname));
119
	_outNode(str, node->args);
120 121 122
	appendStringInfo(str, " :agg_star %s :agg_distinct %s ",
					 node->agg_star ? "true" : "false",
					 node->agg_distinct ? "true" : "false");
123
}
124

125 126 127
static void
_outColumnDef(StringInfo str, ColumnDef *node)
{
128
	appendStringInfo(str, " COLUMNDEF :colname %s :typename ",
B
Bruce Momjian 已提交
129
					 stringStringInfo(node->colname));
130
	_outNode(str, node->typename);
131
	appendStringInfo(str, " :is_not_null %s :is_sequence %s :raw_default ",
B
Bruce Momjian 已提交
132
					 node->is_not_null ? "true" : "false",
133 134 135 136
					 node->is_sequence ? "true" : "false");
	_outNode(str, node->raw_default);
	appendStringInfo(str, " :cooked_default %s :constraints ",
					 stringStringInfo(node->cooked_default));
137
	_outNode(str, node->constraints);
138 139 140 141 142
}

static void
_outTypeName(StringInfo str, TypeName *node)
{
B
Bruce Momjian 已提交
143 144 145 146 147 148
	appendStringInfo(str,
	 " TYPENAME :name %s :timezone %s :setof %s typmod %d :arrayBounds ",
					 stringStringInfo(node->name),
					 node->timezone ? "true" : "false",
					 node->setof ? "true" : "false",
					 node->typmod);
149 150 151 152

	appendStringInfo(str, " :arrayBounds ");
	_outNode(str, node->arrayBounds);
}
153 154 155 156

static void
_outIndexElem(StringInfo str, IndexElem *node)
{
157
	appendStringInfo(str, " INDEXELEM :name %s :args ",
B
Bruce Momjian 已提交
158
					 stringStringInfo(node->name));
159
	_outNode(str, node->args);
M
 
Marc G. Fournier 已提交
160

M
 
Marc G. Fournier 已提交
161
	appendStringInfo(str, " :class %s :typename ", stringStringInfo(node->class));
162
	_outNode(str, node->typename);
163
}
164

165
static void
166
_outQuery(StringInfo str, Query *node)
167
{
168

M
 
Marc G. Fournier 已提交
169
	appendStringInfo(str, " QUERY :command %d ", node->commandType);
170

171 172 173 174 175
	if (node->utilityStmt)
	{
		switch (nodeTag(node->utilityStmt))
		{
			case T_CreateStmt:
M
 
Marc G. Fournier 已提交
176
				appendStringInfo(str, " :create %s ",
B
Bruce Momjian 已提交
177
								 stringStringInfo(((CreateStmt *) (node->utilityStmt))->relname));
178 179 180 181
				_outNode(str, node->utilityStmt);
				break;

			case T_IndexStmt:
M
 
Marc G. Fournier 已提交
182
				appendStringInfo(str, " :index %s on %s ",
B
Bruce Momjian 已提交
183 184
								 stringStringInfo(((IndexStmt *) (node->utilityStmt))->idxname),
								 stringStringInfo(((IndexStmt *) (node->utilityStmt))->relname));
185 186 187 188
				_outNode(str, node->utilityStmt);
				break;

			case T_NotifyStmt:
M
 
Marc G. Fournier 已提交
189
				appendStringInfo(str, " :utility %s ",
B
Bruce Momjian 已提交
190
								 stringStringInfo(((NotifyStmt *) (node->utilityStmt))->relname));
191 192 193
				break;

			default:
194
				appendStringInfo(str, " :utility ? ");
195 196
		}
	}
197
	else
198
		appendStringInfo(str, " :utility <>");
199

B
Bruce Momjian 已提交
200 201 202 203 204 205 206 207 208 209 210
	appendStringInfo(str,
					 " :resultRelation %u :into %s :isPortal %s :isBinary %s :isTemp %s :unionall %s ",
					 node->resultRelation,
					 stringStringInfo(node->into),
					 node->isPortal ? "true" : "false",
					 node->isBinary ? "true" : "false",
					 node->isTemp ? "true" : "false",
					 node->unionall ? "true" : "false");

	appendStringInfo(str, " :unique %s :sortClause ",
					 stringStringInfo(node->uniqueFlag));
211
	_outNode(str, node->sortClause);
M
 
Marc G. Fournier 已提交
212

213
	appendStringInfo(str, " :rtable ");
214
	_outNode(str, node->rtable);
M
 
Marc G. Fournier 已提交
215

216
	appendStringInfo(str, " :targetlist ");
217
	_outNode(str, node->targetList);
M
 
Marc G. Fournier 已提交
218

219
	appendStringInfo(str, " :qual ");
220
	_outNode(str, node->qual);
M
 
Marc G. Fournier 已提交
221

222 223
	appendStringInfo(str, " :groupClause ");
	_outNode(str, node->groupClause);
M
 
Marc G. Fournier 已提交
224

225
	appendStringInfo(str, " :havingQual ");
226
	_outNode(str, node->havingQual);
M
 
Marc G. Fournier 已提交
227 228

	appendStringInfo(str, " :hasAggs %s :hasSubLinks %s :unionClause ",
B
Bruce Momjian 已提交
229 230
					 node->hasAggs ? "true" : "false",
					 node->hasSubLinks ? "true" : "false");
231
	_outNode(str, node->unionClause);
M
 
Marc G. Fournier 已提交
232

B
Hi!  
Bruce Momjian 已提交
233 234 235
	appendStringInfo(str, " :intersectClause ");
	_outNode(str, node->intersectClause);

B
Bruce Momjian 已提交
236 237
	appendStringInfo(str, " :limitOffset ");
	_outNode(str, node->limitOffset);
M
 
Marc G. Fournier 已提交
238

B
Bruce Momjian 已提交
239 240
	appendStringInfo(str, " :limitCount ");
	_outNode(str, node->limitCount);
241 242 243 244

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

245 246 247
}

static void
248
_outSortClause(StringInfo str, SortClause *node)
249
{
250 251
	appendStringInfo(str, " SORTCLAUSE :tleSortGroupRef %d :sortop %u ",
					 node->tleSortGroupRef, node->sortop);
252 253 254 255 256
}

static void
_outGroupClause(StringInfo str, GroupClause *node)
{
257 258
	appendStringInfo(str, " GROUPCLAUSE :tleSortGroupRef %d :sortop %u ",
					 node->tleSortGroupRef, node->sortop);
259 260 261 262 263 264
}

/*
 * print the basic stuff of all nodes that inherit from Plan
 */
static void
265
_outPlanInfo(StringInfo str, Plan *node)
266
{
B
Bruce Momjian 已提交
267
	appendStringInfo(str,
268
				  ":cost %g :rows %.0f :width %d :state %s :qptargetlist ",
B
Bruce Momjian 已提交
269
					 node->cost,
270
					 node->plan_rows,
B
Bruce Momjian 已提交
271 272
					 node->plan_width,
					 node->state ? "not-NULL" : "<>");
273
	_outNode(str, node->targetlist);
M
 
Marc G. Fournier 已提交
274

275
	appendStringInfo(str, " :qpqual ");
276
	_outNode(str, node->qual);
M
 
Marc G. Fournier 已提交
277

278
	appendStringInfo(str, " :lefttree ");
279
	_outNode(str, node->lefttree);
M
 
Marc G. Fournier 已提交
280

281
	appendStringInfo(str, " :righttree ");
282
	_outNode(str, node->righttree);
M
 
Marc G. Fournier 已提交
283

V
Vadim B. Mikheev 已提交
284 285
	appendStringInfo(str, " :extprm ");
	_outIntList(str, node->extParam);
M
 
Marc G. Fournier 已提交
286

V
Vadim B. Mikheev 已提交
287 288
	appendStringInfo(str, " :locprm ");
	_outIntList(str, node->locParam);
M
 
Marc G. Fournier 已提交
289

V
Vadim B. Mikheev 已提交
290 291
	appendStringInfo(str, " :initplan ");
	_outNode(str, node->initPlan);
M
 
Marc G. Fournier 已提交
292

M
 
Marc G. Fournier 已提交
293
	appendStringInfo(str, " :nprm %d ", node->nParamExec);
294 295 296
}

/*
297
 *	Stuff from plannodes.h
298 299
 */
static void
300
_outPlan(StringInfo str, Plan *node)
301
{
302
	appendStringInfo(str, " PLAN ");
303
	_outPlanInfo(str, (Plan *) node);
304 305 306
}

static void
307
_outResult(StringInfo str, Result *node)
308
{
309
	appendStringInfo(str, " RESULT ");
310 311
	_outPlanInfo(str, (Plan *) node);

312
	appendStringInfo(str, " :resconstantqual ");
313 314
	_outNode(str, node->resconstantqual);

315 316 317
}

/*
318
 *	Append is a subclass of Plan.
319 320
 */
static void
B
Bruce Momjian 已提交
321
_outAppend(StringInfo str, Append *node)
322
{
323
	appendStringInfo(str, " APPEND ");
324 325
	_outPlanInfo(str, (Plan *) node);

326 327
	appendStringInfo(str, " :appendplans ");
	_outNode(str, node->appendplans);
328

329 330
	appendStringInfo(str, " :unionrtables ");
	_outNode(str, node->unionrtables);
331

B
Bruce Momjian 已提交
332 333 334
	appendStringInfo(str,
					 " :inheritrelid %u :inheritrtable ",
					 node->inheritrelid);
335
	_outNode(str, node->inheritrtable);
336

337 338 339
}

/*
340
 *	Join is a subclass of Plan
341 342
 */
static void
343
_outJoin(StringInfo str, Join *node)
344
{
345
	appendStringInfo(str, " JOIN ");
346 347
	_outPlanInfo(str, (Plan *) node);

348 349 350
}

/*
351
 *	NestLoop is a subclass of Join
352 353
 */
static void
354
_outNestLoop(StringInfo str, NestLoop *node)
355
{
356
	appendStringInfo(str, " NESTLOOP ");
357
	_outPlanInfo(str, (Plan *) node);
358 359 360
}

/*
361
 *	MergeJoin is a subclass of Join
362 363
 */
static void
364
_outMergeJoin(StringInfo str, MergeJoin *node)
365
{
366
	appendStringInfo(str, " MERGEJOIN ");
367 368
	_outPlanInfo(str, (Plan *) node);

369
	appendStringInfo(str, " :mergeclauses ");
370
	_outNode(str, node->mergeclauses);
371 372 373
}

/*
374
 *	HashJoin is a subclass of Join.
375 376
 */
static void
377
_outHashJoin(StringInfo str, HashJoin *node)
378
{
379
	appendStringInfo(str, " HASHJOIN ");
380 381
	_outPlanInfo(str, (Plan *) node);

382
	appendStringInfo(str, " :hashclauses ");
383 384
	_outNode(str, node->hashclauses);

B
Bruce Momjian 已提交
385 386 387
	appendStringInfo(str,
					 " :hashjoinop %u ",
					 node->hashjoinop);
M
 
Marc G. Fournier 已提交
388

B
Bruce Momjian 已提交
389 390 391
	appendStringInfo(str,
					 " :hashdone %d ",
					 node->hashdone);
392 393
}

V
Vadim B. Mikheev 已提交
394 395 396
static void
_outSubPlan(StringInfo str, SubPlan *node)
{
M
 
Marc G. Fournier 已提交
397
	appendStringInfo(str, " SUBPLAN :plan ");
V
Vadim B. Mikheev 已提交
398
	_outNode(str, node->plan);
M
 
Marc G. Fournier 已提交
399 400

	appendStringInfo(str, " :planid %u :rtable ", node->plan_id);
V
Vadim B. Mikheev 已提交
401
	_outNode(str, node->rtable);
M
 
Marc G. Fournier 已提交
402

V
Vadim B. Mikheev 已提交
403
	appendStringInfo(str, " :setprm ");
404
	_outIntList(str, node->setParam);
M
 
Marc G. Fournier 已提交
405

V
Vadim B. Mikheev 已提交
406
	appendStringInfo(str, " :parprm ");
407
	_outIntList(str, node->parParam);
M
 
Marc G. Fournier 已提交
408

V
Vadim B. Mikheev 已提交
409 410 411 412
	appendStringInfo(str, " :slink ");
	_outNode(str, node->sublink);
}

413
/*
414
 *	Scan is a subclass of Node
415 416
 */
static void
417
_outScan(StringInfo str, Scan *node)
418
{
419
	appendStringInfo(str, " SCAN ");
420 421
	_outPlanInfo(str, (Plan *) node);

422
	appendStringInfo(str, " :scanrelid %u ", node->scanrelid);
423 424 425
}

/*
426
 *	SeqScan is a subclass of Scan
427 428
 */
static void
429
_outSeqScan(StringInfo str, SeqScan *node)
430
{
431
	appendStringInfo(str, " SEQSCAN ");
432 433
	_outPlanInfo(str, (Plan *) node);

434
	appendStringInfo(str, " :scanrelid %u ", node->scanrelid);
435 436 437
}

/*
438
 *	IndexScan is a subclass of Scan
439 440
 */
static void
441
_outIndexScan(StringInfo str, IndexScan *node)
442
{
443
	appendStringInfo(str, " INDEXSCAN ");
444 445
	_outPlanInfo(str, (Plan *) node);

446
	appendStringInfo(str, " :scanrelid %u :indxid ", node->scan.scanrelid);
447 448
	_outIntList(str, node->indxid);

449
	appendStringInfo(str, " :indxqual ");
450 451
	_outNode(str, node->indxqual);

V
Vadim B. Mikheev 已提交
452 453 454
	appendStringInfo(str, " :indxqualorig ");
	_outNode(str, node->indxqualorig);

455
	appendStringInfo(str, " :indxorderdir %d ", node->indxorderdir);
456 457
}

458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
/*
 *	TidScan is a subclass of Scan
 */
static void
_outTidScan(StringInfo str, TidScan *node)
{
	appendStringInfo(str, " TIDSCAN ");
	_outPlanInfo(str, (Plan *) node);

	appendStringInfo(str, " :scanrelid %u ", node->scan.scanrelid);
	appendStringInfo(str, " :needrescan %d ", node->needRescan);

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

}

475
/*
476
 *	Noname is a subclass of Plan
477 478
 */
static void
479
_outNoname(StringInfo str, Noname *node)
480
{
481
	appendStringInfo(str, " NONAME ");
482 483
	_outPlanInfo(str, (Plan *) node);

B
Bruce Momjian 已提交
484 485 486
	appendStringInfo(str, " :nonameid %u :keycount %d ",
					 node->nonameid,
					 node->keycount);
487 488 489
}

/*
490
 *	Sort is a subclass of Noname
491 492
 */
static void
493
_outSort(StringInfo str, Sort *node)
494
{
495
	appendStringInfo(str, " SORT ");
496 497
	_outPlanInfo(str, (Plan *) node);

498
	appendStringInfo(str, " :nonameid %u :keycount %d ",
B
Bruce Momjian 已提交
499 500
					 node->nonameid,
					 node->keycount);
501 502 503
}

static void
B
Bruce Momjian 已提交
504
_outAgg(StringInfo str, Agg *node)
505
{
506

507
	appendStringInfo(str, " AGG ");
508
	_outPlanInfo(str, (Plan *) node);
509 510 511
}

static void
512
_outGroup(StringInfo str, Group *node)
513
{
514
	appendStringInfo(str, " GRP ");
515 516 517
	_outPlanInfo(str, (Plan *) node);

	/* the actual Group fields */
M
 
Marc G. Fournier 已提交
518
	appendStringInfo(str, " :numCols %d :tuplePerGroup %s ",
B
Bruce Momjian 已提交
519 520
					 node->numCols,
					 node->tuplePerGroup ? "true" : "false");
521
}
522

523
/*
524
 *	For some reason, unique is a subclass of Noname.
525 526
 */
static void
527
_outUnique(StringInfo str, Unique *node)
528
{
529
	appendStringInfo(str, " UNIQUE ");
530 531
	_outPlanInfo(str, (Plan *) node);

532
	appendStringInfo(str, " :nonameid %u :keycount %d ",
B
Bruce Momjian 已提交
533 534
					 node->nonameid,
					 node->keycount);
535 536 537 538
}


/*
539
 *	Hash is a subclass of Noname
540 541
 */
static void
542
_outHash(StringInfo str, Hash *node)
543
{
544
	appendStringInfo(str, " HASH ");
545 546
	_outPlanInfo(str, (Plan *) node);

547
	appendStringInfo(str, " :hashkey ");
548
	_outNode(str, node->hashkey);
549 550 551 552
}

/*****************************************************************************
 *
553
 *	Stuff from primnodes.h.
554 555 556 557
 *
 *****************************************************************************/

/*
558
 *	Resdom is a subclass of Node
559 560
 */
static void
561
_outResdom(StringInfo str, Resdom *node)
562
{
563
	appendStringInfo(str, " RESDOM :resno %d :restype %u :restypmod %d",
B
Bruce Momjian 已提交
564 565 566
					 node->resno,
					 node->restype,
					 node->restypmod);
567

568
	appendStringInfo(str, " :resname \"%s\" :reskey %d :reskeyop %u",
B
Bruce Momjian 已提交
569 570 571
					 stringStringInfo(node->resname),
					 node->reskey,
					 node->reskeyop);
572

573 574
	appendStringInfo(str, " :ressortgroupref %d :resjunk %s ",
					 node->ressortgroupref,
B
Bruce Momjian 已提交
575
					 node->resjunk ? "true" : "false");
576 577 578
}

static void
579
_outFjoin(StringInfo str, Fjoin *node)
580
{
581
	int			i;
582

M
 
Marc G. Fournier 已提交
583
	appendStringInfo(str, " FJOIN :initialized %s :nNodes %d ",
B
Bruce Momjian 已提交
584 585
					 node->fj_initialized ? "true" : "false",
					 node->fj_nNodes);
586 587 588 589

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

B
Bruce Momjian 已提交
590 591
	appendStringInfo(str, " :results @ 0x%x :alwaysdone",
					 (int) node->fj_results);
592 593

	for (i = 0; i < node->fj_nNodes; i++)
594
		appendStringInfo(str, (node->fj_alwaysDone[i]) ? "true" : "false");
595 596 597
}

/*
598
 *	Expr is a subclass of Node
599 600
 */
static void
601
_outExpr(StringInfo str, Expr *node)
602
{
603
	char	   *opstr = NULL;
604

M
 
Marc G. Fournier 已提交
605
	appendStringInfo(str, " EXPR :typeOid %u ",
B
Bruce Momjian 已提交
606
					 node->typeOid);
607 608 609

	switch (node->opType)
	{
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
		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;
V
Vadim B. Mikheev 已提交
625 626 627
		case SUBPLAN_EXPR:
			opstr = "subp";
			break;
628
	}
629
	appendStringInfo(str, " :opType %s :oper ", stringStringInfo(opstr));
630
	_outNode(str, node->oper);
M
 
Marc G. Fournier 已提交
631

632
	appendStringInfo(str, " :args ");
633
	_outNode(str, node->args);
634 635 636
}

/*
637
 *	Var is a subclass of Expr
638 639
 */
static void
640
_outVar(StringInfo str, Var *node)
641
{
B
Bruce Momjian 已提交
642 643 644 645 646 647
	appendStringInfo(str,
				" VAR :varno %d :varattno %d :vartype %u :vartypmod %d ",
					 node->varno,
					 node->varattno,
					 node->vartype,
					 node->vartypmod);
M
 
Marc G. Fournier 已提交
648

B
Bruce Momjian 已提交
649 650 651 652
	appendStringInfo(str, " :varlevelsup %u :varnoold %d :varoattno %d",
					 node->varlevelsup,
					 node->varnoold,
					 node->varoattno);
653 654 655
}

/*
656
 *	Const is a subclass of Expr
657 658
 */
static void
659
_outConst(StringInfo str, Const *node)
660
{
B
Bruce Momjian 已提交
661 662 663 664 665
	appendStringInfo(str,
		" CONST :consttype %u :constlen %d :constisnull %s :constvalue ",
					 node->consttype,
					 node->constlen,
					 node->constisnull ? "true" : "false");
M
 
Marc G. Fournier 已提交
666

667
	if (node->constisnull)
B
Bruce Momjian 已提交
668
		appendStringInfo(str, "<>");
669 670
	else
		_outDatum(str, node->constvalue, node->consttype);
M
 
Marc G. Fournier 已提交
671

B
Bruce Momjian 已提交
672 673
	appendStringInfo(str, " :constbyval %s ",
					 node->constbyval ? "true" : "false");
674 675 676
}

/*
B
Bruce Momjian 已提交
677
 *	Aggref
678 679
 */
static void
680
_outAggref(StringInfo str, Aggref *node)
681
{
B
Bruce Momjian 已提交
682
	appendStringInfo(str,
683
					 " AGGREG :aggname %s :basetype %u :aggtype %u :target ",
B
Bruce Momjian 已提交
684 685 686
					 stringStringInfo(node->aggname),
					 node->basetype,
					 node->aggtype);
687
	_outNode(str, node->target);
M
 
Marc G. Fournier 已提交
688

689 690 691 692 693
	appendStringInfo(str, " :usenulls %s :aggstar %s :aggdistinct %s ",
					 node->usenulls ? "true" : "false",
					 node->aggstar ? "true" : "false",
					 node->aggdistinct ? "true" : "false");
	/* aggno is not dumped */
694 695
}

696 697 698 699 700 701
/*
 *	SubLink
 */
static void
_outSubLink(StringInfo str, SubLink *node)
{
B
Bruce Momjian 已提交
702 703 704 705
	appendStringInfo(str,
					 " SUBLINK :subLinkType %d :useor %s :lefthand ",
					 node->subLinkType,
					 node->useor ? "true" : "false");
706
	_outNode(str, node->lefthand);
M
 
Marc G. Fournier 已提交
707

708
	appendStringInfo(str, " :oper ");
B
Bruce Momjian 已提交
709
	_outNode(str, node->oper);
M
 
Marc G. Fournier 已提交
710

711 712 713 714
	appendStringInfo(str, " :subselect ");
	_outNode(str, node->subselect);
}

715
/*
716
 *	Array is a subclass of Expr
717 718
 */
static void
B
Bruce Momjian 已提交
719
_outArray(StringInfo str, Array *node)
720
{
721
	int			i;
722

B
Bruce Momjian 已提交
723 724 725 726 727
	appendStringInfo(str,
	  " ARRAY :arrayelemtype %u :arrayelemlength %d :arrayelembyval %c ",
					 node->arrayelemtype,
					 node->arrayelemlength,
					 node->arrayelembyval ? 't' : 'f');
M
 
Marc G. Fournier 已提交
728

M
 
Marc G. Fournier 已提交
729
	appendStringInfo(str, " :arrayndim %d :arraylow ", node->arrayndim);
730
	for (i = 0; i < node->arrayndim; i++)
M
 
Marc G. Fournier 已提交
731
		appendStringInfo(str, " %d ", node->arraylow.indx[i]);
732
	appendStringInfo(str, " :arrayhigh ");
733
	for (i = 0; i < node->arrayndim; i++)
M
 
Marc G. Fournier 已提交
734 735
		appendStringInfo(str, " %d ", node->arrayhigh.indx[i]);
	appendStringInfo(str, " :arraylen %d ", node->arraylen);
736 737 738
}

/*
739
 *	ArrayRef is a subclass of Expr
740 741
 */
static void
B
Bruce Momjian 已提交
742
_outArrayRef(StringInfo str, ArrayRef *node)
743
{
B
Bruce Momjian 已提交
744
	appendStringInfo(str,
T
Tom Lane 已提交
745
		" ARRAYREF :refelemtype %u :refattrlength %d :refelemlength %d ",
B
Bruce Momjian 已提交
746 747 748
					 node->refelemtype,
					 node->refattrlength,
					 node->refelemlength);
M
 
Marc G. Fournier 已提交
749

B
Bruce Momjian 已提交
750 751
	appendStringInfo(str, " :refelembyval %c :refupperindex ",
					 node->refelembyval ? 't' : 'f');
752 753
	_outNode(str, node->refupperindexpr);

754
	appendStringInfo(str, " :reflowerindex ");
755 756
	_outNode(str, node->reflowerindexpr);

757
	appendStringInfo(str, " :refexpr ");
758 759
	_outNode(str, node->refexpr);

760
	appendStringInfo(str, " :refassgnexpr ");
761
	_outNode(str, node->refassgnexpr);
762 763 764
}

/*
765
 *	Func is a subclass of Expr
766 767
 */
static void
768
_outFunc(StringInfo str, Func *node)
769
{
B
Bruce Momjian 已提交
770 771 772 773 774 775
	appendStringInfo(str,
		   " FUNC :funcid %u :functype %u :funcisindex %s :funcsize %d ",
					 node->funcid,
					 node->functype,
					 node->funcisindex ? "true" : "false",
					 node->funcsize);
M
 
Marc G. Fournier 已提交
776 777

	appendStringInfo(str, " :func_fcache @ 0x%x :func_tlist ",
B
Bruce Momjian 已提交
778
					 (int) node->func_fcache);
779 780 781 782
	_outNode(str, node->func_tlist);

	appendStringInfo(str, " :func_planlist ");
	_outNode(str, node->func_planlist);
783 784 785
}

/*
786
 *	Oper is a subclass of Expr
787 788
 */
static void
789
_outOper(StringInfo str, Oper *node)
790
{
B
Bruce Momjian 已提交
791 792 793 794 795
	appendStringInfo(str,
					 " OPER :opno %u :opid %u :opresulttype %u ",
					 node->opno,
					 node->opid,
					 node->opresulttype);
796 797 798
}

/*
799
 *	Param is a subclass of Expr
800 801
 */
static void
802
_outParam(StringInfo str, Param *node)
803
{
B
Bruce Momjian 已提交
804 805 806 807 808 809
	appendStringInfo(str,
		 " PARAM :paramkind %d :paramid %d :paramname %s :paramtype %u ",
					 node->paramkind,
					 node->paramid,
					 stringStringInfo(node->paramname),
					 node->paramtype);
810 811 812

	appendStringInfo(str, " :param_tlist ");
	_outNode(str, node->param_tlist);
813 814 815
}

/*
816
 *	Stuff from execnodes.h
817 818 819
 */

/*
820
 *	EState is a subclass of Node.
821 822
 */
static void
823
_outEState(StringInfo str, EState *node)
824
{
B
Bruce Momjian 已提交
825 826 827
	appendStringInfo(str,
					 " ESTATE :direction %d :range_table ",
					 node->es_direction);
828 829
	_outNode(str, node->es_range_table);

M
 
Marc G. Fournier 已提交
830
	appendStringInfo(str, " :result_relation_info @ 0x%x ",
B
Bruce Momjian 已提交
831
					 (int) (node->es_result_relation_info));
832 833 834
}

/*
835
 *	Stuff from relation.h
836
 */
837

838
static void
839
_outRelOptInfo(StringInfo str, RelOptInfo *node)
840
{
M
 
Marc G. Fournier 已提交
841
	appendStringInfo(str, " RELOPTINFO :relids ");
842 843
	_outIntList(str, node->relids);

B
Bruce Momjian 已提交
844
	appendStringInfo(str,
845 846 847
	 " :rows %.0f :width %d :indexed %s :pages %ld :tuples %.0f :targetlist ",
					 node->rows,
					 node->width,
B
Bruce Momjian 已提交
848 849
					 node->indexed ? "true" : "false",
					 node->pages,
850
					 node->tuples);
851 852
	_outNode(str, node->targetlist);

853
	appendStringInfo(str, " :pathlist ");
854 855 856 857 858 859 860 861
	_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.
	 */

B
Bruce Momjian 已提交
862 863 864 865
	appendStringInfo(str,
					 " :cheapestpath @ 0x%x :pruneable %s :restrictinfo ",
					 (int) node->cheapestpath,
					 node->pruneable ? "true" : "false");
866
	_outNode(str, node->restrictinfo);
867

868
	appendStringInfo(str, " :joininfo ");
869 870
	_outNode(str, node->joininfo);

871
	appendStringInfo(str, " :innerjoin ");
872
	_outNode(str, node->innerjoin);
873 874
}

875 876 877 878 879 880 881 882 883
static void
_outIndexOptInfo(StringInfo str, IndexOptInfo *node)
{
	appendStringInfo(str, " INDEXOPTINFO :indexoid %u :pages %ld :tuples %g ",
					 node->indexoid,
					 node->pages,
					 node->tuples);
}

884
/*
885
 *	TargetEntry is a subclass of Node.
886 887
 */
static void
888
_outTargetEntry(StringInfo str, TargetEntry *node)
889
{
M
 
Marc G. Fournier 已提交
890
	appendStringInfo(str, " TARGETENTRY :resdom ");
891 892
	_outNode(str, node->resdom);

893 894
	appendStringInfo(str, " :expr ");
	_outNode(str, node->expr);
895
}
896 897

static void
898
_outRangeTblEntry(StringInfo str, RangeTblEntry *node)
899
{
B
Bruce Momjian 已提交
900
	appendStringInfo(str,
901
					 " RTE :relname %s :refname %s :relid %u :inh %s :inFromCl %s :inJoinSet %s :skipAcl %s",
B
Bruce Momjian 已提交
902 903 904 905 906
					 stringStringInfo(node->relname),
					 stringStringInfo(node->refname),
					 node->relid,
					 node->inh ? "true" : "false",
					 node->inFromCl ? "true" : "false",
907
					 node->inJoinSet ? "true" : "false",
B
Bruce Momjian 已提交
908
					 node->skipAcl ? "true" : "false");
909
}
910

911
static void
912
_outRowMark(StringInfo str, RowMark *node)
913 914 915 916
{
	appendStringInfo(str, " ROWMARK :rti %u :info %u", node->rti, node->info);
}

917
/*
918
 *	Path is a subclass of Node.
919 920
 */
static void
921
_outPath(StringInfo str, Path *node)
922
{
923
	appendStringInfo(str, " PATH :pathtype %d :cost %.2f :pathkeys ",
B
Bruce Momjian 已提交
924 925
					 node->pathtype,
					 node->path_cost);
926
	_outNode(str, node->pathkeys);
927 928 929
}

/*
930
 *	IndexPath is a subclass of Path.
931 932
 */
static void
933
_outIndexPath(StringInfo str, IndexPath *node)
934
{
B
Bruce Momjian 已提交
935
	appendStringInfo(str,
936
					 " INDEXPATH :pathtype %d :cost %.2f :pathkeys ",
B
Bruce Momjian 已提交
937 938
					 node->path.pathtype,
					 node->path.path_cost);
939
	_outNode(str, node->path.pathkeys);
940

941
	appendStringInfo(str, " :indexid ");
942 943
	_outIntList(str, node->indexid);

944
	appendStringInfo(str, " :indexqual ");
945
	_outNode(str, node->indexqual);
946 947 948

	appendStringInfo(str, " :joinrelids ");
	_outIntList(str, node->joinrelids);
949 950
}

951 952 953 954 955 956 957
/*
 *	TidPath is a subclass of Path.
 */
static void
_outTidPath(StringInfo str, TidPath *node)
{
	appendStringInfo(str,
958
					 " TIDPATH :pathtype %d :cost %.2f :pathkeys ",
959 960 961 962 963 964 965 966 967 968 969
					 node->path.pathtype,
					 node->path.path_cost);
	_outNode(str, node->path.pathkeys);

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

	appendStringInfo(str, " :un joined_relids ");
	_outIntList(str, node->unjoined_relids);
}

970
/*
971
 *	NestPath is a subclass of Path
972 973
 */
static void
974
_outNestPath(StringInfo str, NestPath *node)
975
{
B
Bruce Momjian 已提交
976
	appendStringInfo(str,
977
					 " NESTPATH :pathtype %d :cost %.2f :pathkeys ",
B
Bruce Momjian 已提交
978 979
					 node->path.pathtype,
					 node->path.path_cost);
980
	_outNode(str, node->path.pathkeys);
981 982 983 984 985 986

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

B
Bruce Momjian 已提交
987
	appendStringInfo(str,
988
					 " :outerjoinpath @ 0x%x :innerjoinpath @ 0x%x ",
B
Bruce Momjian 已提交
989
					 (int) node->outerjoinpath,
990
					 (int) node->innerjoinpath);
991 992 993
}

/*
994
 *	MergePath is a subclass of NestPath.
995 996
 */
static void
997
_outMergePath(StringInfo str, MergePath *node)
998
{
B
Bruce Momjian 已提交
999
	appendStringInfo(str,
1000
					 " MERGEPATH :pathtype %d :cost %.2f :pathkeys ",
B
Bruce Momjian 已提交
1001 1002
					 node->jpath.path.pathtype,
					 node->jpath.path.path_cost);
1003
	_outNode(str, node->jpath.path.pathkeys);
1004 1005 1006 1007 1008 1009

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

B
Bruce Momjian 已提交
1010
	appendStringInfo(str,
1011
					 " :outerjoinpath @ 0x%x :innerjoinpath @ 0x%x ",
B
Bruce Momjian 已提交
1012
					 (int) node->jpath.outerjoinpath,
1013
					 (int) node->jpath.innerjoinpath);
1014

1015
	appendStringInfo(str, " :path_mergeclauses ");
1016 1017
	_outNode(str, node->path_mergeclauses);

1018
	appendStringInfo(str, " :outersortkeys ");
1019 1020
	_outNode(str, node->outersortkeys);

1021
	appendStringInfo(str, " :innersortkeys ");
1022
	_outNode(str, node->innersortkeys);
1023 1024 1025
}

/*
1026
 *	HashPath is a subclass of NestPath.
1027 1028
 */
static void
1029
_outHashPath(StringInfo str, HashPath *node)
1030
{
B
Bruce Momjian 已提交
1031
	appendStringInfo(str,
1032
					 " HASHPATH :pathtype %d :cost %.2f :pathkeys ",
B
Bruce Momjian 已提交
1033 1034
					 node->jpath.path.pathtype,
					 node->jpath.path.path_cost);
1035
	_outNode(str, node->jpath.path.pathkeys);
1036 1037 1038 1039 1040 1041

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

B
Bruce Momjian 已提交
1042
	appendStringInfo(str,
1043
					 " :outerjoinpath @ 0x%x :innerjoinpath @ 0x%x ",
B
Bruce Momjian 已提交
1044
					 (int) node->jpath.outerjoinpath,
1045
					 (int) node->jpath.innerjoinpath);
1046

1047
	appendStringInfo(str, " :path_hashclauses ");
1048
	_outNode(str, node->path_hashclauses);
1049 1050 1051
}

/*
1052
 *	PathKeyItem is a subclass of Node.
1053 1054
 */
static void
1055
_outPathKeyItem(StringInfo str, PathKeyItem *node)
1056
{
1057 1058 1059
	appendStringInfo(str, " PATHKEYITEM :sortop %u :key ",
					 node->sortop);
	_outNode(str, node->key);
1060 1061 1062
}

/*
1063
 *	RestrictInfo is a subclass of Node.
1064 1065
 */
static void
1066
_outRestrictInfo(StringInfo str, RestrictInfo *node)
1067
{
B
Bruce Momjian 已提交
1068
	appendStringInfo(str, " RESTRICTINFO :clause ");
1069 1070
	_outNode(str, node->clause);

1071
	appendStringInfo(str, " :subclauseindices ");
1072
	_outNode(str, node->subclauseindices);
1073

1074 1075 1076
	appendStringInfo(str, " :mergejoinoperator %u ", node->mergejoinoperator);
	appendStringInfo(str, " :left_sortop %u ", node->left_sortop);
	appendStringInfo(str, " :right_sortop %u ", node->right_sortop);
M
 
Marc G. Fournier 已提交
1077
	appendStringInfo(str, " :hashjoinoperator %u ", node->hashjoinoperator);
1078 1079 1080
}

/*
1081
 *	JoinInfo is a subclass of Node.
1082 1083
 */
static void
1084
_outJoinInfo(StringInfo str, JoinInfo *node)
1085
{
B
Bruce Momjian 已提交
1086 1087
	appendStringInfo(str, " JINFO :unjoined_relids ");
	_outIntList(str, node->unjoined_relids);
1088

1089 1090
	appendStringInfo(str, " :jinfo_restrictinfo ");
	_outNode(str, node->jinfo_restrictinfo);
1091 1092 1093 1094 1095 1096 1097 1098
}

/*
 * Print the value of a Datum given its type.
 */
static void
_outDatum(StringInfo str, Datum value, Oid type)
{
B
Bruce Momjian 已提交
1099
	char	   *s;
1100
	Size		length,
B
Bruce Momjian 已提交
1101
				typeLength;
1102 1103
	bool		byValue;
	int			i;
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115

	/*
	 * 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);
M
 
Marc G. Fournier 已提交
1116
		appendStringInfo(str, " %d [ ", length);
1117
		for (i = 0; i < sizeof(Datum); i++)
M
 
Marc G. Fournier 已提交
1118 1119
			appendStringInfo(str, " %d ", (int) (s[i]));
		appendStringInfo(str, "] ");
1120
	}
1121 1122 1123 1124
	else
	{							/* !byValue */
		s = (char *) DatumGetPointer(value);
		if (!PointerIsValid(s))
M
 
Marc G. Fournier 已提交
1125
			appendStringInfo(str, " 0 [ ] ");
1126 1127
		else
		{
B
Bruce Momjian 已提交
1128

1129 1130 1131 1132 1133 1134
			/*
			 * 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);
M
 
Marc G. Fournier 已提交
1135
			appendStringInfo(str, " %d [ ", length);
1136
			for (i = 0; i < length; i++)
M
 
Marc G. Fournier 已提交
1137 1138
				appendStringInfo(str, " %d ", (int) (s[i]));
			appendStringInfo(str, "] ");
1139
		}
1140 1141 1142 1143
	}
}

static void
1144
_outIter(StringInfo str, Iter *node)
1145
{
M
 
Marc G. Fournier 已提交
1146
	appendStringInfo(str, " ITER :iterexpr ");
1147
	_outNode(str, node->iterexpr);
1148 1149 1150
}

static void
1151
_outStream(StringInfo str, Stream *node)
1152
{
B
Bruce Momjian 已提交
1153 1154 1155 1156 1157 1158
	appendStringInfo(str,
					 " STREAM :pathptr @ 0x%x :cinfo @ 0x%x :clausetype %d :upstream @ 0x%x ",
					 (int) node->pathptr,
					 (int) node->cinfo,
					 (int) node->clausetype,
					 (int) node->upstream);
1159

B
Bruce Momjian 已提交
1160 1161 1162 1163 1164 1165
	appendStringInfo(str,
		   " :downstream @ 0x%x :groupup %d :groupcost %f :groupsel %f ",
					 (int) node->downstream,
					 node->groupup,
					 node->groupcost,
					 node->groupsel);
1166
}
1167

1168 1169 1170
static void
_outAExpr(StringInfo str, A_Expr *node)
{
1171
	appendStringInfo(str, "EXPR ");
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189
	switch (node->oper)
	{
		case AND:
			appendStringInfo(str, "AND");
			break;
		case OR:
			appendStringInfo(str, "OR");
			break;
		case NOT:
			appendStringInfo(str, "NOT");
			break;
		case ISNULL:
			appendStringInfo(str, "ISNULL");
			break;
		case NOTNULL:
			appendStringInfo(str, "NOTNULL");
			break;
		default:
1190
			appendStringInfo(str, stringStringInfo(node->opname));
1191 1192
			break;
	}
1193 1194 1195 1196 1197
	_outNode(str, node->lexpr);
	_outNode(str, node->rexpr);
	return;
}

1198
static void
1199
_outValue(StringInfo str, Value *value)
1200
{
1201 1202
	switch (value->type)
	{
B
Bruce Momjian 已提交
1203
			case T_String:
M
 
Marc G. Fournier 已提交
1204
			appendStringInfo(str, " \"%s\" ", stringStringInfo(value->val.str));
1205 1206
			break;
		case T_Integer:
1207
			appendStringInfo(str, " %ld ", value->val.ival);
1208 1209
			break;
		case T_Float:
1210
			appendStringInfo(str, " %f ", value->val.dval);
1211 1212 1213
			break;
		default:
			break;
1214 1215
	}
	return;
1216 1217
}

1218 1219 1220
static void
_outIdent(StringInfo str, Ident *node)
{
1221
	appendStringInfo(str, " IDENT \"%s\" ", stringStringInfo(node->name));
1222 1223 1224
	return;
}

1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242
static void
_outAttr(StringInfo str, Attr *node)
{
	List	   *l;

	appendStringInfo(str, " ATTR \"%s\" ", stringStringInfo(node->relname));

	appendStringInfo(str, "(");
	foreach(l, node->attrs)
	{
		_outNode(str, lfirst(l));
		if (lnext(l))
			appendStringInfo(str, ",");
	}
	appendStringInfo(str, ")");
	return;
}

1243 1244 1245
static void
_outAConst(StringInfo str, A_Const *node)
{
1246
	appendStringInfo(str, "CONST ");
1247 1248 1249 1250
	_outValue(str, &(node->val));
	return;
}

T
Thomas G. Lockhart 已提交
1251 1252 1253
static void
_outConstraint(StringInfo str, Constraint *node)
{
B
Bruce Momjian 已提交
1254
	appendStringInfo(str, " %s :type", stringStringInfo(node->name));
T
Thomas G. Lockhart 已提交
1255 1256 1257 1258

	switch (node->contype)
	{
		case CONSTR_PRIMARY:
1259
			appendStringInfo(str, " PRIMARY KEY ");
T
Thomas G. Lockhart 已提交
1260 1261 1262 1263
			_outNode(str, node->keys);
			break;

		case CONSTR_CHECK:
1264 1265 1266 1267
			appendStringInfo(str, " CHECK :raw ");
			_outNode(str, node->raw_expr);
			appendStringInfo(str, " :cooked %s ",
							 stringStringInfo(node->cooked_expr));
T
Thomas G. Lockhart 已提交
1268 1269 1270
			break;

		case CONSTR_DEFAULT:
1271 1272 1273 1274
			appendStringInfo(str, " DEFAULT :raw ");
			_outNode(str, node->raw_expr);
			appendStringInfo(str, " :cooked %s ",
							 stringStringInfo(node->cooked_expr));
T
Thomas G. Lockhart 已提交
1275 1276 1277
			break;

		case CONSTR_NOTNULL:
1278
			appendStringInfo(str, " NOT NULL ");
T
Thomas G. Lockhart 已提交
1279 1280 1281
			break;

		case CONSTR_UNIQUE:
1282
			appendStringInfo(str, " UNIQUE ");
T
Thomas G. Lockhart 已提交
1283 1284 1285 1286
			_outNode(str, node->keys);
			break;

		default:
1287
			appendStringInfo(str, "<unrecognized constraint>");
T
Thomas G. Lockhart 已提交
1288 1289 1290 1291 1292
			break;
	}
}

static void
1293
_outCaseExpr(StringInfo str, CaseExpr *node)
T
Thomas G. Lockhart 已提交
1294
{
1295
	appendStringInfo(str, "CASE ");
T
Thomas G. Lockhart 已提交
1296
	_outNode(str, node->args);
M
 
Marc G. Fournier 已提交
1297

1298
	appendStringInfo(str, " :default ");
T
Thomas G. Lockhart 已提交
1299
	_outNode(str, node->defresult);
M
 
Marc G. Fournier 已提交
1300

T
Thomas G. Lockhart 已提交
1301 1302 1303 1304
	return;
}

static void
1305
_outCaseWhen(StringInfo str, CaseWhen *node)
T
Thomas G. Lockhart 已提交
1306
{
1307
	appendStringInfo(str, " WHEN ");
T
Thomas G. Lockhart 已提交
1308
	_outNode(str, node->expr);
M
 
Marc G. Fournier 已提交
1309

1310
	appendStringInfo(str, " :then ");
T
Thomas G. Lockhart 已提交
1311
	_outNode(str, node->result);
M
 
Marc G. Fournier 已提交
1312

T
Thomas G. Lockhart 已提交
1313 1314 1315
	return;
}

1316 1317
/*
 * _outNode -
1318
 *	  converts a Node into ascii string and append it to 'str'
1319 1320 1321 1322
 */
static void
_outNode(StringInfo str, void *obj)
{
1323 1324
	if (obj == NULL)
	{
B
Bruce Momjian 已提交
1325
		appendStringInfo(str, "<>");
1326 1327
		return;
	}
1328

1329 1330
	if (nodeTag(obj) == T_List)
	{
1331
		List	   *l;
1332 1333 1334 1335 1336 1337 1338 1339 1340

		appendStringInfo(str, "(");
		foreach(l, (List *) obj)
		{
			_outNode(str, lfirst(l));
			if (lnext(l))
				appendStringInfo(str, " ");
		}
		appendStringInfo(str, ")");
1341
	}
1342 1343 1344 1345 1346
	else
	{
		appendStringInfo(str, "{");
		switch (nodeTag(obj))
		{
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
			case T_CreateStmt:
				_outCreateStmt(str, obj);
				break;
			case T_IndexStmt:
				_outIndexStmt(str, obj);
				break;

			case T_ColumnDef:
				_outColumnDef(str, obj);
				break;
1357 1358 1359
			case T_TypeName:
				_outTypeName(str, obj);
				break;
1360 1361 1362
			case T_IndexElem:
				_outIndexElem(str, obj);
				break;
1363 1364 1365
			case T_Query:
				_outQuery(str, obj);
				break;
1366 1367 1368 1369 1370
			case T_SortClause:
				_outSortClause(str, obj);
				break;
			case T_GroupClause:
				_outGroupClause(str, obj);
1371
				break;
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401
			case T_Plan:
				_outPlan(str, obj);
				break;
			case T_Result:
				_outResult(str, obj);
				break;
			case T_Append:
				_outAppend(str, obj);
				break;
			case T_Join:
				_outJoin(str, obj);
				break;
			case T_NestLoop:
				_outNestLoop(str, obj);
				break;
			case T_MergeJoin:
				_outMergeJoin(str, obj);
				break;
			case T_HashJoin:
				_outHashJoin(str, obj);
				break;
			case T_Scan:
				_outScan(str, obj);
				break;
			case T_SeqScan:
				_outSeqScan(str, obj);
				break;
			case T_IndexScan:
				_outIndexScan(str, obj);
				break;
1402 1403 1404
			case T_TidScan:
				_outTidScan(str, obj);
				break;
1405 1406
			case T_Noname:
				_outNoname(str, obj);
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422
				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;
V
Vadim B. Mikheev 已提交
1423 1424 1425
			case T_SubPlan:
				_outSubPlan(str, obj);
				break;
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440
			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;
B
Bruce Momjian 已提交
1441 1442
			case T_Aggref:
				_outAggref(str, obj);
1443
				break;
1444 1445 1446
			case T_SubLink:
				_outSubLink(str, obj);
				break;
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464
			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;
B
Bruce Momjian 已提交
1465
			case T_RelOptInfo:
B
Bruce Momjian 已提交
1466
				_outRelOptInfo(str, obj);
1467
				break;
1468 1469 1470
			case T_IndexOptInfo:
				_outIndexOptInfo(str, obj);
				break;
1471 1472 1473 1474 1475 1476
			case T_TargetEntry:
				_outTargetEntry(str, obj);
				break;
			case T_RangeTblEntry:
				_outRangeTblEntry(str, obj);
				break;
1477 1478 1479
			case T_RowMark:
				_outRowMark(str, obj);
				break;
1480 1481 1482 1483 1484 1485
			case T_Path:
				_outPath(str, obj);
				break;
			case T_IndexPath:
				_outIndexPath(str, obj);
				break;
1486 1487 1488
			case T_TidPath:
				_outTidPath(str, obj);
				break;
1489 1490
			case T_NestPath:
				_outNestPath(str, obj);
1491 1492 1493 1494 1495 1496 1497
				break;
			case T_MergePath:
				_outMergePath(str, obj);
				break;
			case T_HashPath:
				_outHashPath(str, obj);
				break;
1498 1499
			case T_PathKeyItem:
				_outPathKeyItem(str, obj);
1500
				break;
1501 1502
			case T_RestrictInfo:
				_outRestrictInfo(str, obj);
1503
				break;
1504 1505
			case T_JoinInfo:
				_outJoinInfo(str, obj);
1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517
				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;
1518 1519 1520 1521 1522 1523 1524 1525 1526
			case T_A_Expr:
				_outAExpr(str, obj);
				break;
			case T_Ident:
				_outIdent(str, obj);
				break;
			case T_A_Const:
				_outAConst(str, obj);
				break;
T
Thomas G. Lockhart 已提交
1527 1528 1529 1530 1531 1532 1533 1534 1535
			case T_Constraint:
				_outConstraint(str, obj);
				break;
			case T_CaseExpr:
				_outCaseExpr(str, obj);
				break;
			case T_CaseWhen:
				_outCaseWhen(str, obj);
				break;
1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548

			case T_VariableSetStmt:
				break;
			case T_SelectStmt:
				_outSelectStmt(str, obj);
				break;
			case T_FuncCall:
				_outFuncCall(str, obj);
				break;
			case T_Attr:
				_outAttr(str, obj);
				break;

1549
			default:
B
Bruce Momjian 已提交
1550
				elog(NOTICE, "_outNode: don't know how to print type %d ",
1551 1552
					 nodeTag(obj));
				break;
1553 1554
		}
		appendStringInfo(str, "}");
1555
	}
1556
	return;
1557 1558 1559 1560
}

/*
 * nodeToString -
1561
 *	   returns the ascii representation of the Node as a palloc'd string
1562
 */
1563
char *
1564 1565
nodeToString(void *obj)
{
B
Bruce Momjian 已提交
1566
	StringInfoData str;
1567

1568 1569 1570 1571
	/* see stringinfo.h for an explanation of this maneuver */
	initStringInfo(&str);
	_outNode(&str, obj);
	return str.data;
1572
}