equalfuncs.c 19.0 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
 *
B
Add:  
Bruce Momjian 已提交
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.69 2000/07/17 03:05:01 tgl Exp $
28 29 30
 *
 *-------------------------------------------------------------------------
 */
31

32 33 34
#include "postgres.h"

#include "nodes/plannodes.h"
B
Bruce Momjian 已提交
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:
V
Vadim B. Mikheev 已提交
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
_equalArray(Array *a, Array *b)
298
{
299
	if (a->arrayelemtype != b->arrayelemtype)
300
		return false;
301 302
	/* We need not check arrayelemlength, arrayelembyval if types match */
	if (a->arrayndim != b->arrayndim)
303
		return false;
304 305
	/* XXX shouldn't we be checking all indices??? */
	if (a->arraylow.indx[0] != b->arraylow.indx[0])
306
		return false;
307
	if (a->arrayhigh.indx[0] != b->arrayhigh.indx[0])
308
		return false;
309
	if (a->arraylen != b->arraylen)
310
		return false;
311

312
	return true;
313 314
}

315
static bool
316
_equalArrayRef(ArrayRef *a, ArrayRef *b)
317
{
318
	if (a->refelemtype != b->refelemtype)
319
		return false;
320
	if (a->refattrlength != b->refattrlength)
321
		return false;
322
	if (a->refelemlength != b->refelemlength)
323
		return false;
324
	if (a->refelembyval != b->refelembyval)
325
		return false;
326 327 328 329 330 331 332
	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);
333 334
}

B
Bruce Momjian 已提交
335
/*
336
 * Stuff from relation.h
B
Bruce Momjian 已提交
337
 */
338

B
Bruce Momjian 已提交
339
static bool
340
_equalRelOptInfo(RelOptInfo *a, RelOptInfo *b)
B
Bruce Momjian 已提交
341
{
342 343 344

	/*
	 * We treat RelOptInfos as equal if they refer to the same base rels
345 346
	 * joined in the same order.  Is this sufficient?
	 */
347
	return equali(a->relids, b->relids);
B
Bruce Momjian 已提交
348 349
}

350 351 352
static bool
_equalIndexOptInfo(IndexOptInfo *a, IndexOptInfo *b)
{
353 354 355 356

	/*
	 * We treat IndexOptInfos as equal if they refer to the same index. Is
	 * this sufficient?
357 358 359 360 361 362
	 */
	if (a->indexoid != b->indexoid)
		return false;
	return true;
}

363
static bool
364
_equalPathKeyItem(PathKeyItem *a, PathKeyItem *b)
365
{
366
	if (a->sortop != b->sortop)
367
		return false;
368
	if (!equal(a->key, b->key))
369 370
		return false;
	return true;
371 372
}

373
static bool
374
_equalPath(Path *a, Path *b)
375
{
376
	if (a->pathtype != b->pathtype)
377
		return false;
378
	if (!equal(a->parent, b->parent))
379
		return false;
380 381 382

	/*
	 * do not check path costs, since they may not be set yet, and being
383
	 * float values there are roundoff error issues anyway...
384
	 */
385
	if (!equal(a->pathkeys, b->pathkeys))
386 387
		return false;
	return true;
388 389
}

390
static bool
391
_equalIndexPath(IndexPath *a, IndexPath *b)
392
{
393
	if (!_equalPath((Path *) a, (Path *) b))
394
		return false;
395
	if (!equali(a->indexid, b->indexid))
396
		return false;
397
	if (!equal(a->indexqual, b->indexqual))
398
		return false;
399 400
	if (a->indexscandir != b->indexscandir)
		return false;
401 402
	if (!equali(a->joinrelids, b->joinrelids))
		return false;
403 404 405 406

	/*
	 * Skip 'rows' because of possibility of floating-point roundoff
	 * error. It should be derivable from the other fields anyway.
407
	 */
408
	return true;
409 410
}

411 412 413 414 415 416 417 418 419 420 421 422
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;
}

423
static bool
424
_equalJoinPath(JoinPath *a, JoinPath *b)
425
{
426
	if (!_equalPath((Path *) a, (Path *) b))
427
		return false;
428
	if (!equal(a->outerjoinpath, b->outerjoinpath))
429
		return false;
430
	if (!equal(a->innerjoinpath, b->innerjoinpath))
431
		return false;
432 433
	if (!equal(a->joinrestrictinfo, b->joinrestrictinfo))
		return false;
434
	return true;
435 436
}

437
static bool
438
_equalNestPath(NestPath *a, NestPath *b)
439
{
440
	if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
441 442
		return false;
	return true;
443 444
}

445
static bool
446
_equalMergePath(MergePath *a, MergePath *b)
447
{
448
	if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
449
		return false;
450
	if (!equal(a->path_mergeclauses, b->path_mergeclauses))
451
		return false;
452
	if (!equal(a->outersortkeys, b->outersortkeys))
453
		return false;
454
	if (!equal(a->innersortkeys, b->innersortkeys))
455 456
		return false;
	return true;
457 458
}

