outfuncs.c 33.9 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.99 1999/12/10 07:37:31 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 268 269 270 271 272
	appendStringInfo(str,
				  ":cost %g :size %d :width %d :state %s :qptargetlist ",
					 node->cost,
					 node->plan_size,
					 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 683 684 685 686
	appendStringInfo(str,
				 " AGGREG :aggname %s :basetype %u :aggtype %u :target ",
					 stringStringInfo(node->aggname),
					 node->basetype,
					 node->aggtype);
687
	_outNode(str, node->target);
M
 
Marc G. Fournier 已提交
688

689
	appendStringInfo(str, " :usenulls %s ",
B
Bruce Momjian 已提交
690
					 node->usenulls ? "true" : "false");
691 692
}

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

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

708 709 710 711
	appendStringInfo(str, " :subselect ");
	_outNode(str, node->subselect);
}

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

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

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

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

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

751
	appendStringInfo(str, " :reflowerindex ");
752 753
	_outNode(str, node->reflowerindexpr);

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

757
	appendStringInfo(str, " :refassgnexpr ");
758
	_outNode(str, node->refassgnexpr);
759 760 761
}

/*
762
 *	Func is a subclass of Expr
763 764
 */
static void
765
_outFunc(StringInfo str, Func *node)
766
{
B
Bruce Momjian 已提交
767 768 769 770 771 772
	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 已提交
773 774

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

	appendStringInfo(str, " :func_planlist ");
	_outNode(str, node->func_planlist);
780 781 782
}

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

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

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

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

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

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

/*
832
 *	Stuff from relation.h
833 834
 */
static void
835
_outRelOptInfo(StringInfo str, RelOptInfo *node)
836
{
M
 
Marc G. Fournier 已提交
837
	appendStringInfo(str, " RELOPTINFO :relids ");
838 839
	_outIntList(str, node->relids);

B
Bruce Momjian 已提交
840 841 842 843 844 845 846
	appendStringInfo(str,
	 " :indexed %s :pages %u :tuples %u :size %u :width %u :targetlist ",
					 node->indexed ? "true" : "false",
					 node->pages,
					 node->tuples,
					 node->size,
					 node->width);
847 848
	_outNode(str, node->targetlist);

849
	appendStringInfo(str, " :pathlist ");
850 851 852 853 854 855 856 857
	_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 已提交
858 859 860 861
	appendStringInfo(str,
					 " :cheapestpath @ 0x%x :pruneable %s :restrictinfo ",
					 (int) node->cheapestpath,
					 node->pruneable ? "true" : "false");
862
	_outNode(str, node->restrictinfo);
863

864
	appendStringInfo(str, " :joininfo ");
865 866
	_outNode(str, node->joininfo);

867
	appendStringInfo(str, " :innerjoin ");
868
	_outNode(str, node->innerjoin);
869 870 871
}

/*
872
 *	TargetEntry is a subclass of Node.
873 874
 */
static void
875
_outTargetEntry(StringInfo str, TargetEntry *node)
876
{
M
 
Marc G. Fournier 已提交
877
	appendStringInfo(str, " TARGETENTRY :resdom ");
878 879
	_outNode(str, node->resdom);

880 881
	appendStringInfo(str, " :expr ");
	_outNode(str, node->expr);
882
}
883 884

static void
885
_outRangeTblEntry(StringInfo str, RangeTblEntry *node)
886
{
B
Bruce Momjian 已提交
887
	appendStringInfo(str,
888
					 " RTE :relname %s :refname %s :relid %u :inh %s :inFromCl %s :inJoinSet %s :skipAcl %s",
B
Bruce Momjian 已提交
889 890 891 892 893
					 stringStringInfo(node->relname),
					 stringStringInfo(node->refname),
					 node->relid,
					 node->inh ? "true" : "false",
					 node->inFromCl ? "true" : "false",
894
					 node->inJoinSet ? "true" : "false",
B
Bruce Momjian 已提交
895
					 node->skipAcl ? "true" : "false");
896
}
897

898
static void
899
_outRowMark(StringInfo str, RowMark *node)
900 901 902 903
{
	appendStringInfo(str, " ROWMARK :rti %u :info %u", node->rti, node->info);
}

904
/*
905
 *	Path is a subclass of Node.
906 907
 */
