equalfuncs.c 18.4 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * equalfuncs.c
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *	  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
 * deal with already-executing plan trees.  By leaving the state subnodes
 * 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.
 *
 * Another class of nodes not currently handled is nodes that appear
 * only in "raw" parsetrees (gram.y output not yet analyzed by the parser).
 * Perhaps some day that will need to be supported.
 *
22
 *
Bruce Momjian's avatar
Add:  
Bruce Momjian committed
23 24
 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
 * Portions Copyright (c) 1994, Regents of the University of California
25 26
 *
 * IDENTIFICATION
27
 *	  $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.70 2000/07/22 04:22:46 tgl Exp $
28 29 30
 *
 *-------------------------------------------------------------------------
 */
31

32 33 34
#include "postgres.h"

#include "nodes/plannodes.h"
Bruce Momjian's avatar
Bruce Momjian committed
35
#include "nodes/relation.h"
36 37
#include "utils/datum.h"

38
static bool equali(List *a, List *b);
39

40

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

45
static bool
46
_equalResdom(Resdom *a, Resdom *b)
47
{
48
	if (a->resno != b->resno)
49
		return false;
50
	if (a->restype != b->restype)
51
		return false;
52
	if (a->restypmod != b->restypmod)
53
		return false;
54 55 56 57 58 59 60 61 62 63 64 65
	if (a->resname && b->resname)
	{
		if (strcmp(a->resname, b->resname) != 0)
			return false;
	}
	else
	{
		/* must both be null to be equal */
		if (a->resname != b->resname)
			return false;
	}
	if (a->ressortgroupref != b->ressortgroupref)
66
		return false;
67
	if (a->reskey != b->reskey)
68
		return false;
69
	if (a->reskeyop != b->reskeyop)
70
		return false;
71
	/* we ignore resjunk flag ... is this correct? */
72

73
	return true;
74 75
}

76
static bool
77
_equalFjoin(Fjoin *a, Fjoin *b)
78
{
79
	int			nNodes;
80 81

	if (a->fj_initialized != b->fj_initialized)
82
		return false;
83
	if (a->fj_nNodes != b->fj_nNodes)
84
		return false;
85
	if (!equal(a->fj_innerNode, b->fj_innerNode))
86
		return false;
87 88 89

	nNodes = a->fj_nNodes;
	if (memcmp(a->fj_results, b->fj_results, nNodes * sizeof(Datum)) != 0)
90
		return false;
91
	if (memcmp(a->fj_alwaysDone, b->fj_alwaysDone, nNodes * sizeof(bool)) != 0)
92
		return false;
93

94
	return true;
95 96
}

97
static bool
98
_equalExpr(Expr *a, Expr *b)
99
{
100 101 102 103 104

	/*
	 * 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.
105
	 */
106
	if (a->opType != b->opType)
107
		return false;
108
	if (!equal(a->oper, b->oper))
109
		return false;
110
	if (!equal(a->args, b->args))
111
		return false;
112

113
	return true;
114 115
}

116 117 118
static bool
_equalAttr(Attr *a, Attr *b)
{
119
	if (strcmp(a->relname, b->relname) != 0)
120
		return false;
121
	if (!equal(a->attrs, b->attrs))
122 123
		return false;

124
	return true;
125 126
}

127
static bool
128
_equalVar(Var *a, Var *b)
129
{
130
	if (a->varno != b->varno)
131
		return false;
132
	if (a->varattno != b->varattno)
133
		return false;
134
	if (a->vartype != b->vartype)
135
		return false;
136
	if (a->vartypmod != b->vartypmod)
137
		return false;
138
	if (a->varlevelsup != b->varlevelsup)
139
		return false;
140
	if (a->varnoold != b->varnoold)
141
		return false;
142
	if (a->varoattno != b->varoattno)
143
		return false;
144

145
	return true;
146 147
}

148
static bool
149
_equalOper(Oper *a, Oper *b)
150
{
151
	if (a->opno != b->opno)
152
		return false;
153
	if (a->opresulttype != b->opresulttype)
154
		return false;
155 156 157

	/*
	 * We do not examine opid, opsize, or op_fcache, since these are
158 159 160 161 162
	 * logically derived from opno, and they may not be set yet depending
	 * on how far along the node is in the parse/plan pipeline.
	 *
	 * It's probably not really necessary to check opresulttype either...
	 */
163

164
	return true;
165 166
}

