]> granicus.if.org Git - postgresql/blob - src/backend/nodes/equalfuncs.c
PREPARE/EXECUTE statements. Patch by Neil Conway, some kibitzing
[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.155 2002/08/27 04:55:07 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 (!equal(a->actions, b->actions))
1007                 return false;
1008
1009         return true;
1010 }
1011
1012 static bool
1013 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1014 {
1015         if (!equal(a->relation, b->relation))
1016                 return false;
1017
1018         return true;
1019 }
1020
1021 static bool
1022 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1023 {
1024         if (!equal(a->relation, b->relation))
1025                 return false;
1026
1027         return true;
1028 }
1029
1030 static bool
1031 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1032 {
1033         if (!equal(a->relation, b->relation))
1034                 return false;
1035
1036         return true;
1037 }
1038
1039 static bool
1040 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1041 {
1042         if (a->command != b->command)
1043                 return false;
1044         if (!equal(a->options, b->options))
1045                 return false;
1046
1047         return true;
1048 }
1049
1050 static bool
1051 _equalCompositeTypeStmt(CompositeTypeStmt *a, CompositeTypeStmt *b)
1052 {
1053         if (!equal(a->typevar, b->typevar))
1054                 return false;
1055         if (!equal(a->coldeflist, b->coldeflist))
1056                 return false;
1057
1058         return true;
1059 }
1060
1061 static bool
1062 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1063 {
1064         if (!equal(a->view, b->view))
1065                 return false;
1066         if (!equal(a->aliases, b->aliases))
1067                 return false;
1068         if (!equal(a->query, b->query))
1069                 return false;
1070
1071         return true;
1072 }
1073
1074 static bool
1075 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1076 {
1077         if (!equalstr(a->filename, b->filename))
1078                 return false;
1079
1080         return true;
1081 }
1082
1083 static bool
1084 _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
1085 {
1086         if (!equal(a->domainname, b->domainname))
1087                 return false;
1088         if (!equal(a->typename, b->typename))
1089                 return false;
1090         if (!equal(a->constraints, b->constraints))
1091                 return false;
1092
1093         return true;
1094 }
1095
1096 static bool
1097 _equalCreateOpClassStmt(CreateOpClassStmt *a, CreateOpClassStmt *b)
1098 {
1099         if (!equal(a->opclassname, b->opclassname))
1100                 return false;
1101         if (!equalstr(a->amname, b->amname))
1102                 return false;
1103         if (!equal(a->datatype, b->datatype))
1104                 return false;
1105         if (!equal(a->items, b->items))
1106                 return false;
1107         if (a->isDefault != b->isDefault)
1108                 return false;
1109
1110         return true;
1111 }
1112
1113 static bool
1114 _equalCreateOpClassItem(CreateOpClassItem *a, CreateOpClassItem *b)
1115 {
1116         if (a->itemtype != b->itemtype)
1117                 return false;
1118         if (!equal(a->name, b->name))
1119                 return false;
1120         if (!equal(a->args, b->args))
1121                 return false;
1122         if (a->number != b->number)
1123                 return false;
1124         if (a->recheck != b->recheck)
1125                 return false;
1126         if (!equal(a->storedtype, b->storedtype))
1127                 return false;
1128
1129         return true;
1130 }
1131
1132 static bool
1133 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1134 {
1135         if (!equalstr(a->dbname, b->dbname))
1136                 return false;
1137         if (!equal(a->options, b->options))
1138                 return false;
1139
1140         return true;
1141 }
1142
1143 static bool
1144 _equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
1145 {
1146         if (!equalstr(a->dbname, b->dbname))
1147                 return false;
1148         if (!equalstr(a->variable, b->variable))
1149                 return false;
1150         if (!equal(a->value, b->value))
1151                 return false;
1152
1153         return true;
1154 }
1155
1156 static bool
1157 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1158 {
1159         if (!equalstr(a->dbname, b->dbname))
1160                 return false;
1161
1162         return true;
1163 }
1164
1165 static bool
1166 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1167 {
1168         if (a->vacuum != b->vacuum)
1169                 return false;
1170         if (a->full != b->full)
1171                 return false;
1172         if (a->analyze != b->analyze)
1173                 return false;
1174         if (a->freeze != b->freeze)
1175                 return false;
1176         if (a->verbose != b->verbose)
1177                 return false;
1178         if (!equal(a->relation, b->relation))
1179                 return false;
1180         if (!equal(a->va_cols, b->va_cols))
1181                 return false;
1182
1183         return true;
1184 }
1185
1186 static bool
1187 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1188 {
1189         if (!equal(a->query, b->query))
1190                 return false;
1191         if (a->verbose != b->verbose)
1192                 return false;
1193         if (a->analyze != b->analyze)
1194                 return false;
1195
1196         return true;
1197 }
1198
1199 static bool
1200 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1201 {
1202         if (!equal(a->sequence, b->sequence))
1203                 return false;
1204         if (!equal(a->options, b->options))
1205                 return false;
1206
1207         return true;
1208 }
1209
1210 static bool
1211 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1212 {
1213         if (!equalstr(a->name, b->name))
1214                 return false;
1215         if (!equal(a->args, b->args))
1216                 return false;
1217         if (a->is_local != b->is_local)
1218                 return false;
1219
1220         return true;
1221 }
1222
1223 static bool
1224 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1225 {
1226         if (!equalstr(a->name, b->name))
1227                 return false;
1228
1229         return true;
1230 }
1231
1232 static bool
1233 _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
1234 {
1235         if (!equalstr(a->name, b->name))
1236                 return false;
1237
1238         return true;
1239 }
1240
1241 static bool
1242 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1243 {
1244         if (!equalstr(a->trigname, b->trigname))
1245                 return false;
1246         if (!equal(a->relation, b->relation))
1247                 return false;
1248         if (!equal(a->funcname, b->funcname))
1249                 return false;
1250         if (!equal(a->args, b->args))
1251                 return false;
1252         if (a->before != b->before)
1253                 return false;
1254         if (a->row != b->row)
1255                 return false;
1256         if (strcmp(a->actions, b->actions) != 0)
1257                 return false;
1258         if (!equalstr(a->lang, b->lang))
1259                 return false;
1260         if (!equalstr(a->text, b->text))
1261                 return false;
1262         if (!equal(a->attr, b->attr))
1263                 return false;
1264         if (!equalstr(a->when, b->when))
1265                 return false;
1266         if (a->isconstraint != b->isconstraint)
1267                 return false;
1268         if (a->deferrable != b->deferrable)
1269                 return false;
1270         if (a->initdeferred != b->initdeferred)
1271                 return false;
1272         if (!equal(a->constrrel, b->constrrel))
1273                 return false;
1274
1275         return true;
1276 }
1277
1278 static bool
1279 _equalDropPropertyStmt(DropPropertyStmt *a, DropPropertyStmt *b)
1280 {
1281         if (!equal(a->relation, b->relation))
1282                 return false;
1283         if (!equalstr(a->property, b->property))
1284                 return false;
1285         if (a->removeType != b->removeType)
1286                 return false;
1287         if (a->behavior != b->behavior)
1288                 return false;
1289
1290         return true;
1291 }
1292
1293 static bool
1294 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1295 {
1296         if (!equalstr(a->plname, b->plname))
1297                 return false;
1298         if (!equal(a->plhandler, b->plhandler))
1299                 return false;
1300         if (!equal(a->plvalidator, b->plvalidator))
1301                 return false;
1302         if (a->pltrusted != b->pltrusted)
1303                 return false;
1304
1305         return true;
1306 }
1307
1308 static bool
1309 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1310 {
1311         if (!equalstr(a->plname, b->plname))
1312                 return false;
1313         if (a->behavior != b->behavior)
1314                 return false;
1315
1316         return true;
1317 }
1318
1319 static bool
1320 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1321 {
1322         if (!equalstr(a->user, b->user))
1323                 return false;
1324         if (!equal(a->options, b->options))
1325                 return false;
1326
1327         return true;
1328 }
1329
1330 static bool
1331 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1332 {
1333         if (!equalstr(a->user, b->user))
1334                 return false;
1335         if (!equal(a->options, b->options))
1336                 return false;
1337
1338         return true;
1339 }
1340
1341 static bool
1342 _equalAlterUserSetStmt(AlterUserSetStmt *a, AlterUserSetStmt *b)
1343 {
1344         if (!equalstr(a->user, b->user))
1345                 return false;
1346         if (!equalstr(a->variable, b->variable))
1347                 return false;
1348         if (!equal(a->value, b->value))
1349                 return false;
1350
1351         return true;
1352 }
1353
1354 static bool
1355 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1356 {
1357         if (!equal(a->users, b->users))
1358                 return false;
1359
1360         return true;
1361 }
1362
1363 static bool
1364 _equalLockStmt(LockStmt *a, LockStmt *b)
1365 {
1366         if (!equal(a->relations, b->relations))
1367                 return false;
1368         if (a->mode != b->mode)
1369                 return false;
1370
1371         return true;
1372 }
1373
1374 static bool
1375 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1376 {
1377         if (!equal(a->constraints, b->constraints))
1378                 return false;
1379         if (a->deferred != b->deferred)
1380                 return false;
1381
1382         return true;
1383 }
1384
1385 static bool
1386 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1387 {
1388         if (!equalstr(a->name, b->name))
1389                 return false;
1390         if (!equal(a->options, b->options))
1391                 return false;
1392
1393         return true;
1394 }
1395
1396 static bool
1397 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1398 {
1399         if (!equalstr(a->name, b->name))
1400                 return false;
1401         if (a->action != b->action)
1402                 return false;
1403         if (!equal(a->listUsers, b->listUsers))
1404                 return false;
1405
1406         return true;
1407 }
1408
1409 static bool
1410 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1411 {
1412         if (!equalstr(a->name, b->name))
1413                 return false;
1414
1415         return true;
1416 }
1417
1418 static bool
1419 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1420 {
1421         if (a->reindexType != b->reindexType)
1422                 return false;
1423         if (!equal(a->relation, b->relation))
1424                 return false;
1425         if (!equalstr(a->name, b->name))
1426                 return false;
1427         if (a->force != b->force)
1428                 return false;
1429         if (a->all != b->all)
1430                 return false;
1431
1432         return true;
1433 }
1434
1435 static bool
1436 _equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
1437 {
1438         if (!equalstr(a->schemaname, b->schemaname))
1439                 return false;
1440         if (!equalstr(a->authid, b->authid))
1441                 return false;
1442         if (!equal(a->schemaElts, b->schemaElts))
1443                 return false;
1444
1445         return true;
1446 }
1447
1448 static bool
1449 _equalCreateConversionStmt(CreateConversionStmt *a, CreateConversionStmt *b)
1450 {
1451         if (!equal(a->conversion_name, b->conversion_name))
1452                 return false;
1453         if (!equalstr(a->for_encoding_name, b->for_encoding_name))
1454                 return false;
1455         if (!equalstr(a->to_encoding_name, b->to_encoding_name))
1456                 return false;
1457         if (!equal(a->func_name, b->func_name))
1458                 return false;
1459         if (a->def != b->def)
1460                 return false;
1461
1462         return true;
1463 }
1464
1465 static bool
1466 _equalCreateCastStmt(CreateCastStmt *a, CreateCastStmt *b)
1467 {
1468         if (!equal(a->sourcetype, b->sourcetype))
1469                 return false;
1470         if (!equal(a->targettype, b->targettype))
1471                 return false;
1472         if (!equal(a->func, b->func))
1473                 return false;
1474         if (a->implicit != b->implicit)
1475                 return false;
1476
1477         return true;
1478 }
1479
1480 static bool
1481 _equalDropCastStmt(DropCastStmt *a, DropCastStmt *b)
1482 {
1483         if (!equal(a->sourcetype, b->sourcetype))
1484                 return false;
1485         if (!equal(a->targettype, b->targettype))
1486                 return false;
1487         if (a->behavior != b->behavior)
1488                 return false;
1489
1490         return true;
1491 }
1492
1493 static bool
1494 _equalPrepareStmt(PrepareStmt *a, PrepareStmt *b)
1495 {
1496         if (!equalstr(a->name, b->name))
1497                 return false;
1498         if (!equal(a->argtypes, b->argtypes))
1499                 return false;
1500         if (!equali(a->argtype_oids, b->argtype_oids))
1501                 return false;
1502         if (!equal(a->query, b->query))
1503                 return false;
1504
1505         return true;
1506 }
1507
1508 static bool
1509 _equalExecuteStmt(ExecuteStmt *a, ExecuteStmt *b)
1510 {
1511         if (!equalstr(a->name, b->name))
1512                 return false;
1513         if (!equal(a->into, b->into))
1514                 return false;
1515         if (!equal(a->params, b->params))
1516                 return false;
1517
1518         return true;
1519 }
1520
1521 static bool
1522 _equalDeallocateStmt(DeallocateStmt *a, DeallocateStmt *b)
1523 {
1524         if (!equalstr(a->name, b->name))
1525                 return false;
1526
1527         return true;
1528 }
1529
1530 static bool
1531 _equalAExpr(A_Expr *a, A_Expr *b)
1532 {
1533         if (a->oper != b->oper)
1534                 return false;
1535         if (!equal(a->name, b->name))
1536                 return false;
1537         if (!equal(a->lexpr, b->lexpr))
1538                 return false;
1539         if (!equal(a->rexpr, b->rexpr))
1540                 return false;
1541
1542         return true;
1543 }
1544
1545 static bool
1546 _equalColumnRef(ColumnRef *a, ColumnRef *b)
1547 {
1548         if (!equal(a->fields, b->fields))
1549                 return false;
1550         if (!equal(a->indirection, b->indirection))
1551                 return false;
1552
1553         return true;
1554 }
1555
1556 static bool
1557 _equalParamRef(ParamRef *a, ParamRef *b)
1558 {
1559         if (a->number != b->number)
1560                 return false;
1561         if (!equal(a->fields, b->fields))
1562                 return false;
1563         if (!equal(a->indirection, b->indirection))
1564                 return false;
1565
1566         return true;
1567 }
1568
1569 static bool
1570 _equalAConst(A_Const *a, A_Const *b)
1571 {
1572         if (!equal(&a->val, &b->val))
1573                 return false;
1574         if (!equal(a->typename, b->typename))
1575                 return false;
1576
1577         return true;
1578 }
1579
1580 static bool
1581 _equalFuncCall(FuncCall *a, FuncCall *b)
1582 {
1583         if (!equal(a->funcname, b->funcname))
1584                 return false;
1585         if (!equal(a->args, b->args))
1586                 return false;
1587         if (a->agg_star != b->agg_star)
1588                 return false;
1589         if (a->agg_distinct != b->agg_distinct)
1590                 return false;
1591
1592         return true;
1593 }
1594
1595 static bool
1596 _equalAIndices(A_Indices *a, A_Indices *b)
1597 {
1598         if (!equal(a->lidx, b->lidx))
1599                 return false;
1600         if (!equal(a->uidx, b->uidx))
1601                 return false;
1602
1603         return true;
1604 }
1605
1606 static bool
1607 _equalExprFieldSelect(ExprFieldSelect *a, ExprFieldSelect *b)
1608 {
1609         if (!equal(a->arg, b->arg))
1610                 return false;
1611         if (!equal(a->fields, b->fields))
1612                 return false;
1613         if (!equal(a->indirection, b->indirection))
1614                 return false;
1615
1616         return true;
1617 }
1618
1619 static bool
1620 _equalResTarget(ResTarget *a, ResTarget *b)
1621 {
1622         if (!equalstr(a->name, b->name))
1623                 return false;
1624         if (!equal(a->indirection, b->indirection))
1625                 return false;
1626         if (!equal(a->val, b->val))
1627                 return false;
1628
1629         return true;
1630 }
1631
1632 static bool
1633 _equalTypeCast(TypeCast *a, TypeCast *b)
1634 {
1635         if (!equal(a->arg, b->arg))
1636                 return false;
1637         if (!equal(a->typename, b->typename))
1638                 return false;
1639
1640         return true;
1641 }
1642
1643 static bool
1644 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1645 {
1646         if (!equal(a->useOp, b->useOp))
1647                 return false;
1648         if (!equal(a->node, b->node))
1649                 return false;
1650
1651         return true;
1652 }
1653
1654 static bool
1655 _equalAlias(Alias *a, Alias *b)
1656 {
1657         if (!equalstr(a->aliasname, b->aliasname))
1658                 return false;
1659         if (!equal(a->colnames, b->colnames))
1660                 return false;
1661
1662         return true;
1663 }
1664
1665 static bool
1666 _equalRangeVar(RangeVar *a, RangeVar *b)
1667 {
1668         if (!equalstr(a->catalogname, b->catalogname))
1669                 return false;
1670         if (!equalstr(a->schemaname, b->schemaname))
1671                 return false;
1672         if (!equalstr(a->relname, b->relname))
1673                 return false;
1674         if (a->inhOpt != b->inhOpt)
1675                 return false;
1676         if (a->istemp != b->istemp)
1677                 return false;
1678         if (!equal(a->alias, b->alias))
1679                 return false;
1680
1681         return true;
1682 }
1683
1684 static bool
1685 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1686 {
1687         if (!equal(a->subquery, b->subquery))
1688                 return false;
1689         if (!equal(a->alias, b->alias))
1690                 return false;
1691
1692         return true;
1693 }
1694
1695 static bool
1696 _equalRangeFunction(RangeFunction *a, RangeFunction *b)
1697 {
1698         if (!equal(a->funccallnode, b->funccallnode))
1699                 return false;
1700         if (!equal(a->alias, b->alias))
1701                 return false;
1702         if (!equal(a->coldeflist, b->coldeflist))
1703                 return false;
1704
1705         return true;
1706 }
1707
1708 static bool
1709 _equalTypeName(TypeName *a, TypeName *b)
1710 {
1711         if (!equal(a->names, b->names))
1712                 return false;
1713         if (a->typeid != b->typeid)
1714                 return false;
1715         if (a->timezone != b->timezone)
1716                 return false;
1717         if (a->setof != b->setof)
1718                 return false;
1719         if (a->pct_type != b->pct_type)
1720                 return false;
1721         if (a->typmod != b->typmod)
1722                 return false;
1723         if (!equal(a->arrayBounds, b->arrayBounds))
1724                 return false;
1725
1726         return true;
1727 }
1728
1729 static bool
1730 _equalIndexElem(IndexElem *a, IndexElem *b)
1731 {
1732         if (!equalstr(a->name, b->name))
1733                 return false;
1734         if (!equal(a->funcname, b->funcname))
1735                 return false;
1736         if (!equal(a->args, b->args))
1737                 return false;
1738         if (!equal(a->opclass, b->opclass))
1739                 return false;
1740
1741         return true;
1742 }
1743
1744 static bool
1745 _equalColumnDef(ColumnDef *a, ColumnDef *b)
1746 {
1747         if (!equalstr(a->colname, b->colname))
1748                 return false;
1749         if (!equal(a->typename, b->typename))
1750                 return false;
1751         if (a->is_not_null != b->is_not_null)
1752                 return false;
1753         if (!equal(a->raw_default, b->raw_default))
1754                 return false;
1755         if (!equalstr(a->cooked_default, b->cooked_default))
1756                 return false;
1757         if (!equal(a->constraints, b->constraints))
1758                 return false;
1759         if (!equal(a->support, b->support))
1760                 return false;
1761
1762         return true;
1763 }
1764
1765 static bool
1766 _equalConstraint(Constraint *a, Constraint *b)
1767 {
1768         if (a->contype != b->contype)
1769                 return false;
1770         if (!equalstr(a->name, b->name))
1771                 return false;
1772         if (!equal(a->raw_expr, b->raw_expr))
1773                 return false;
1774         if (!equalstr(a->cooked_expr, b->cooked_expr))
1775                 return false;
1776         if (!equal(a->keys, b->keys))
1777                 return false;
1778
1779         return true;
1780 }
1781
1782 static bool
1783 _equalDefElem(DefElem *a, DefElem *b)
1784 {
1785         if (!equalstr(a->defname, b->defname))
1786                 return false;
1787         if (!equal(a->arg, b->arg))
1788                 return false;
1789
1790         return true;
1791 }
1792
1793 static bool
1794 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
1795 {
1796         if (!equal(a->resdom, b->resdom))
1797                 return false;
1798         if (!equal(a->fjoin, b->fjoin))
1799                 return false;
1800         if (!equal(a->expr, b->expr))
1801                 return false;
1802
1803         return true;
1804 }
1805
1806 static bool
1807 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
1808 {
1809         if (a->rtekind != b->rtekind)
1810                 return false;
1811         if (a->relid != b->relid)
1812                 return false;
1813         if (!equal(a->subquery, b->subquery))
1814                 return false;
1815         if (!equal(a->funcexpr, b->funcexpr))
1816                 return false;
1817         if (!equal(a->coldeflist, b->coldeflist))
1818                 return false;
1819         if (a->jointype != b->jointype)
1820                 return false;
1821         if (!equal(a->joinaliasvars, b->joinaliasvars))
1822                 return false;
1823         if (!equal(a->alias, b->alias))
1824                 return false;
1825         if (!equal(a->eref, b->eref))
1826                 return false;
1827         if (a->inh != b->inh)
1828                 return false;
1829         if (a->inFromCl != b->inFromCl)
1830                 return false;
1831         if (a->checkForRead != b->checkForRead)
1832                 return false;
1833         if (a->checkForWrite != b->checkForWrite)
1834                 return false;
1835         if (a->checkAsUser != b->checkAsUser)
1836                 return false;
1837
1838         return true;
1839 }
1840
1841 static bool
1842 _equalSortClause(SortClause *a, SortClause *b)
1843 {
1844         if (a->tleSortGroupRef != b->tleSortGroupRef)
1845                 return false;
1846         if (a->sortop != b->sortop)
1847                 return false;
1848
1849         return true;
1850 }
1851
1852 static bool
1853 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
1854 {
1855         if (!equalstr(a->constr_name, b->constr_name))
1856                 return false;
1857         if (!equal(a->pktable, b->pktable))
1858                 return false;
1859         if (!equal(a->fk_attrs, b->fk_attrs))
1860                 return false;
1861         if (!equal(a->pk_attrs, b->pk_attrs))
1862                 return false;
1863         if (a->fk_matchtype != b->fk_matchtype)
1864                 return false;
1865         if (a->fk_upd_action != b->fk_upd_action)
1866                 return false;
1867         if (a->fk_del_action != b->fk_del_action)
1868                 return false;
1869         if (a->deferrable != b->deferrable)
1870                 return false;
1871         if (a->initdeferred != b->initdeferred)
1872                 return false;
1873         if (a->skip_validation != b->skip_validation)
1874                 return false;
1875
1876         return true;
1877 }
1878
1879 static bool
1880 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
1881 {
1882         if (a->casetype != b->casetype)
1883                 return false;
1884         if (!equal(a->arg, b->arg))
1885                 return false;
1886         if (!equal(a->args, b->args))
1887                 return false;
1888         if (!equal(a->defresult, b->defresult))
1889                 return false;
1890
1891         return true;
1892 }
1893
1894 static bool
1895 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
1896 {
1897         if (!equal(a->expr, b->expr))
1898                 return false;
1899         if (!equal(a->result, b->result))
1900                 return false;
1901
1902         return true;
1903 }
1904
1905 static bool
1906 _equalNullTest(NullTest *a, NullTest *b)
1907 {
1908         if (!equal(a->arg, b->arg))
1909                 return false;
1910         if (a->nulltesttype != b->nulltesttype)
1911                 return false;
1912         return true;
1913 }
1914
1915 static bool
1916 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
1917 {
1918         if (!equal(a->arg, b->arg))
1919                 return false;
1920         if (a->booltesttype != b->booltesttype)
1921                 return false;
1922         return true;
1923 }
1924
1925 /*
1926  * Stuff from pg_list.h
1927  */
1928
1929 static bool
1930 _equalValue(Value *a, Value *b)
1931 {
1932         if (a->type != b->type)
1933                 return false;
1934
1935         switch (a->type)
1936         {
1937                 case T_Integer:
1938                         return a->val.ival == b->val.ival;
1939                 case T_Float:
1940                 case T_String:
1941                 case T_BitString:
1942                         return strcmp(a->val.str, b->val.str) == 0;
1943                 case T_Null:
1944                         /* nothing to do */
1945                         break;
1946                 default:
1947                         elog(ERROR, "_equalValue: unknown node type %d", a->type);
1948                         break;
1949         }
1950
1951         return true;
1952 }
1953
1954 /*
1955  * equal
1956  *        returns whether two nodes are equal
1957  */
1958 bool
1959 equal(void *a, void *b)
1960 {
1961         bool            retval = false;
1962
1963         if (a == b)
1964                 return true;
1965
1966         /*
1967          * note that a!=b, so only one of them can be NULL
1968          */
1969         if (a == NULL || b == NULL)
1970                 return false;
1971
1972         /*
1973          * are they the same type of nodes?
1974          */
1975         if (nodeTag(a) != nodeTag(b))
1976                 return false;
1977
1978         switch (nodeTag(a))
1979         {
1980                 case T_SubPlan:
1981                         retval = _equalSubPlan(a, b);
1982                         break;
1983
1984                 case T_Resdom:
1985                         retval = _equalResdom(a, b);
1986                         break;
1987                 case T_Fjoin:
1988                         retval = _equalFjoin(a, b);
1989                         break;
1990                 case T_Expr:
1991                         retval = _equalExpr(a, b);
1992                         break;
1993                 case T_Var:
1994                         retval = _equalVar(a, b);
1995                         break;
1996                 case T_Oper:
1997                         retval = _equalOper(a, b);
1998                         break;
1999                 case T_Const:
2000                         retval = _equalConst(a, b);
2001                         break;
2002                 case T_Param:
2003                         retval = _equalParam(a, b);
2004                         break;
2005                 case T_Aggref:
2006                         retval = _equalAggref(a, b);
2007                         break;
2008                 case T_SubLink:
2009                         retval = _equalSubLink(a, b);
2010                         break;
2011                 case T_Func:
2012                         retval = _equalFunc(a, b);
2013                         break;
2014                 case T_FieldSelect:
2015                         retval = _equalFieldSelect(a, b);
2016                         break;
2017                 case T_ArrayRef:
2018                         retval = _equalArrayRef(a, b);
2019                         break;
2020                 case T_RelabelType:
2021                         retval = _equalRelabelType(a, b);
2022                         break;
2023                 case T_RangeTblRef:
2024                         retval = _equalRangeTblRef(a, b);
2025                         break;
2026                 case T_FromExpr:
2027                         retval = _equalFromExpr(a, b);
2028                         break;
2029                 case T_JoinExpr:
2030                         retval = _equalJoinExpr(a, b);
2031                         break;
2032
2033                 case T_RelOptInfo:
2034                         retval = _equalRelOptInfo(a, b);
2035                         break;
2036                 case T_Path:
2037                         retval = _equalPath(a, b);
2038                         break;
2039                 case T_IndexPath:
2040                         retval = _equalIndexPath(a, b);
2041                         break;
2042                 case T_NestPath:
2043                         retval = _equalNestPath(a, b);
2044                         break;
2045                 case T_MergePath:
2046                         retval = _equalMergePath(a, b);
2047                         break;
2048                 case T_HashPath:
2049                         retval = _equalHashPath(a, b);
2050                         break;
2051                 case T_PathKeyItem:
2052                         retval = _equalPathKeyItem(a, b);
2053                         break;
2054                 case T_RestrictInfo:
2055                         retval = _equalRestrictInfo(a, b);
2056                         break;
2057                 case T_JoinInfo:
2058                         retval = _equalJoinInfo(a, b);
2059                         break;
2060                 case T_TidPath:
2061                         retval = _equalTidPath(a, b);
2062                         break;
2063                 case T_AppendPath:
2064                         retval = _equalAppendPath(a, b);
2065                         break;
2066                 case T_IndexOptInfo:
2067                         retval = _equalIndexOptInfo(a, b);
2068                         break;
2069
2070                 case T_List:
2071                         {
2072                                 List       *la = (List *) a;
2073                                 List       *lb = (List *) b;
2074                                 List       *l;
2075
2076                                 /*
2077                                  * Try to reject by length check before we grovel through
2078                                  * all the elements...
2079                                  */
2080                                 if (length(la) != length(lb))
2081                                         return false;
2082                                 foreach(l, la)
2083                                 {
2084                                         if (!equal(lfirst(l), lfirst(lb)))
2085                                                 return false;
2086                                         lb = lnext(lb);
2087                                 }
2088                                 retval = true;
2089                         }
2090                         break;
2091
2092                 case T_Integer:
2093                 case T_Float:
2094                 case T_String:
2095                 case T_BitString:
2096                 case T_Null:
2097                         retval = _equalValue(a, b);
2098                         break;
2099
2100                 case T_Query:
2101                         retval = _equalQuery(a, b);
2102                         break;
2103                 case T_InsertStmt:
2104                         retval = _equalInsertStmt(a, b);
2105                         break;
2106                 case T_DeleteStmt:
2107                         retval = _equalDeleteStmt(a, b);
2108                         break;
2109                 case T_UpdateStmt:
2110                         retval = _equalUpdateStmt(a, b);
2111                         break;
2112                 case T_SelectStmt:
2113                         retval = _equalSelectStmt(a, b);
2114                         break;
2115                 case T_SetOperationStmt:
2116                         retval = _equalSetOperationStmt(a, b);
2117                         break;
2118                 case T_AlterTableStmt:
2119                         retval = _equalAlterTableStmt(a, b);
2120                         break;
2121                 case T_GrantStmt:
2122                         retval = _equalGrantStmt(a, b);
2123                         break;
2124                 case T_ClosePortalStmt:
2125                         retval = _equalClosePortalStmt(a, b);
2126                         break;
2127                 case T_ClusterStmt:
2128                         retval = _equalClusterStmt(a, b);
2129                         break;
2130                 case T_CopyStmt:
2131                         retval = _equalCopyStmt(a, b);
2132                         break;
2133                 case T_CreateStmt:
2134                         retval = _equalCreateStmt(a, b);
2135                         break;
2136                 case T_DefineStmt:
2137                         retval = _equalDefineStmt(a, b);
2138                         break;
2139                 case T_DropStmt:
2140                         retval = _equalDropStmt(a, b);
2141                         break;
2142                 case T_TruncateStmt:
2143                         retval = _equalTruncateStmt(a, b);
2144                         break;
2145                 case T_CommentStmt:
2146                         retval = _equalCommentStmt(a, b);
2147                         break;
2148                 case T_FetchStmt:
2149                         retval = _equalFetchStmt(a, b);
2150                         break;
2151                 case T_IndexStmt:
2152                         retval = _equalIndexStmt(a, b);
2153                         break;
2154                 case T_CreateFunctionStmt:
2155                         retval = _equalCreateFunctionStmt(a, b);
2156                         break;
2157                 case T_RemoveAggrStmt:
2158                         retval = _equalRemoveAggrStmt(a, b);
2159                         break;
2160                 case T_RemoveFuncStmt:
2161                         retval = _equalRemoveFuncStmt(a, b);
2162                         break;
2163                 case T_RemoveOperStmt:
2164                         retval = _equalRemoveOperStmt(a, b);
2165                         break;
2166                 case T_RemoveOpClassStmt:
2167                         retval = _equalRemoveOpClassStmt(a, b);
2168                         break;
2169                 case T_RenameStmt:
2170                         retval = _equalRenameStmt(a, b);
2171                         break;
2172                 case T_RuleStmt:
2173                         retval = _equalRuleStmt(a, b);
2174                         break;
2175                 case T_NotifyStmt:
2176                         retval = _equalNotifyStmt(a, b);
2177                         break;
2178                 case T_ListenStmt:
2179                         retval = _equalListenStmt(a, b);
2180                         break;
2181                 case T_UnlistenStmt:
2182                         retval = _equalUnlistenStmt(a, b);
2183                         break;
2184                 case T_TransactionStmt:
2185                         retval = _equalTransactionStmt(a, b);
2186                         break;
2187                 case T_CompositeTypeStmt:
2188                         retval = _equalCompositeTypeStmt(a, b);
2189                         break;
2190                 case T_ViewStmt:
2191                         retval = _equalViewStmt(a, b);
2192                         break;
2193                 case T_LoadStmt:
2194                         retval = _equalLoadStmt(a, b);
2195                         break;
2196                 case T_CreateDomainStmt:
2197                         retval = _equalCreateDomainStmt(a, b);
2198                         break;
2199                 case T_CreateOpClassStmt:
2200                         retval = _equalCreateOpClassStmt(a, b);
2201                         break;
2202                 case T_CreateOpClassItem:
2203                         retval = _equalCreateOpClassItem(a, b);
2204                         break;
2205                 case T_CreatedbStmt:
2206                         retval = _equalCreatedbStmt(a, b);
2207                         break;
2208                 case T_AlterDatabaseSetStmt:
2209                         retval = _equalAlterDatabaseSetStmt(a, b);
2210                         break;
2211                 case T_DropdbStmt:
2212                         retval = _equalDropdbStmt(a, b);
2213                         break;
2214                 case T_VacuumStmt:
2215                         retval = _equalVacuumStmt(a, b);
2216                         break;
2217                 case T_ExplainStmt:
2218                         retval = _equalExplainStmt(a, b);
2219                         break;
2220                 case T_CreateSeqStmt:
2221                         retval = _equalCreateSeqStmt(a, b);
2222                         break;
2223                 case T_VariableSetStmt:
2224                         retval = _equalVariableSetStmt(a, b);
2225                         break;
2226                 case T_VariableShowStmt:
2227                         retval = _equalVariableShowStmt(a, b);
2228                         break;
2229                 case T_VariableResetStmt:
2230                         retval = _equalVariableResetStmt(a, b);
2231                         break;
2232                 case T_CreateTrigStmt:
2233                         retval = _equalCreateTrigStmt(a, b);
2234                         break;
2235                 case T_DropPropertyStmt:
2236                         retval = _equalDropPropertyStmt(a, b);
2237                         break;
2238                 case T_CreatePLangStmt:
2239                         retval = _equalCreatePLangStmt(a, b);
2240                         break;
2241                 case T_DropPLangStmt:
2242                         retval = _equalDropPLangStmt(a, b);
2243                         break;
2244                 case T_CreateUserStmt:
2245                         retval = _equalCreateUserStmt(a, b);
2246                         break;
2247                 case T_AlterUserStmt:
2248                         retval = _equalAlterUserStmt(a, b);
2249                         break;
2250                 case T_AlterUserSetStmt:
2251                         retval = _equalAlterUserSetStmt(a, b);
2252                         break;
2253                 case T_DropUserStmt:
2254                         retval = _equalDropUserStmt(a, b);
2255                         break;
2256                 case T_LockStmt:
2257                         retval = _equalLockStmt(a, b);
2258                         break;
2259                 case T_ConstraintsSetStmt:
2260                         retval = _equalConstraintsSetStmt(a, b);
2261                         break;
2262                 case T_CreateGroupStmt:
2263                         retval = _equalCreateGroupStmt(a, b);
2264                         break;
2265                 case T_AlterGroupStmt:
2266                         retval = _equalAlterGroupStmt(a, b);
2267                         break;
2268                 case T_DropGroupStmt:
2269                         retval = _equalDropGroupStmt(a, b);
2270                         break;
2271                 case T_ReindexStmt:
2272                         retval = _equalReindexStmt(a, b);
2273                         break;
2274                 case T_CheckPointStmt:
2275                         retval = true;
2276                         break;
2277                 case T_CreateSchemaStmt:
2278                         retval = _equalCreateSchemaStmt(a, b);
2279                         break;
2280                 case T_CreateConversionStmt:
2281                         retval = _equalCreateConversionStmt(a, b);
2282                         break;
2283                 case T_CreateCastStmt:
2284                         retval = _equalCreateCastStmt(a, b);
2285                         break;
2286                 case T_DropCastStmt:
2287                         retval = _equalDropCastStmt(a, b);
2288                         break;
2289                 case T_PrepareStmt:
2290                         retval = _equalPrepareStmt(a, b);
2291                         break;
2292                 case T_ExecuteStmt:
2293                         retval = _equalExecuteStmt(a, b);
2294                         break;
2295                 case T_DeallocateStmt:
2296                         retval = _equalDeallocateStmt(a, b);
2297                         break;
2298
2299                 case T_A_Expr:
2300                         retval = _equalAExpr(a, b);
2301                         break;
2302                 case T_ColumnRef:
2303                         retval = _equalColumnRef(a, b);
2304                         break;
2305                 case T_ParamRef:
2306                         retval = _equalParamRef(a, b);
2307                         break;
2308                 case T_A_Const:
2309                         retval = _equalAConst(a, b);
2310                         break;
2311                 case T_FuncCall:
2312                         retval = _equalFuncCall(a, b);
2313                         break;
2314                 case T_A_Indices:
2315                         retval = _equalAIndices(a, b);
2316                         break;
2317                 case T_ExprFieldSelect:
2318                         retval = _equalExprFieldSelect(a, b);
2319                         break;
2320                 case T_ResTarget:
2321                         retval = _equalResTarget(a, b);
2322                         break;
2323                 case T_TypeCast:
2324                         retval = _equalTypeCast(a, b);
2325                         break;
2326                 case T_SortGroupBy:
2327                         retval = _equalSortGroupBy(a, b);
2328                         break;
2329                 case T_Alias:
2330                         retval = _equalAlias(a, b);
2331                         break;
2332                 case T_RangeVar:
2333                         retval = _equalRangeVar(a, b);
2334                         break;
2335                 case T_RangeSubselect:
2336                         retval = _equalRangeSubselect(a, b);
2337                         break;
2338                 case T_RangeFunction:
2339                         retval = _equalRangeFunction(a, b);
2340                         break;
2341                 case T_TypeName:
2342                         retval = _equalTypeName(a, b);
2343                         break;
2344                 case T_IndexElem:
2345                         retval = _equalIndexElem(a, b);
2346                         break;
2347                 case T_ColumnDef:
2348                         retval = _equalColumnDef(a, b);
2349                         break;
2350                 case T_Constraint:
2351                         retval = _equalConstraint(a, b);
2352                         break;
2353                 case T_DefElem:
2354                         retval = _equalDefElem(a, b);
2355                         break;
2356                 case T_TargetEntry:
2357                         retval = _equalTargetEntry(a, b);
2358                         break;
2359                 case T_RangeTblEntry:
2360                         retval = _equalRangeTblEntry(a, b);
2361                         break;
2362                 case T_SortClause:
2363                         retval = _equalSortClause(a, b);
2364                         break;
2365                 case T_GroupClause:
2366                         /* GroupClause is equivalent to SortClause */
2367                         retval = _equalSortClause(a, b);
2368                         break;
2369                 case T_CaseExpr:
2370                         retval = _equalCaseExpr(a, b);
2371                         break;
2372                 case T_CaseWhen:
2373                         retval = _equalCaseWhen(a, b);
2374                         break;
2375                 case T_NullTest:
2376                         retval = _equalNullTest(a, b);
2377                         break;
2378                 case T_BooleanTest:
2379                         retval = _equalBooleanTest(a, b);
2380                         break;
2381                 case T_FkConstraint:
2382                         retval = _equalFkConstraint(a, b);
2383                         break;
2384                 case T_PrivGrantee:
2385                         retval = _equalPrivGrantee(a, b);
2386                         break;
2387                 case T_FuncWithArgs:
2388                         retval = _equalFuncWithArgs(a, b);
2389                         break;
2390                 case T_InsertDefault:
2391                         retval = _equalInsertDefault(a, b);
2392                         break;
2393
2394                 default:
2395                         elog(WARNING, "equal: don't know whether nodes of type %d are equal",
2396                                  nodeTag(a));
2397                         break;
2398         }
2399
2400         return retval;
2401 }