static void
908
_outPath(StringInfo str, Path *node)
909
{
910
	appendStringInfo(str, " PATH :pathtype %d :cost %f :pathkeys ",
B
Bruce Momjian 已提交
911 912
					 node->pathtype,
					 node->path_cost);
913
	_outNode(str, node->pathkeys);
914 915 916
}

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

928
	appendStringInfo(str, " :indexid ");
929 930
	_outIntList(str, node->indexid);

931
	appendStringInfo(str, " :indexqual ");
932
	_outNode(str, node->indexqual);
933 934 935

	appendStringInfo(str, " :joinrelids ");
	_outIntList(str, node->joinrelids);
936 937
}

938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
/*
 *	TidPath is a subclass of Path.
 */
static void
_outTidPath(StringInfo str, TidPath *node)
{
	appendStringInfo(str,
					 " TIDPATH :pathtype %d :cost %f :pathkeys ",
					 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);
}

957
/*
958
 *	NestPath is a subclass of Path
959 960
 */
static void
961
_outNestPath(StringInfo str, NestPath *node)
962
{
B
Bruce Momjian 已提交
963 964 965 966
	appendStringInfo(str,
					 " NESTPATH :pathtype %d :cost %f :pathkeys ",
					 node->path.pathtype,
					 node->path.path_cost);
967
	_outNode(str, node->path.pathkeys);
968

969 970
	appendStringInfo(str, " :pathinfo ");
	_outNode(str, node->pathinfo);
971 972 973 974 975 976

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

B
Bruce Momjian 已提交
977
	appendStringInfo(str,
978
					 " :outerjoinpath @ 0x%x :innerjoinpath @ 0x%x ",
B
Bruce Momjian 已提交
979
					 (int) node->outerjoinpath,
980
					 (int) node->innerjoinpath);
981 982 983
}

/*
984
 *	MergePath is a subclass of NestPath.
985 986
 */
static void
987
_outMergePath(StringInfo str, MergePath *node)
988
{
B
Bruce Momjian 已提交
989 990 991 992
	appendStringInfo(str,
					 " MERGEPATH :pathtype %d :cost %f :pathkeys ",
					 node->jpath.path.pathtype,
					 node->jpath.path.path_cost);
993
	_outNode(str, node->jpath.path.pathkeys);
994

995 996
	appendStringInfo(str, " :pathinfo ");
	_outNode(str, node->jpath.pathinfo);
997 998 999 1000 1001 1002

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

B
Bruce Momjian 已提交
1003
	appendStringInfo(str,
1004
					 " :outerjoinpath @ 0x%x :innerjoinpath @ 0x%x ",
B
Bruce Momjian 已提交
1005
					 (int) node->jpath.outerjoinpath,
1006
					 (int) node->jpath.innerjoinpath);
1007

1008
	appendStringInfo(str, " :path_mergeclauses ");
1009 1010
	_outNode(str, node->path_mergeclauses);

1011
	appendStringInfo(str, " :outersortkeys ");
1012 1013
	_outNode(str, node->outersortkeys);

1014
	appendStringInfo(str, " :innersortkeys ");
1015
	_outNode(str, node->innersortkeys);
1016 1017 1018
}

/*
1019
 *	HashPath is a subclass of NestPath.
1020 1021
 */
static void
1022
_outHashPath(StringInfo str, HashPath *node)
1023
{
B
Bruce Momjian 已提交
1024 1025 1026 1027
	appendStringInfo(str,
					 " HASHPATH :pathtype %d :cost %f :pathkeys ",
					 node->jpath.path.pathtype,
					 node->jpath.path.path_cost);
1028
	_outNode(str, node->jpath.path.pathkeys);
1029

1030 1031
	appendStringInfo(str, " :pathinfo ");
	_outNode(str, node->jpath.pathinfo);
1032 1033 1034 1035 1036 1037

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

B
Bruce Momjian 已提交
1038
	appendStringInfo(str,
1039
					 " :outerjoinpath @ 0x%x :innerjoinpath @ 0x%x ",
B
Bruce Momjian 已提交
1040
					 (int) node->jpath.outerjoinpath,
1041
					 (int) node->jpath.innerjoinpath);
1042

1043
	appendStringInfo(str, " :path_hashclauses ");
1044
	_outNode(str, node->path_hashclauses);
1045 1046 1047
}

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

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

B
Bruce Momjian 已提交
1067
	appendStringInfo(str,
1068
					 " :selectivity %f :subclauseindices ",
1069
					 node->selectivity);