167
static bool
168
_equalConst(Const *a, Const *b)
169
{
170
	if (a->consttype != b->consttype)
171
		return false;
172
	if (a->constlen != b->constlen)
173
		return false;
174
	if (a->constisnull != b->constisnull)
175
		return false;
176
	if (a->constbyval != b->constbyval)
177
		return false;
178
	/* XXX What about constisset and constiscast? */
179

180
	/*
181 182 183
	 * 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...
184 185 186
	 */
	if (a->constisnull)
		return true;
187 188
	return datumIsEqual(a->constvalue, b->constvalue,
						a->constbyval, a->constlen);
189 190
}

191
static bool
192
_equalParam(Param *a, Param *b)
193
{
194
	if (a->paramkind != b->paramkind)
195
		return false;
196
	if (a->paramtype != b->paramtype)
197
		return false;
198
	if (!equal(a->param_tlist, b->param_tlist))
199
		return false;
200 201 202

	switch (a->paramkind)
	{
203 204 205 206
		case PARAM_NAMED:
		case PARAM_NEW:
		case PARAM_OLD:
			if (strcmp(a->paramname, b->paramname) != 0)
207
				return false;
208 209
			break;
		case PARAM_NUM:
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
210
		case PARAM_EXEC:
211
			if (a->paramid != b->paramid)
212
				return false;
213 214 215 216 217 218
			break;
		case PARAM_INVALID:

			/*
			 * XXX: Hmmm... What are we supposed to return in this case ??
			 */
219
			return true;
220 221
			break;
		default:
222
			elog(ERROR, "_equalParam: Invalid paramkind value: %d",
223
				 a->paramkind);
224 225
	}

226
	return true;
227 228
}

229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
static bool
_equalFunc(Func *a, Func *b)
{
	if (a->funcid != b->funcid)
		return false;
	if (a->functype != b->functype)
		return false;
	if (a->funcisindex != b->funcisindex)
		return false;
	if (a->funcsize != b->funcsize)
		return false;
	/* Note we do not look at func_fcache */
	if (!equal(a->func_tlist, b->func_tlist))
		return false;
	if (!equal(a->func_planlist, b->func_planlist))
		return false;

	return true;
}

249 250 251 252 253 254 255 256 257 258 259
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;
260 261 262 263
	if (a->aggstar != b->aggstar)
		return false;
	if (a->aggdistinct != b->aggdistinct)
		return false;
264
	/* ignore aggno, which is only a private field for the executor */
265 266 267
	return true;
}

268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
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;
}

284 285 286 287 288 289 290 291 292 293 294 295
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;
}

296
static bool
297
_equalArrayRef(ArrayRef *a, ArrayRef *b)
298
{
299
	if (a->refelemtype != b->refelemtype)
300
		return false;
301
	if (a->refattrlength != b->refattrlength)
302
		return false;
303
	if (a->refelemlength != b->refelemlength)
304
		return false;
305
	if (a->refelembyval != b->refelembyval)
306
		return false;
307 308 309 310 311 312 313
	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);
314 315
}

316
/*
317
 * Stuff from relation.h
318
 */
319

320
static bool
321
_equalRelOptInfo(RelOptInfo *a, RelOptInfo *b)
322
{
323 324 325

	/*
	 * We treat RelOptInfos as equal if they refer to the same base rels
326 327
	 * joined in the same order.  Is this sufficient?
	 */
328
	return equali(a->relids, b->relids);
329 330
}

331 332 333
static bool
_equalIndexOptInfo(IndexOptInfo *a, IndexOptInfo *b)
{
334 335 336 337

	/*
	 * We treat IndexOptInfos as equal if they refer to the same index. Is
	 * this sufficient?
338 339 340 341 342 343
	 */
	if (a->indexoid != b->indexoid)
		return false;
	return true;
}

344
static bool
345
_equalPathKeyItem(PathKeyItem *a, PathKeyItem *b)
346
{
347
	if (a->sortop != b->sortop)
348
		return false;
349
	if (!equal(a->key, b->key))
350 351
		return false;
	return true;
352 353
}

