]> granicus.if.org Git - postgresql/blob - src/backend/nodes/equalfuncs.c
538a773e31b406b3e9388b69617d3681b12f4cf4
[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.108 2001/11/05 05:00:14 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         if (!equal(a->rtable, b->rtable))
597                 return false;
598         if (!equal(a->jointree, b->jointree))
599                 return false;
600         if (!equali(a->rowMarks, b->rowMarks))
601                 return false;
602         if (!equal(a->targetList, b->targetList))
603                 return false;
604         if (!equal(a->groupClause, b->groupClause))
605                 return false;
606         if (!equal(a->havingQual, b->havingQual))
607                 return false;
608         if (!equal(a->distinctClause, b->distinctClause))
609                 return false;
610         if (!equal(a->sortClause, b->sortClause))
611                 return false;
612         if (!equal(a->limitOffset, b->limitOffset))
613                 return false;
614         if (!equal(a->limitCount, b->limitCount))
615                 return false;
616         if (!equal(a->setOperations, b->setOperations))
617                 return false;
618         if (!equali(a->resultRelations, b->resultRelations))
619                 return false;
620
621         /*
622          * We do not check the internal-to-the-planner fields: base_rel_list,
623          * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. They
624          * might not be set yet, and in any case they should be derivable from
625          * the other fields.
626          */
627         return true;
628 }
629
630 static bool
631 _equalInsertStmt(InsertStmt *a, InsertStmt *b)
632 {
633         if (!equalstr(a->relname, b->relname))
634                 return false;
635         if (!equal(a->cols, b->cols))
636                 return false;
637         if (!equal(a->targetList, b->targetList))
638                 return false;
639         if (!equal(a->selectStmt, b->selectStmt))
640                 return false;
641
642         return true;
643 }
644
645 static bool
646 _equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
647 {
648         if (!equalstr(a->relname, b->relname))
649                 return false;
650         if (!equal(a->whereClause, b->whereClause))
651                 return false;
652         if (a->inhOpt != b->inhOpt)
653                 return false;
654
655         return true;
656 }
657
658 static bool
659 _equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
660 {
661         if (!equalstr(a->relname, b->relname))
662                 return false;
663         if (!equal(a->targetList, b->targetList))
664                 return false;
665         if (!equal(a->whereClause, b->whereClause))
666                 return false;
667         if (!equal(a->fromClause, b->fromClause))
668                 return false;
669         if (a->inhOpt != b->inhOpt)
670                 return false;
671
672         return true;
673 }
674
675 static bool
676 _equalSelectStmt(SelectStmt *a, SelectStmt *b)
677 {
678         if (!equal(a->distinctClause, b->distinctClause))
679                 return false;
680         if (!equalstr(a->into, b->into))
681                 return false;
682         if (a->istemp != b->istemp)
683                 return false;
684         if (!equal(a->intoColNames, b->intoColNames))
685                 return false;
686         if (!equal(a->targetList, b->targetList))
687                 return false;
688         if (!equal(a->fromClause, b->fromClause))
689                 return false;
690         if (!equal(a->whereClause, b->whereClause))
691                 return false;
692         if (!equal(a->groupClause, b->groupClause))
693                 return false;
694         if (!equal(a->havingClause, b->havingClause))
695                 return false;
696         if (!equal(a->sortClause, b->sortClause))
697                 return false;
698         if (!equalstr(a->portalname, b->portalname))
699                 return false;
700         if (a->binary != b->binary)
701                 return false;
702         if (!equal(a->limitOffset, b->limitOffset))
703                 return false;
704         if (!equal(a->limitCount, b->limitCount))
705                 return false;
706         if (!equal(a->forUpdate, b->forUpdate))
707                 return false;
708         if (a->op != b->op)
709                 return false;
710         if (a->all != b->all)
711                 return false;
712         if (!equal(a->larg, b->larg))
713                 return false;
714         if (!equal(a->rarg, b->rarg))
715                 return false;
716
717         return true;
718 }
719
720 static bool
721 _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
722 {
723         if (a->op != b->op)
724                 return false;
725         if (a->all != b->all)
726                 return false;
727         if (!equal(a->larg, b->larg))
728                 return false;
729         if (!equal(a->rarg, b->rarg))
730                 return false;
731         if (!equali(a->colTypes, b->colTypes))
732                 return false;
733
734         return true;
735 }
736
737 static bool
738 _equalAlterTableStmt(AlterTableStmt *a, AlterTableStmt *b)
739 {
740         if (a->subtype != b->subtype)
741                 return false;
742         if (!equalstr(a->relname, b->relname))
743                 return false;
744         if (a->inhOpt != b->inhOpt)
745                 return false;
746         if (!equalstr(a->name, b->name))
747                 return false;
748         if (!equal(a->def, b->def))
749                 return false;
750         if (a->behavior != b->behavior)
751                 return false;
752
753         return true;
754 }
755
756 static bool
757 _equalGrantStmt(GrantStmt *a, GrantStmt *b)
758 {
759         if (a->is_grant != b->is_grant)
760                 return false;
761         if (!equal(a->relnames, b->relnames))
762                 return false;
763         if (!equalstr(a->privileges, b->privileges))
764                 return false;
765         if (!equal(a->grantees, b->grantees))
766                 return false;
767
768         return true;
769 }
770
771 static bool
772 _equalPrivGrantee(PrivGrantee *a, PrivGrantee *b)
773 {
774         return equalstr(a->username, b->username)
775                 && equalstr(a->groupname, b->groupname);
776 }
777
778 static bool
779 _equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
780 {
781         if (!equalstr(a->portalname, b->portalname))
782                 return false;
783
784         return true;
785 }
786
787 static bool
788 _equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
789 {
790         if (!equalstr(a->relname, b->relname))
791                 return false;
792         if (!equalstr(a->indexname, b->indexname))
793                 return false;
794
795         return true;
796 }
797
798 static bool
799 _equalCopyStmt(CopyStmt *a, CopyStmt *b)
800 {
801         if (a->binary != b->binary)
802                 return false;
803         if (!equalstr(a->relname, b->relname))
804                 return false;
805         if (a->oids != b->oids)
806                 return false;
807         if (a->direction != b->direction)
808                 return false;
809         if (!equalstr(a->filename, b->filename))
810                 return false;
811         if (!equalstr(a->delimiter, b->delimiter))
812                 return false;
813         if (!equalstr(a->null_print, b->null_print))
814                 return false;
815
816         return true;
817 }
818
819 static bool
820 _equalCreateStmt(CreateStmt *a, CreateStmt *b)
821 {
822         if (!equalstr(a->relname, b->relname))
823                 return false;
824         if (!equal(a->tableElts, b->tableElts))
825                 return false;
826         if (!equal(a->inhRelnames, b->inhRelnames))
827                 return false;
828         if (!equal(a->constraints, b->constraints))
829                 return false;
830         if (a->istemp != b->istemp)
831                 return false;
832         if (a->hasoids != b->hasoids)
833                 return false;
834
835         return true;
836 }
837
838 static bool
839 _equalVersionStmt(VersionStmt *a, VersionStmt *b)
840 {
841         if (!equalstr(a->relname, b->relname))
842                 return false;
843         if (a->direction != b->direction)
844                 return false;
845         if (!equalstr(a->fromRelname, b->fromRelname))
846                 return false;
847         if (!equalstr(a->date, b->date))
848                 return false;
849
850         return true;
851 }
852
853 static bool
854 _equalDefineStmt(DefineStmt *a, DefineStmt *b)
855 {
856         if (a->defType != b->defType)
857                 return false;
858         if (!equalstr(a->defname, b->defname))
859                 return false;
860         if (!equal(a->definition, b->definition))
861                 return false;
862
863         return true;
864 }
865
866 static bool
867 _equalDropStmt(DropStmt *a, DropStmt *b)
868 {
869         if (!equal(a->names, b->names))
870                 return false;
871         if (a->removeType != b->removeType)
872                 return false;
873
874         return true;
875 }
876
877 static bool
878 _equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
879 {
880         if (!equalstr(a->relName, b->relName))
881                 return false;
882
883         return true;
884 }
885
886 static bool
887 _equalCommentStmt(CommentStmt *a, CommentStmt *b)
888 {
889         if (a->objtype != b->objtype)
890                 return false;
891         if (!equalstr(a->objname, b->objname))
892                 return false;
893         if (!equalstr(a->objproperty, b->objproperty))
894                 return false;
895         if (!equal(a->objlist, b->objlist))
896                 return false;
897         if (!equalstr(a->comment, b->comment))
898                 return false;
899
900         return true;
901 }
902
903 static bool
904 _equalFetchStmt(FetchStmt *a, FetchStmt *b)
905 {
906         if (a->direction != b->direction)
907                 return false;
908         if (a->howMany != b->howMany)
909                 return false;
910         if (!equalstr(a->portalname, b->portalname))
911                 return false;
912         if (a->ismove != b->ismove)
913                 return false;
914
915         return true;
916 }
917
918 static bool
919 _equalIndexStmt(IndexStmt *a, IndexStmt *b)
920 {
921         if (!equalstr(a->idxname, b->idxname))
922                 return false;
923         if (!equalstr(a->relname, b->relname))
924                 return false;
925         if (!equalstr(a->accessMethod, b->accessMethod))
926                 return false;
927         if (!equal(a->indexParams, b->indexParams))
928                 return false;
929         if (!equal(a->whereClause, b->whereClause))
930                 return false;
931         if (!equal(a->rangetable, b->rangetable))
932                 return false;
933         if (a->unique != b->unique)
934                 return false;
935         if (a->primary != b->primary)
936                 return false;
937
938         return true;
939 }
940
941 static bool
942 _equalProcedureStmt(ProcedureStmt *a, ProcedureStmt *b)
943 {
944         if (a->replace != b->replace)
945                 return false;
946         if (!equalstr(a->funcname, b->funcname))
947                 return false;
948         if (!equal(a->argTypes, b->argTypes))
949                 return false;
950         if (!equal(a->returnType, b->returnType))
951                 return false;
952         if (!equal(a->withClause, b->withClause))
953                 return false;
954         if (!equal(a->as, b->as))
955                 return false;
956         if (!equalstr(a->language, b->language))
957                 return false;
958
959         return true;
960 }
961
962 static bool
963 _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
964 {
965         if (!equalstr(a->aggname, b->aggname))
966                 return false;
967         if (!equal(a->aggtype, b->aggtype))
968                 return false;
969
970         return true;
971 }
972
973 static bool
974 _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
975 {
976         if (!equalstr(a->funcname, b->funcname))
977                 return false;
978         if (!equal(a->args, b->args))
979                 return false;
980
981         return true;
982 }
983
984 static bool
985 _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
986 {
987         if (!equalstr(a->opname, b->opname))
988                 return false;
989         if (!equal(a->args, b->args))
990                 return false;
991
992         return true;
993 }
994
995
996 static bool
997 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
998 {
999         if (!equalstr(a->relname, b->relname))
1000                 return false;
1001         if (a->inhOpt != b->inhOpt)
1002                 return false;
1003         if (!equalstr(a->column, b->column))
1004                 return false;
1005         if (!equalstr(a->newname, b->newname))
1006                 return false;
1007
1008         return true;
1009 }
1010
1011 static bool
1012 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
1013 {
1014         if (!equalstr(a->rulename, b->rulename))
1015                 return false;
1016         if (!equal(a->whereClause, b->whereClause))
1017                 return false;
1018         if (a->event != b->event)
1019                 return false;
1020         if (!equal(a->object, b->object))
1021                 return false;
1022         if (a->instead != b->instead)
1023                 return false;
1024         if (!equal(a->actions, b->actions))
1025                 return false;
1026
1027         return true;
1028 }
1029
1030 static bool
1031 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1032 {
1033         if (!equalstr(a->relname, b->relname))
1034                 return false;
1035
1036         return true;
1037 }
1038
1039 static bool
1040 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1041 {
1042         if (!equalstr(a->relname, b->relname))
1043                 return false;
1044
1045         return true;
1046 }
1047
1048 static bool
1049 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1050 {
1051         if (!equalstr(a->relname, b->relname))
1052                 return false;
1053
1054         return true;
1055 }
1056
1057 static bool
1058 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1059 {
1060         if (a->command != b->command)
1061                 return false;
1062
1063         return true;
1064 }
1065
1066 static bool
1067 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1068 {
1069         if (!equalstr(a->viewname, b->viewname))
1070                 return false;
1071         if (!equal(a->aliases, b->aliases))
1072                 return false;
1073         if (!equal(a->query, b->query))
1074                 return false;
1075
1076         return true;
1077 }
1078
1079 static bool
1080 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1081 {
1082         if (!equalstr(a->filename, b->filename))
1083                 return false;
1084
1085         return true;
1086 }
1087
1088 static bool
1089 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1090 {
1091         if (!equalstr(a->dbname, b->dbname))
1092                 return false;
1093         if (!equalstr(a->dbpath, b->dbpath))
1094                 return false;
1095         if (!equalstr(a->dbtemplate, b->dbtemplate))
1096                 return false;
1097         if (a->encoding != b->encoding)
1098                 return false;
1099
1100         return true;
1101 }
1102
1103 static bool
1104 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1105 {
1106         if (!equalstr(a->dbname, b->dbname))
1107                 return false;
1108
1109         return true;
1110 }
1111
1112 static bool
1113 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1114 {
1115         if (a->vacuum != b->vacuum)
1116                 return false;
1117         if (a->full != b->full)
1118                 return false;
1119         if (a->analyze != b->analyze)
1120                 return false;
1121         if (a->freeze != b->freeze)
1122                 return false;
1123         if (a->verbose != b->verbose)
1124                 return false;
1125         if (!equalstr(a->vacrel, b->vacrel))
1126                 return false;
1127         if (!equal(a->va_cols, b->va_cols))
1128                 return false;
1129
1130         return true;
1131 }
1132
1133 static bool
1134 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1135 {
1136         if (!equal(a->query, b->query))
1137                 return false;
1138         if (a->verbose != b->verbose)
1139                 return false;
1140         if (a->analyze != b->analyze)
1141                 return false;
1142
1143         return true;
1144 }
1145
1146 static bool
1147 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1148 {
1149         if (!equalstr(a->seqname, b->seqname))
1150                 return false;
1151         if (!equal(a->options, b->options))
1152                 return false;
1153
1154         return true;
1155 }
1156
1157 static bool
1158 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1159 {
1160         if (!equalstr(a->name, b->name))
1161                 return false;
1162         if (!equal(a->args, b->args))
1163                 return false;
1164
1165         return true;
1166 }
1167
1168 static bool
1169 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1170 {
1171         if (!equalstr(a->name, b->name))
1172                 return false;
1173
1174         return true;
1175 }
1176
1177 static bool
1178 _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
1179 {
1180         if (!equalstr(a->name, b->name))
1181                 return false;
1182
1183         return true;
1184 }
1185
1186 static bool
1187 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1188 {
1189         if (!equalstr(a->trigname, b->trigname))
1190                 return false;
1191         if (!equalstr(a->relname, b->relname))
1192                 return false;
1193         if (!equalstr(a->funcname, b->funcname))
1194                 return false;
1195         if (!equal(a->args, b->args))
1196                 return false;
1197         if (a->before != b->before)
1198                 return false;
1199         if (a->row != b->row)
1200                 return false;
1201         if (strcmp(a->actions, b->actions) != 0)
1202                 return false;
1203         if (!equalstr(a->lang, b->lang))
1204                 return false;
1205         if (!equalstr(a->text, b->text))
1206                 return false;
1207         if (!equal(a->attr, b->attr))
1208                 return false;
1209         if (!equalstr(a->when, b->when))
1210                 return false;
1211         if (a->isconstraint != b->isconstraint)
1212                 return false;
1213         if (a->deferrable != b->deferrable)
1214                 return false;
1215         if (a->initdeferred != b->initdeferred)
1216                 return false;
1217         if (!equalstr(a->constrrelname, b->constrrelname))
1218                 return false;
1219
1220         return true;
1221 }
1222
1223 static bool
1224 _equalDropTrigStmt(DropTrigStmt *a, DropTrigStmt *b)
1225 {
1226         if (!equalstr(a->trigname, b->trigname))
1227                 return false;
1228         if (!equalstr(a->relname, b->relname))
1229                 return false;
1230
1231         return true;
1232 }
1233
1234 static bool
1235 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1236 {
1237         if (!equalstr(a->plname, b->plname))
1238                 return false;
1239         if (!equalstr(a->plhandler, b->plhandler))
1240                 return false;
1241         if (!equalstr(a->plcompiler, b->plcompiler))
1242                 return false;
1243         if (a->pltrusted != b->pltrusted)
1244                 return false;
1245
1246         return true;
1247 }
1248
1249 static bool
1250 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1251 {
1252         if (!equalstr(a->plname, b->plname))
1253                 return false;
1254
1255         return true;
1256 }
1257
1258 static bool
1259 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1260 {
1261         if (!equalstr(a->user, b->user))
1262                 return false;
1263         if (!equal(a->options, b->options))
1264                 return false;
1265
1266         return true;
1267 }
1268
1269 static bool
1270 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1271 {
1272         if (!equalstr(a->user, b->user))
1273                 return false;
1274         if (!equal(a->options, b->options))
1275                 return false;
1276
1277         return true;
1278 }
1279
1280 static bool
1281 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1282 {
1283         if (!equal(a->users, b->users))
1284                 return false;
1285
1286         return true;
1287 }
1288
1289 static bool
1290 _equalLockStmt(LockStmt *a, LockStmt *b)
1291 {
1292         if (!equal(a->rellist, b->rellist))
1293                 return false;
1294         if (a->mode != b->mode)
1295                 return false;
1296
1297         return true;
1298 }
1299
1300 static bool
1301 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1302 {
1303         if (!equal(a->constraints, b->constraints))
1304                 return false;
1305         if (a->deferred != b->deferred)
1306                 return false;
1307
1308         return true;
1309 }
1310
1311 static bool
1312 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1313 {
1314         if (!equalstr(a->name, b->name))
1315                 return false;
1316         if (!equal(a->options, b->options))
1317                 return false;
1318
1319         return true;
1320 }
1321
1322 static bool
1323 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1324 {
1325         if (!equalstr(a->name, b->name))
1326                 return false;
1327         if (a->action != b->action)
1328                 return false;
1329         if (!equal(a->listUsers, b->listUsers))
1330                 return false;
1331
1332         return true;
1333 }
1334
1335 static bool
1336 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1337 {
1338         if (!equalstr(a->name, b->name))
1339                 return false;
1340
1341         return true;
1342 }
1343
1344 static bool
1345 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1346 {
1347         if (a->reindexType != b->reindexType)
1348                 return false;
1349         if (!equalstr(a->name, b->name))
1350                 return false;
1351         if (a->force != b->force)
1352                 return false;
1353         if (a->all != b->all)
1354                 return false;
1355
1356         return true;
1357 }
1358
1359 static bool
1360 _equalAExpr(A_Expr *a, A_Expr *b)
1361 {
1362         if (a->oper != b->oper)
1363                 return false;
1364         if (!equalstr(a->opname, b->opname))
1365                 return false;
1366         if (!equal(a->lexpr, b->lexpr))
1367                 return false;
1368         if (!equal(a->rexpr, b->rexpr))
1369                 return false;
1370
1371         return true;
1372 }
1373
1374 static bool
1375 _equalAttr(Attr *a, Attr *b)
1376 {
1377         if (strcmp(a->relname, b->relname) != 0)
1378                 return false;
1379         if (!equal(a->paramNo, b->paramNo))
1380                 return false;
1381         if (!equal(a->attrs, b->attrs))
1382                 return false;
1383         if (!equal(a->indirection, b->indirection))
1384                 return false;
1385
1386         return true;
1387 }
1388
1389 static bool
1390 _equalAConst(A_Const *a, A_Const *b)
1391 {
1392         if (!equal(&a->val, &b->val))
1393                 return false;
1394         if (!equal(a->typename, b->typename))
1395                 return false;
1396
1397         return true;
1398 }
1399
1400 static bool
1401 _equalParamNo(ParamNo *a, ParamNo *b)
1402 {
1403         if (a->number != b->number)
1404                 return false;
1405         if (!equal(a->typename, b->typename))
1406                 return false;
1407         if (!equal(a->indirection, b->indirection))
1408                 return false;
1409
1410         return true;
1411 }
1412
1413 static bool
1414 _equalIdent(Ident *a, Ident *b)
1415 {
1416         if (!equalstr(a->name, b->name))
1417                 return false;
1418         if (!equal(a->indirection, b->indirection))
1419                 return false;
1420         if (a->isRel != b->isRel)
1421                 return false;
1422
1423         return true;
1424 }
1425
1426 static bool
1427 _equalFuncCall(FuncCall *a, FuncCall *b)
1428 {
1429         if (!equalstr(a->funcname, b->funcname))
1430                 return false;
1431         if (!equal(a->args, b->args))
1432                 return false;
1433         if (a->agg_star != b->agg_star)
1434                 return false;
1435         if (a->agg_distinct != b->agg_distinct)
1436                 return false;
1437
1438         return true;
1439 }
1440
1441 static bool
1442 _equalAIndices(A_Indices *a, A_Indices *b)
1443 {
1444         if (!equal(a->lidx, b->lidx))
1445                 return false;
1446         if (!equal(a->uidx, b->uidx))
1447                 return false;
1448
1449         return true;
1450 }
1451
1452 static bool
1453 _equalResTarget(ResTarget *a, ResTarget *b)
1454 {
1455         if (!equalstr(a->name, b->name))
1456                 return false;
1457         if (!equal(a->indirection, b->indirection))
1458                 return false;
1459         if (!equal(a->val, b->val))
1460                 return false;
1461
1462         return true;
1463 }
1464
1465 static bool
1466 _equalTypeCast(TypeCast *a, TypeCast *b)
1467 {
1468         if (!equal(a->arg, b->arg))
1469                 return false;
1470         if (!equal(a->typename, b->typename))
1471                 return false;
1472
1473         return true;
1474 }
1475
1476 static bool
1477 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1478 {
1479         if (!equalstr(a->useOp, b->useOp))
1480                 return false;
1481         if (!equal(a->node, b->node))
1482                 return false;
1483
1484         return true;
1485 }
1486
1487 static bool
1488 _equalRangeVar(RangeVar *a, RangeVar *b)
1489 {
1490         if (!equalstr(a->relname, b->relname))
1491                 return false;
1492         if (a->inhOpt != b->inhOpt)
1493                 return false;
1494         if (!equal(a->name, b->name))
1495                 return false;
1496
1497         return true;
1498 }
1499
1500 static bool
1501 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1502 {
1503         if (!equal(a->subquery, b->subquery))
1504                 return false;
1505         if (!equal(a->name, b->name))
1506                 return false;
1507
1508         return true;
1509 }
1510
1511 static bool
1512 _equalTypeName(TypeName *a, TypeName *b)
1513 {
1514         if (!equalstr(a->name, b->name))
1515                 return false;
1516         if (a->timezone != b->timezone)
1517                 return false;
1518         if (a->setof != b->setof)
1519                 return false;
1520         if (a->typmod != b->typmod)
1521                 return false;
1522         if (!equal(a->arrayBounds, b->arrayBounds))
1523                 return false;
1524
1525         return true;
1526 }
1527
1528 static bool
1529 _equalIndexElem(IndexElem *a, IndexElem *b)
1530 {
1531         if (!equalstr(a->name, b->name))
1532                 return false;
1533         if (!equal(a->args, b->args))
1534                 return false;
1535         if (!equalstr(a->class, b->class))
1536                 return false;
1537
1538         return true;
1539 }
1540
1541 static bool
1542 _equalColumnDef(ColumnDef *a, ColumnDef *b)
1543 {
1544         if (!equalstr(a->colname, b->colname))
1545                 return false;
1546         if (!equal(a->typename, b->typename))
1547                 return false;
1548         if (a->is_not_null != b->is_not_null)
1549                 return false;
1550         if (!equal(a->raw_default, b->raw_default))
1551                 return false;
1552         if (!equalstr(a->cooked_default, b->cooked_default))
1553                 return false;
1554         if (!equal(a->constraints, b->constraints))
1555                 return false;
1556
1557         return true;
1558 }
1559
1560 static bool
1561 _equalConstraint(Constraint *a, Constraint *b)
1562 {
1563         if (a->contype != b->contype)
1564                 return false;
1565         if (!equalstr(a->name, b->name))
1566                 return false;
1567         if (!equal(a->raw_expr, b->raw_expr))
1568                 return false;
1569         if (!equalstr(a->cooked_expr, b->cooked_expr))
1570                 return false;
1571         if (!equal(a->keys, b->keys))
1572                 return false;
1573
1574         return true;
1575 }
1576
1577 static bool
1578 _equalDefElem(DefElem *a, DefElem *b)
1579 {
1580         if (!equalstr(a->defname, b->defname))
1581                 return false;
1582         if (!equal(a->arg, b->arg))
1583                 return false;
1584
1585         return true;
1586 }
1587
1588 static bool
1589 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
1590 {
1591         if (!equal(a->resdom, b->resdom))
1592                 return false;
1593         if (!equal(a->fjoin, b->fjoin))
1594                 return false;
1595         if (!equal(a->expr, b->expr))
1596                 return false;
1597
1598         return true;
1599 }
1600
1601 static bool
1602 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
1603 {
1604         if (!equalstr(a->relname, b->relname))
1605                 return false;
1606         if (a->relid != b->relid)
1607                 return false;
1608         if (!equal(a->subquery, b->subquery))
1609                 return false;
1610         if (!equal(a->alias, b->alias))
1611                 return false;
1612         if (!equal(a->eref, b->eref))
1613                 return false;
1614         if (a->inh != b->inh)
1615                 return false;
1616         if (a->inFromCl != b->inFromCl)
1617                 return false;
1618         if (a->checkForRead != b->checkForRead)
1619                 return false;
1620         if (a->checkForWrite != b->checkForWrite)
1621                 return false;
1622         if (a->checkAsUser != b->checkAsUser)
1623                 return false;
1624
1625         return true;
1626 }
1627
1628 static bool
1629 _equalSortClause(SortClause *a, SortClause *b)
1630 {
1631         if (a->tleSortGroupRef != b->tleSortGroupRef)
1632                 return false;
1633         if (a->sortop != b->sortop)
1634                 return false;
1635
1636         return true;
1637 }
1638
1639 static bool
1640 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
1641 {
1642         if (!equalstr(a->constr_name, b->constr_name))
1643                 return false;
1644         if (!equalstr(a->pktable_name, b->pktable_name))
1645                 return false;
1646         if (!equal(a->fk_attrs, b->fk_attrs))
1647                 return false;
1648         if (!equal(a->pk_attrs, b->pk_attrs))
1649                 return false;
1650         if (!equalstr(a->match_type, b->match_type))
1651                 return false;
1652         if (a->actions != b->actions)
1653                 return false;
1654         if (a->deferrable != b->deferrable)
1655                 return false;
1656         if (a->initdeferred != b->initdeferred)
1657                 return false;
1658
1659         return true;
1660 }
1661
1662 static bool
1663 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
1664 {
1665         if (a->casetype != b->casetype)
1666                 return false;
1667         if (!equal(a->arg, b->arg))
1668                 return false;
1669         if (!equal(a->args, b->args))
1670                 return false;
1671         if (!equal(a->defresult, b->defresult))
1672                 return false;
1673
1674         return true;
1675 }
1676
1677 static bool
1678 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
1679 {
1680         if (!equal(a->expr, b->expr))
1681                 return false;
1682         if (!equal(a->result, b->result))
1683                 return false;
1684
1685         return true;
1686 }
1687
1688 static bool
1689 _equalNullTest(NullTest *a, NullTest *b)
1690 {
1691         if (!equal(a->arg, b->arg))
1692                 return false;
1693         if (a->nulltesttype != b->nulltesttype)
1694                 return false;
1695         return true;
1696 }
1697
1698 static bool
1699 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
1700 {
1701         if (!equal(a->arg, b->arg))
1702                 return false;
1703         if (a->booltesttype != b->booltesttype)
1704                 return false;
1705         return true;
1706 }
1707
1708 /*
1709  * Stuff from pg_list.h
1710  */
1711
1712 static bool
1713 _equalValue(Value *a, Value *b)
1714 {
1715         if (a->type != b->type)
1716                 return false;
1717
1718         switch (a->type)
1719         {
1720                 case T_Integer:
1721                         return a->val.ival == b->val.ival;
1722                 case T_Float:
1723                 case T_String:
1724                 case T_BitString:
1725                         return strcmp(a->val.str, b->val.str) == 0;
1726                 default:
1727                         break;
1728         }
1729
1730         return true;
1731 }
1732
1733 /*
1734  * equal
1735  *        returns whether two nodes are equal
1736  */
1737 bool
1738 equal(void *a, void *b)
1739 {
1740         bool            retval = false;
1741
1742         if (a == b)
1743                 return true;
1744
1745         /*
1746          * note that a!=b, so only one of them can be NULL
1747          */
1748         if (a == NULL || b == NULL)
1749                 return false;
1750
1751         /*
1752          * are they the same type of nodes?
1753          */
1754         if (nodeTag(a) != nodeTag(b))
1755                 return false;
1756
1757         switch (nodeTag(a))
1758         {
1759                 case T_SubPlan:
1760                         retval = _equalSubPlan(a, b);
1761                         break;
1762
1763                 case T_Resdom:
1764                         retval = _equalResdom(a, b);
1765                         break;
1766                 case T_Fjoin:
1767                         retval = _equalFjoin(a, b);
1768                         break;
1769                 case T_Expr:
1770                         retval = _equalExpr(a, b);
1771                         break;
1772                 case T_Var:
1773                         retval = _equalVar(a, b);
1774                         break;
1775                 case T_Oper:
1776                         retval = _equalOper(a, b);
1777                         break;
1778                 case T_Const:
1779                         retval = _equalConst(a, b);
1780                         break;
1781                 case T_Param:
1782                         retval = _equalParam(a, b);
1783                         break;
1784                 case T_Aggref:
1785                         retval = _equalAggref(a, b);
1786                         break;
1787                 case T_SubLink:
1788                         retval = _equalSubLink(a, b);
1789                         break;
1790                 case T_Func:
1791                         retval = _equalFunc(a, b);
1792                         break;
1793                 case T_FieldSelect:
1794                         retval = _equalFieldSelect(a, b);
1795                         break;
1796                 case T_ArrayRef:
1797                         retval = _equalArrayRef(a, b);
1798                         break;
1799                 case T_Iter:
1800                         retval = _equalIter(a, b);
1801                         break;
1802                 case T_RelabelType:
1803                         retval = _equalRelabelType(a, b);
1804                         break;
1805                 case T_RangeTblRef:
1806                         retval = _equalRangeTblRef(a, b);
1807                         break;
1808                 case T_FromExpr:
1809                         retval = _equalFromExpr(a, b);
1810                         break;
1811                 case T_JoinExpr:
1812                         retval = _equalJoinExpr(a, b);
1813                         break;
1814
1815                 case T_RelOptInfo:
1816                         retval = _equalRelOptInfo(a, b);
1817                         break;
1818                 case T_Path:
1819                         retval = _equalPath(a, b);
1820                         break;
1821                 case T_IndexPath:
1822                         retval = _equalIndexPath(a, b);
1823                         break;
1824                 case T_NestPath:
1825                         retval = _equalNestPath(a, b);
1826                         break;
1827                 case T_MergePath:
1828                         retval = _equalMergePath(a, b);
1829                         break;
1830                 case T_HashPath:
1831                         retval = _equalHashPath(a, b);
1832                         break;
1833                 case T_PathKeyItem:
1834                         retval = _equalPathKeyItem(a, b);
1835                         break;
1836                 case T_RestrictInfo:
1837                         retval = _equalRestrictInfo(a, b);
1838                         break;
1839                 case T_JoinInfo:
1840                         retval = _equalJoinInfo(a, b);
1841                         break;
1842                 case T_Stream:
1843                         retval = _equalStream(a, b);
1844                         break;
1845                 case T_TidPath:
1846                         retval = _equalTidPath(a, b);
1847                         break;
1848                 case T_AppendPath:
1849                         retval = _equalAppendPath(a, b);
1850                         break;
1851                 case T_IndexOptInfo:
1852                         retval = _equalIndexOptInfo(a, b);
1853                         break;
1854
1855                 case T_List:
1856                         {
1857                                 List       *la = (List *) a;
1858                                 List       *lb = (List *) b;
1859                                 List       *l;
1860
1861                                 /*
1862                                  * Try to reject by length check before we grovel through
1863                                  * all the elements...
1864                                  */
1865                                 if (length(la) != length(lb))
1866                                         return false;
1867                                 foreach(l, la)
1868                                 {
1869                                         if (!equal(lfirst(l), lfirst(lb)))
1870                                                 return false;
1871                                         lb = lnext(lb);
1872                                 }
1873                                 retval = true;
1874                         }
1875                         break;
1876                 case T_Integer:
1877                 case T_Float:
1878                 case T_String:
1879                 case T_BitString:
1880                         retval = _equalValue(a, b);
1881                         break;
1882
1883                 case T_Query:
1884                         retval = _equalQuery(a, b);
1885                         break;
1886                 case T_InsertStmt:
1887                         retval = _equalInsertStmt(a, b);
1888                         break;
1889                 case T_DeleteStmt:
1890                         retval = _equalDeleteStmt(a, b);
1891                         break;
1892                 case T_UpdateStmt:
1893                         retval = _equalUpdateStmt(a, b);
1894                         break;
1895                 case T_SelectStmt:
1896                         retval = _equalSelectStmt(a, b);
1897                         break;
1898                 case T_SetOperationStmt:
1899                         retval = _equalSetOperationStmt(a, b);
1900                         break;
1901                 case T_AlterTableStmt:
1902                         retval = _equalAlterTableStmt(a, b);
1903                         break;
1904                 case T_GrantStmt:
1905                         retval = _equalGrantStmt(a, b);
1906                         break;
1907                 case T_ClosePortalStmt:
1908                         retval = _equalClosePortalStmt(a, b);
1909                         break;
1910                 case T_ClusterStmt:
1911                         retval = _equalClusterStmt(a, b);
1912                         break;
1913                 case T_CopyStmt:
1914                         retval = _equalCopyStmt(a, b);
1915                         break;
1916                 case T_CreateStmt:
1917                         retval = _equalCreateStmt(a, b);
1918                         break;
1919                 case T_VersionStmt:
1920                         retval = _equalVersionStmt(a, b);
1921                         break;
1922                 case T_DefineStmt:
1923                         retval = _equalDefineStmt(a, b);
1924                         break;
1925                 case T_DropStmt:
1926                         retval = _equalDropStmt(a, b);
1927                         break;
1928                 case T_TruncateStmt:
1929                         retval = _equalTruncateStmt(a, b);
1930                         break;
1931                 case T_CommentStmt:
1932                         retval = _equalCommentStmt(a, b);
1933                         break;
1934                 case T_FetchStmt:
1935                         retval = _equalFetchStmt(a, b);
1936                         break;
1937                 case T_IndexStmt:
1938                         retval = _equalIndexStmt(a, b);
1939                         break;
1940                 case T_ProcedureStmt:
1941                         retval = _equalProcedureStmt(a, b);
1942                         break;
1943                 case T_RemoveAggrStmt:
1944                         retval = _equalRemoveAggrStmt(a, b);
1945                         break;
1946                 case T_RemoveFuncStmt:
1947                         retval = _equalRemoveFuncStmt(a, b);
1948                         break;
1949                 case T_RemoveOperStmt:
1950                         retval = _equalRemoveOperStmt(a, b);
1951                         break;
1952                 case T_RenameStmt:
1953                         retval = _equalRenameStmt(a, b);
1954                         break;
1955                 case T_RuleStmt:
1956                         retval = _equalRuleStmt(a, b);
1957                         break;
1958                 case T_NotifyStmt:
1959                         retval = _equalNotifyStmt(a, b);
1960                         break;
1961                 case T_ListenStmt:
1962                         retval = _equalListenStmt(a, b);
1963                         break;
1964                 case T_UnlistenStmt:
1965                         retval = _equalUnlistenStmt(a, b);
1966                         break;
1967                 case T_TransactionStmt:
1968                         retval = _equalTransactionStmt(a, b);
1969                         break;
1970                 case T_ViewStmt:
1971                         retval = _equalViewStmt(a, b);
1972                         break;
1973                 case T_LoadStmt:
1974                         retval = _equalLoadStmt(a, b);
1975                         break;
1976                 case T_CreatedbStmt:
1977                         retval = _equalCreatedbStmt(a, b);
1978                         break;
1979                 case T_DropdbStmt:
1980                         retval = _equalDropdbStmt(a, b);
1981                         break;
1982                 case T_VacuumStmt:
1983                         retval = _equalVacuumStmt(a, b);
1984                         break;
1985                 case T_ExplainStmt:
1986                         retval = _equalExplainStmt(a, b);
1987                         break;
1988                 case T_CreateSeqStmt:
1989                         retval = _equalCreateSeqStmt(a, b);
1990                         break;
1991                 case T_VariableSetStmt:
1992                         retval = _equalVariableSetStmt(a, b);
1993                         break;
1994                 case T_VariableShowStmt:
1995                         retval = _equalVariableShowStmt(a, b);
1996                         break;
1997                 case T_VariableResetStmt:
1998                         retval = _equalVariableResetStmt(a, b);
1999                         break;
2000                 case T_CreateTrigStmt:
2001                         retval = _equalCreateTrigStmt(a, b);
2002                         break;
2003                 case T_DropTrigStmt:
2004                         retval = _equalDropTrigStmt(a, b);
2005                         break;
2006                 case T_CreatePLangStmt:
2007                         retval = _equalCreatePLangStmt(a, b);
2008                         break;
2009                 case T_DropPLangStmt:
2010                         retval = _equalDropPLangStmt(a, b);
2011                         break;
2012                 case T_CreateUserStmt:
2013                         retval = _equalCreateUserStmt(a, b);
2014                         break;
2015                 case T_AlterUserStmt:
2016                         retval = _equalAlterUserStmt(a, b);
2017                         break;
2018                 case T_DropUserStmt:
2019                         retval = _equalDropUserStmt(a, b);
2020                         break;
2021                 case T_LockStmt:
2022                         retval = _equalLockStmt(a, b);
2023                         break;
2024                 case T_ConstraintsSetStmt:
2025                         retval = _equalConstraintsSetStmt(a, b);
2026                         break;
2027                 case T_CreateGroupStmt:
2028                         retval = _equalCreateGroupStmt(a, b);
2029                         break;
2030                 case T_AlterGroupStmt:
2031                         retval = _equalAlterGroupStmt(a, b);
2032                         break;
2033                 case T_DropGroupStmt:
2034                         retval = _equalDropGroupStmt(a, b);
2035                         break;
2036                 case T_ReindexStmt:
2037                         retval = _equalReindexStmt(a, b);
2038                         break;
2039                 case T_CheckPointStmt:
2040                         retval = true;
2041                         break;
2042
2043                 case T_A_Expr:
2044                         retval = _equalAExpr(a, b);
2045                         break;
2046                 case T_Attr:
2047                         retval = _equalAttr(a, b);
2048                         break;
2049                 case T_A_Const:
2050                         retval = _equalAConst(a, b);
2051                         break;
2052                 case T_ParamNo:
2053                         retval = _equalParamNo(a, b);
2054                         break;
2055                 case T_Ident:
2056                         retval = _equalIdent(a, b);
2057                         break;
2058                 case T_FuncCall:
2059                         retval = _equalFuncCall(a, b);
2060                         break;
2061                 case T_A_Indices:
2062                         retval = _equalAIndices(a, b);
2063                         break;
2064                 case T_ResTarget:
2065                         retval = _equalResTarget(a, b);
2066                         break;
2067                 case T_TypeCast:
2068                         retval = _equalTypeCast(a, b);
2069                         break;
2070                 case T_SortGroupBy:
2071                         retval = _equalSortGroupBy(a, b);
2072                         break;
2073                 case T_RangeVar:
2074                         retval = _equalRangeVar(a, b);
2075                         break;
2076                 case T_RangeSubselect:
2077                         retval = _equalRangeSubselect(a, b);
2078                         break;
2079                 case T_TypeName:
2080                         retval = _equalTypeName(a, b);
2081                         break;
2082                 case T_IndexElem:
2083                         retval = _equalIndexElem(a, b);
2084                         break;
2085                 case T_ColumnDef:
2086                         retval = _equalColumnDef(a, b);
2087                         break;
2088                 case T_Constraint:
2089                         retval = _equalConstraint(a, b);
2090                         break;
2091                 case T_DefElem:
2092                         retval = _equalDefElem(a, b);
2093                         break;
2094                 case T_TargetEntry:
2095                         retval = _equalTargetEntry(a, b);
2096                         break;
2097                 case T_RangeTblEntry:
2098                         retval = _equalRangeTblEntry(a, b);
2099                         break;
2100                 case T_SortClause:
2101                         retval = _equalSortClause(a, b);
2102                         break;
2103                 case T_GroupClause:
2104                         /* GroupClause is equivalent to SortClause */
2105                         retval = _equalSortClause(a, b);
2106                         break;
2107                 case T_CaseExpr:
2108                         retval = _equalCaseExpr(a, b);
2109                         break;
2110                 case T_CaseWhen:
2111                         retval = _equalCaseWhen(a, b);
2112                         break;
2113                 case T_NullTest:
2114                         retval = _equalNullTest(a, b);
2115                         break;
2116                 case T_BooleanTest:
2117                         retval = _equalBooleanTest(a, b);
2118                         break;
2119                 case T_FkConstraint:
2120                         retval = _equalFkConstraint(a, b);
2121                         break;
2122                 case T_PrivGrantee:
2123                         retval = _equalPrivGrantee(a, b);
2124                         break;
2125
2126                 default:
2127                         elog(NOTICE, "equal: don't know whether nodes of type %d are equal",
2128                                  nodeTag(a));
2129                         break;
2130         }
2131
2132         return retval;
2133 }