equalfuncs.c 42.5 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * equalfuncs.c
4 5 6 7 8
 *	  Equality functions to compare node trees.
 *
 * NOTE: a general convention when copying or comparing plan nodes is
 * that we ignore the executor state subnode.  We do not need to look
 * at it because no current uses of copyObject() or equal() need to
9
 * deal with already-executing plan trees.	By leaving the state subnodes
10 11 12 13 14 15 16 17
 * out, we avoid needing to write copy/compare routines for all the
 * different executor state node types.
 *
 * Currently, in fact, equal() doesn't know how to compare Plan nodes
 * at all, let alone their executor-state subnodes.  This will probably
 * need to be fixed someday, but presently there is no need to compare
 * plan trees.
 *
18
 *
19
 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
Bruce Momjian's avatar
Add:  
Bruce Momjian committed
20
 * Portions Copyright (c) 1994, Regents of the University of California
21 22
 *
 * IDENTIFICATION
23
 *	  $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.101 2001/08/16 20:38:53 tgl Exp $
24 25 26
 *
 *-------------------------------------------------------------------------
 */
27

28 29 30
#include "postgres.h"

#include "nodes/plannodes.h"
Bruce Momjian's avatar
Bruce Momjian committed
31
#include "nodes/relation.h"
32 33
#include "utils/datum.h"

34 35