1070
	_outNode(str, node->subclauseindices);
1071

1072 1073 1074
	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 已提交
1075
	appendStringInfo(str, " :hashjoinoperator %u ", node->hashjoinoperator);
1076 1077 1078
}

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

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

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

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

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

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

static void
1149
_outStream(StringInfo str, Stream *node)
1150
{
B
Bruce Momjian 已提交
1151 1152 1153 1154 1155 1156
	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);
1157

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

1166 1167 1168
static void
_outAExpr(StringInfo str, A_Expr *node)
{
1169
	appendStringInfo(str, "EXPR ");
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
	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:
1188
			appendStringInfo(str, stringStringInfo(node->opname));
1189 1190
			break;
	}
1191 1192 1193 1194 1195
	_outNode(str, node->lexpr);
	_outNode(str, node->rexpr);
	return;
}

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

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

1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
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;
}

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

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

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

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

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

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

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

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

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

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

T
Thomas G. Lockhart 已提交
1299 1300 1301 1302
	return;
}

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

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

T
Thomas G. Lockhart 已提交
1311 1312 1313
	return;
}

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

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

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

			case T_ColumnDef:
				_outColumnDef(str, obj);
				break;
1355 1356 1357
			case T_TypeName:
				_outTypeName(str, obj);
				break;
1358 1359 1360
			case T_IndexElem:
				_outIndexElem(str, obj);
				break;
1361 1362 1363
			case T_Query:
				_outQuery(str, obj);
				break;
1364 1365 1366 1367 1368
			case T_SortClause:
				_outSortClause(str, obj);
				break;
			case T_GroupClause:
				_outGroupClause(str, obj);
1369
				break;
1370 1371 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
			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;
1400 1401 1402
			case T_TidScan:
				_outTidScan(str, obj);
				break;
1403 1404
			case T_Noname:
				_outNoname(str, obj);
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420
				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 已提交
1421 1422 1423
			case T_SubPlan:
				_outSubPlan(str, obj);
				break;
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438
			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 已提交
1439 1440
			case T_Aggref:
				_outAggref(str, obj);
1441
				break;
1442 1443 1444
			case T_SubLink:
				_outSubLink(str, obj);
				break;
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462
			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 已提交
1463
			case T_RelOptInfo:
B
Bruce Momjian 已提交
1464
				_outRelOptInfo(str, obj);
1465 1466 1467 1468 1469 1470 1471
				break;
			case T_TargetEntry:
				_outTargetEntry(str, obj);
				break;
			case T_RangeTblEntry:
				_outRangeTblEntry(str, obj);
				break;
1472 1473 1474
			case T_RowMark:
				_outRowMark(str, obj);
				break;
1475 1476 1477 1478 1479 1480
			case T_Path:
				_outPath(str, obj);
				break;
			case T_IndexPath:
				_outIndexPath(str, obj);
				break;
1481 1482 1483
			case T_TidPath:
				_outTidPath(str, obj);
				break;
1484 1485
			case T_NestPath:
				_outNestPath(str, obj);
1486 1487 1488 1489 1490 1491 1492
				break;
			case T_MergePath:
				_outMergePath(str, obj);
				break;
			case T_HashPath:
				_outHashPath(str, obj);
				break;
1493 1494
			case T_PathKeyItem:
				_outPathKeyItem(str, obj);
1495
				break;
1496 1497
			case T_RestrictInfo:
				_outRestrictInfo(str, obj);
1498
				break;
1499 1500
			case T_JoinInfo:
				_outJoinInfo(str, obj);
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512
				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;
1513 1514 1515 1516 1517 1518 1519 1520 1521
			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 已提交
1522 1523 1524 1525 1526 1527 1528 1529 1530
			case T_Constraint:
				_outConstraint(str, obj);
				break;
			case T_CaseExpr:
				_outCaseExpr(str, obj);
				break;
			case T_CaseWhen:
				_outCaseWhen(str, obj);
				break;
1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543

			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;

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

/*
 * nodeToString -
1556
 *	   returns the ascii representation of the Node as a palloc'd string
1557
 */
1558
char *
1559 1560
nodeToString(void *obj)
{
B
Bruce Momjian 已提交
1561
	StringInfoData str;
1562

1563 1564 1565 1566
	/* see stringinfo.h for an explanation of this maneuver */
	initStringInfo(&str);
	_outNode(&str, obj);
	return str.data;
1567
}