354
static bool
355
_equalPath(Path *a, Path *b)
356
{
357
	if (a->pathtype != b->pathtype)
358
		return false;
359
	if (!equal(a->parent, b->parent))
360
		return false;
361 362 363

	/*
	 * do not check path costs, since they may not be set yet, and being
364
	 * float values there are roundoff error issues anyway...
365
	 */
366
	if (!equal(a->pathkeys, b->pathkeys))
367 368
		return false;
	return true;
369 370
}

371
static bool
372
_equalIndexPath(IndexPath *a, IndexPath *b)
373
{
374
	if (!_equalPath((Path *) a, (Path *) b))
375
		return false;
376
	if (!equali(a->indexid, b->indexid))
377
		return false;
378
	if (!equal(a->indexqual, b->indexqual))
379
		return false;
380 381
	if (a->indexscandir != b->indexscandir)
		return false;
382 383
	if (!equali(a->joinrelids, b->joinrelids))
		return false;
384 385 386 387

	/*
	 * Skip 'rows' because of possibility of floating-point roundoff
	 * error. It should be derivable from the other fields anyway.
388
	 */
389
	return true;
390 391
}

392 393 394 395 396 397 398 399 400 401 402 403
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;
}

404
static bool
405
_equalJoinPath(JoinPath *a, JoinPath *b)
406
{
407
	if (!_equalPath((Path *) a, (Path *) b))
408
		return false;
409
	if (!equal(a->outerjoinpath, b->outerjoinpath))
410
		return false;
411
	if (!equal(a->innerjoinpath, b->innerjoinpath))
412
		return false;
413 414
	if (!equal(a->joinrestrictinfo, b->joinrestrictinfo))
		return false;
415
	return true;
416 417
}

418
static bool
419
_equalNestPath(NestPath *a, NestPath *b)
420
{
421
	if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
422 423
		return false;
	return true;
424 425
}

426
static bool
427
_equalMergePath(MergePath *a, MergePath *b)
428
{
429
	if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
430
		return false;
431
	if (!equal(a->path_mergeclauses, b->path_mergeclauses))
432
		return false;
433
	if (!equal(a->outersortkeys, b->outersortkeys))
434
		return false;
435
	if (!equal(a->innersortkeys, b->innersortkeys))
436 437
		return false;
	return true;
438 439
}

440
static bool
441
_equalHashPath(HashPath *a, HashPath *b)
442
{
443
	if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
444
		return false;
445
	if (!equal(a->path_hashclauses, b->path_hashclauses))
446 447
		return false;
	return true;
448 449
}

Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
450 451 452
static bool
_equalSubPlan(SubPlan *a, SubPlan *b)
{
453
	/* should compare plans, but have to settle for comparing plan IDs */
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
454
	if (a->plan_id != b->plan_id)
455
		return false;
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
456

457 458 459
	if (!equal(a->rtable, b->rtable))
		return false;

460
	if (!equal(a->sublink, b->sublink))
461
		return false;
462

463
	return true;
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
464 465
}

466
static bool
467
_equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
468
{
469
	if (!equal(a->clause, b->clause))
470
		return false;
471
	if (!equal(a->subclauseindices, b->subclauseindices))
472
		return false;
473
	if (a->mergejoinoperator != b->mergejoinoperator)
474
		return false;
475 476 477 478 479
	if (a->left_sortop != b->left_sortop)
		return false;
	if (a->right_sortop != b->right_sortop)
		return false;
	if (a->hashjoinoperator != b->hashjoinoperator)
480 481
		return false;
	return true;
482 483
}

484
static bool
485
_equalJoinInfo(JoinInfo *a, JoinInfo *b)
486
{
487
	if (!equali(a->unjoined_relids, b->unjoined_relids))
488
		return false;
489
	if (!equal(a->jinfo_restrictinfo, b->jinfo_restrictinfo))
490
		return false;
491
	return true;
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
}

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);
}

520
/*
521
 *	Stuff from execnodes.h
522 523 524
 */

/*
525
 *	EState is a subclass of Node.
526
 */
527
static bool
528
_equalEState(EState *a, EState *b)
529
{
530
	if (a->es_direction != b->es_direction)
531
		return false;
532 533

	if (!equal(a->es_range_table, b->es_range_table))
534
		return false;
535 536

	if (a->es_result_relation_info != b->es_result_relation_info)
537
		return false;
538

539
	return true;
540 541
}

