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