]> granicus.if.org Git - postgresql/blob - src/backend/nodes/equalfuncs.c
Get rid of long-since-vestigial Iter node type, in favor of adding a
[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.132 2002/05/12 23:43:02 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         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 (a->binary != b->binary)
803                 return false;
804         if (!equal(a->relation, b->relation))
805                 return false;
806         if (a->oids != b->oids)
807                 return false;
808         if (a->direction != b->direction)
809                 return false;
810         if (!equalstr(a->filename, b->filename))
811                 return false;
812         if (!equalstr(a->delimiter, b->delimiter))
813                 return false;
814         if (!equalstr(a->null_print, b->null_print))
815                 return false;
816
817         return true;
818 }
819
820 static bool
821 _equalCreateStmt(CreateStmt *a, CreateStmt *b)
822 {
823         if (!equal(a->relation, b->relation))
824                 return false;
825         if (!equal(a->tableElts, b->tableElts))
826                 return false;
827         if (!equal(a->inhRelations, b->inhRelations))
828                 return false;
829         if (!equal(a->constraints, b->constraints))
830                 return false;
831         if (a->hasoids != b->hasoids)
832                 return false;
833
834         return true;
835 }
836
837 static bool
838 _equalDefineStmt(DefineStmt *a, DefineStmt *b)
839 {
840         if (a->defType != b->defType)
841                 return false;
842         if (!equal(a->defnames, b->defnames))
843                 return false;
844         if (!equal(a->definition, b->definition))
845                 return false;
846
847         return true;
848 }
849
850 static bool
851 _equalDropStmt(DropStmt *a, DropStmt *b)
852 {
853         if (!equal(a->objects, b->objects))
854                 return false;
855         if (a->removeType != b->removeType)
856                 return false;
857         if (a->behavior != b->behavior)
858                 return false;
859
860         return true;
861 }
862
863 static bool
864 _equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
865 {
866         if (!equal(a->relation, b->relation))
867                 return false;
868
869         return true;
870 }
871
872 static bool
873 _equalCommentStmt(CommentStmt *a, CommentStmt *b)
874 {
875         if (a->objtype != b->objtype)
876                 return false;
877         if (!equal(a->objname, b->objname))
878                 return false;
879         if (!equal(a->objargs, b->objargs))
880                 return false;
881         if (!equalstr(a->comment, b->comment))
882                 return false;
883
884         return true;
885 }
886
887 static bool
888 _equalFetchStmt(FetchStmt *a, FetchStmt *b)
889 {
890         if (a->direction != b->direction)
891                 return false;
892         if (a->howMany != b->howMany)
893                 return false;
894         if (!equalstr(a->portalname, b->portalname))
895                 return false;
896         if (a->ismove != b->ismove)
897                 return false;
898
899         return true;
900 }
901
902 static bool
903 _equalIndexStmt(IndexStmt *a, IndexStmt *b)
904 {
905         if (!equalstr(a->idxname, b->idxname))
906                 return false;
907         if (!equal(a->relation, b->relation))
908                 return false;
909         if (!equalstr(a->accessMethod, b->accessMethod))
910                 return false;
911         if (!equal(a->indexParams, b->indexParams))
912                 return false;
913         if (!equal(a->whereClause, b->whereClause))
914                 return false;
915         if (!equal(a->rangetable, b->rangetable))
916                 return false;
917         if (a->unique != b->unique)
918                 return false;
919         if (a->primary != b->primary)
920                 return false;
921
922         return true;
923 }
924
925 static bool
926 _equalProcedureStmt(ProcedureStmt *a, ProcedureStmt *b)
927 {
928         if (a->replace != b->replace)
929                 return false;
930         if (!equal(a->funcname, b->funcname))
931                 return false;
932         if (!equal(a->argTypes, b->argTypes))
933                 return false;
934         if (!equal(a->returnType, b->returnType))
935                 return false;
936         if (!equal(a->withClause, b->withClause))
937                 return false;
938         if (!equal(a->as, b->as))
939                 return false;
940         if (!equalstr(a->language, b->language))
941                 return false;
942
943         return true;
944 }
945
946 static bool
947 _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
948 {
949         if (!equal(a->aggname, b->aggname))
950                 return false;
951         if (!equal(a->aggtype, b->aggtype))
952                 return false;
953
954         return true;
955 }
956
957 static bool
958 _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
959 {
960         if (!equal(a->funcname, b->funcname))
961                 return false;
962         if (!equal(a->args, b->args))
963                 return false;
964
965         return true;
966 }
967
968 static bool
969 _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
970 {
971         if (!equal(a->opname, b->opname))
972                 return false;
973         if (!equal(a->args, b->args))
974                 return false;
975
976         return true;
977 }
978
979
980 static bool
981 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
982 {
983         if (!equal(a->relation, b->relation))
984                 return false;
985         if (!equalstr(a->oldname, b->oldname))
986                 return false;
987         if (!equalstr(a->newname, b->newname))
988                 return false;
989         if (a->renameType != b->renameType)
990                 return false;
991
992         return true;
993 }
994
995 static bool
996 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
997 {
998         if (!equal(a->relation, b->relation))
999                 return false;
1000         if (!equalstr(a->rulename, b->rulename))
1001                 return false;
1002         if (!equal(a->whereClause, b->whereClause))
1003                 return false;
1004         if (a->event != b->event)
1005                 return false;
1006         if (a->instead != b->instead)
1007                 return false;
1008         if (!equal(a->actions, b->actions))
1009                 return false;
1010
1011         return true;
1012 }
1013
1014 static bool
1015 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1016 {
1017         if (!equal(a->relation, b->relation))
1018                 return false;
1019
1020         return true;
1021 }
1022
1023 static bool
1024 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1025 {
1026         if (!equal(a->relation, b->relation))
1027                 return false;
1028
1029         return true;
1030 }
1031
1032 static bool
1033 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1034 {
1035         if (!equal(a->relation, b->relation))
1036                 return false;
1037
1038         return true;
1039 }
1040
1041 static bool
1042 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1043 {
1044         if (a->command != b->command)
1045                 return false;
1046
1047         return true;
1048 }
1049
1050 static bool
1051 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1052 {
1053         if (!equal(a->view, b->view))
1054                 return false;
1055         if (!equal(a->aliases, b->aliases))
1056                 return false;
1057         if (!equal(a->query, b->query))
1058                 return false;
1059
1060         return true;
1061 }
1062
1063 static bool
1064 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1065 {
1066         if (!equalstr(a->filename, b->filename))
1067                 return false;
1068
1069         return true;
1070 }
1071
1072 static bool
1073 _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
1074 {
1075         if (!equal(a->domainname, b->domainname))
1076                 return false;
1077         if (!equal(a->typename, b->typename))
1078                 return false;
1079         if (!equal(a->constraints, b->constraints))
1080                 return false;
1081
1082         return true;
1083 }
1084
1085 static bool
1086 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1087 {
1088         if (!equalstr(a->dbname, b->dbname))
1089                 return false;
1090         if (!equalstr(a->dbowner, b->dbowner))
1091                 return false;
1092         if (!equalstr(a->dbpath, b->dbpath))
1093                 return false;
1094         if (!equalstr(a->dbtemplate, b->dbtemplate))
1095                 return false;
1096         if (a->encoding != b->encoding)
1097                 return false;
1098
1099         return true;
1100 }
1101
1102 static bool
1103 _equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
1104 {
1105         if (!equalstr(a->dbname, b->dbname))
1106                 return false;
1107         if (!equalstr(a->variable, b->variable))
1108                 return false;
1109         if (!equal(a->value, b->value))
1110                 return false;
1111
1112         return true;
1113 }
1114
1115 static bool
1116 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1117 {
1118         if (!equalstr(a->dbname, b->dbname))
1119                 return false;
1120
1121         return true;
1122 }
1123
1124 static bool
1125 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1126 {
1127         if (a->vacuum != b->vacuum)
1128                 return false;
1129         if (a->full != b->full)
1130                 return false;
1131         if (a->analyze != b->analyze)
1132                 return false;
1133         if (a->freeze != b->freeze)
1134                 return false;
1135         if (a->verbose != b->verbose)
1136                 return false;
1137         if (!equal(a->relation, b->relation))
1138                 return false;
1139         if (!equal(a->va_cols, b->va_cols))
1140                 return false;
1141
1142         return true;
1143 }
1144
1145 static bool
1146 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1147 {
1148         if (!equal(a->query, b->query))
1149                 return false;
1150         if (a->verbose != b->verbose)
1151                 return false;
1152         if (a->analyze != b->analyze)
1153                 return false;
1154
1155         return true;
1156 }
1157
1158 static bool
1159 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1160 {
1161         if (!equal(a->sequence, b->sequence))
1162                 return false;
1163         if (!equal(a->options, b->options))
1164                 return false;
1165
1166         return true;
1167 }
1168
1169 static bool
1170 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1171 {
1172         if (!equalstr(a->name, b->name))
1173                 return false;
1174         if (!equal(a->args, b->args))
1175                 return false;
1176
1177         return true;
1178 }
1179
1180 static bool
1181 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1182 {
1183         if (!equalstr(a->name, b->name))
1184                 return false;
1185
1186         return true;
1187 }
1188
1189 static bool
1190 _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
1191 {
1192         if (!equalstr(a->name, b->name))
1193                 return false;
1194
1195         return true;
1196 }
1197
1198 static bool
1199 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1200 {
1201         if (!equalstr(a->trigname, b->trigname))
1202                 return false;
1203         if (!equal(a->relation, b->relation))
1204                 return false;
1205         if (!equal(a->funcname, b->funcname))
1206                 return false;
1207         if (!equal(a->args, b->args))
1208                 return false;
1209         if (a->before != b->before)
1210                 return false;
1211         if (a->row != b->row)
1212                 return false;
1213         if (strcmp(a->actions, b->actions) != 0)
1214                 return false;
1215         if (!equalstr(a->lang, b->lang))
1216                 return false;
1217         if (!equalstr(a->text, b->text))
1218                 return false;
1219         if (!equal(a->attr, b->attr))
1220                 return false;
1221         if (!equalstr(a->when, b->when))
1222                 return false;
1223         if (a->isconstraint != b->isconstraint)
1224                 return false;
1225         if (a->deferrable != b->deferrable)
1226                 return false;
1227         if (a->initdeferred != b->initdeferred)
1228                 return false;
1229         if (!equal(a->constrrel, b->constrrel))
1230                 return false;
1231
1232         return true;
1233 }
1234
1235 static bool
1236 _equalDropPropertyStmt(DropPropertyStmt *a, DropPropertyStmt *b)
1237 {
1238         if (!equal(a->relation, b->relation))
1239                 return false;
1240         if (!equalstr(a->property, b->property))
1241                 return false;
1242         if (a->removeType != b->removeType)
1243                 return false;
1244
1245         return true;
1246 }
1247
1248 static bool
1249 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1250 {
1251         if (!equalstr(a->plname, b->plname))
1252                 return false;
1253         if (!equal(a->plhandler, b->plhandler))
1254                 return false;
1255         if (!equalstr(a->plcompiler, b->plcompiler))
1256                 return false;
1257         if (a->pltrusted != b->pltrusted)
1258                 return false;
1259
1260         return true;
1261 }
1262
1263 static bool
1264 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1265 {
1266         if (!equalstr(a->plname, b->plname))
1267                 return false;
1268
1269         return true;
1270 }
1271
1272 static bool
1273 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1274 {
1275         if (!equalstr(a->user, b->user))
1276                 return false;
1277         if (!equal(a->options, b->options))
1278                 return false;
1279
1280         return true;
1281 }
1282
1283 static bool
1284 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1285 {
1286         if (!equalstr(a->user, b->user))
1287                 return false;
1288         if (!equal(a->options, b->options))
1289                 return false;
1290
1291         return true;
1292 }
1293
1294 static bool
1295 _equalAlterUserSetStmt(AlterUserSetStmt *a, AlterUserSetStmt *b)
1296 {
1297         if (!equalstr(a->user, b->user))
1298                 return false;
1299         if (!equalstr(a->variable, b->variable))
1300                 return false;
1301         if (!equal(a->value, b->value))
1302                 return false;
1303
1304         return true;
1305 }
1306
1307 static bool
1308 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1309 {
1310         if (!equal(a->users, b->users))
1311                 return false;
1312
1313         return true;
1314 }
1315
1316 static bool
1317 _equalLockStmt(LockStmt *a, LockStmt *b)
1318 {
1319         if (!equal(a->relations, b->relations))
1320                 return false;
1321         if (a->mode != b->mode)
1322                 return false;
1323
1324         return true;
1325 }
1326
1327 static bool
1328 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1329 {
1330         if (!equal(a->constraints, b->constraints))
1331                 return false;
1332         if (a->deferred != b->deferred)
1333                 return false;
1334
1335         return true;
1336 }
1337
1338 static bool
1339 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1340 {
1341         if (!equalstr(a->name, b->name))
1342                 return false;
1343         if (!equal(a->options, b->options))
1344                 return false;
1345
1346         return true;
1347 }
1348
1349 static bool
1350 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1351 {
1352         if (!equalstr(a->name, b->name))
1353                 return false;
1354         if (a->action != b->action)
1355                 return false;
1356         if (!equal(a->listUsers, b->listUsers))
1357                 return false;
1358
1359         return true;
1360 }
1361
1362 static bool
1363 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1364 {
1365         if (!equalstr(a->name, b->name))
1366                 return false;
1367
1368         return true;
1369 }
1370
1371 static bool
1372 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1373 {
1374         if (a->reindexType != b->reindexType)
1375                 return false;
1376         if (!equal(a->relation, b->relation))
1377                 return false;
1378         if (!equalstr(a->name, b->name))
1379                 return false;
1380         if (a->force != b->force)
1381                 return false;
1382         if (a->all != b->all)
1383                 return false;
1384
1385         return true;
1386 }
1387
1388 static bool
1389 _equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
1390 {
1391         if (!equalstr(a->schemaname, b->schemaname))
1392                 return false;
1393         if (!equalstr(a->authid, b->authid))
1394                 return false;
1395         if (!equal(a->schemaElts, b->schemaElts))
1396                 return false;
1397
1398         return true;
1399 }
1400
1401 static bool
1402 _equalAExpr(A_Expr *a, A_Expr *b)
1403 {
1404         if (a->oper != b->oper)
1405                 return false;
1406         if (!equal(a->name, b->name))
1407                 return false;
1408         if (!equal(a->lexpr, b->lexpr))
1409                 return false;
1410         if (!equal(a->rexpr, b->rexpr))
1411                 return false;
1412
1413         return true;
1414 }
1415
1416 static bool
1417 _equalColumnRef(ColumnRef *a, ColumnRef *b)
1418 {
1419         if (!equal(a->fields, b->fields))
1420                 return false;
1421         if (!equal(a->indirection, b->indirection))
1422                 return false;
1423
1424         return true;
1425 }
1426
1427 static bool
1428 _equalParamRef(ParamRef *a, ParamRef *b)
1429 {
1430         if (a->number != b->number)
1431                 return false;
1432         if (!equal(a->fields, b->fields))
1433                 return false;
1434         if (!equal(a->indirection, b->indirection))
1435                 return false;
1436
1437         return true;
1438 }
1439
1440 static bool
1441 _equalAConst(A_Const *a, A_Const *b)
1442 {
1443         if (!equal(&a->val, &b->val))
1444                 return false;
1445         if (!equal(a->typename, b->typename))
1446                 return false;
1447
1448         return true;
1449 }
1450
1451 static bool
1452 _equalIdent(Ident *a, Ident *b)
1453 {
1454         if (!equalstr(a->name, b->name))
1455                 return false;
1456
1457         return true;
1458 }
1459
1460 static bool
1461 _equalFuncCall(FuncCall *a, FuncCall *b)
1462 {
1463         if (!equal(a->funcname, b->funcname))
1464                 return false;
1465         if (!equal(a->args, b->args))
1466                 return false;
1467         if (a->agg_star != b->agg_star)
1468                 return false;
1469         if (a->agg_distinct != b->agg_distinct)
1470                 return false;
1471
1472         return true;
1473 }
1474
1475 static bool
1476 _equalAIndices(A_Indices *a, A_Indices *b)
1477 {
1478         if (!equal(a->lidx, b->lidx))
1479                 return false;
1480         if (!equal(a->uidx, b->uidx))
1481                 return false;
1482
1483         return true;
1484 }
1485
1486 static bool
1487 _equalExprFieldSelect(ExprFieldSelect *a, ExprFieldSelect *b)
1488 {
1489         if (!equal(a->arg, b->arg))
1490                 return false;
1491         if (!equal(a->fields, b->fields))
1492                 return false;
1493         if (!equal(a->indirection, b->indirection))
1494                 return false;
1495
1496         return true;
1497 }
1498
1499 static bool
1500 _equalResTarget(ResTarget *a, ResTarget *b)
1501 {
1502         if (!equalstr(a->name, b->name))
1503                 return false;
1504         if (!equal(a->indirection, b->indirection))
1505                 return false;
1506         if (!equal(a->val, b->val))
1507                 return false;
1508
1509         return true;
1510 }
1511
1512 static bool
1513 _equalTypeCast(TypeCast *a, TypeCast *b)
1514 {
1515         if (!equal(a->arg, b->arg))
1516                 return false;
1517         if (!equal(a->typename, b->typename))
1518                 return false;
1519
1520         return true;
1521 }
1522
1523 static bool
1524 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1525 {
1526         if (!equal(a->useOp, b->useOp))
1527                 return false;
1528         if (!equal(a->node, b->node))
1529                 return false;
1530
1531         return true;
1532 }
1533
1534 static bool
1535 _equalAlias(Alias *a, Alias *b)
1536 {
1537         if (!equalstr(a->aliasname, b->aliasname))
1538                 return false;
1539         if (!equal(a->colnames, b->colnames))
1540                 return false;
1541
1542         return true;
1543 }
1544
1545 static bool
1546 _equalRangeVar(RangeVar *a, RangeVar *b)
1547 {
1548         if (!equalstr(a->catalogname, b->catalogname))
1549                 return false;
1550         if (!equalstr(a->schemaname, b->schemaname))
1551                 return false;
1552         if (!equalstr(a->relname, b->relname))
1553                 return false;
1554         if (a->inhOpt != b->inhOpt)
1555                 return false;
1556         if (a->istemp != b->istemp)
1557                 return false;
1558         if (!equal(a->alias, b->alias))
1559                 return false;
1560
1561         return true;
1562 }
1563
1564 static bool
1565 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1566 {
1567         if (!equal(a->subquery, b->subquery))
1568                 return false;
1569         if (!equal(a->alias, b->alias))
1570                 return false;
1571
1572         return true;
1573 }
1574
1575 static bool
1576 _equalRangeFunction(RangeFunction *a, RangeFunction *b)
1577 {
1578         if (!equal(a->funccallnode, b->funccallnode))
1579                 return false;
1580         if (!equal(a->alias, b->alias))
1581                 return false;
1582
1583         return true;
1584 }
1585
1586 static bool
1587 _equalTypeName(TypeName *a, TypeName *b)
1588 {
1589         if (!equal(a->names, b->names))
1590                 return false;
1591         if (a->typeid != b->typeid)
1592                 return false;
1593         if (a->timezone != b->timezone)
1594                 return false;
1595         if (a->setof != b->setof)
1596                 return false;
1597         if (a->pct_type != b->pct_type)
1598                 return false;
1599         if (a->typmod != b->typmod)
1600                 return false;
1601         if (!equal(a->arrayBounds, b->arrayBounds))
1602                 return false;
1603
1604         return true;
1605 }
1606
1607 static bool
1608 _equalIndexElem(IndexElem *a, IndexElem *b)
1609 {
1610         if (!equalstr(a->name, b->name))
1611                 return false;
1612         if (!equal(a->funcname, b->funcname))
1613                 return false;
1614         if (!equal(a->args, b->args))
1615                 return false;
1616         if (!equal(a->opclass, b->opclass))
1617                 return false;
1618
1619         return true;
1620 }
1621
1622 static bool
1623 _equalColumnDef(ColumnDef *a, ColumnDef *b)
1624 {
1625         if (!equalstr(a->colname, b->colname))
1626                 return false;
1627         if (!equal(a->typename, b->typename))
1628                 return false;
1629         if (a->is_not_null != b->is_not_null)
1630                 return false;
1631         if (!equal(a->raw_default, b->raw_default))
1632                 return false;
1633         if (!equalstr(a->cooked_default, b->cooked_default))
1634                 return false;
1635         if (!equal(a->constraints, b->constraints))
1636                 return false;
1637
1638         return true;
1639 }
1640
1641 static bool
1642 _equalConstraint(Constraint *a, Constraint *b)
1643 {
1644         if (a->contype != b->contype)
1645                 return false;
1646         if (!equalstr(a->name, b->name))
1647                 return false;
1648         if (!equal(a->raw_expr, b->raw_expr))
1649                 return false;
1650         if (!equalstr(a->cooked_expr, b->cooked_expr))
1651                 return false;
1652         if (!equal(a->keys, b->keys))
1653                 return false;
1654
1655         return true;
1656 }
1657
1658 static bool
1659 _equalDefElem(DefElem *a, DefElem *b)
1660 {
1661         if (!equalstr(a->defname, b->defname))
1662                 return false;
1663         if (!equal(a->arg, b->arg))
1664                 return false;
1665
1666         return true;
1667 }
1668
1669 static bool
1670 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
1671 {
1672         if (!equal(a->resdom, b->resdom))
1673                 return false;
1674         if (!equal(a->fjoin, b->fjoin))
1675                 return false;
1676         if (!equal(a->expr, b->expr))
1677                 return false;
1678
1679         return true;
1680 }
1681
1682 static bool
1683 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
1684 {
1685         if (a->rtekind != b->rtekind)
1686                 return false;
1687         if (a->relid != b->relid)
1688                 return false;
1689         if (!equal(a->subquery, b->subquery))
1690                 return false;
1691         if (!equal(a->funcexpr, b->funcexpr))
1692                 return false;
1693         if (a->jointype != b->jointype)
1694                 return false;
1695         if (!equal(a->joinaliasvars, b->joinaliasvars))
1696                 return false;
1697         if (!equal(a->alias, b->alias))
1698                 return false;
1699         if (!equal(a->eref, b->eref))
1700                 return false;
1701         if (a->inh != b->inh)
1702                 return false;
1703         if (a->inFromCl != b->inFromCl)
1704                 return false;
1705         if (a->checkForRead != b->checkForRead)
1706                 return false;
1707         if (a->checkForWrite != b->checkForWrite)
1708                 return false;
1709         if (a->checkAsUser != b->checkAsUser)
1710                 return false;
1711
1712         return true;
1713 }
1714
1715 static bool
1716 _equalSortClause(SortClause *a, SortClause *b)
1717 {
1718         if (a->tleSortGroupRef != b->tleSortGroupRef)
1719                 return false;
1720         if (a->sortop != b->sortop)
1721                 return false;
1722
1723         return true;
1724 }
1725
1726 static bool
1727 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
1728 {
1729         if (!equalstr(a->constr_name, b->constr_name))
1730                 return false;
1731         if (!equal(a->pktable, b->pktable))
1732                 return false;
1733         if (!equal(a->fk_attrs, b->fk_attrs))
1734                 return false;
1735         if (!equal(a->pk_attrs, b->pk_attrs))
1736                 return false;
1737         if (!equalstr(a->match_type, b->match_type))
1738                 return false;
1739         if (a->actions != b->actions)
1740                 return false;
1741         if (a->deferrable != b->deferrable)
1742                 return false;
1743         if (a->initdeferred != b->initdeferred)
1744                 return false;
1745
1746         return true;
1747 }
1748
1749 static bool
1750 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
1751 {
1752         if (a->casetype != b->casetype)
1753                 return false;
1754         if (!equal(a->arg, b->arg))
1755                 return false;
1756         if (!equal(a->args, b->args))
1757                 return false;
1758         if (!equal(a->defresult, b->defresult))
1759                 return false;
1760
1761         return true;
1762 }
1763
1764 static bool
1765 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
1766 {
1767         if (!equal(a->expr, b->expr))
1768                 return false;
1769         if (!equal(a->result, b->result))
1770                 return false;
1771
1772         return true;
1773 }
1774
1775 static bool
1776 _equalNullTest(NullTest *a, NullTest *b)
1777 {
1778         if (!equal(a->arg, b->arg))
1779                 return false;
1780         if (a->nulltesttype != b->nulltesttype)
1781                 return false;
1782         return true;
1783 }
1784
1785 static bool
1786 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
1787 {
1788         if (!equal(a->arg, b->arg))
1789                 return false;
1790         if (a->booltesttype != b->booltesttype)
1791                 return false;
1792         return true;
1793 }
1794
1795 /*
1796  * Stuff from pg_list.h
1797  */
1798
1799 static bool
1800 _equalValue(Value *a, Value *b)
1801 {
1802         if (a->type != b->type)
1803                 return false;
1804
1805         switch (a->type)
1806         {
1807                 case T_Integer:
1808                         return a->val.ival == b->val.ival;
1809                 case T_Float:
1810                 case T_String:
1811                 case T_BitString:
1812                         return strcmp(a->val.str, b->val.str) == 0;
1813                 default:
1814                         break;
1815         }
1816
1817         return true;
1818 }
1819
1820 /*
1821  * equal
1822  *        returns whether two nodes are equal
1823  */
1824 bool
1825 equal(void *a, void *b)
1826 {
1827         bool            retval = false;
1828
1829         if (a == b)
1830                 return true;
1831
1832         /*
1833          * note that a!=b, so only one of them can be NULL
1834          */
1835         if (a == NULL || b == NULL)
1836                 return false;
1837
1838         /*
1839          * are they the same type of nodes?
1840          */
1841         if (nodeTag(a) != nodeTag(b))
1842                 return false;
1843
1844         switch (nodeTag(a))
1845         {
1846                 case T_SubPlan:
1847                         retval = _equalSubPlan(a, b);
1848                         break;
1849
1850                 case T_Resdom:
1851                         retval = _equalResdom(a, b);
1852                         break;
1853                 case T_Fjoin:
1854                         retval = _equalFjoin(a, b);
1855                         break;
1856                 case T_Expr:
1857                         retval = _equalExpr(a, b);
1858                         break;
1859                 case T_Var:
1860                         retval = _equalVar(a, b);
1861                         break;
1862                 case T_Oper:
1863                         retval = _equalOper(a, b);
1864                         break;
1865                 case T_Const:
1866                         retval = _equalConst(a, b);
1867                         break;
1868                 case T_Param:
1869                         retval = _equalParam(a, b);
1870                         break;
1871                 case T_Aggref:
1872                         retval = _equalAggref(a, b);
1873                         break;
1874                 case T_SubLink:
1875                         retval = _equalSubLink(a, b);
1876                         break;
1877                 case T_Func:
1878                         retval = _equalFunc(a, b);
1879                         break;
1880                 case T_FieldSelect:
1881                         retval = _equalFieldSelect(a, b);
1882                         break;
1883                 case T_ArrayRef:
1884                         retval = _equalArrayRef(a, b);
1885                         break;
1886                 case T_RelabelType:
1887                         retval = _equalRelabelType(a, b);
1888                         break;
1889                 case T_RangeTblRef:
1890                         retval = _equalRangeTblRef(a, b);
1891                         break;
1892                 case T_FromExpr:
1893                         retval = _equalFromExpr(a, b);
1894                         break;
1895                 case T_JoinExpr:
1896                         retval = _equalJoinExpr(a, b);
1897                         break;
1898
1899                 case T_RelOptInfo:
1900                         retval = _equalRelOptInfo(a, b);
1901                         break;
1902                 case T_Path:
1903                         retval = _equalPath(a, b);
1904                         break;
1905                 case T_IndexPath:
1906                         retval = _equalIndexPath(a, b);
1907                         break;
1908                 case T_NestPath:
1909                         retval = _equalNestPath(a, b);
1910                         break;
1911                 case T_MergePath:
1912                         retval = _equalMergePath(a, b);
1913                         break;
1914                 case T_HashPath:
1915                         retval = _equalHashPath(a, b);
1916                         break;
1917                 case T_PathKeyItem:
1918                         retval = _equalPathKeyItem(a, b);
1919                         break;
1920                 case T_RestrictInfo:
1921                         retval = _equalRestrictInfo(a, b);
1922                         break;
1923                 case T_JoinInfo:
1924                         retval = _equalJoinInfo(a, b);
1925                         break;
1926                 case T_Stream:
1927                         retval = _equalStream(a, b);
1928                         break;
1929                 case T_TidPath:
1930                         retval = _equalTidPath(a, b);
1931                         break;
1932                 case T_AppendPath:
1933                         retval = _equalAppendPath(a, b);
1934                         break;
1935                 case T_IndexOptInfo:
1936                         retval = _equalIndexOptInfo(a, b);
1937                         break;
1938
1939                 case T_List:
1940                         {
1941                                 List       *la = (List *) a;
1942                                 List       *lb = (List *) b;
1943                                 List       *l;
1944
1945                                 /*
1946                                  * Try to reject by length check before we grovel through
1947                                  * all the elements...
1948                                  */
1949                                 if (length(la) != length(lb))
1950                                         return false;
1951                                 foreach(l, la)
1952                                 {
1953                                         if (!equal(lfirst(l), lfirst(lb)))
1954                                                 return false;
1955                                         lb = lnext(lb);
1956                                 }
1957                                 retval = true;
1958                         }
1959                         break;
1960                 case T_Integer:
1961                 case T_Float:
1962                 case T_String:
1963                 case T_BitString:
1964                         retval = _equalValue(a, b);
1965                         break;
1966
1967                 case T_Query:
1968                         retval = _equalQuery(a, b);
1969                         break;
1970                 case T_InsertStmt:
1971                         retval = _equalInsertStmt(a, b);
1972                         break;
1973                 case T_DeleteStmt:
1974                         retval = _equalDeleteStmt(a, b);
1975                         break;
1976                 case T_UpdateStmt:
1977                         retval = _equalUpdateStmt(a, b);
1978                         break;
1979                 case T_SelectStmt:
1980                         retval = _equalSelectStmt(a, b);
1981                         break;
1982                 case T_SetOperationStmt:
1983                         retval = _equalSetOperationStmt(a, b);
1984                         break;
1985                 case T_AlterTableStmt:
1986                         retval = _equalAlterTableStmt(a, b);
1987                         break;
1988                 case T_GrantStmt:
1989                         retval = _equalGrantStmt(a, b);
1990                         break;
1991                 case T_ClosePortalStmt:
1992                         retval = _equalClosePortalStmt(a, b);
1993                         break;
1994                 case T_ClusterStmt:
1995                         retval = _equalClusterStmt(a, b);
1996                         break;
1997                 case T_CopyStmt:
1998                         retval = _equalCopyStmt(a, b);
1999                         break;
2000                 case T_CreateStmt:
2001                         retval = _equalCreateStmt(a, b);
2002                         break;
2003                 case T_DefineStmt:
2004                         retval = _equalDefineStmt(a, b);
2005                         break;
2006                 case T_DropStmt:
2007                         retval = _equalDropStmt(a, b);
2008                         break;
2009                 case T_TruncateStmt:
2010                         retval = _equalTruncateStmt(a, b);
2011                         break;
2012                 case T_CommentStmt:
2013                         retval = _equalCommentStmt(a, b);
2014                         break;
2015                 case T_FetchStmt:
2016                         retval = _equalFetchStmt(a, b);
2017                         break;
2018                 case T_IndexStmt:
2019                         retval = _equalIndexStmt(a, b);
2020                         break;
2021                 case T_ProcedureStmt:
2022                         retval = _equalProcedureStmt(a, b);
2023                         break;
2024                 case T_RemoveAggrStmt:
2025                         retval = _equalRemoveAggrStmt(a, b);
2026                         break;
2027                 case T_RemoveFuncStmt:
2028                         retval = _equalRemoveFuncStmt(a, b);
2029                         break;
2030                 case T_RemoveOperStmt:
2031                         retval = _equalRemoveOperStmt(a, b);
2032                         break;
2033                 case T_RenameStmt:
2034                         retval = _equalRenameStmt(a, b);
2035                         break;
2036                 case T_RuleStmt:
2037                         retval = _equalRuleStmt(a, b);
2038                         break;
2039                 case T_NotifyStmt:
2040                         retval = _equalNotifyStmt(a, b);
2041                         break;
2042                 case T_ListenStmt:
2043                         retval = _equalListenStmt(a, b);
2044                         break;
2045                 case T_UnlistenStmt:
2046                         retval = _equalUnlistenStmt(a, b);
2047                         break;
2048                 case T_TransactionStmt:
2049                         retval = _equalTransactionStmt(a, b);
2050                         break;
2051                 case T_ViewStmt:
2052                         retval = _equalViewStmt(a, b);
2053                         break;
2054                 case T_LoadStmt:
2055                         retval = _equalLoadStmt(a, b);
2056                         break;
2057                 case T_CreateDomainStmt:
2058                         retval = _equalCreateDomainStmt(a, b);
2059                         break;
2060                 case T_CreatedbStmt:
2061                         retval = _equalCreatedbStmt(a, b);
2062                         break;
2063                 case T_AlterDatabaseSetStmt:
2064                         retval = _equalAlterDatabaseSetStmt(a, b);
2065                         break;
2066                 case T_DropdbStmt:
2067                         retval = _equalDropdbStmt(a, b);
2068                         break;
2069                 case T_VacuumStmt:
2070                         retval = _equalVacuumStmt(a, b);
2071                         break;
2072                 case T_ExplainStmt:
2073                         retval = _equalExplainStmt(a, b);
2074                         break;
2075                 case T_CreateSeqStmt:
2076                         retval = _equalCreateSeqStmt(a, b);
2077                         break;
2078                 case T_VariableSetStmt:
2079                         retval = _equalVariableSetStmt(a, b);
2080                         break;
2081                 case T_VariableShowStmt:
2082                         retval = _equalVariableShowStmt(a, b);
2083                         break;
2084                 case T_VariableResetStmt:
2085                         retval = _equalVariableResetStmt(a, b);
2086                         break;
2087                 case T_CreateTrigStmt:
2088                         retval = _equalCreateTrigStmt(a, b);
2089                         break;
2090                 case T_DropPropertyStmt:
2091                         retval = _equalDropPropertyStmt(a, b);
2092                         break;
2093                 case T_CreatePLangStmt:
2094                         retval = _equalCreatePLangStmt(a, b);
2095                         break;
2096                 case T_DropPLangStmt:
2097                         retval = _equalDropPLangStmt(a, b);
2098                         break;
2099                 case T_CreateUserStmt:
2100                         retval = _equalCreateUserStmt(a, b);
2101                         break;
2102                 case T_AlterUserStmt:
2103                         retval = _equalAlterUserStmt(a, b);
2104                         break;
2105                 case T_AlterUserSetStmt:
2106                         retval = _equalAlterUserSetStmt(a, b);
2107                         break;
2108                 case T_DropUserStmt:
2109                         retval = _equalDropUserStmt(a, b);
2110                         break;
2111                 case T_LockStmt:
2112                         retval = _equalLockStmt(a, b);
2113                         break;
2114                 case T_ConstraintsSetStmt:
2115                         retval = _equalConstraintsSetStmt(a, b);
2116                         break;
2117                 case T_CreateGroupStmt:
2118                         retval = _equalCreateGroupStmt(a, b);
2119                         break;
2120                 case T_AlterGroupStmt:
2121                         retval = _equalAlterGroupStmt(a, b);
2122                         break;
2123                 case T_DropGroupStmt:
2124                         retval = _equalDropGroupStmt(a, b);
2125                         break;
2126                 case T_ReindexStmt:
2127                         retval = _equalReindexStmt(a, b);
2128                         break;
2129                 case T_CheckPointStmt:
2130                         retval = true;
2131                         break;
2132                 case T_CreateSchemaStmt:
2133                         retval = _equalCreateSchemaStmt(a, b);
2134                         break;
2135
2136                 case T_A_Expr:
2137                         retval = _equalAExpr(a, b);
2138                         break;
2139                 case T_ColumnRef:
2140                         retval = _equalColumnRef(a, b);
2141                         break;
2142                 case T_ParamRef:
2143                         retval = _equalParamRef(a, b);
2144                         break;
2145                 case T_A_Const:
2146                         retval = _equalAConst(a, b);
2147                         break;
2148                 case T_Ident:
2149                         retval = _equalIdent(a, b);
2150                         break;
2151                 case T_FuncCall:
2152                         retval = _equalFuncCall(a, b);
2153                         break;
2154                 case T_A_Indices:
2155                         retval = _equalAIndices(a, b);
2156                         break;
2157                 case T_ExprFieldSelect:
2158                         retval = _equalExprFieldSelect(a, b);
2159                         break;
2160                 case T_ResTarget:
2161                         retval = _equalResTarget(a, b);
2162                         break;
2163                 case T_TypeCast:
2164                         retval = _equalTypeCast(a, b);
2165                         break;
2166                 case T_SortGroupBy:
2167                         retval = _equalSortGroupBy(a, b);
2168                         break;
2169                 case T_Alias:
2170                         retval = _equalAlias(a, b);
2171                         break;
2172                 case T_RangeVar:
2173                         retval = _equalRangeVar(a, b);
2174                         break;
2175                 case T_RangeSubselect:
2176                         retval = _equalRangeSubselect(a, b);
2177                         break;
2178                 case T_RangeFunction:
2179                         retval = _equalRangeFunction(a, b);
2180                         break;
2181                 case T_TypeName:
2182                         retval = _equalTypeName(a, b);
2183                         break;
2184                 case T_IndexElem:
2185                         retval = _equalIndexElem(a, b);
2186                         break;
2187                 case T_ColumnDef:
2188                         retval = _equalColumnDef(a, b);
2189                         break;
2190                 case T_Constraint:
2191                         retval = _equalConstraint(a, b);
2192                         break;
2193                 case T_DefElem:
2194                         retval = _equalDefElem(a, b);
2195                         break;
2196                 case T_TargetEntry:
2197                         retval = _equalTargetEntry(a, b);
2198                         break;
2199                 case T_RangeTblEntry:
2200                         retval = _equalRangeTblEntry(a, b);
2201                         break;
2202                 case T_SortClause:
2203                         retval = _equalSortClause(a, b);
2204                         break;
2205                 case T_GroupClause:
2206                         /* GroupClause is equivalent to SortClause */
2207                         retval = _equalSortClause(a, b);
2208                         break;
2209                 case T_CaseExpr:
2210                         retval = _equalCaseExpr(a, b);
2211                         break;
2212                 case T_CaseWhen:
2213                         retval = _equalCaseWhen(a, b);
2214                         break;
2215                 case T_NullTest:
2216                         retval = _equalNullTest(a, b);
2217                         break;
2218                 case T_BooleanTest:
2219                         retval = _equalBooleanTest(a, b);
2220                         break;
2221                 case T_FkConstraint:
2222                         retval = _equalFkConstraint(a, b);
2223                         break;
2224                 case T_PrivGrantee:
2225                         retval = _equalPrivGrantee(a, b);
2226                         break;
2227                 case T_FuncWithArgs:
2228                         retval = _equalFuncWithArgs(a, b);
2229                         break;
2230                 case T_InsertDefault:
2231                         retval = _equalInsertDefault(a, b);
2232                         break;
2233
2234                 default:
2235                         elog(WARNING, "equal: don't know whether nodes of type %d are equal",
2236                                  nodeTag(a));
2237                         break;
2238         }
2239
2240         return retval;
2241 }