542 543 544 545 546 547 548 549 550 551 552 553 554
/*
 * 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;
Bruce Momjian's avatar
Bruce Momjian committed
555 556
	if (a->into && b->into)
	{
557 558
		if (strcmp(a->into, b->into) != 0)
			return false;
Bruce Momjian's avatar
Bruce Momjian committed
559 560 561
	}
	else
	{
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
		if (a->into != b->into)
			return false;
	}
	if (a->isPortal != b->isPortal)
		return false;
	if (a->isBinary != b->isBinary)
		return false;
	if (a->isTemp != b->isTemp)
		return false;
	if (a->unionall != b->unionall)
		return false;
	if (a->hasAggs != b->hasAggs)
		return false;
	if (a->hasSubLinks != b->hasSubLinks)
		return false;
577 578 579 580 581 582 583 584
	if (!equal(a->rtable, b->rtable))
		return false;
	if (!equal(a->targetList, b->targetList))
		return false;
	if (!equal(a->qual, b->qual))
		return false;
	if (!equal(a->rowMark, b->rowMark))
		return false;
585 586
	if (!equal(a->distinctClause, b->distinctClause))
		return false;
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
	if (!equal(a->sortClause, b->sortClause))
		return false;
	if (!equal(a->groupClause, b->groupClause))
		return false;
	if (!equal(a->havingQual, b->havingQual))
		return false;
	if (!equal(a->intersectClause, b->intersectClause))
		return false;
	if (!equal(a->unionClause, b->unionClause))
		return false;
	if (!equal(a->limitOffset, b->limitOffset))
		return false;
	if (!equal(a->limitCount, b->limitCount))
		return false;

Bruce Momjian's avatar
Bruce Momjian committed
602
	/*
603
	 * We do not check the internal-to-the-planner fields: base_rel_list,
604 605 606
	 * 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.
607 608 609 610 611 612 613
	 */
	return true;
}

static bool
_equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
{
Bruce Momjian's avatar
Bruce Momjian committed
614 615
	if (a->relname && b->relname)
	{
616 617
		if (strcmp(a->relname, b->relname) != 0)
			return false;
Bruce Momjian's avatar
Bruce Momjian committed
618 619 620
	}
	else
	{
621 622 623
		if (a->relname != b->relname)
			return false;
	}
624 625
	if (!equal(a->ref, b->ref))
		return false;
626 627 628 629 630 631
	if (a->relid != b->relid)
		return false;
	if (a->inh != b->inh)
		return false;
	if (a->inFromCl != b->inFromCl)
		return false;
632 633
	if (a->inJoinSet != b->inJoinSet)
		return false;
634 635 636 637 638 639
	if (a->skipAcl != b->skipAcl)
		return false;

	return true;
}

640 641 642 643 644 645 646 647 648 649 650
static bool
_equalSortClause(SortClause *a, SortClause *b)
{
	if (a->tleSortGroupRef != b->tleSortGroupRef)
		return false;
	if (a->sortop != b->sortop)
		return false;

	return true;
}

651 652 653 654 655 656 657 658 659 660 661
static bool
_equalRowMark(RowMark *a, RowMark *b)
{
	if (a->rti != b->rti)
		return false;
	if (a->info != b->info)
		return false;

	return true;
}

662
static bool
663
_equalTargetEntry(TargetEntry *a, TargetEntry *b)
664
{
665
	if (!equal(a->resdom, b->resdom))
666
		return false;
667
	if (!equal(a->fjoin, b->fjoin))
668
		return false;
669
	if (!equal(a->expr, b->expr))
670
		return false;
671

672
	return true;
673 674
}

675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
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;
}

701
/*
702
 * Stuff from pg_list.h
703
 */
704

705
static bool
706
_equalValue(Value *a, Value *b)
707
{
708
	if (a->type != b->type)
709
		return false;
710 711 712

	switch (a->type)
	{
713
		case T_Integer:
714
			return a->val.ival == b->val.ival;
715
		case T_Float:
716 717
		case T_String:
			return strcmp(a->val.str, b->val.str) == 0;
718 719
		default:
			break;
720 721
	}

722
	return true;
723 724 725
}

/*
726
 * equal
727
 *	  returns whether two nodes are equal
728 729 730 731
 */
