OSDN Git Service

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