]> granicus.if.org Git - postgresql/blob - src/backend/nodes/equalfuncs.c
Restructure command-completion-report code so that there is just one
[postgresql] / src / backend / nodes / equalfuncs.c
1 /*-------------------------------------------------------------------------
2  *
3  * equalfuncs.c
4  *        Equality functions to compare node trees.
5  *
6  * NOTE: a general convention when copying or comparing plan nodes is
7  * that we ignore the executor state subnode.  We do not need to look
8  * 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  * out, we avoid needing to write copy/compare routines for all the
11  * different executor state node types.
12  *
13  * Currently, in fact, equal() doesn't know how to compare Plan nodes
14  * at all, let alone their executor-state subnodes.  This will probably
15  * need to be fixed someday, but presently there is no need to compare
16  * plan trees.
17  *
18  *
19  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
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.111 2002/02/26 22:47:05 tgl Exp $
24  *
25  *-------------------------------------------------------------------------
26  */
27
28 #include "postgres.h"
29
30 #include "nodes/plannodes.h"
31 #include "nodes/relation.h"
32 #include "utils/datum.h"
33
34
35 /* Macro for comparing string fields that might be NULL */
36 #define equalstr(a, b)  \
37         (((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
38
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         if (!equalstr(a->resname, b->resname))
54                 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         nNodes = a->fj_nNodes;
79         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          * We do not examine typeOid, since the optimizer often doesn't bother
92          * to set it in created nodes, and it is logically a derivative of the
93          * oper field anyway.
94          */
95         if (a->opType != b->opType)
96                 return false;
97         if (!equal(a->oper, b->oper))
98                 return false;
99         if (!equal(a->args, b->args))
100                 return false;
101
102         return true;
103 }
104
105 static bool
106 _equalVar(Var *a, Var *b)
107 {
108         if (a->varno != b->varno)
109                 return false;
110         if (a->varattno != b->varattno)
111                 return false;
112         if (a->vartype != b->vartype)
113                 return false;
114         if (a->vartypmod != b->vartypmod)
115                 return false;
116         if (a->varlevelsup != b->varlevelsup)
117                 return false;
118         if (a->varnoold != b->varnoold)
119                 return false;
120         if (a->varoattno != b->varoattno)
121                 return false;
122
123         return true;
124 }
125
126 static bool
127 _equalOper(Oper *a, Oper *b)
128 {
129         if (a->opno != b->opno)
130                 return false;
131         if (a->opresulttype != b->opresulttype)
132                 return false;
133
134         /*
135          * We do not examine opid or op_fcache, since these are logically
136          * derived from opno, and they may not be set yet depending on how far
137          * along the node is in the parse/plan pipeline.
138          *
139          * (Besides, op_fcache is executor state, which we don't check --- see
140          * notes at head of file.)
141          *
142          * It's probably not really necessary to check opresulttype either...
143          */
144
145         return true;
146 }
147
148 static bool
149 _equalConst(Const *a, Const *b)
150 {
151         if (a->consttype != b->consttype)
152                 return false;
153         if (a->constlen != b->constlen)
154                 return false;
155         if (a->constisnull != b->constisnull)
156                 return false;
157         if (a->constbyval != b->constbyval)
158                 return false;
159         /* XXX What about constisset and constiscast? */
160
161         /*
162          * We treat all NULL constants of the same type as equal. Someday this
163          * might need to change?  But datumIsEqual doesn't work on nulls,
164          * so...
165          */
166         if (a->constisnull)
167                 return true;
168         return datumIsEqual(a->constvalue, b->constvalue,
169                                                 a->constbyval, a->constlen);
170 }
171
172 static bool
173 _equalParam(Param *a, Param *b)
174 {
175         if (a->paramkind != b->paramkind)
176                 return false;
177         if (a->paramtype != b->paramtype)
178                 return false;
179
180         switch (a->paramkind)
181         {
182                 case PARAM_NAMED:
183                 case PARAM_NEW:
184                 case PARAM_OLD:
185                         if (strcmp(a->paramname, b->paramname) != 0)
186                                 return false;
187                         break;
188                 case PARAM_NUM:
189                 case PARAM_EXEC:
190                         if (a->paramid != b->paramid)
191                                 return false;
192                         break;
193                 case PARAM_INVALID:
194
195                         /*
196                          * XXX: Hmmm... What are we supposed to return in this case ??
197                          */
198                         return true;
199                         break;
200                 default:
201                         elog(ERROR, "_equalParam: Invalid paramkind value: %d",
202                                  a->paramkind);
203         }
204
205         return true;
206 }
207
208 static bool
209 _equalFunc(Func *a, Func *b)
210 {
211         if (a->funcid != b->funcid)
212                 return false;
213         if (a->functype != b->functype)
214                 return false;
215         /* Note we do not look at func_fcache; see notes for _equalOper */
216
217         return true;
218 }
219
220 static bool
221 _equalAggref(Aggref *a, Aggref *b)
222 {
223         if (strcmp(a->aggname, b->aggname) != 0)
224                 return false;
225         if (a->basetype != b->basetype)
226                 return false;
227         if (a->aggtype != b->aggtype)
228                 return false;
229         if (!equal(a->target, b->target))
230                 return false;
231         if (a->aggstar != b->aggstar)
232                 return false;
233         if (a->aggdistinct != b->aggdistinct)
234                 return false;
235         /* ignore aggno, which is only a private field for the executor */
236         return true;
237 }
238
239 static bool
240 _equalSubLink(SubLink *a, SubLink *b)
241 {
242         if (a->subLinkType != b->subLinkType)
243                 return false;
244         if (a->useor != b->useor)
245                 return false;
246         if (!equal(a->lefthand, b->lefthand))
247                 return false;
248         if (!equal(a->oper, b->oper))
249                 return false;
250         if (!equal(a->subselect, b->subselect))
251                 return false;
252         return true;
253 }
254
255 static bool
256 _equalArrayRef(ArrayRef *a, ArrayRef *b)
257 {
258         if (a->refelemtype != b->refelemtype)
259                 return false;
260         if (a->refattrlength != b->refattrlength)
261                 return false;
262         if (a->refelemlength != b->refelemlength)
263                 return false;
264         if (a->refelembyval != b->refelembyval)
265                 return false;
266         if (!equal(a->refupperindexpr, b->refupperindexpr))
267                 return false;
268         if (!equal(a->reflowerindexpr, b->reflowerindexpr))
269                 return false;
270         if (!equal(a->refexpr, b->refexpr))
271                 return false;
272         return equal(a->refassgnexpr, b->refassgnexpr);
273 }
274
275 static bool
276 _equalFieldSelect(FieldSelect *a, FieldSelect *b)
277 {
278         if (!equal(a->arg, b->arg))
279                 return false;
280         if (a->fieldnum != b->fieldnum)
281                 return false;
282         if (a->resulttype != b->resulttype)
283                 return false;
284         if (a->resulttypmod != b->resulttypmod)
285                 return false;
286         return true;
287 }
288
289 static bool
290 _equalRelabelType(RelabelType *a, RelabelType *b)
291 {
292         if (!equal(a->arg, b->arg))
293                 return false;
294         if (a->resulttype != b->resulttype)
295                 return false;
296         if (a->resulttypmod != b->resulttypmod)
297                 return false;
298         return true;
299 }
300
301 static bool
302 _equalRangeTblRef(RangeTblRef *a, RangeTblRef *b)
303 {
304         if (a->rtindex != b->rtindex)
305                 return false;
306
307         return true;
308 }
309
310 static bool
311 _equalFromExpr(FromExpr *a, FromExpr *b)
312 {
313         if (!equal(a->fromlist, b->fromlist))
314                 return false;
315         if (!equal(a->quals, b->quals))
316                 return false;
317
318         return true;
319 }
320
321 static bool
322 _equalJoinExpr(JoinExpr *a, JoinExpr *b)
323 {
324         if (a->jointype != b->jointype)
325                 return false;
326         if (a->isNatural != b->isNatural)
327                 return false;
328         if (!equal(a->larg, b->larg))
329                 return false;
330         if (!equal(a->rarg, b->rarg))
331                 return false;
332         if (!equal(a->using, b->using))
333                 return false;
334         if (!equal(a->quals, b->quals))
335                 return false;
336         if (!equal(a->alias, b->alias))
337                 return false;
338         if (!equal(a->colnames, b->colnames))
339                 return false;
340         if (!equal(a->colvars, b->colvars))
341                 return false;
342
343         return true;
344 }
345
346 /*
347  * Stuff from relation.h
348  */
349
350 static bool
351 _equalRelOptInfo(RelOptInfo *a, RelOptInfo *b)
352 {
353         /*
354          * We treat RelOptInfos as equal if they refer to the same base rels
355          * joined in the same order.  Is this appropriate/sufficient?
356          */
357         return equali(a->relids, b->relids);
358 }
359
360 static bool
361 _equalIndexOptInfo(IndexOptInfo *a, IndexOptInfo *b)
362 {
363         /*
364          * We treat IndexOptInfos as equal if they refer to the same index. Is
365          * this sufficient?
366          */
367         if (a->indexoid != b->indexoid)
368                 return false;
369         return true;
370 }
371
372 static bool
373 _equalPathKeyItem(PathKeyItem *a, PathKeyItem *b)
374 {
375         if (a->sortop != b->sortop)
376                 return false;
377         if (!equal(a->key, b->key))
378                 return false;
379         return true;
380 }
381
382 static bool
383 _equalPath(Path *a, Path *b)
384 {
385         if (a->pathtype != b->pathtype)
386                 return false;
387         if (!equal(a->parent, b->parent))
388                 return false;
389
390         /*
391          * do not check path costs, since they may not be set yet, and being
392          * float values there are roundoff error issues anyway...
393          */
394         if (!equal(a->pathkeys, b->pathkeys))
395                 return false;
396         return true;
397 }
398
399 static bool
400 _equalIndexPath(IndexPath *a, IndexPath *b)
401 {
402         if (!_equalPath((Path *) a, (Path *) b))
403                 return false;
404         if (!equal(a->indexinfo, b->indexinfo))
405                 return false;
406         if (!equal(a->indexqual, b->indexqual))
407                 return false;
408         if (a->indexscandir != b->indexscandir)
409                 return false;
410         if (!equali(a->joinrelids, b->joinrelids))
411                 return false;
412         if (a->alljoinquals != b->alljoinquals)
413                 return false;
414
415         /*
416          * Skip 'rows' because of possibility of floating-point roundoff
417          * error. It should be derivable from the other fields anyway.
418          */
419         return true;
420 }
421
422 static bool
423 _equalTidPath(TidPath *a, TidPath *b)
424 {
425         if (!_equalPath((Path *) a, (Path *) b))
426                 return false;
427         if (!equal(a->tideval, b->tideval))
428                 return false;
429         if (!equali(a->unjoined_relids, b->unjoined_relids))
430                 return false;
431         return true;
432 }
433
434 static bool
435 _equalAppendPath(AppendPath *a, AppendPath *b)
436 {
437         if (!_equalPath((Path *) a, (Path *) b))
438                 return false;
439         if (!equal(a->subpaths, b->subpaths))
440                 return false;
441         return true;
442 }
443
444 static bool
445 _equalJoinPath(JoinPath *a, JoinPath *b)
446 {
447         if (!_equalPath((Path *) a, (Path *) b))
448                 return false;
449         if (a->jointype != b->jointype)
450                 return false;
451         if (!equal(a->outerjoinpath, b->outerjoinpath))
452                 return false;
453         if (!equal(a->innerjoinpath, b->innerjoinpath))
454                 return false;
455         if (!equal(a->joinrestrictinfo, b->joinrestrictinfo))
456                 return false;
457         return true;
458 }
459
460 static bool
461 _equalNestPath(NestPath *a, NestPath *b)
462 {
463         if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
464                 return false;
465         return true;
466 }
467
468 static bool
469 _equalMergePath(MergePath *a, MergePath *b)
470 {
471         if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
472                 return false;
473         if (!equal(a->path_mergeclauses, b->path_mergeclauses))
474                 return false;
475         if (!equal(a->outersortkeys, b->outersortkeys))
476                 return false;
477         if (!equal(a->innersortkeys, b->innersortkeys))
478                 return false;
479         return true;
480 }
481
482 static bool
483 _equalHashPath(HashPath *a, HashPath *b)
484 {
485         if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
486                 return false;
487         if (!equal(a->path_hashclauses, b->path_hashclauses))
488                 return false;
489         return true;
490 }
491
492 static bool
493 _equalSubPlan(SubPlan *a, SubPlan *b)
494 {
495         /* should compare plans, but have to settle for comparing plan IDs */
496         if (a->plan_id != b->plan_id)
497                 return false;
498
499         if (!equal(a->rtable, b->rtable))
500                 return false;
501
502         if (!equal(a->sublink, b->sublink))
503                 return false;
504
505         return true;
506 }
507
508 static bool
509 _equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
510 {
511         if (!equal(a->clause, b->clause))
512                 return false;
513         if (a->ispusheddown != b->ispusheddown)
514                 return false;
515
516         /*
517          * We ignore eval_cost, this_selec, left/right_pathkey, and
518          * left/right_bucketsize, since they may not be set yet, and should be
519          * derivable from the clause anyway.  Probably it's not really
520          * necessary to compare any of these remaining fields ...
521          */
522         if (!equal(a->subclauseindices, b->subclauseindices))
523                 return false;
524         if (a->mergejoinoperator != b->mergejoinoperator)
525                 return false;
526         if (a->left_sortop != b->left_sortop)
527                 return false;
528         if (a->right_sortop != b->right_sortop)
529                 return false;
530         if (a->hashjoinoperator != b->hashjoinoperator)
531                 return false;
532         return true;
533 }
534
535 static bool
536 _equalJoinInfo(JoinInfo *a, JoinInfo *b)
537 {
538         if (!equali(a->unjoined_relids, b->unjoined_relids))
539                 return false;
540         if (!equal(a->jinfo_restrictinfo, b->jinfo_restrictinfo))
541                 return false;
542         return true;
543 }
544
545 static bool
546 _equalIter(Iter *a, Iter *b)
547 {
548         return equal(a->iterexpr, b->iterexpr);
549 }
550
551 static bool
552 _equalStream(Stream *a, Stream *b)
553 {
554         if (a->clausetype != b->clausetype)
555                 return false;
556         if (a->groupup != b->groupup)
557                 return false;
558         if (a->groupcost != b->groupcost)
559                 return false;
560         if (a->groupsel != b->groupsel)
561                 return false;
562         if (!equal(a->pathptr, b->pathptr))
563                 return false;
564         if (!equal(a->cinfo, b->cinfo))
565                 return false;
566         if (!equal(a->upstream, b->upstream))
567                 return false;
568         return equal(a->downstream, b->downstream);
569 }
570
571 /*
572  * Stuff from parsenodes.h
573  */
574
575 static bool
576 _equalQuery(Query *a, Query *b)
577 {
578         if (a->commandType != b->commandType)
579                 return false;
580         if (!equal(a->utilityStmt, b->utilityStmt))
581                 return false;
582         if (a->resultRelation != b->resultRelation)
583                 return false;
584         if (!equalstr(a->into, b->into))
585                 return false;
586         if (a->isPortal != b->isPortal)
587                 return false;
588         if (a->isBinary != b->isBinary)
589                 return false;
590         if (a->isTemp != b->isTemp)
591                 return false;
592         if (a->hasAggs != b->hasAggs)
593                 return false;
594         if (a->hasSubLinks != b->hasSubLinks)
595                 return false;
596         /* we deliberately ignore originalQuery */
597         if (!equal(a->rtable, b->rtable))
598                 return false;
599         if (!equal(a->jointree, b->jointree))
600                 return false;
601         if (!equali(a->rowMarks, b->rowMarks))
602                 return false;
603         if (!equal(a->targetList, b->targetList))
604                 return false;
605         if (!equal(a->groupClause, b->groupClause))
606                 return false;
607         if (!equal(a->havingQual, b->havingQual))
608                 return false;
609         if (!equal(a->distinctClause, b->distinctClause))
610                 return false;
611         if (!equal(a->sortClause, b->sortClause))
612                 return false;
613         if (!equal(a->limitOffset, b->limitOffset))
614                 return false;
615         if (!equal(a->limitCount, b->limitCount))
616                 return false;
617         if (!equal(a->setOperations, b->setOperations))
618                 return false;
619         if (!equali(a->resultRelations, b->resultRelations))
620                 return false;
621
622         /*
623          * We do not check the internal-to-the-planner fields: base_rel_list,
624          * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. They
625          * might not be set yet, and in any case they should be derivable from
626          * the other fields.
627          */
628         return true;
629 }
630
631 static bool
632 _equalInsertStmt(InsertStmt *a, InsertStmt *b)
633 {
634         if (!equalstr(a->relname, b->relname))
635                 return false;
636         if (!equal(a->cols, b->cols))
637                 return false;
638         if (!equal(a->targetList, b->targetList))
639                 return false;
640         if (!equal(a->selectStmt, b->selectStmt))
641                 return false;
642
643         return true;
644 }
645
646 static bool
647 _equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
648 {
649         if (!equalstr(a->relname, b->relname))
650                 return false;
651         if (!equal(a->whereClause, b->whereClause))
652                 return false;
653         if (a->inhOpt != b->inhOpt)
654                 return false;
655
656         return true;
657 }
658
659 static bool
660 _equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
661 {
662         if (!equalstr(a->relname, b->relname))
663                 return false;
664         if (!equal(a->targetList, b->targetList))
665                 return false;
666         if (!equal(a->whereClause, b->whereClause))
667                 return false;
668         if (!equal(a->fromClause, b->fromClause))
669                 return false;
670         if (a->inhOpt != b->inhOpt)
671                 return false;
672
673         return true;
674 }
675
676 static bool
677 _equalSelectStmt(SelectStmt *a, SelectStmt *b)
678 {
679         if (!equal(a->distinctClause, b->distinctClause))
680                 return false;
681         if (!equalstr(a->into, b->into))
682                 return false;
683         if (a->istemp != b->istemp)
684                 return false;
685         if (!equal(a->intoColNames, b->intoColNames))
686                 return false;
687         if (!equal(a->targetList, b->targetList))
688                 return false;
689         if (!equal(a->fromClause, b->fromClause))
690                 return false;
691         if (!equal(a->whereClause, b->whereClause))
692                 return false;
693         if (!equal(a->groupClause, b->groupClause))
694                 return false;
695         if (!equal(a->havingClause, b->havingClause))
696                 return false;
697         if (!equal(a->sortClause, b->sortClause))
698                 return false;
699         if (!equalstr(a->portalname, b->portalname))
700                 return false;
701         if (a->binary != b->binary)
702                 return false;
703         if (!equal(a->limitOffset, b->limitOffset))
704                 return false;
705         if (!equal(a->limitCount, b->limitCount))
706                 return false;
707         if (!equal(a->forUpdate, b->forUpdate))
708                 return false;
709         if (a->op != b->op)
710                 return false;
711         if (a->all != b->all)
712                 return false;
713         if (!equal(a->larg, b->larg))
714                 return false;
715         if (!equal(a->rarg, b->rarg))
716                 return false;
717
718         return true;
719 }
720
721 static bool
722 _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
723 {
724         if (a->op != b->op)
725                 return false;
726         if (a->all != b->all)
727                 return false;
728         if (!equal(a->larg, b->larg))
729                 return false;
730         if (!equal(a->rarg, b->rarg))
731                 return false;
732         if (!equali(a->colTypes, b->colTypes))
733                 return false;
734
735         return true;
736 }
737
738 static bool
739 _equalAlterTableStmt(AlterTableStmt *a, AlterTableStmt *b)
740 {
741         if (a->subtype != b->subtype)
742                 return false;
743         if (!equalstr(a->relname, b->relname))
744                 return false;
745         if (a->inhOpt != b->inhOpt)
746                 return false;
747         if (!equalstr(a->name, b->name))
748                 return false;
749         if (!equal(a->def, b->def))
750                 return false;
751         if (a->behavior != b->behavior)
752                 return false;
753
754         return true;
755 }
756
757 static bool
758 _equalGrantStmt(GrantStmt *a, GrantStmt *b)
759 {
760         if (a->is_grant != b->is_grant)
761                 return false;
762         if (a->objtype != b->objtype)
763                 return false;
764         if (!equal(a->objects, b->objects))
765                 return false;
766         if (!equal(a->privileges, b->privileges))
767                 return false;
768         if (!equal(a->grantees, b->grantees))
769                 return false;
770
771         return true;
772 }
773
774 static bool
775 _equalPrivGrantee(PrivGrantee *a, PrivGrantee *b)
776 {
777         return equalstr(a->username, b->username)
778                 && equalstr(a->groupname, b->groupname);
779 }
780
781 static bool
782 _equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
783 {
784         return equalstr(a->funcname, b->funcname)
785                 && equal(a->funcargs, b->funcargs);
786 }
787
788 static bool
789 _equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
790 {
791         if (!equalstr(a->portalname, b->portalname))
792                 return false;
793
794         return true;
795 }
796
797 static bool
798 _equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
799 {
800         if (!equalstr(a->relname, b->relname))
801                 return false;
802         if (!equalstr(a->indexname, b->indexname))
803                 return false;
804
805         return true;
806 }
807
808 static bool
809 _equalCopyStmt(CopyStmt *a, CopyStmt *b)
810 {
811         if (a->binary != b->binary)
812                 return false;
813         if (!equalstr(a->relname, b->relname))
814                 return false;
815         if (a->oids != b->oids)
816                 return false;
817         if (a->direction != b->direction)
818                 return false;
819         if (!equalstr(a->filename, b->filename))
820                 return false;
821         if (!equalstr(a->delimiter, b->delimiter))
822                 return false;
823         if (!equalstr(a->null_print, b->null_print))
824                 return false;
825
826         return true;
827 }
828
829 static bool
830 _equalCreateStmt(CreateStmt *a, CreateStmt *b)
831 {
832         if (!equalstr(a->relname, b->relname))
833                 return false;
834         if (!equal(a->tableElts, b->tableElts))
835                 return false;
836         if (!equal(a->inhRelnames, b->inhRelnames))
837                 return false;
838         if (!equal(a->constraints, b->constraints))
839                 return false;
840         if (a->istemp != b->istemp)
841                 return false;
842         if (a->hasoids != b->hasoids)
843                 return false;
844
845         return true;
846 }
847
848 static bool
849 _equalVersionStmt(VersionStmt *a, VersionStmt *b)
850 {
851         if (!equalstr(a->relname, b->relname))
852                 return false;
853         if (a->direction != b->direction)
854                 return false;
855         if (!equalstr(a->fromRelname, b->fromRelname))
856                 return false;
857         if (!equalstr(a->date, b->date))
858                 return false;
859
860         return true;
861 }
862
863 static bool
864 _equalDefineStmt(DefineStmt *a, DefineStmt *b)
865 {
866         if (a->defType != b->defType)
867                 return false;
868         if (!equalstr(a->defname, b->defname))
869                 return false;
870         if (!equal(a->definition, b->definition))
871                 return false;
872
873         return true;
874 }
875
876 static bool
877 _equalDropStmt(DropStmt *a, DropStmt *b)
878 {
879         if (!equal(a->names, b->names))
880                 return false;
881         if (a->removeType != b->removeType)
882                 return false;
883
884         return true;
885 }
886
887 static bool
888 _equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
889 {
890         if (!equalstr(a->relName, b->relName))
891                 return false;
892
893         return true;
894 }
895
896 static bool
897 _equalCommentStmt(CommentStmt *a, CommentStmt *b)
898 {
899         if (a->objtype != b->objtype)
900                 return false;
901         if (!equalstr(a->objname, b->objname))
902                 return false;
903         if (!equalstr(a->objproperty, b->objproperty))
904                 return false;
905         if (!equal(a->objlist, b->objlist))
906                 return false;
907         if (!equalstr(a->comment, b->comment))
908                 return false;
909
910         return true;
911 }
912
913 static bool
914 _equalFetchStmt(FetchStmt *a, FetchStmt *b)
915 {
916         if (a->direction != b->direction)
917                 return false;
918         if (a->howMany != b->howMany)
919                 return false;
920         if (!equalstr(a->portalname, b->portalname))
921                 return false;
922         if (a->ismove != b->ismove)
923                 return false;
924
925         return true;
926 }
927
928 static bool
929 _equalIndexStmt(IndexStmt *a, IndexStmt *b)
930 {
931         if (!equalstr(a->idxname, b->idxname))
932                 return false;
933         if (!equalstr(a->relname, b->relname))
934                 return false;
935         if (!equalstr(a->accessMethod, b->accessMethod))
936                 return false;
937         if (!equal(a->indexParams, b->indexParams))
938                 return false;
939         if (!equal(a->whereClause, b->whereClause))
940                 return false;
941         if (!equal(a->rangetable, b->rangetable))
942                 return false;
943         if (a->unique != b->unique)
944                 return false;
945         if (a->primary != b->primary)
946                 return false;
947
948         return true;
949 }
950
951 static bool
952 _equalProcedureStmt(ProcedureStmt *a, ProcedureStmt *b)
953 {
954         if (a->replace != b->replace)
955                 return false;
956         if (!equalstr(a->funcname, b->funcname))
957                 return false;
958         if (!equal(a->argTypes, b->argTypes))
959                 return false;
960         if (!equal(a->returnType, b->returnType))
961                 return false;
962         if (!equal(a->withClause, b->withClause))
963                 return false;
964         if (!equal(a->as, b->as))
965                 return false;
966         if (!equalstr(a->language, b->language))
967                 return false;
968
969         return true;
970 }
971
972 static bool
973 _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
974 {
975         if (!equalstr(a->aggname, b->aggname))
976                 return false;
977         if (!equal(a->aggtype, b->aggtype))
978                 return false;
979
980         return true;
981 }
982
983 static bool
984 _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
985 {
986         if (!equalstr(a->funcname, b->funcname))
987                 return false;
988         if (!equal(a->args, b->args))
989                 return false;
990
991         return true;
992 }
993
994 static bool
995 _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
996 {
997         if (!equalstr(a->opname, b->opname))
998                 return false;
999         if (!equal(a->args, b->args))
1000                 return false;
1001
1002         return true;
1003 }
1004
1005
1006 static bool
1007 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
1008 {
1009         if (!equalstr(a->relname, b->relname))
1010                 return false;
1011         if (a->inhOpt != b->inhOpt)
1012                 return false;
1013         if (!equalstr(a->column, b->column))
1014                 return false;
1015         if (!equalstr(a->newname, b->newname))
1016                 return false;
1017
1018         return true;
1019 }
1020
1021 static bool
1022 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
1023 {
1024         if (!equalstr(a->rulename, b->rulename))
1025                 return false;
1026         if (!equal(a->whereClause, b->whereClause))
1027                 return false;
1028         if (a->event != b->event)
1029                 return false;
1030         if (!equal(a->object, b->object))
1031                 return false;
1032         if (a->instead != b->instead)
1033                 return false;
1034         if (!equal(a->actions, b->actions))
1035                 return false;
1036
1037         return true;
1038 }
1039
1040 static bool
1041 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1042 {
1043         if (!equalstr(a->relname, b->relname))
1044                 return false;
1045
1046         return true;
1047 }
1048
1049 static bool
1050 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1051 {
1052         if (!equalstr(a->relname, b->relname))
1053                 return false;
1054
1055         return true;
1056 }
1057
1058 static bool
1059 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1060 {
1061         if (!equalstr(a->relname, b->relname))
1062                 return false;
1063
1064         return true;
1065 }
1066
1067 static bool
1068 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1069 {
1070         if (a->command != b->command)
1071                 return false;
1072
1073         return true;
1074 }
1075
1076 static bool
1077 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1078 {
1079         if (!equalstr(a->viewname, b->viewname))
1080                 return false;
1081         if (!equal(a->aliases, b->aliases))
1082                 return false;
1083         if (!equal(a->query, b->query))
1084                 return false;
1085
1086         return true;
1087 }
1088
1089 static bool
1090 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1091 {
1092         if (!equalstr(a->filename, b->filename))
1093                 return false;
1094
1095         return true;
1096 }
1097
1098 static bool
1099 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1100 {
1101         if (!equalstr(a->dbname, b->dbname))
1102                 return false;
1103         if (!equalstr(a->dbowner, b->dbowner))
1104                 return false;
1105         if (!equalstr(a->dbpath, b->dbpath))
1106                 return false;
1107         if (!equalstr(a->dbtemplate, b->dbtemplate))
1108                 return false;
1109         if (a->encoding != b->encoding)
1110                 return false;
1111
1112         return true;
1113 }
1114
1115 static bool
1116 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1117 {
1118         if (!equalstr(a->dbname, b->dbname))
1119                 return false;
1120
1121         return true;
1122 }
1123
1124 static bool
1125 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1126 {
1127         if (a->vacuum != b->vacuum)
1128                 return false;
1129         if (a->full != b->full)
1130                 return false;
1131         if (a->analyze != b->analyze)
1132                 return false;
1133         if (a->freeze != b->freeze)
1134                 return false;
1135         if (a->verbose != b->verbose)
1136                 return false;
1137         if (!equalstr(a->vacrel, b->vacrel))
1138                 return false;
1139         if (!equal(a->va_cols, b->va_cols))
1140                 return false;
1141
1142         return true;
1143 }
1144
1145 static bool
1146 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1147 {
1148         if (!equal(a->query, b->query))
1149                 return false;
1150         if (a->verbose != b->verbose)
1151                 return false;
1152         if (a->analyze != b->analyze)
1153                 return false;
1154
1155         return true;
1156 }
1157
1158 static bool
1159 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1160 {
1161         if (!equalstr(a->seqname, b->seqname))
1162                 return false;
1163         if (!equal(a->options, b->options))
1164                 return false;
1165
1166         return true;
1167 }
1168
1169 static bool
1170 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1171 {
1172         if (!equalstr(a->name, b->name))
1173                 return false;
1174         if (!equal(a->args, b->args))
1175                 return false;
1176
1177         return true;
1178 }
1179
1180 static bool
1181 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1182 {
1183         if (!equalstr(a->name, b->name))
1184                 return false;
1185
1186         return true;
1187 }
1188
1189 static bool
1190 _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
1191 {
1192         if (!equalstr(a->name, b->name))
1193                 return false;
1194
1195         return true;
1196 }
1197
1198 static bool
1199 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1200 {
1201         if (!equalstr(a->trigname, b->trigname))
1202                 return false;
1203         if (!equalstr(a->relname, b->relname))
1204                 return false;
1205         if (!equalstr(a->funcname, b->funcname))
1206                 return false;
1207         if (!equal(a->args, b->args))
1208                 return false;
1209         if (a->before != b->before)
1210                 return false;
1211         if (a->row != b->row)
1212                 return false;
1213         if (strcmp(a->actions, b->actions) != 0)
1214                 return false;
1215         if (!equalstr(a->lang, b->lang))
1216                 return false;
1217         if (!equalstr(a->text, b->text))
1218                 return false;
1219         if (!equal(a->attr, b->attr))
1220                 return false;
1221         if (!equalstr(a->when, b->when))
1222                 return false;
1223         if (a->isconstraint != b->isconstraint)
1224                 return false;
1225         if (a->deferrable != b->deferrable)
1226                 return false;
1227         if (a->initdeferred != b->initdeferred)
1228                 return false;
1229         if (!equalstr(a->constrrelname, b->constrrelname))
1230                 return false;
1231
1232         return true;
1233 }
1234
1235 static bool
1236 _equalDropTrigStmt(DropTrigStmt *a, DropTrigStmt *b)
1237 {
1238         if (!equalstr(a->trigname, b->trigname))
1239                 return false;
1240         if (!equalstr(a->relname, b->relname))
1241                 return false;
1242
1243         return true;
1244 }
1245
1246 static bool
1247 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1248 {
1249         if (!equalstr(a->plname, b->plname))
1250                 return false;
1251         if (!equalstr(a->plhandler, b->plhandler))
1252                 return false;
1253         if (!equalstr(a->plcompiler, b->plcompiler))
1254                 return false;
1255         if (a->pltrusted != b->pltrusted)
1256                 return false;
1257
1258         return true;
1259 }
1260
1261 static bool
1262 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1263 {
1264         if (!equalstr(a->plname, b->plname))
1265                 return false;
1266
1267         return true;
1268 }
1269
1270 static bool
1271 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1272 {
1273         if (!equalstr(a->user, b->user))
1274                 return false;
1275         if (!equal(a->options, b->options))
1276                 return false;
1277
1278         return true;
1279 }
1280
1281 static bool
1282 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1283 {
1284         if (!equalstr(a->user, b->user))
1285                 return false;
1286         if (!equal(a->options, b->options))
1287                 return false;
1288
1289         return true;
1290 }
1291
1292 static bool
1293 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1294 {
1295         if (!equal(a->users, b->users))
1296                 return false;
1297
1298         return true;
1299 }
1300
1301 static bool
1302 _equalLockStmt(LockStmt *a, LockStmt *b)
1303 {
1304         if (!equal(a->rellist, b->rellist))
1305                 return false;
1306         if (a->mode != b->mode)
1307                 return false;
1308
1309         return true;
1310 }
1311
1312 static bool
1313 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1314 {
1315         if (!equal(a->constraints, b->constraints))
1316                 return false;
1317         if (a->deferred != b->deferred)
1318                 return false;
1319
1320         return true;
1321 }
1322
1323 static bool
1324 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1325 {
1326         if (!equalstr(a->name, b->name))
1327                 return false;
1328         if (!equal(a->options, b->options))
1329                 return false;
1330
1331         return true;
1332 }
1333
1334 static bool
1335 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1336 {
1337         if (!equalstr(a->name, b->name))
1338                 return false;
1339         if (a->action != b->action)
1340                 return false;
1341         if (!equal(a->listUsers, b->listUsers))
1342                 return false;
1343
1344         return true;
1345 }
1346
1347 static bool
1348 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1349 {
1350         if (!equalstr(a->name, b->name))
1351                 return false;
1352
1353         return true;
1354 }
1355
1356 static bool
1357 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1358 {
1359         if (a->reindexType != b->reindexType)
1360                 return false;
1361         if (!equalstr(a->name, b->name))
1362                 return false;
1363         if (a->force != b->force)
1364                 return false;
1365         if (a->all != b->all)
1366                 return false;
1367
1368         return true;
1369 }
1370
1371 static bool
1372 _equalAExpr(A_Expr *a, A_Expr *b)
1373 {
1374         if (a->oper != b->oper)
1375                 return false;
1376         if (!equalstr(a->opname, b->opname))
1377                 return false;
1378         if (!equal(a->lexpr, b->lexpr))
1379                 return false;
1380         if (!equal(a->rexpr, b->rexpr))
1381                 return false;
1382
1383         return true;
1384 }
1385
1386 static bool
1387 _equalAttr(Attr *a, Attr *b)
1388 {
1389         if (strcmp(a->relname, b->relname) != 0)
1390                 return false;
1391         if (!equal(a->paramNo, b->paramNo))
1392                 return false;
1393         if (!equal(a->attrs, b->attrs))
1394                 return false;
1395         if (!equal(a->indirection, b->indirection))
1396                 return false;
1397
1398         return true;
1399 }
1400
1401 static bool
1402 _equalAConst(A_Const *a, A_Const *b)
1403 {
1404         if (!equal(&a->val, &b->val))
1405                 return false;
1406         if (!equal(a->typename, b->typename))
1407                 return false;
1408
1409         return true;
1410 }
1411
1412 static bool
1413 _equalParamNo(ParamNo *a, ParamNo *b)
1414 {
1415         if (a->number != b->number)
1416                 return false;
1417         if (!equal(a->typename, b->typename))
1418                 return false;
1419         if (!equal(a->indirection, b->indirection))
1420                 return false;
1421
1422         return true;
1423 }
1424
1425 static bool
1426 _equalIdent(Ident *a, Ident *b)
1427 {
1428         if (!equalstr(a->name, b->name))
1429                 return false;
1430         if (!equal(a->indirection, b->indirection))
1431                 return false;
1432         if (a->isRel != b->isRel)
1433                 return false;
1434
1435         return true;
1436 }
1437
1438 static bool
1439 _equalFuncCall(FuncCall *a, FuncCall *b)
1440 {
1441         if (!equalstr(a->funcname, b->funcname))
1442                 return false;
1443         if (!equal(a->args, b->args))
1444                 return false;
1445         if (a->agg_star != b->agg_star)
1446                 return false;
1447         if (a->agg_distinct != b->agg_distinct)
1448                 return false;
1449
1450         return true;
1451 }
1452
1453 static bool
1454 _equalAIndices(A_Indices *a, A_Indices *b)
1455 {
1456         if (!equal(a->lidx, b->lidx))
1457                 return false;
1458         if (!equal(a->uidx, b->uidx))
1459                 return false;
1460
1461         return true;
1462 }
1463
1464 static bool
1465 _equalResTarget(ResTarget *a, ResTarget *b)
1466 {
1467         if (!equalstr(a->name, b->name))
1468                 return false;
1469         if (!equal(a->indirection, b->indirection))
1470                 return false;
1471         if (!equal(a->val, b->val))
1472                 return false;
1473
1474         return true;
1475 }
1476
1477 static bool
1478 _equalTypeCast(TypeCast *a, TypeCast *b)
1479 {
1480         if (!equal(a->arg, b->arg))
1481                 return false;
1482         if (!equal(a->typename, b->typename))
1483                 return false;
1484
1485         return true;
1486 }
1487
1488 static bool
1489 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1490 {
1491         if (!equalstr(a->useOp, b->useOp))
1492                 return false;
1493         if (!equal(a->node, b->node))
1494                 return false;
1495
1496         return true;
1497 }
1498
1499 static bool
1500 _equalRangeVar(RangeVar *a, RangeVar *b)
1501 {
1502         if (!equalstr(a->relname, b->relname))
1503                 return false;
1504         if (a->inhOpt != b->inhOpt)
1505                 return false;
1506         if (!equal(a->name, b->name))
1507                 return false;
1508
1509         return true;
1510 }
1511
1512 static bool
1513 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1514 {
1515         if (!equal(a->subquery, b->subquery))
1516                 return false;
1517         if (!equal(a->name, b->name))
1518                 return false;
1519
1520         return true;
1521 }
1522
1523 static bool
1524 _equalTypeName(TypeName *a, TypeName *b)
1525 {
1526         if (!equalstr(a->name, b->name))
1527                 return false;
1528         if (a->timezone != b->timezone)
1529                 return false;
1530         if (a->setof != b->setof)
1531                 return false;
1532         if (a->typmod != b->typmod)
1533                 return false;
1534         if (!equal(a->arrayBounds, b->arrayBounds))
1535                 return false;
1536
1537         return true;
1538 }
1539
1540 static bool
1541 _equalIndexElem(IndexElem *a, IndexElem *b)
1542 {
1543         if (!equalstr(a->name, b->name))
1544                 return false;
1545         if (!equal(a->args, b->args))
1546                 return false;
1547         if (!equalstr(a->class, b->class))
1548                 return false;
1549
1550         return true;
1551 }
1552
1553 static bool
1554 _equalColumnDef(ColumnDef *a, ColumnDef *b)
1555 {
1556         if (!equalstr(a->colname, b->colname))
1557                 return false;
1558         if (!equal(a->typename, b->typename))
1559                 return false;
1560         if (a->is_not_null != b->is_not_null)
1561                 return false;
1562         if (!equal(a->raw_default, b->raw_default))
1563                 return false;
1564         if (!equalstr(a->cooked_default, b->cooked_default))
1565                 return false;
1566         if (!equal(a->constraints, b->constraints))
1567                 return false;
1568
1569         return true;
1570 }
1571
1572 static bool
1573 _equalConstraint(Constraint *a, Constraint *b)
1574 {
1575         if (a->contype != b->contype)
1576                 return false;
1577         if (!equalstr(a->name, b->name))
1578                 return false;
1579         if (!equal(a->raw_expr, b->raw_expr))
1580                 return false;
1581         if (!equalstr(a->cooked_expr, b->cooked_expr))
1582                 return false;
1583         if (!equal(a->keys, b->keys))
1584                 return false;
1585
1586         return true;
1587 }
1588
1589 static bool
1590 _equalDefElem(DefElem *a, DefElem *b)
1591 {
1592         if (!equalstr(a->defname, b->defname))
1593                 return false;
1594         if (!equal(a->arg, b->arg))
1595                 return false;
1596
1597         return true;
1598 }
1599
1600 static bool
1601 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
1602 {
1603         if (!equal(a->resdom, b->resdom))
1604                 return false;
1605         if (!equal(a->fjoin, b->fjoin))
1606                 return false;
1607         if (!equal(a->expr, b->expr))
1608                 return false;
1609
1610         return true;
1611 }
1612
1613 static bool
1614 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
1615 {
1616         if (!equalstr(a->relname, b->relname))
1617                 return false;
1618         if (a->relid != b->relid)
1619                 return false;
1620         if (!equal(a->subquery, b->subquery))
1621                 return false;
1622         if (!equal(a->alias, b->alias))
1623                 return false;
1624         if (!equal(a->eref, b->eref))
1625                 return false;
1626         if (a->inh != b->inh)
1627                 return false;
1628         if (a->inFromCl != b->inFromCl)
1629                 return false;
1630         if (a->checkForRead != b->checkForRead)
1631                 return false;
1632         if (a->checkForWrite != b->checkForWrite)
1633                 return false;
1634         if (a->checkAsUser != b->checkAsUser)
1635                 return false;
1636
1637         return true;
1638 }
1639
1640 static bool
1641 _equalSortClause(SortClause *a, SortClause *b)
1642 {
1643         if (a->tleSortGroupRef != b->tleSortGroupRef)
1644                 return false;
1645         if (a->sortop != b->sortop)
1646                 return false;
1647
1648         return true;
1649 }
1650
1651 static bool
1652 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
1653 {
1654         if (!equalstr(a->constr_name, b->constr_name))
1655                 return false;
1656         if (!equalstr(a->pktable_name, b->pktable_name))
1657                 return false;
1658         if (!equal(a->fk_attrs, b->fk_attrs))
1659                 return false;
1660         if (!equal(a->pk_attrs, b->pk_attrs))
1661                 return false;
1662         if (!equalstr(a->match_type, b->match_type))
1663                 return false;
1664         if (a->actions != b->actions)
1665                 return false;
1666         if (a->deferrable != b->deferrable)
1667                 return false;
1668         if (a->initdeferred != b->initdeferred)
1669                 return false;
1670
1671         return true;
1672 }
1673
1674 static bool
1675 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
1676 {
1677         if (a->casetype != b->casetype)
1678                 return false;
1679         if (!equal(a->arg, b->arg))
1680                 return false;
1681         if (!equal(a->args, b->args))
1682                 return false;
1683         if (!equal(a->defresult, b->defresult))
1684                 return false;
1685
1686         return true;
1687 }
1688
1689 static bool
1690 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
1691 {
1692         if (!equal(a->expr, b->expr))
1693                 return false;
1694         if (!equal(a->result, b->result))
1695                 return false;
1696
1697         return true;
1698 }
1699
1700 static bool
1701 _equalNullTest(NullTest *a, NullTest *b)
1702 {
1703         if (!equal(a->arg, b->arg))
1704                 return false;
1705         if (a->nulltesttype != b->nulltesttype)
1706                 return false;
1707         return true;
1708 }
1709
1710 static bool
1711 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
1712 {
1713         if (!equal(a->arg, b->arg))
1714                 return false;
1715         if (a->booltesttype != b->booltesttype)
1716                 return false;
1717         return true;
1718 }
1719
1720 /*
1721  * Stuff from pg_list.h
1722  */
1723
1724 static bool
1725 _equalValue(Value *a, Value *b)
1726 {
1727         if (a->type != b->type)
1728                 return false;
1729
1730         switch (a->type)
1731         {
1732                 case T_Integer:
1733                         return a->val.ival == b->val.ival;
1734                 case T_Float:
1735                 case T_String:
1736                 case T_BitString:
1737                         return strcmp(a->val.str, b->val.str) == 0;
1738                 default:
1739                         break;
1740         }
1741
1742         return true;
1743 }
1744
1745 /*
1746  * equal
1747  *        returns whether two nodes are equal
1748  */
1749 bool
1750 equal(void *a, void *b)
1751 {
1752         bool            retval = false;
1753
1754         if (a == b)
1755                 return true;
1756
1757         /*
1758          * note that a!=b, so only one of them can be NULL
1759          */
1760         if (a == NULL || b == NULL)
1761                 return false;
1762
1763         /*
1764          * are they the same type of nodes?
1765          */
1766         if (nodeTag(a) != nodeTag(b))
1767                 return false;
1768
1769         switch (nodeTag(a))
1770         {
1771                 case T_SubPlan:
1772                         retval = _equalSubPlan(a, b);
1773                         break;
1774
1775                 case T_Resdom:
1776                         retval = _equalResdom(a, b);
1777                         break;
1778                 case T_Fjoin:
1779                         retval = _equalFjoin(a, b);
1780                         break;
1781                 case T_Expr:
1782                         retval = _equalExpr(a, b);
1783                         break;
1784                 case T_Var:
1785                         retval = _equalVar(a, b);
1786                         break;
1787                 case T_Oper:
1788                         retval = _equalOper(a, b);
1789                         break;
1790                 case T_Const:
1791                         retval = _equalConst(a, b);
1792                         break;
1793                 case T_Param:
1794                         retval = _equalParam(a, b);
1795                         break;
1796                 case T_Aggref:
1797                         retval = _equalAggref(a, b);
1798                         break;
1799                 case T_SubLink:
1800                         retval = _equalSubLink(a, b);
1801                         break;
1802                 case T_Func:
1803                         retval = _equalFunc(a, b);
1804                         break;
1805                 case T_FieldSelect:
1806                         retval = _equalFieldSelect(a, b);
1807                         break;
1808                 case T_ArrayRef:
1809                         retval = _equalArrayRef(a, b);
1810                         break;
1811                 case T_Iter:
1812                         retval = _equalIter(a, b);
1813                         break;
1814                 case T_RelabelType:
1815                         retval = _equalRelabelType(a, b);
1816                         break;
1817                 case T_RangeTblRef:
1818                         retval = _equalRangeTblRef(a, b);
1819                         break;
1820                 case T_FromExpr:
1821                         retval = _equalFromExpr(a, b);
1822                         break;
1823                 case T_JoinExpr:
1824                         retval = _equalJoinExpr(a, b);
1825                         break;
1826
1827                 case T_RelOptInfo:
1828                         retval = _equalRelOptInfo(a, b);
1829                         break;
1830                 case T_Path:
1831                         retval = _equalPath(a, b);
1832                         break;
1833                 case T_IndexPath:
1834                         retval = _equalIndexPath(a, b);
1835                         break;
1836                 case T_NestPath:
1837                         retval = _equalNestPath(a, b);
1838                         break;
1839                 case T_MergePath:
1840                         retval = _equalMergePath(a, b);
1841                         break;
1842                 case T_HashPath:
1843                         retval = _equalHashPath(a, b);
1844                         break;
1845                 case T_PathKeyItem:
1846                         retval = _equalPathKeyItem(a, b);
1847                         break;
1848                 case T_RestrictInfo:
1849                         retval = _equalRestrictInfo(a, b);
1850                         break;
1851                 case T_JoinInfo:
1852                         retval = _equalJoinInfo(a, b);
1853                         break;
1854                 case T_Stream:
1855                         retval = _equalStream(a, b);
1856                         break;
1857                 case T_TidPath:
1858                         retval = _equalTidPath(a, b);
1859                         break;
1860                 case T_AppendPath:
1861                         retval = _equalAppendPath(a, b);
1862                         break;
1863                 case T_IndexOptInfo:
1864                         retval = _equalIndexOptInfo(a, b);
1865                         break;
1866
1867                 case T_List:
1868                         {
1869                                 List       *la = (List *) a;
1870                                 List       *lb = (List *) b;
1871                                 List       *l;
1872
1873                                 /*
1874                                  * Try to reject by length check before we grovel through
1875                                  * all the elements...
1876                                  */
1877                                 if (length(la) != length(lb))
1878                                         return false;
1879                                 foreach(l, la)
1880                                 {
1881                                         if (!equal(lfirst(l), lfirst(lb)))
1882                                                 return false;
1883                                         lb = lnext(lb);
1884                                 }
1885                                 retval = true;
1886                         }
1887                         break;
1888                 case T_Integer:
1889                 case T_Float:
1890                 case T_String:
1891                 case T_BitString:
1892                         retval = _equalValue(a, b);
1893                         break;
1894
1895                 case T_Query:
1896                         retval = _equalQuery(a, b);
1897                         break;
1898                 case T_InsertStmt:
1899                         retval = _equalInsertStmt(a, b);
1900                         break;
1901                 case T_DeleteStmt:
1902                         retval = _equalDeleteStmt(a, b);
1903                         break;
1904                 case T_UpdateStmt:
1905                         retval = _equalUpdateStmt(a, b);
1906                         break;
1907                 case T_SelectStmt:
1908                         retval = _equalSelectStmt(a, b);
1909                         break;
1910                 case T_SetOperationStmt:
1911                         retval = _equalSetOperationStmt(a, b);
1912                         break;
1913                 case T_AlterTableStmt:
1914                         retval = _equalAlterTableStmt(a, b);
1915                         break;
1916                 case T_GrantStmt:
1917                         retval = _equalGrantStmt(a, b);
1918                         break;
1919                 case T_ClosePortalStmt:
1920                         retval = _equalClosePortalStmt(a, b);
1921                         break;
1922                 case T_ClusterStmt:
1923                         retval = _equalClusterStmt(a, b);
1924                         break;
1925                 case T_CopyStmt:
1926                         retval = _equalCopyStmt(a, b);
1927                         break;
1928                 case T_CreateStmt:
1929                         retval = _equalCreateStmt(a, b);
1930                         break;
1931                 case T_VersionStmt:
1932                         retval = _equalVersionStmt(a, b);
1933                         break;
1934                 case T_DefineStmt:
1935                         retval = _equalDefineStmt(a, b);
1936                         break;
1937                 case T_DropStmt:
1938                         retval = _equalDropStmt(a, b);
1939                         break;
1940                 case T_TruncateStmt:
1941                         retval = _equalTruncateStmt(a, b);
1942                         break;
1943                 case T_CommentStmt:
1944                         retval = _equalCommentStmt(a, b);
1945                         break;
1946                 case T_FetchStmt:
1947                         retval = _equalFetchStmt(a, b);
1948                         break;
1949                 case T_IndexStmt:
1950                         retval = _equalIndexStmt(a, b);
1951                         break;
1952                 case T_ProcedureStmt:
1953                         retval = _equalProcedureStmt(a, b);
1954                         break;
1955                 case T_RemoveAggrStmt:
1956                         retval = _equalRemoveAggrStmt(a, b);
1957                         break;
1958                 case T_RemoveFuncStmt:
1959                         retval = _equalRemoveFuncStmt(a, b);
1960                         break;
1961                 case T_RemoveOperStmt:
1962                         retval = _equalRemoveOperStmt(a, b);
1963                         break;
1964                 case T_RenameStmt:
1965                         retval = _equalRenameStmt(a, b);
1966                         break;
1967                 case T_RuleStmt:
1968                         retval = _equalRuleStmt(a, b);
1969                         break;
1970                 case T_NotifyStmt:
1971                         retval = _equalNotifyStmt(a, b);
1972                         break;
1973                 case T_ListenStmt:
1974                         retval = _equalListenStmt(a, b);
1975                         break;
1976                 case T_UnlistenStmt:
1977                         retval = _equalUnlistenStmt(a, b);
1978                         break;
1979                 case T_TransactionStmt:
1980                         retval = _equalTransactionStmt(a, b);
1981                         break;
1982                 case T_ViewStmt:
1983                         retval = _equalViewStmt(a, b);
1984                         break;
1985                 case T_LoadStmt:
1986                         retval = _equalLoadStmt(a, b);
1987                         break;
1988                 case T_CreatedbStmt:
1989                         retval = _equalCreatedbStmt(a, b);
1990                         break;
1991                 case T_DropdbStmt:
1992                         retval = _equalDropdbStmt(a, b);
1993                         break;
1994                 case T_VacuumStmt:
1995                         retval = _equalVacuumStmt(a, b);
1996                         break;
1997                 case T_ExplainStmt:
1998                         retval = _equalExplainStmt(a, b);
1999                         break;
2000                 case T_CreateSeqStmt:
2001                         retval = _equalCreateSeqStmt(a, b);
2002                         break;
2003                 case T_VariableSetStmt:
2004                         retval = _equalVariableSetStmt(a, b);
2005                         break;
2006                 case T_VariableShowStmt:
2007                         retval = _equalVariableShowStmt(a, b);
2008                         break;
2009                 case T_VariableResetStmt:
2010                         retval = _equalVariableResetStmt(a, b);
2011                         break;
2012                 case T_CreateTrigStmt:
2013                         retval = _equalCreateTrigStmt(a, b);
2014                         break;
2015                 case T_DropTrigStmt:
2016                         retval = _equalDropTrigStmt(a, b);
2017                         break;
2018                 case T_CreatePLangStmt:
2019                         retval = _equalCreatePLangStmt(a, b);
2020                         break;
2021                 case T_DropPLangStmt:
2022                         retval = _equalDropPLangStmt(a, b);
2023                         break;
2024                 case T_CreateUserStmt:
2025                         retval = _equalCreateUserStmt(a, b);
2026                         break;
2027                 case T_AlterUserStmt:
2028                         retval = _equalAlterUserStmt(a, b);
2029                         break;
2030                 case T_DropUserStmt:
2031                         retval = _equalDropUserStmt(a, b);
2032                         break;
2033                 case T_LockStmt:
2034                         retval = _equalLockStmt(a, b);
2035                         break;
2036                 case T_ConstraintsSetStmt:
2037                         retval = _equalConstraintsSetStmt(a, b);
2038                         break;
2039                 case T_CreateGroupStmt:
2040                         retval = _equalCreateGroupStmt(a, b);
2041                         break;
2042                 case T_AlterGroupStmt:
2043                         retval = _equalAlterGroupStmt(a, b);
2044                         break;
2045                 case T_DropGroupStmt:
2046                         retval = _equalDropGroupStmt(a, b);
2047                         break;
2048                 case T_ReindexStmt:
2049                         retval = _equalReindexStmt(a, b);
2050                         break;
2051                 case T_CheckPointStmt:
2052                         retval = true;
2053                         break;
2054
2055                 case T_A_Expr:
2056                         retval = _equalAExpr(a, b);
2057                         break;
2058                 case T_Attr:
2059                         retval = _equalAttr(a, b);
2060                         break;
2061                 case T_A_Const:
2062                         retval = _equalAConst(a, b);
2063                         break;
2064                 case T_ParamNo:
2065                         retval = _equalParamNo(a, b);
2066                         break;
2067                 case T_Ident:
2068                         retval = _equalIdent(a, b);
2069                         break;
2070                 case T_FuncCall:
2071                         retval = _equalFuncCall(a, b);
2072                         break;
2073                 case T_A_Indices:
2074                         retval = _equalAIndices(a, b);
2075                         break;
2076                 case T_ResTarget:
2077                         retval = _equalResTarget(a, b);
2078                         break;
2079                 case T_TypeCast:
2080                         retval = _equalTypeCast(a, b);
2081                         break;
2082                 case T_SortGroupBy:
2083                         retval = _equalSortGroupBy(a, b);
2084                         break;
2085                 case T_RangeVar:
2086                         retval = _equalRangeVar(a, b);
2087                         break;
2088                 case T_RangeSubselect:
2089                         retval = _equalRangeSubselect(a, b);
2090                         break;
2091                 case T_TypeName:
2092                         retval = _equalTypeName(a, b);
2093                         break;
2094                 case T_IndexElem:
2095                         retval = _equalIndexElem(a, b);
2096                         break;
2097                 case T_ColumnDef:
2098                         retval = _equalColumnDef(a, b);
2099                         break;
2100                 case T_Constraint:
2101                         retval = _equalConstraint(a, b);
2102                         break;
2103                 case T_DefElem:
2104                         retval = _equalDefElem(a, b);
2105                         break;
2106                 case T_TargetEntry:
2107                         retval = _equalTargetEntry(a, b);
2108                         break;
2109                 case T_RangeTblEntry:
2110                         retval = _equalRangeTblEntry(a, b);
2111                         break;
2112                 case T_SortClause:
2113                         retval = _equalSortClause(a, b);
2114                         break;
2115                 case T_GroupClause:
2116                         /* GroupClause is equivalent to SortClause */
2117                         retval = _equalSortClause(a, b);
2118                         break;
2119                 case T_CaseExpr:
2120                         retval = _equalCaseExpr(a, b);
2121                         break;
2122                 case T_CaseWhen:
2123                         retval = _equalCaseWhen(a, b);
2124                         break;
2125                 case T_NullTest:
2126                         retval = _equalNullTest(a, b);
2127                         break;
2128                 case T_BooleanTest:
2129                         retval = _equalBooleanTest(a, b);
2130                         break;
2131                 case T_FkConstraint:
2132                         retval = _equalFkConstraint(a, b);
2133                         break;
2134                 case T_PrivGrantee:
2135                         retval = _equalPrivGrantee(a, b);
2136                         break;
2137                 case T_FuncWithArgs:
2138                         retval = _equalFuncWithArgs(a, b);
2139                         break;
2140
2141                 default:
2142                         elog(NOTICE, "equal: don't know whether nodes of type %d are equal",
2143                                  nodeTag(a));
2144                         break;
2145         }
2146
2147         return retval;
2148 }