459
static bool
460
_equalHashPath(HashPath *a, HashPath *b)
461
{
462
	if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
463
		return false;
464
	if (!equal(a->path_hashclauses, b->path_hashclauses))
465 466
		return false;
	return true;
467 468
}

V
Vadim B. Mikheev 已提交
469 470 471
static bool
_equalSubPlan(SubPlan *a, SubPlan *b)
{
472
	/* should compare plans, but have to settle for comparing plan IDs */
V
Vadim B. Mikheev 已提交
473
	if (a->plan_id != b->plan_id)
474
		return false;
V
Vadim B. Mikheev 已提交
475

476 477 478
	if (!equal(a->rtable, b->rtable))
		return false;

479
	if (!equal(a->sublink, b->sublink))
480
		return false;
481

482
	return true;
V
Vadim B. Mikheev 已提交
483 484
}

485
static bool
486
_equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
487
{
488
	if (!equal(a->clause, b->clause))
489
		return false;
490
	if (!equal(a->subclauseindices, b->subclauseindices))
491
		return false;
492
	if (a->mergejoinoperator != b->mergejoinoperator)
493
		return false;
494 495 496 497 498
	if (a->left_sortop != b->left_sortop)
		return false;
	if (a->right_sortop != b->right_sortop)
		return false;
	if (a->hashjoinoperator != b->hashjoinoperator)
499 500
		return false;
	return true;
501 502
}

503
static bool
504
_equalJoinInfo(JoinInfo *a, JoinInfo *b)
505
{
506
	if (!equali(a->unjoined_relids, b->unjoined_relids))
507
		return false;
508
	if (!equal(a->jinfo_restrictinfo, b->jinfo_restrictinfo))
509
		return false;
510
	return true;
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
}

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

539
/*
540
 *	Stuff from execnodes.h
541 542 543
 */

/*
544
 *	EState is a subclass of Node.
545
 */
546
static bool
547
_equalEState(EState *a, EState *b)
548
{
549
	if (a->es_direction != b->es_direction)
550
		return false;
551 552

	if (!equal(a->es_range_table, b->es_range_table))
553
		return false;
554 555

	if (a->es_result_relation_info != b->es_result_relation_info)
556
		return false;
557

558
	return true;
559 560
}

561 562 563 564 565 566 567 568 569 570 571 572 573
/*
 * 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;
B
Bruce Momjian 已提交
574 575
	if (a->into && b->into)
	{
576 577
		if (strcmp(a->into, b->into) != 0)
			return false;
B
Bruce Momjian 已提交
578 579 580
	}
	else
	{
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
		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;
596 597 598 599 600 601 602 603
	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;
604 605
	if (!equal(a->distinctClause, b->distinctClause))
		return false;
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
	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;

B
Bruce Momjian 已提交
621
	/*
622
	 * We do not check the internal-to-the-planner fields: base_rel_list,
623 624 625
	 * 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.
626 627 628 629 630 631 632
	 */
	return true;
}

static bool
_equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
{
B
Bruce Momjian 已提交
633 634
	if (a->relname && b->relname)
	{
635 636
		if (strcmp(a->relname, b->relname) != 0)
			return false;
B
Bruce Momjian 已提交
637 638 639
	}
	else
	{
640 641 642
		if (a->relname != b->relname)
			return false;
	}
643 644
	if (!equal(a->ref, b->ref))
		return false;
645 646 647 648 649 650
	if (a->relid != b->relid)
		return false;
	if (a->inh != b->inh)
		return false;
	if (a->inFromCl != b->inFromCl)
		return false;
651 652
	if (a->inJoinSet != b->inJoinSet)
		return false;
653 654 655 656 657 658
	if (a->skipAcl != b->skipAcl)
		return false;

	return true;
}

659 660 661 662 663 664 665 666 667 668 669
static bool
_equalSortClause(SortClause *a, SortClause *b)
{
	if (a->tleSortGroupRef != b->tleSortGroupRef)
		return false;
	if (a->sortop != b->sortop)
		return false;

	return true;
}

670 671 672 673 674 675 676 677 678 679 680
static bool
_equalRowMark(RowMark *a, RowMark *b)
{
	if (a->rti != b->rti)
		return false;
	if (a->info != b->info)
		return false;

	return true;
}

681
static bool
682
_equalTargetEntry(TargetEntry *a, TargetEntry *b)
683
{
684
	if (!equal(a->resdom, b->resdom))
685
		return false;
686
	if (!equal(a->fjoin, b->fjoin))
687
		return false;
688
	if (!equal(a->expr, b->expr))
689
		return false;
690

691
	return true;
692 693
}

694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
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;
}

720
/*
721
 * Stuff from pg_list.h
722
 */
723

