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