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