OSDN Git Service

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