bool
equal(void *a, void *b)
{
732
	bool		retval = false;
733

734
	if (a == b)
735
		return true;
736 737 738 739 740

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

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

	switch (nodeTag(a))
	{
751 752 753
		case T_SubPlan:
			retval = _equalSubPlan(a, b);
			break;
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
		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;
775 776
		case T_Aggref:
			retval = _equalAggref(a, b);
777 778 779
			break;
		case T_SubLink:
			retval = _equalSubLink(a, b);
780
			break;
781 782 783
		case T_Func:
			retval = _equalFunc(a, b);
			break;
784 785
		case T_ArrayRef:
			retval = _equalArrayRef(a, b);
786
			break;
787 788
		case T_Iter:
			retval = _equalIter(a, b);
789
			break;
790 791 792 793 794
		case T_RelabelType:
			retval = _equalRelabelType(a, b);
			break;
		case T_RelOptInfo:
			retval = _equalRelOptInfo(a, b);
795 796 797 798 799 800 801
			break;
		case T_Path:
			retval = _equalPath(a, b);
			break;
		case T_IndexPath:
			retval = _equalIndexPath(a, b);
			break;
802 803
		case T_NestPath:
			retval = _equalNestPath(a, b);
804 805 806 807 808 809 810
			break;
		case T_MergePath:
			retval = _equalMergePath(a, b);
			break;
		case T_HashPath:
			retval = _equalHashPath(a, b);
			break;
811 812
		case T_PathKeyItem:
			retval = _equalPathKeyItem(a, b);
813
			break;
814 815
		case T_RestrictInfo:
			retval = _equalRestrictInfo(a, b);
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
816
			break;
817 818
		case T_JoinInfo:
			retval = _equalJoinInfo(a, b);
819
			break;
820 821 822 823 824 825 826 827 828
		case T_Stream:
			retval = _equalStream(a, b);
			break;
		case T_TidPath:
			retval = _equalTidPath(a, b);
			break;
		case T_IndexOptInfo:
			retval = _equalIndexOptInfo(a, b);
			break;
829 830 831
		case T_EState:
			retval = _equalEState(a, b);
			break;
832 833
		case T_Attr:
			retval = _equalAttr(a, b);
834 835
			break;
		case T_List:
836
			{
837 838 839 840
				List	   *la = (List *) a;
				List	   *lb = (List *) b;
				List	   *l;

841 842
				/*
				 * Try to reject by length check before we grovel through
843 844 845
				 * all the elements...
				 */
				if (length(la) != length(lb))
846
					return false;
847 848 849
				foreach(l, la)
				{
					if (!equal(lfirst(l), lfirst(lb)))
850
						return false;
851 852 853
					lb = lnext(lb);
				}
				retval = true;
854
			}
855
			break;
856 857 858 859 860
		case T_Integer:
		case T_Float:
		case T_String:
			retval = _equalValue(a, b);
			break;
861 862 863
		case T_Query:
			retval = _equalQuery(a, b);
			break;
864 865 866
		case T_TargetEntry:
			retval = _equalTargetEntry(a, b);
			break;
867 868 869
		case T_RangeTblEntry:
			retval = _equalRangeTblEntry(a, b);
			break;
870 871 872 873 874 875 876
		case T_SortClause:
			retval = _equalSortClause(a, b);
			break;
		case T_GroupClause:
			/* GroupClause is equivalent to SortClause */
			retval = _equalSortClause(a, b);
			break;
877 878 879 880 881 882
		case T_CaseExpr:
			retval = _equalCaseExpr(a, b);
			break;
		case T_CaseWhen:
			retval = _equalCaseWhen(a, b);
			break;
883 884 885 886
		case T_RowMark:
			retval = _equalRowMark(a, b);
			break;

887 888 889 890
		default:
			elog(NOTICE, "equal: don't know whether nodes of type %d are equal",
				 nodeTag(a));
			break;
891
	}
892 893

	return retval;
894 895 896
}

/*
897
 * equali
898
 *	  compares two lists of integers
899
 */
900
static bool
901
equali(List *a, List *b)
902
{
903
	List	   *l;
904

905
	foreach(l, a)
906
	{
907 908 909
		if (b == NIL)
			return false;
		if (lfirsti(l) != lfirsti(b))
910
			return false;
911
		b = lnext(b);
912
	}
913 914
	if (b != NIL)
		return false;
915
	return true;
916
}