/* Macro for comparing string fields that might be NULL */
36
#define equalstr(a, b)	\
37 38
	(((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))

39

40
/*
41
 *	Stuff from primnodes.h
42 43
 */

44
static bool
45
_equalResdom(Resdom *a, Resdom *b)
46
{
47
	if (a->resno != b->resno)
48
		return false;
49
	if (a->restype != b->restype)
50
		return false;
51
	if (a->restypmod != b->restypmod)
52
		return false;
53 54
	if (!equalstr(a->resname, b->resname))
		return false;
55
	if (a->ressortgroupref != b->ressortgroupref)
56
		return false;
57
	if (a->reskey != b->reskey)
58
		return false;
59
	if (a->reskeyop != b->reskeyop)
60
		return false;
61
	/* we ignore resjunk flag ... is this correct? */
62

63
	return true;
64 65
}

66
static bool
67
_equalFjoin(Fjoin *a, Fjoin *b)
68
{
69
	int			nNodes;
70 71

	if (a->fj_initialized != b->fj_initialized)
72
		return false;
73
	if (a->fj_nNodes != b->fj_nNodes)
74
		return false;
75
	if (!equal(a->fj_innerNode, b->fj_innerNode))
76
		return false;
77 78 79

	nNodes = a->fj_nNodes;
	if (memcmp(a->fj_results, b->fj_results, nNodes * sizeof(Datum)) != 0)
80
		return false;
81
	if (memcmp(a->fj_alwaysDone, b->fj_alwaysDone, nNodes * sizeof(bool)) != 0)
82
		return false;
83

84
	return true;
85 86
}

87
static bool
88
_equalExpr(Expr *a, Expr *b)
89
{
90 91 92 93 94

	/*
	 * We do not examine typeOid, since the optimizer often doesn't bother
	 * to set it in created nodes, and it is logically a derivative of the
	 * oper field anyway.
95
	 */
96
	if (a->opType != b->opType)
97
		return false;
98
	if (!equal(a->oper, b->oper))
99
		return false;
100
	if (!equal(a->args, b->args))
101
		return false;
102

103
	return true;
104 105
}

106
static bool
107
_equalVar(Var *a, Var *b)
108
{
109
	if (a->varno != b->varno)
110
		return false;
111
	if (a->varattno != b->varattno)
112
		return false;
113
	if (a->vartype != b->vartype)
114
		return false;
115
	if (a->vartypmod != b->vartypmod)
116
		return false;
117
	if (a->varlevelsup != b->varlevelsup)
118
		return false;
119
	if (a->varnoold != b->varnoold)
120
		return false;
121
	if (a->varoattno != b->varoattno)
122
		return false;
123

124
	return true;
125 126
}

127
static bool
128
_equalOper(Oper *a, Oper *b)
129
{
130
	if (a->opno != b->opno)
131
		return false;
132
	if (a->opresulttype != b->opresulttype)
133
		return false;
134 135

	/*
136 137 138
	 * We do not examine opid or op_fcache, since these are logically
	 * derived from opno, and they may not be set yet depending on how far
	 * along the node is in the parse/plan pipeline.
139
	 *
140 141 142
	 * (Besides, op_fcache is executor state, which we don't check --- see
	 * notes at head of file.)
	 *
143 144
	 * It's probably not really necessary to check opresulttype either...
	 */
145

146
	return true;
147 148
}

149
static bool
150
_equalConst(Const *a, Const *b)
151
{
152
	if (a->consttype != b->consttype)
153
		return false;
154
	if (a->constlen != b->constlen)
155
		return false;
156
	if (a->constisnull != b->constisnull)
157
		return false;
158
	if (a->constbyval != b->constbyval)
159
		return false;
160
	/* XXX What about constisset and constiscast? */
161

162
	/*
163 164 165
	 * We treat all NULL constants of the same type as equal. Someday this
	 * might need to change?  But datumIsEqual doesn't work on nulls,
	 * so...
166 167 168
	 */
	if (a->constisnull)
		return true;
169 170
	return datumIsEqual(a->constvalue, b->constvalue,
						a->constbyval, a->constlen);
171 172
}

173
static bool
174
_equalParam(Param *a, Param *b)
175
{
176
	if (a->paramkind != b->paramkind)
177
		return false;
178
	if (a->paramtype != b->paramtype)
179
		return false;
180 181 182

	switch (a->paramkind)
	{
183 184 185 186
		case PARAM_NAMED:
		case PARAM_NEW:
		case PARAM_OLD:
			if (strcmp(a->paramname, b->paramname) != 0)
187
				return false;
188 189
			break;
		case PARAM_NUM:
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
190
		case PARAM_EXEC:
191
			if (a->paramid != b->paramid)
192
				return false;
193 194 195 196 197 198
			break;
		case PARAM_INVALID:

			/*
			 * XXX: Hmmm... What are we supposed to return in this case ??
			 */
199
			return true;
200 201
			break;
		default:
202
			elog(ERROR, "_equalParam: Invalid paramkind value: %d",
203
				 a->paramkind);
204 205
	}

206
	return true;
207 208
}

209 210 211 212 213 214 215
static bool
_equalFunc(Func *a, Func *b)
{
	if (a->funcid != b->funcid)
		return false;
	if (a->functype != b->functype)
		return false;
216
	/* Note we do not look at func_fcache; see notes for _equalOper */
217 218 219 220

	return true;
}

221 222 223 224 225 226 227 228 229 230 231
static bool
_equalAggref(Aggref *a, Aggref *b)
{
	if (strcmp(a->aggname, b->aggname) != 0)
		return false;
	if (a->basetype != b->basetype)
		return false;
	if (a->aggtype != b->aggtype)
		return false;
	if (!equal(a->target, b->target))
		return false;
232 233 234 235
	if (a->aggstar != b->aggstar)
		return false;
	if (a->aggdistinct != b->aggdistinct)
		return false;
236
	/* ignore aggno, which is only a private field for the executor */
237 238 239
	return true;
}

240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
static bool
_equalSubLink(SubLink *a, SubLink *b)
{
	if (a->subLinkType != b->subLinkType)
		return false;
	if (a->useor != b->useor)
		return false;
	if (!equal(a->lefthand, b->lefthand))
		return false;
	if (!equal(a->oper, b->oper))
		return false;
	if (!equal(a->subselect, b->subselect))
		return false;
	return true;
}

256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
static bool
_equalArrayRef(ArrayRef *a, ArrayRef *b)
{
	if (a->refelemtype != b->refelemtype)
		return false;
	if (a->refattrlength != b->refattrlength)
		return false;
	if (a->refelemlength != b->refelemlength)
		return false;
	if (a->refelembyval != b->refelembyval)
		return false;
	if (!equal(a->refupperindexpr, b->refupperindexpr))
		return false;
	if (!equal(a->reflowerindexpr, b->reflowerindexpr))
		return false;
	if (!equal(a->refexpr, b->refexpr))
		return false;
	return equal(a->refassgnexpr, b->refassgnexpr);
}

276 277 278 279 280 281 282 283 284 285 286 287 288 289
static bool
_equalFieldSelect(FieldSelect *a, FieldSelect *b)
{
	if (!equal(a->arg, b->arg))
		return false;
	if (a->fieldnum != b->fieldnum)
		return false;
	if (a->resulttype != b->resulttype)
		return false;
	if (a->resulttypmod != b->resulttypmod)
		return false;
	return true;
}

290 291 292 293 294 295 296 297 298 299 300 301
static bool
_equalRelabelType(RelabelType *a, RelabelType *b)
{
	if (!equal(a->arg, b->arg))
		return false;
	if (a->resulttype != b->resulttype)
		return false;
	if (a->resulttypmod != b->resulttypmod)
		return false;
	return true;
}

302
static bool
303
_equalRangeTblRef(RangeTblRef *a, RangeTblRef *b)
304
{
305
	if (a->rtindex != b->rtindex)
306
		return false;
307 308 309 310

	return true;
}

311 312 313 314 315 316 317 318 319 320 321
static bool
_equalFromExpr(FromExpr *a, FromExpr *b)
{
	if (!equal(a->fromlist, b->fromlist))
		return false;
	if (!equal(a->quals, b->quals))
		return false;

	return true;
}

322 323 324 325
static bool
_equalJoinExpr(JoinExpr *a, JoinExpr *b)
{
	if (a->jointype != b->jointype)
326
		return false;
327
	if (a->isNatural != b->isNatural)
328
		return false;
329
	if (!equal(a->larg, b->larg))
330
		return false;
331
	if (!equal(a->rarg, b->rarg))
332
		return false;
333
	if (!equal(a->using, b->using))
334
		return false;
335
	if (!equal(a->quals, b->quals))
336
		return false;
337 338 339 340 341 342 343 344
	if (!equal(a->alias, b->alias))
		return false;
	if (!equal(a->colnames, b->colnames))
		return false;
	if (!equal(a->colvars, b->colvars))
		return false;

	return true;
345 346
}

347
/*
348
 * Stuff from relation.h
349
 */
350

351
static bool
352
_equalRelOptInfo(RelOptInfo *a, RelOptInfo *b)
353
{
354 355 356

	/*
	 * We treat RelOptInfos as equal if they refer to the same base rels
357
	 * joined in the same order.  Is this appropriate/sufficient?
358
	 */
359
	return equali(a->relids, b->relids);
360 361
}

362 363 364
static bool
_equalIndexOptInfo(IndexOptInfo *a, IndexOptInfo *b)
{
365 366 367 368

	/*
	 * We treat IndexOptInfos as equal if they refer to the same index. Is
	 * this sufficient?
369 370 371 372 373 374
	 */
	if (a->indexoid != b->indexoid)
		return false;
	return true;
}

375
static bool
376
_equalPathKeyItem(PathKeyItem *a, PathKeyItem *b)
377
{
378
	if (a->sortop != b->sortop)
379
		return false;
380
	if (!equal(a->key, b->key))
381 382
		return false;
	return true;
383 384
}

385
static bool
386
_equalPath(Path *a, Path *b)
387
{
388
	if (a->pathtype != b->pathtype)
389
		return false;
390
	if (!equal(a->parent, b->parent))
391
		return false;
392 393 394

	/*
	 * do not check path costs, since they may not be set yet, and being
395
	 * float values there are roundoff error issues anyway...
396
	 */
397
	if (!equal(a->pathkeys, b->pathkeys))
398 399
		return false;
	return true;
400 401
}

402
static bool
403
_equalIndexPath(IndexPath *a, IndexPath *b)
404
{
405
	if (!_equalPath((Path *) a, (Path *) b))
406
		return false;
407
	if (!equal(a->indexinfo, b->indexinfo))
408
		return false;
409
	if (!equal(a->indexqual, b->indexqual))
410
		return false;
411 412
	if (a->indexscandir != b->indexscandir)
		return false;
413 414
	if (!equali(a->joinrelids, b->joinrelids))
		return false;
415 416
	if (a->alljoinquals != b->alljoinquals)
		return false;
417 418 419 420

	/*
	 * Skip 'rows' because of possibility of floating-point roundoff
	 * error. It should be derivable from the other fields anyway.
421
	 */
422
	return true;
423 424
}

425 426 427 428 429 430 431 432 433 434 435 436
static bool
_equalTidPath(TidPath *a, TidPath *b)
{
	if (!_equalPath((Path *) a, (Path *) b))
		return false;
	if (!equal(a->tideval, b->tideval))
		return false;
	if (!equali(a->unjoined_relids, b->unjoined_relids))
		return false;
	return true;
}

437 438 439 440 441 442 443 444 445 446
static bool
_equalAppendPath(AppendPath *a, AppendPath *b)
{
	if (!_equalPath((Path *) a, (Path *) b))
		return false;
	if (!equal(a->subpaths, b->subpaths))
		return false;
	return true;
}

447
static bool
448
_equalJoinPath(JoinPath *a, JoinPath *b)
449
{
450
	if (!_equalPath((Path *) a, (Path *) b))
451
		return false;
452 453
	if (a->jointype != b->jointype)
		return false;
454
	if (!equal(a->outerjoinpath, b->outerjoinpath))
455
		return false;
456
	if (!equal(a->innerjoinpath, b->innerjoinpath))
457
		return false;
458 459
	if (!equal(a->joinrestrictinfo, b->joinrestrictinfo))
		return false;
460
	return true;
461 462
}

463
static bool
464
_equalNestPath(NestPath *a, NestPath *b)
465
{
466
	if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
467 468
		return false;
	return true;
469 470
}

471
static bool
472
_equalMergePath(MergePath *a, MergePath *b)
473
{
474
	if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
475
		return false;
476
	if (!equal(a->path_mergeclauses, b->path_mergeclauses))
477
		return false;
478
	if (!equal(a->outersortkeys, b->outersortkeys))
479
		return false;
480
	if (!equal(a->innersortkeys, b->innersortkeys))
481 482
		return false;
	return true;
483 484
}

485
static bool
486
_equalHashPath(HashPath *a, HashPath *b)
487
{
488
	if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
489
		return false;
490
	if (!equal(a->path_hashclauses, b->path_hashclauses))
491 492
		return false;
	return true;
493 494
}

Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
495 496 497
static bool
_equalSubPlan(SubPlan *a, SubPlan *b)
{
498
	/* should compare plans, but have to settle for comparing plan IDs */
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
499
	if (a->plan_id != b->plan_id)
500
		return false;
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
501

502 503 504
	if (!equal(a->rtable, b->rtable))
		return false;

505
	if (!equal(a->sublink, b->sublink))
506
		return false;
507

508
	return true;
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
509 510
}

511
static bool
512
_equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
513
{
514
	if (!equal(a->clause, b->clause))
515
		return false;
516
	if (a->ispusheddown != b->ispusheddown)
517
		return false;
518 519 520 521 522 523
	/*
	 * We ignore eval_cost, this_selec, left/right_pathkey, and
	 * left/right_bucketsize, since they may not be set yet, and should be
	 * derivable from the clause anyway.  Probably it's not really necessary
	 * to compare any of these remaining fields ...
	 */
524
	if (!equal(a->subclauseindices, b->subclauseindices))
525
		return false;
526
	if (a->mergejoinoperator != b->mergejoinoperator)
527
		return false;
528 529 530 531 532
	if (a->left_sortop != b->left_sortop)
		return false;
	if (a->right_sortop != b->right_sortop)
		return false;
	if (a->hashjoinoperator != b->hashjoinoperator)
533 534
		return false;
	return true;
535 536
}

537
static bool
538
_equalJoinInfo(JoinInfo *a, JoinInfo *b)
539
{
540
	if (!equali(a->unjoined_relids, b->unjoined_relids))
541
		return false;
542
	if (!equal(a->jinfo_restrictinfo, b->jinfo_restrictinfo))
543
		return false;
544
	return true;
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
}

static bool
_equalIter(Iter *a, Iter *b)
{
	return equal(a->iterexpr, b->iterexpr);
}

static bool
_equalStream(Stream *a, Stream *b)
{
	if (a->clausetype != b->clausetype)
		return false;
	if (a->groupup != b->groupup)
		return false;
	if (a->groupcost != b->groupcost)
		return false;
	if (a->groupsel != b->groupsel)
		return false;
	if (!equal(a->pathptr, b->pathptr))
		return false;
	if (!equal(a->cinfo, b->cinfo))
		return false;
	if (!equal(a->upstream, b->upstream))
		return false;
	return equal(a->downstream, b->downstream);
}

573 574 575 576 577 578 579 580 581 582 583 584 585
/*
 * Stuff from parsenodes.h
 */

static bool
_equalQuery(Query *a, Query *b)
{
	if (a->commandType != b->commandType)
		return false;
	if (!equal(a->utilityStmt, b->utilityStmt))
		return false;
	if (a->resultRelation != b->resultRelation)
		return false;
586 587
	if (!equalstr(a->into, b->into))
		return false;
588 589 590 591 592 593 594 595 596 597
	if (a->isPortal != b->isPortal)
		return false;
	if (a->isBinary != b->isBinary)
		return false;
	if (a->isTemp != b->isTemp)
		return false;
	if (a->hasAggs != b->hasAggs)
		return false;
	if (a->hasSubLinks != b->hasSubLinks)
		return false;
598 599
	if (!equal(a->rtable, b->rtable))
		return false;
600 601
	if (!equal(a->jointree, b->jointree))
		return false;
602
	if (!equali(a->rowMarks, b->rowMarks))
603
		return false;
604
	if (!equal(a->targetList, b->targetList))
605 606 607 608 609
		return false;
	if (!equal(a->groupClause, b->groupClause))
		return false;
	if (!equal(a->havingQual, b->havingQual))
		return false;
610
	if (!equal(a->distinctClause, b->distinctClause))
611
		return false;
612
	if (!equal(a->sortClause, b->sortClause))
613 614 615 616 617
		return false;
	if (!equal(a->limitOffset, b->limitOffset))
		return false;
	if (!equal(a->limitCount, b->limitCount))
		return false;
618 619
	if (!equal(a->setOperations, b->setOperations))
		return false;
620 621
	if (!equali(a->resultRelations, b->resultRelations))
		return false;
622

Bruce Momjian's avatar
Bruce Momjian committed
623
	/*
624
	 * We do not check the internal-to-the-planner fields: base_rel_list,
625 626 627
	 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys.
	 * They might not be set yet, and in any case they should be derivable
	 * from the other fields.
628 629 630 631 632
	 */
	return true;
}

static bool
633 634 635 636 637 638 639 640
_equalInsertStmt(InsertStmt *a, InsertStmt *b)
{
	if (!equalstr(a->relname, b->relname))
		return false;
	if (!equal(a->cols, b->cols))
		return false;
	if (!equal(a->targetList, b->targetList))
		return false;
641
	if (!equal(a->selectStmt, b->selectStmt))
642 643 644 645 646 647 648 649 650 651 652 653
		return false;

	return true;
}

static bool
_equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
{
	if (!equalstr(a->relname, b->relname))
		return false;
	if (!equal(a->whereClause, b->whereClause))
		return false;
654
	if (a->inhOpt != b->inhOpt)
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
		return false;

	return true;
}

static bool
_equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
{
	if (!equalstr(a->relname, b->relname))
		return false;
	if (!equal(a->targetList, b->targetList))
		return false;
	if (!equal(a->whereClause, b->whereClause))
		return false;
	if (!equal(a->fromClause, b->fromClause))
		return false;
671
	if (a->inhOpt != b->inhOpt)
672 673 674 675 676 677 678 679 680 681 682 683
		return false;

	return true;
}

static bool
_equalSelectStmt(SelectStmt *a, SelectStmt *b)
{
	if (!equal(a->distinctClause, b->distinctClause))
		return false;
	if (!equalstr(a->into, b->into))
		return false;
684 685
	if (a->istemp != b->istemp)
		return false;
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
	if (!equal(a->targetList, b->targetList))
		return false;
	if (!equal(a->fromClause, b->fromClause))
		return false;
	if (!equal(a->whereClause, b->whereClause))
		return false;
	if (!equal(a->groupClause, b->groupClause))
		return false;
	if (!equal(a->havingClause, b->havingClause))
		return false;
	if (!equal(a->sortClause, b->sortClause))
		return false;
	if (!equalstr(a->portalname, b->portalname))
		return false;
	if (a->binary != b->binary)
		return false;
	if (!equal(a->limitOffset, b->limitOffset))
		return false;
	if (!equal(a->limitCount, b->limitCount))
		return false;
	if (!equal(a->forUpdate, b->forUpdate))
		return false;
708 709 710 711 712 713 714 715
	if (a->op != b->op)
		return false;
	if (a->all != b->all)
		return false;
	if (!equal(a->larg, b->larg))
		return false;
	if (!equal(a->rarg, b->rarg))
		return false;
716 717 718 719

	return true;
}

720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
static bool
_equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
{
	if (a->op != b->op)
		return false;
	if (a->all != b->all)
		return false;
	if (!equal(a->larg, b->larg))
		return false;
	if (!equal(a->rarg, b->rarg))
		return false;
	if (!equali(a->colTypes, b->colTypes))
		return false;

	return true;
}

737 738
static bool
_equalAlterTableStmt(AlterTableStmt *a, AlterTableStmt *b)
739
{
740 741 742 743
	if (a->subtype != b->subtype)
		return false;
	if (!equalstr(a->relname, b->relname))
		return false;
744
	if (a->inhOpt != b->inhOpt)
745 746 747 748 749 750 751 752 753 754 755 756
		return false;
	if (!equalstr(a->name, b->name))
		return false;
	if (!equal(a->def, b->def))
		return false;
	if (a->behavior != b->behavior)
		return false;

	return true;
}

static bool
757
_equalGrantStmt(GrantStmt *a, GrantStmt *b)
758
{
759
	if (a->is_grant != b->is_grant)
760
		return false;
761 762 763 764 765
	if (!equal(a->relnames, b->relnames))
		return false;
	if (!equalstr(a->privileges, b->privileges))
		return false;
	if (!equal(a->grantees, b->grantees))
766
		return false;
767 768 769 770

	return true;
}

771 772 773 774 775 776 777
static bool
_equalPrivGrantee(PrivGrantee *a, PrivGrantee *b)
{
	return equalstr(a->username, b->username)
		&& equalstr(a->groupname, b->groupname);
}	

778 779 780 781
static bool
_equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
{
	if (!equalstr(a->portalname, b->portalname))
782
		return false;
783 784 785 786 787 788 789 790

	return true;
}

static bool
_equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
{
	if (!equalstr(a->relname, b->relname))
791
		return false;
792
	if (!equalstr(a->indexname, b->indexname))
793 794 795 796 797
		return false;

	return true;
}

798
static bool
799
_equalCopyStmt(CopyStmt *a, CopyStmt *b)
800
{
801
	if (a->binary != b->binary)
802
		return false;
803 804 805 806 807 808 809 810 811 812 813
	if (!equalstr(a->relname, b->relname))
		return false;
	if (a->oids != b->oids)
		return false;
	if (a->direction != b->direction)
		return false;
	if (!equalstr(a->filename, b->filename))
		return false;
	if (!equalstr(a->delimiter, b->delimiter))
		return false;
	if (!equalstr(a->null_print, b->null_print))
814 815 816 817 818
		return false;

	return true;
}

819
static bool
820
_equalCreateStmt(CreateStmt *a, CreateStmt *b)
821
{
822 823 824 825 826 827 828
	if (!equalstr(a->relname, b->relname))
		return false;
	if (!equal(a->tableElts, b->tableElts))
		return false;
	if (!equal(a->inhRelnames, b->inhRelnames))
		return false;
	if (!equal(a->constraints, b->constraints))
829
		return false;
830 831 832 833
	if (a->istemp != b->istemp)
		return false;
	if (a->hasoids != b->hasoids)
		return false;
834 835 836 837

	return true;
}

838
static bool
839
_equalVersionStmt(VersionStmt *a, VersionStmt *b)
840
{
841
	if (!equalstr(a->relname, b->relname))
842
		return false;
843
	if (a->direction != b->direction)
844
		return false;
845 846 847
	if (!equalstr(a->fromRelname, b->fromRelname))
		return false;
	if (!equalstr(a->date, b->date))
848
		return false;
849

850
	return true;
851 852
}

853
static bool
854
_equalDefineStmt(DefineStmt *a, DefineStmt *b)
855
{
856
	if (a->defType != b->defType)
857
		return false;
858
	if (!equalstr(a->defname, b->defname))
859
		return false;
860
	if (!equal(a->definition, b->definition))
861 862 863 864 865 866
		return false;

	return true;
}

static bool
867
_equalDropStmt(DropStmt *a, DropStmt *b)
868
{
869
	if (!equal(a->names, b->names))
870
		return false;
871
	if (a->removeType != b->removeType)
872 873 874 875 876
		return false;

	return true;
}

877 878 879 880 881 882 883 884
static bool
_equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
{
	if (!equalstr(a->relName, b->relName))
		return false;

	return true;
}
885

886
static bool
887
_equalCommentStmt(CommentStmt *a, CommentStmt *b)
888
{
889 890 891 892 893 894 895 896 897
	if (a->objtype != b->objtype)
		return false;
	if (!equalstr(a->objname, b->objname))
		return false;
	if (!equalstr(a->objproperty, b->objproperty))
		return false;
	if (!equal(a->objlist, b->objlist))
		return false;
	if (!equalstr(a->comment, b->comment))
898
		return false;
899

900 901 902 903 904
	return true;
}

static bool
_equalFetchStmt(FetchStmt *a, FetchStmt *b)
905
{
906 907 908 909 910 911 912 913
	if (a->direction != b->direction)
		return false;
	if (a->howMany != b->howMany)
		return false;
	if (!equalstr(a->portalname, b->portalname))
		return false;
	if (a->ismove != b->ismove)
		return false;
914

915 916
	return true;
}
917

918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937
static bool
_equalIndexStmt(IndexStmt *a, IndexStmt *b)
{
	if (!equalstr(a->idxname, b->idxname))
		return false;
	if (!equalstr(a->relname, b->relname))
		return false;
	if (!equalstr(a->accessMethod, b->accessMethod))
		return false;
	if (!equal(a->indexParams, b->indexParams))
		return false;
	if (!equal(a->withClause, b->withClause))
		return false;
	if (!equal(a->whereClause, b->whereClause))
		return false;
	if (!equal(a->rangetable, b->rangetable))
		return false;
	if (a->unique != b->unique)
		return false;
	if (a->primary != b->primary)
938
		return false;
939

940 941 942 943 944 945 946 947
	return true;
}

static bool
_equalProcedureStmt(ProcedureStmt *a, ProcedureStmt *b)
{
	if (!equalstr(a->funcname, b->funcname))
		return false;
948
	if (!equal(a->argTypes, b->argTypes))
949 950 951 952 953 954 955 956
		return false;
	if (!equal(a->returnType, b->returnType))
		return false;
	if (!equal(a->withClause, b->withClause))
		return false;
	if (!equal(a->as, b->as))
		return false;
	if (!equalstr(a->language, b->language))
957
		return false;
958

959 960 961 962 963 964 965 966
	return true;
}

static bool
_equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
{
	if (!equalstr(a->aggname, b->aggname))
		return false;
967
	if (!equal(a->aggtype, b->aggtype))
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
		return false;

	return true;
}

static bool
_equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
{
	if (!equalstr(a->funcname, b->funcname))
		return false;
	if (!equal(a->args, b->args))
		return false;

	return true;
}

static bool
_equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
{
	if (!equalstr(a->opname, b->opname))
		return false;
	if (!equal(a->args, b->args))
		return false;

	return true;
}


static bool
_equalRenameStmt(RenameStmt *a, RenameStmt *b)
{
	if (!equalstr(a->relname, b->relname))
		return false;
1001
	if (a->inhOpt != b->inhOpt)
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
		return false;
	if (!equalstr(a->column, b->column))
		return false;
	if (!equalstr(a->newname, b->newname))
		return false;

	return true;
}

static bool
_equalRuleStmt(RuleStmt *a, RuleStmt *b)
{
	if (!equalstr(a->rulename, b->rulename))
		return false;
	if (!equal(a->whereClause, b->whereClause))
		return false;
	if (a->event != b->event)
		return false;
	if (!equal(a->object, b->object))
		return false;
	if (a->instead != b->instead)
		return false;
	if (!equal(a->actions, b->actions))
		return false;

	return true;
}

static bool
_equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
{
	if (!equalstr(a->relname, b->relname))
		return false;

	return true;
}

static bool
_equalListenStmt(ListenStmt *a, ListenStmt *b)
{
	if (!equalstr(a->relname, b->relname))
		return false;

	return true;
}

static bool
_equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
{
	if (!equalstr(a->relname, b->relname))
		return false;

	return true;
}

static bool
_equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
{
	if (a->command != b->command)
		return false;

	return true;
}

static bool
_equalViewStmt(ViewStmt *a, ViewStmt *b)
{
	if (!equalstr(a->viewname, b->viewname))
		return false;
	if (!equal(a->aliases, b->aliases))
		return false;
	if (!equal(a->query, b->query))
		return false;

	return true;
}

static bool
_equalLoadStmt(LoadStmt *a, LoadStmt *b)
{
	if (!equalstr(a->filename, b->filename))
		return false;

	return true;
}

static bool
_equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
{
	if (!equalstr(a->dbname, b->dbname))
		return false;
	if (!equalstr(a->dbpath, b->dbpath))
		return false;
1095 1096
	if (!equalstr(a->dbtemplate, b->dbtemplate))
		return false;
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
	if (a->encoding != b->encoding)
		return false;

	return true;
}

static bool
_equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
{
	if (!equalstr(a->dbname, b->dbname))
		return false;

	return true;
}

static bool
_equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
{
1115
	if (a->vacuum != b->vacuum)
1116
		return false;
1117 1118
	if (a->full != b->full)
		return false;
1119 1120
	if (a->analyze != b->analyze)
		return false;
1121 1122
	if (a->verbose != b->verbose)
		return false;
1123 1124
	if (!equalstr(a->vacrel, b->vacrel))
		return false;
1125
	if (!equal(a->va_cols, b->va_cols))
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
		return false;

	return true;
}

static bool
_equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
{
	if (!equal(a->query, b->query))
		return false;
	if (a->verbose != b->verbose)
		return false;

	return true;
}

static bool
_equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
{
	if (!equalstr(a->seqname, b->seqname))
		return false;
	if (!equal(a->options, b->options))
		return false;

	return true;
}

static bool
_equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
{
	if (!equalstr(a->name, b->name))
		return false;
	if (!equalstr(a->value, b->value))
		return false;

	return true;
}

static bool
_equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
{
	if (!equalstr(a->name, b->name))
		return false;

	return true;
}

static bool
_equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
{
	if (!equalstr(a->name, b->name))
		return false;

	return true;
}

static bool
_equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
{
	if (!equalstr(a->trigname, b->trigname))
		return false;
	if (!equalstr(a->relname, b->relname))
		return false;
	if (!equalstr(a->funcname, b->funcname))
		return false;
	if (!equal(a->args, b->args))
		return false;
	if (a->before != b->before)
		return false;
	if (a->row != b->row)
		return false;
	if (strcmp(a->actions, b->actions) != 0)
		return false;
	if (!equalstr(a->lang, b->lang))
		return false;
	if (!equalstr(a->text, b->text))
		return false;
	if (!equal(a->attr, b->attr))
		return false;
	if (!equalstr(a->when, b->when))
		return false;
	if (a->isconstraint != b->isconstraint)
		return false;
	if (a->deferrable != b->deferrable)
		return false;
	if (a->initdeferred != b->initdeferred)
		return false;
	if (!equalstr(a->constrrelname, b->constrrelname))
		return false;

	return true;
}

static bool
_equalDropTrigStmt(DropTrigStmt *a, DropTrigStmt *b)
{
	if (!equalstr(a->trigname, b->trigname))
		return false;
	if (!equalstr(a->relname, b->relname))
		return false;

	return true;
}

static bool
_equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
{
	if (!equalstr(a->plname, b->plname))
		return false;
	if (!equalstr(a->plhandler, b->plhandler))
		return false;
	if (!equalstr(a->plcompiler, b->plcompiler))
		return false;
	if (a->pltrusted != b->pltrusted)
		return false;

	return true;
}

static bool
_equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
{
	if (!equalstr(a->plname, b->plname))
		return false;

	return true;
}

static bool
_equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
{
	if (!equalstr(a->user, b->user))
		return false;
1259
	if (!equal(a->options, b->options))
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
		return false;

	return true;
}

static bool
_equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
{
	if (!equalstr(a->user, b->user))
		return false;
1270
	if (!equal(a->options, b->options))
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287
		return false;

	return true;
}

static bool
_equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
{
	if (!equal(a->users, b->users))
		return false;

	return true;
}

static bool
_equalLockStmt(LockStmt *a, LockStmt *b)
{
1288
	if (!equal(a->rellist, b->rellist))
1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311
		return false;
	if (a->mode != b->mode)
		return false;

	return true;
}

static bool
_equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
{
	if (!equal(a->constraints, b->constraints))
		return false;
	if (a->deferred != b->deferred)
		return false;

	return true;
}

static bool
_equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
{
	if (!equalstr(a->name, b->name))
		return false;
1312
	if (!equal(a->options, b->options))
1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 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 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 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 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
		return false;

	return true;
}

static bool
_equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
{
	if (!equalstr(a->name, b->name))
		return false;
	if (a->action != b->action)
		return false;
	if (!equal(a->listUsers, b->listUsers))
		return false;

	return true;
}

static bool
_equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
{
	if (!equalstr(a->name, b->name))
		return false;

	return true;
}

static bool
_equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
{
	if (a->reindexType != b->reindexType)
		return false;
	if (!equalstr(a->name, b->name))
		return false;
	if (a->force != b->force)
		return false;
	if (a->all != b->all)
		return false;

	return true;
}

static bool
_equalAExpr(A_Expr *a, A_Expr *b)
{
	if (a->oper != b->oper)
		return false;
	if (!equalstr(a->opname, b->opname))
		return false;
	if (!equal(a->lexpr, b->lexpr))
		return false;
	if (!equal(a->rexpr, b->rexpr))
		return false;

	return true;
}

static bool
_equalAttr(Attr *a, Attr *b)
{
	if (strcmp(a->relname, b->relname) != 0)
		return false;
	if (!equal(a->paramNo, b->paramNo))
		return false;
	if (!equal(a->attrs, b->attrs))
		return false;
	if (!equal(a->indirection, b->indirection))
		return false;

	return true;
}

static bool
_equalAConst(A_Const *a, A_Const *b)
{
	if (!equal(&a->val, &b->val))
		return false;
	if (!equal(a->typename, b->typename))
		return false;

	return true;
}

static bool
_equalParamNo(ParamNo *a, ParamNo *b)
{
	if (a->number != b->number)
		return false;
	if (!equal(a->typename, b->typename))
		return false;
	if (!equal(a->indirection, b->indirection))
		return false;

	return true;
}

static bool
_equalIdent(Ident *a, Ident *b)
{
	if (!equalstr(a->name, b->name))
		return false;
	if (!equal(a->indirection, b->indirection))
		return false;
	if (a->isRel != b->isRel)
		return false;

	return true;
}

static bool
_equalFuncCall(FuncCall *a, FuncCall *b)
{
	if (!equalstr(a->funcname, b->funcname))
		return false;
	if (!equal(a->args, b->args))
		return false;
	if (a->agg_star != b->agg_star)
		return false;
	if (a->agg_distinct != b->agg_distinct)
		return false;

	return true;
}

static bool
_equalAIndices(A_Indices *a, A_Indices *b)
{
	if (!equal(a->lidx, b->lidx))
		return false;
	if (!equal(a->uidx, b->uidx))
		return false;

	return true;
}

static bool
_equalResTarget(ResTarget *a, ResTarget *b)
{
	if (!equalstr(a->name, b->name))
		return false;
	if (!equal(a->indirection, b->indirection))
		return false;
	if (!equal(a->val, b->val))
		return false;

	return true;
}

static bool
_equalTypeCast(TypeCast *a, TypeCast *b)
{
	if (!equal(a->arg, b->arg))
		return false;
	if (!equal(a->typename, b->typename))
		return false;

	return true;
}

static bool
1473
_equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1474
{
1475
	if (!equalstr(a->useOp, b->useOp))
1476
		return false;
1477
	if (!equal(a->node, b->node))
1478 1479 1480 1481 1482 1483
		return false;

	return true;
}

static bool
1484
_equalRangeVar(RangeVar *a, RangeVar *b)
1485
{
1486
	if (!equalstr(a->relname, b->relname))
1487
		return false;
1488
	if (a->inhOpt != b->inhOpt)
1489 1490
		return false;
	if (!equal(a->name, b->name))
1491 1492 1493 1494 1495 1496
		return false;

	return true;
}

static bool
1497
_equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1498
{
1499
	if (!equal(a->subquery, b->subquery))
1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 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
		return false;
	if (!equal(a->name, b->name))
		return false;

	return true;
}

static bool
_equalTypeName(TypeName *a, TypeName *b)
{
	if (!equalstr(a->name, b->name))
		return false;
	if (a->timezone != b->timezone)
		return false;
	if (a->setof != b->setof)
		return false;
	if (a->typmod != b->typmod)
		return false;
	if (!equal(a->arrayBounds, b->arrayBounds))
		return false;

	return true;
}

static bool
_equalIndexElem(IndexElem *a, IndexElem *b)
{
	if (!equalstr(a->name, b->name))
		return false;
	if (!equal(a->args, b->args))
		return false;
	if (!equalstr(a->class, b->class))
		return false;

	return true;
}

static bool
_equalColumnDef(ColumnDef *a, ColumnDef *b)
{
	if (!equalstr(a->colname, b->colname))
		return false;
	if (!equal(a->typename, b->typename))
		return false;
	if (a->is_not_null != b->is_not_null)
		return false;
	if (!equal(a->raw_default, b->raw_default))
		return false;
	if (!equalstr(a->cooked_default, b->cooked_default))
		return false;
	if (!equal(a->constraints, b->constraints))
		return false;

	return true;
}

static bool
_equalConstraint(Constraint *a, Constraint *b)
{
	if (a->contype != b->contype)
		return false;
	if (!equalstr(a->name, b->name))
		return false;
	if (!equal(a->raw_expr, b->raw_expr))
		return false;
	if (!equalstr(a->cooked_expr, b->cooked_expr))
		return false;
	if (!equal(a->keys, b->keys))
		return false;

	return true;
}

static bool
_equalDefElem(DefElem *a, DefElem *b)
{
	if (!equalstr(a->defname, b->defname))
		return false;
	if (!equal(a->arg, b->arg))
		return false;

	return true;
}

static bool
_equalTargetEntry(TargetEntry *a, TargetEntry *b)
{
	if (!equal(a->resdom, b->resdom))
		return false;
	if (!equal(a->fjoin, b->fjoin))
		return false;
	if (!equal(a->expr, b->expr))
		return false;

	return true;
}

static bool
_equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
{
	if (!equalstr(a->relname, b->relname))
		return false;
	if (a->relid != b->relid)
		return false;
1604 1605
	if (!equal(a->subquery, b->subquery))
		return false;
1606 1607 1608 1609
	if (!equal(a->alias, b->alias))
		return false;
	if (!equal(a->eref, b->eref))
		return false;
1610 1611 1612 1613
	if (a->inh != b->inh)
		return false;
	if (a->inFromCl != b->inFromCl)
		return false;
1614 1615 1616 1617 1618
	if (a->checkForRead != b->checkForRead)
		return false;
	if (a->checkForWrite != b->checkForWrite)
		return false;
	if (a->checkAsUser != b->checkAsUser)
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 1683
		return false;

	return true;
}

static bool
_equalSortClause(SortClause *a, SortClause *b)
{
	if (a->tleSortGroupRef != b->tleSortGroupRef)
		return false;
	if (a->sortop != b->sortop)
		return false;

	return true;
}

static bool
_equalFkConstraint(FkConstraint *a, FkConstraint *b)
{
	if (!equalstr(a->constr_name, b->constr_name))
		return false;
	if (!equalstr(a->pktable_name, b->pktable_name))
		return false;
	if (!equal(a->fk_attrs, b->fk_attrs))
		return false;
	if (!equal(a->pk_attrs, b->pk_attrs))
		return false;
	if (!equalstr(a->match_type, b->match_type))
		return false;
	if (a->actions != b->actions)
		return false;
	if (a->deferrable != b->deferrable)
		return false;
	if (a->initdeferred != b->initdeferred)
		return false;

	return true;
}

static bool
_equalCaseExpr(CaseExpr *a, CaseExpr *b)
{
	if (a->casetype != b->casetype)
		return false;
	if (!equal(a->arg, b->arg))
		return false;
	if (!equal(a->args, b->args))
		return false;
	if (!equal(a->defresult, b->defresult))
		return false;

	return true;
}

static bool
_equalCaseWhen(CaseWhen *a, CaseWhen *b)
{
	if (!equal(a->expr, b->expr))
		return false;
	if (!equal(a->result, b->result))
		return false;

	return true;
}

1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703
static bool
_equalNullTest(NullTest *a, NullTest *b)
{
	if (!equal(a->arg, b->arg))
		return false;
	if (a->nulltesttype != b->nulltesttype)
		return false;
	return true;
}

static bool
_equalBooleanTest(BooleanTest *a, BooleanTest *b)
{
	if (!equal(a->arg, b->arg))
		return false;
	if (a->booltesttype != b->booltesttype)
		return false;
	return true;
}

1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719
/*
 * Stuff from pg_list.h
 */

static bool
_equalValue(Value *a, Value *b)
{
	if (a->type != b->type)
		return false;

	switch (a->type)
	{
		case T_Integer:
			return a->val.ival == b->val.ival;
		case T_Float:
		case T_String:
1720
		case T_BitString:
1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756
			return strcmp(a->val.str, b->val.str) == 0;
		default:
			break;
	}

	return true;
}

/*
 * equal
 *	  returns whether two nodes are equal
 */
bool
equal(void *a, void *b)
{
	bool		retval = false;

	if (a == b)
		return true;

	/*
	 * note that a!=b, so only one of them can be NULL
	 */
	if (a == NULL || b == NULL)
		return false;

	/*
	 * are they the same type of nodes?
	 */
	if (nodeTag(a) != nodeTag(b))
		return false;

	switch (nodeTag(a))
	{
		case T_SubPlan:
			retval = _equalSubPlan(a, b);
1757
			break;
1758

1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779
		case T_Resdom:
			retval = _equalResdom(a, b);
			break;
		case T_Fjoin:
			retval = _equalFjoin(a, b);
			break;
		case T_Expr:
			retval = _equalExpr(a, b);
			break;
		case T_Var:
			retval = _equalVar(a, b);
			break;
		case T_Oper:
			retval = _equalOper(a, b);
			break;
		case T_Const:
			retval = _equalConst(a, b);
			break;
		case T_Param:
			retval = _equalParam(a, b);
			break;
1780 1781
		case T_Aggref:
			retval = _equalAggref(a, b);
1782 1783 1784
			break;
		case T_SubLink:
			retval = _equalSubLink(a, b);
1785
			break;
1786 1787 1788
		case T_Func:
			retval = _equalFunc(a, b);
			break;
1789 1790 1791
		case T_FieldSelect:
			retval = _equalFieldSelect(a, b);
			break;
1792 1793
		case T_ArrayRef:
			retval = _equalArrayRef(a, b);
1794
			break;
1795 1796
		case T_Iter:
			retval = _equalIter(a, b);
1797
			break;
1798 1799 1800
		case T_RelabelType:
			retval = _equalRelabelType(a, b);
			break;
1801 1802 1803
		case T_RangeTblRef:
			retval = _equalRangeTblRef(a, b);
			break;
1804 1805 1806
		case T_FromExpr:
			retval = _equalFromExpr(a, b);
			break;
1807 1808 1809
		case T_JoinExpr:
			retval = _equalJoinExpr(a, b);
			break;
1810

1811 1812
		case T_RelOptInfo:
			retval = _equalRelOptInfo(a, b);
1813 1814 1815 1816 1817 1818 1819
			break;
		case T_Path:
			retval = _equalPath(a, b);
			break;
		case T_IndexPath:
			retval = _equalIndexPath(a, b);
			break;
1820 1821
		case T_NestPath:
			retval = _equalNestPath(a, b);
1822 1823 1824 1825 1826 1827 1828
			break;
		case T_MergePath:
			retval = _equalMergePath(a, b);
			break;
		case T_HashPath:
			retval = _equalHashPath(a, b);
			break;
1829 1830
		case T_PathKeyItem:
			retval = _equalPathKeyItem(a, b);
1831
			break;
1832 1833
		case T_RestrictInfo:
			retval = _equalRestrictInfo(a, b);
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
1834
			break;
1835 1836
		case T_JoinInfo:
			retval = _equalJoinInfo(a, b);
1837
			break;
1838 1839 1840 1841 1842 1843
		case T_Stream:
			retval = _equalStream(a, b);
			break;
		case T_TidPath:
			retval = _equalTidPath(a, b);
			break;
1844 1845 1846
		case T_AppendPath:
			retval = _equalAppendPath(a, b);
			break;
1847 1848 1849
		case T_IndexOptInfo:
			retval = _equalIndexOptInfo(a, b);
			break;
1850

1851
		case T_List:
1852
			{
1853 1854 1855 1856
				List	   *la = (List *) a;
				List	   *lb = (List *) b;
				List	   *l;

1857 1858
				/*
				 * Try to reject by length check before we grovel through
1859 1860 1861
				 * all the elements...
				 */
				if (length(la) != length(lb))
1862
					return false;
1863 1864 1865
				foreach(l, la)
				{
					if (!equal(lfirst(l), lfirst(lb)))
1866
						return false;
1867 1868 1869
					lb = lnext(lb);
				}
				retval = true;
1870
			}
1871
			break;
1872 1873 1874
		case T_Integer:
		case T_Float:
		case T_String:
1875
		case T_BitString:
1876 1877
			retval = _equalValue(a, b);
			break;
1878

1879 1880 1881
		case T_Query:
			retval = _equalQuery(a, b);
			break;
1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893
		case T_InsertStmt:
			retval = _equalInsertStmt(a, b);
			break;
		case T_DeleteStmt:
			retval = _equalDeleteStmt(a, b);
			break;
		case T_UpdateStmt:
			retval = _equalUpdateStmt(a, b);
			break;
		case T_SelectStmt:
			retval = _equalSelectStmt(a, b);
			break;
1894 1895 1896
		case T_SetOperationStmt:
			retval = _equalSetOperationStmt(a, b);
			break;
1897 1898 1899
		case T_AlterTableStmt:
			retval = _equalAlterTableStmt(a, b);
			break;
1900 1901
		case T_GrantStmt:
			retval = _equalGrantStmt(a, b);
1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034
			break;
		case T_ClosePortalStmt:
			retval = _equalClosePortalStmt(a, b);
			break;
		case T_ClusterStmt:
			retval = _equalClusterStmt(a, b);
			break;
		case T_CopyStmt:
			retval = _equalCopyStmt(a, b);
			break;
		case T_CreateStmt:
			retval = _equalCreateStmt(a, b);
			break;
		case T_VersionStmt:
			retval = _equalVersionStmt(a, b);
			break;
		case T_DefineStmt:
			retval = _equalDefineStmt(a, b);
			break;
		case T_DropStmt:
			retval = _equalDropStmt(a, b);
			break;
		case T_TruncateStmt:
			retval = _equalTruncateStmt(a, b);
			break;
		case T_CommentStmt:
			retval = _equalCommentStmt(a, b);
			break;
		case T_FetchStmt:
			retval = _equalFetchStmt(a, b);
			break;
		case T_IndexStmt:
			retval = _equalIndexStmt(a, b);
			break;
		case T_ProcedureStmt:
			retval = _equalProcedureStmt(a, b);
			break;
		case T_RemoveAggrStmt:
			retval = _equalRemoveAggrStmt(a, b);
			break;
		case T_RemoveFuncStmt:
			retval = _equalRemoveFuncStmt(a, b);
			break;
		case T_RemoveOperStmt:
			retval = _equalRemoveOperStmt(a, b);
			break;
		case T_RenameStmt:
			retval = _equalRenameStmt(a, b);
			break;
		case T_RuleStmt:
			retval = _equalRuleStmt(a, b);
			break;
		case T_NotifyStmt:
			retval = _equalNotifyStmt(a, b);
			break;
		case T_ListenStmt:
			retval = _equalListenStmt(a, b);
			break;
		case T_UnlistenStmt:
			retval = _equalUnlistenStmt(a, b);
			break;
		case T_TransactionStmt:
			retval = _equalTransactionStmt(a, b);
			break;
		case T_ViewStmt:
			retval = _equalViewStmt(a, b);
			break;
		case T_LoadStmt:
			retval = _equalLoadStmt(a, b);
			break;
		case T_CreatedbStmt:
			retval = _equalCreatedbStmt(a, b);
			break;
		case T_DropdbStmt:
			retval = _equalDropdbStmt(a, b);
			break;
		case T_VacuumStmt:
			retval = _equalVacuumStmt(a, b);
			break;
		case T_ExplainStmt:
			retval = _equalExplainStmt(a, b);
			break;
		case T_CreateSeqStmt:
			retval = _equalCreateSeqStmt(a, b);
			break;
		case T_VariableSetStmt:
			retval = _equalVariableSetStmt(a, b);
			break;
		case T_VariableShowStmt:
			retval = _equalVariableShowStmt(a, b);
			break;
		case T_VariableResetStmt:
			retval = _equalVariableResetStmt(a, b);
			break;
		case T_CreateTrigStmt:
			retval = _equalCreateTrigStmt(a, b);
			break;
		case T_DropTrigStmt:
			retval = _equalDropTrigStmt(a, b);
			break;
		case T_CreatePLangStmt:
			retval = _equalCreatePLangStmt(a, b);
			break;
		case T_DropPLangStmt:
			retval = _equalDropPLangStmt(a, b);
			break;
		case T_CreateUserStmt:
			retval = _equalCreateUserStmt(a, b);
			break;
		case T_AlterUserStmt:
			retval = _equalAlterUserStmt(a, b);
			break;
		case T_DropUserStmt:
			retval = _equalDropUserStmt(a, b);
			break;
		case T_LockStmt:
			retval = _equalLockStmt(a, b);
			break;
		case T_ConstraintsSetStmt:
			retval = _equalConstraintsSetStmt(a, b);
			break;
		case T_CreateGroupStmt:
			retval = _equalCreateGroupStmt(a, b);
			break;
		case T_AlterGroupStmt:
			retval = _equalAlterGroupStmt(a, b);
			break;
		case T_DropGroupStmt:
			retval = _equalDropGroupStmt(a, b);
			break;
		case T_ReindexStmt:
			retval = _equalReindexStmt(a, b);
			break;
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
2035 2036 2037
		case T_CheckPointStmt:
			retval = true;
			break;
2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071

		case T_A_Expr:
			retval = _equalAExpr(a, b);
			break;
		case T_Attr:
			retval = _equalAttr(a, b);
			break;
		case T_A_Const:
			retval = _equalAConst(a, b);
			break;
		case T_ParamNo:
			retval = _equalParamNo(a, b);
			break;
		case T_Ident:
			retval = _equalIdent(a, b);
			break;
		case T_FuncCall:
			retval = _equalFuncCall(a, b);
			break;
		case T_A_Indices:
			retval = _equalAIndices(a, b);
			break;
		case T_ResTarget:
			retval = _equalResTarget(a, b);
			break;
		case T_TypeCast:
			retval = _equalTypeCast(a, b);
			break;
		case T_SortGroupBy:
			retval = _equalSortGroupBy(a, b);
			break;
		case T_RangeVar:
			retval = _equalRangeVar(a, b);
			break;
2072 2073 2074
		case T_RangeSubselect:
			retval = _equalRangeSubselect(a, b);
			break;
2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089
		case T_TypeName:
			retval = _equalTypeName(a, b);
			break;
		case T_IndexElem:
			retval = _equalIndexElem(a, b);
			break;
		case T_ColumnDef:
			retval = _equalColumnDef(a, b);
			break;
		case T_Constraint:
			retval = _equalConstraint(a, b);
			break;
		case T_DefElem:
			retval = _equalDefElem(a, b);
			break;
2090 2091 2092
		case T_TargetEntry:
			retval = _equalTargetEntry(a, b);
			break;
2093 2094 2095
		case T_RangeTblEntry:
			retval = _equalRangeTblEntry(a, b);
			break;
2096 2097 2098 2099 2100 2101 2102
		case T_SortClause:
			retval = _equalSortClause(a, b);
			break;
		case T_GroupClause:
			/* GroupClause is equivalent to SortClause */
			retval = _equalSortClause(a, b);
			break;
2103 2104 2105 2106 2107 2108
		case T_CaseExpr:
			retval = _equalCaseExpr(a, b);
			break;
		case T_CaseWhen:
			retval = _equalCaseWhen(a, b);
			break;
2109 2110 2111 2112 2113 2114
		case T_NullTest:
			retval = _equalNullTest(a, b);
			break;
		case T_BooleanTest:
			retval = _equalBooleanTest(a, b);
			break;
2115 2116 2117
		case T_FkConstraint:
			retval = _equalFkConstraint(a, b);
			break;
2118 2119 2120
		case T_PrivGrantee:
			retval = _equalPrivGrantee(a, b);
			break;
2121

2122 2123 2124 2125
		default:
			elog(NOTICE, "equal: don't know whether nodes of type %d are equal",
				 nodeTag(a));
			break;
2126
	}
2127 2128

	return retval;
2129
}