724
static bool
725
_equalValue(Value *a, Value *b)
726
{
727
	if (a->type != b->type)
728
		return false;
729 730 731

	switch (a->type)
	{
732
		case T_Integer:
733
			return a->val.ival == b->val.ival;
734
		case T_Float:
735 736
		case T_String:
			return strcmp(a->val.str, b->val.str) == 0;
737 738
		default:
			break;
739 740
	}

741
	return true;
742 743 744
}

/*
745
 * equal
746
 *	  returns whether two nodes are equal
747 748 749 750
 */
bool
equal(void *a, void *b)
{
751
	bool		retval = false;
752

753
	if (a == b)
754
		return true;
755 756 757 758 759

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

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

	switch (nodeTag(a))
	{
770 771 772
		case T_SubPlan:
			retval = _equalSubPlan(a, b);
			break;
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
		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;
794 795
		case T_Aggref:
			retval = _equalAggref(a, b);
796 797 798
			break;
		case T_SubLink:
			retval = _equalSubLink(a, b);
799
			break;
800 801 802
		case T_Func:
			retval = _equalFunc(a, b);
			break;
803 804
		case T_Array:
			retval = _equalArray(a, b);
805
			break;
806 807
		case T_ArrayRef:
			retval = _equalArrayRef(a, b);
B
Bruce Momjian 已提交
808
			break;
809 810
		case T_Iter:
			retval = _equalIter(a, b);
811
			break;
812 813 814 815 816
		case T_RelabelType:
			retval = _equalRelabelType(a, b);
			break;
		case T_RelOptInfo:
			retval = _equalRelOptInfo(a, b);
817 818 819 820 821 822 823
			break;
		case T_Path:
			retval = _equalPath(a, b);
			break;
		case T_IndexPath:
			retval = _equalIndexPath(a, b);
			break;
824 825
		case T_NestPath:
			retval = _equalNestPath(a, b);
826 827 828 829 830 831 832
			break;
		case T_MergePath:
			retval = _equalMergePath(a, b);
			break;
		case T_HashPath:
			retval = _equalHashPath(a, b);
			break;
833 834
		case T_PathKeyItem:
			retval = _equalPathKeyItem(a, b);
835
			break;
836 837
		case T_RestrictInfo:
			retval = _equalRestrictInfo(a, b);
V
Vadim B. Mikheev 已提交
838
			break;
839 840
		case T_JoinInfo:
			retval = _equalJoinInfo(a, b);
841
			break;
842 843 844 845 846 847 848 849 850
		case T_Stream:
			retval = _equalStream(a, b);
			break;
		case T_TidPath:
			retval = _equalTidPath(a, b);
			break;
		case T_IndexOptInfo:
			retval = _equalIndexOptInfo(a, b);
			break;
851 852 853
		case T_EState:
			retval = _equalEState(a, b);
			break;
854 855
		case T_Attr:
			retval = _equalAttr(a, b);
856 857
			break;
		case T_List:
858
			{
859 860 861 862
				List	   *la = (List *) a;
				List	   *lb = (List *) b;
				List	   *l;

863 864
				/*
				 * Try to reject by length check before we grovel through
865 866 867
				 * all the elements...
				 */
				if (length(la) != length(lb))
868
					return false;
869 870 871
				foreach(l, la)
				{
					if (!equal(lfirst(l), lfirst(lb)))
872
						return false;
873 874 875
					lb = lnext(lb);
				}
				retval = true;
876
			}
877
			break;
878 879 880 881 882
		case T_Integer:
		case T_Float:
		case T_String:
			retval = _equalValue(a, b);
			break;
883 884 885
		case T_Query:
			retval = _equalQuery(a, b);
			break;
886 887 888
		case T_TargetEntry:
			retval = _equalTargetEntry(a, b);
			break;
889 890 891
		case T_RangeTblEntry:
			retval = _equalRangeTblEntry(a, b);
			break;
892 893 894 895 896 897 898
		case T_SortClause:
			retval = _equalSortClause(a, b);
			break;
		case T_GroupClause:
			/* GroupClause is equivalent to SortClause */
			retval = _equalSortClause(a, b);
			break;
899 900 901 902 903 904
		case T_CaseExpr:
			retval = _equalCaseExpr(a, b);
			break;
		case T_CaseWhen:
			retval = _equalCaseWhen(a, b);
			break;
905 906 907 908
		case T_RowMark:
			retval = _equalRowMark(a, b);
			break;

909 910 911 912
		default:
			elog(NOTICE, "equal: don't know whether nodes of type %d are equal",
				 nodeTag(a));
			break;
913
	}
914 915

	return retval;
916 917 918
}

/*
919
 * equali
920
 *	  compares two lists of integers
921
 */
922
static bool
923
equali(List *a, List *b)
924
{
925
	List	   *l;
926

927
	foreach(l, a)
928
	{
929 930 931
		if (b == NIL)
			return false;
		if (lfirsti(l) != lfirsti(b))
932
			return false;
933
		b = lnext(b);
934
	}
935 936
	if (b != NIL)
		return false;
937
	return true;
938
}