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