Get rid of the rather fuzzily defined FlattenedSubLink node type in favor of
[PostgreSQL.git] / src / backend / nodes / equalfuncs.c
blob6326f3b9f436982bbd6336381ffbfac84290d054
1 /*-------------------------------------------------------------------------
3 * equalfuncs.c
4 * Equality functions to compare node trees.
6 * NOTE: we currently support comparing all node types found in parse
7 * trees. We do not support comparing executor state trees; there
8 * is no need for that, and no point in maintaining all the code that
9 * would be needed. We also do not support comparing Path trees, mainly
10 * because the circular linkages between RelOptInfo and Path nodes can't
11 * be handled easily in a simple depth-first traversal.
13 * Currently, in fact, equal() doesn't know how to compare Plan trees
14 * either. This might need to be fixed someday.
16 * NOTE: it is intentional that parse location fields (in nodes that have
17 * one) are not compared. This is because we want, for example, a variable
18 * "x" to be considered equal() to another reference to "x" in the query.
21 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
22 * Portions Copyright (c) 1994, Regents of the University of California
24 * IDENTIFICATION
25 * $PostgreSQL$
27 *-------------------------------------------------------------------------
30 #include "postgres.h"
32 #include "nodes/relation.h"
33 #include "utils/datum.h"
37 * Macros to simplify comparison of different kinds of fields. Use these
38 * wherever possible to reduce the chance for silly typos. Note that these
39 * hard-wire the convention that the local variables in an Equal routine are
40 * named 'a' and 'b'.
43 /* Compare a simple scalar field (int, float, bool, enum, etc) */
44 #define COMPARE_SCALAR_FIELD(fldname) \
45 do { \
46 if (a->fldname != b->fldname) \
47 return false; \
48 } while (0)
50 /* Compare a field that is a pointer to some kind of Node or Node tree */
51 #define COMPARE_NODE_FIELD(fldname) \
52 do { \
53 if (!equal(a->fldname, b->fldname)) \
54 return false; \
55 } while (0)
57 /* Compare a field that is a pointer to a Bitmapset */
58 #define COMPARE_BITMAPSET_FIELD(fldname) \
59 do { \
60 if (!bms_equal(a->fldname, b->fldname)) \
61 return false; \
62 } while (0)
64 /* Compare a field that is a pointer to a C string, or perhaps NULL */
65 #define COMPARE_STRING_FIELD(fldname) \
66 do { \
67 if (!equalstr(a->fldname, b->fldname)) \
68 return false; \
69 } while (0)
71 /* Macro for comparing string fields that might be NULL */
72 #define equalstr(a, b) \
73 (((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
75 /* Compare a field that is a pointer to a simple palloc'd object of size sz */
76 #define COMPARE_POINTER_FIELD(fldname, sz) \
77 do { \
78 if (memcmp(a->fldname, b->fldname, (sz)) != 0) \
79 return false; \
80 } while (0)
82 /* Compare a parse location field (this is a no-op, per note above) */
83 #define COMPARE_LOCATION_FIELD(fldname) \
84 ((void) 0)
88 * Stuff from primnodes.h
91 static bool
92 _equalAlias(Alias *a, Alias *b)
94 COMPARE_STRING_FIELD(aliasname);
95 COMPARE_NODE_FIELD(colnames);
97 return true;
100 static bool
101 _equalRangeVar(RangeVar *a, RangeVar *b)
103 COMPARE_STRING_FIELD(catalogname);
104 COMPARE_STRING_FIELD(schemaname);
105 COMPARE_STRING_FIELD(relname);
106 COMPARE_SCALAR_FIELD(inhOpt);
107 COMPARE_SCALAR_FIELD(istemp);
108 COMPARE_NODE_FIELD(alias);
109 COMPARE_LOCATION_FIELD(location);
111 return true;
114 static bool
115 _equalIntoClause(IntoClause *a, IntoClause *b)
117 COMPARE_NODE_FIELD(rel);
118 COMPARE_NODE_FIELD(colNames);
119 COMPARE_NODE_FIELD(options);
120 COMPARE_SCALAR_FIELD(onCommit);
121 COMPARE_STRING_FIELD(tableSpaceName);
123 return true;
127 * We don't need an _equalExpr because Expr is an abstract supertype which
128 * should never actually get instantiated. Also, since it has no common
129 * fields except NodeTag, there's no need for a helper routine to factor
130 * out comparing the common fields...
133 static bool
134 _equalVar(Var *a, Var *b)
136 COMPARE_SCALAR_FIELD(varno);
137 COMPARE_SCALAR_FIELD(varattno);
138 COMPARE_SCALAR_FIELD(vartype);
139 COMPARE_SCALAR_FIELD(vartypmod);
140 COMPARE_SCALAR_FIELD(varlevelsup);
141 COMPARE_SCALAR_FIELD(varnoold);
142 COMPARE_SCALAR_FIELD(varoattno);
143 COMPARE_LOCATION_FIELD(location);
145 return true;
148 static bool
149 _equalConst(Const *a, Const *b)
151 COMPARE_SCALAR_FIELD(consttype);
152 COMPARE_SCALAR_FIELD(consttypmod);
153 COMPARE_SCALAR_FIELD(constlen);
154 COMPARE_SCALAR_FIELD(constisnull);
155 COMPARE_SCALAR_FIELD(constbyval);
156 COMPARE_LOCATION_FIELD(location);
159 * We treat all NULL constants of the same type as equal. Someday this
160 * might need to change? But datumIsEqual doesn't work on nulls, so...
162 if (a->constisnull)
163 return true;
164 return datumIsEqual(a->constvalue, b->constvalue,
165 a->constbyval, a->constlen);
168 static bool
169 _equalParam(Param *a, Param *b)
171 COMPARE_SCALAR_FIELD(paramkind);
172 COMPARE_SCALAR_FIELD(paramid);
173 COMPARE_SCALAR_FIELD(paramtype);
174 COMPARE_SCALAR_FIELD(paramtypmod);
175 COMPARE_LOCATION_FIELD(location);
177 return true;
180 static bool
181 _equalAggref(Aggref *a, Aggref *b)
183 COMPARE_SCALAR_FIELD(aggfnoid);
184 COMPARE_SCALAR_FIELD(aggtype);
185 COMPARE_NODE_FIELD(args);
186 COMPARE_SCALAR_FIELD(agglevelsup);
187 COMPARE_SCALAR_FIELD(aggstar);
188 COMPARE_SCALAR_FIELD(aggdistinct);
189 COMPARE_LOCATION_FIELD(location);
191 return true;
194 static bool
195 _equalWindowFunc(WindowFunc *a, WindowFunc *b)
197 COMPARE_SCALAR_FIELD(winfnoid);
198 COMPARE_SCALAR_FIELD(wintype);
199 COMPARE_NODE_FIELD(args);
200 COMPARE_SCALAR_FIELD(winref);
201 COMPARE_SCALAR_FIELD(winstar);
202 COMPARE_SCALAR_FIELD(winagg);
203 COMPARE_LOCATION_FIELD(location);
205 return true;
208 static bool
209 _equalArrayRef(ArrayRef *a, ArrayRef *b)
211 COMPARE_SCALAR_FIELD(refarraytype);
212 COMPARE_SCALAR_FIELD(refelemtype);
213 COMPARE_SCALAR_FIELD(reftypmod);
214 COMPARE_NODE_FIELD(refupperindexpr);
215 COMPARE_NODE_FIELD(reflowerindexpr);
216 COMPARE_NODE_FIELD(refexpr);
217 COMPARE_NODE_FIELD(refassgnexpr);
219 return true;
222 static bool
223 _equalFuncExpr(FuncExpr *a, FuncExpr *b)
225 COMPARE_SCALAR_FIELD(funcid);
226 COMPARE_SCALAR_FIELD(funcresulttype);
227 COMPARE_SCALAR_FIELD(funcretset);
230 * Special-case COERCE_DONTCARE, so that planner can build coercion nodes
231 * that are equal() to both explicit and implicit coercions.
233 if (a->funcformat != b->funcformat &&
234 a->funcformat != COERCE_DONTCARE &&
235 b->funcformat != COERCE_DONTCARE)
236 return false;
238 COMPARE_NODE_FIELD(args);
239 COMPARE_LOCATION_FIELD(location);
241 return true;
244 static bool
245 _equalOpExpr(OpExpr *a, OpExpr *b)
247 COMPARE_SCALAR_FIELD(opno);
250 * Special-case opfuncid: it is allowable for it to differ if one node
251 * contains zero and the other doesn't. This just means that the one node
252 * isn't as far along in the parse/plan pipeline and hasn't had the
253 * opfuncid cache filled yet.
255 if (a->opfuncid != b->opfuncid &&
256 a->opfuncid != 0 &&
257 b->opfuncid != 0)
258 return false;
260 COMPARE_SCALAR_FIELD(opresulttype);
261 COMPARE_SCALAR_FIELD(opretset);
262 COMPARE_NODE_FIELD(args);
263 COMPARE_LOCATION_FIELD(location);
265 return true;
268 static bool
269 _equalDistinctExpr(DistinctExpr *a, DistinctExpr *b)
271 COMPARE_SCALAR_FIELD(opno);
274 * Special-case opfuncid: it is allowable for it to differ if one node
275 * contains zero and the other doesn't. This just means that the one node
276 * isn't as far along in the parse/plan pipeline and hasn't had the
277 * opfuncid cache filled yet.
279 if (a->opfuncid != b->opfuncid &&
280 a->opfuncid != 0 &&
281 b->opfuncid != 0)
282 return false;
284 COMPARE_SCALAR_FIELD(opresulttype);
285 COMPARE_SCALAR_FIELD(opretset);
286 COMPARE_NODE_FIELD(args);
287 COMPARE_LOCATION_FIELD(location);
289 return true;
292 static bool
293 _equalScalarArrayOpExpr(ScalarArrayOpExpr *a, ScalarArrayOpExpr *b)
295 COMPARE_SCALAR_FIELD(opno);
298 * Special-case opfuncid: it is allowable for it to differ if one node
299 * contains zero and the other doesn't. This just means that the one node
300 * isn't as far along in the parse/plan pipeline and hasn't had the
301 * opfuncid cache filled yet.
303 if (a->opfuncid != b->opfuncid &&
304 a->opfuncid != 0 &&
305 b->opfuncid != 0)
306 return false;
308 COMPARE_SCALAR_FIELD(useOr);
309 COMPARE_NODE_FIELD(args);
310 COMPARE_LOCATION_FIELD(location);
312 return true;
315 static bool
316 _equalBoolExpr(BoolExpr *a, BoolExpr *b)
318 COMPARE_SCALAR_FIELD(boolop);
319 COMPARE_NODE_FIELD(args);
320 COMPARE_LOCATION_FIELD(location);
322 return true;
325 static bool
326 _equalSubLink(SubLink *a, SubLink *b)
328 COMPARE_SCALAR_FIELD(subLinkType);
329 COMPARE_NODE_FIELD(testexpr);
330 COMPARE_NODE_FIELD(operName);
331 COMPARE_NODE_FIELD(subselect);
332 COMPARE_LOCATION_FIELD(location);
334 return true;
337 static bool
338 _equalSubPlan(SubPlan *a, SubPlan *b)
340 COMPARE_SCALAR_FIELD(subLinkType);
341 COMPARE_NODE_FIELD(testexpr);
342 COMPARE_NODE_FIELD(paramIds);
343 COMPARE_SCALAR_FIELD(plan_id);
344 COMPARE_SCALAR_FIELD(firstColType);
345 COMPARE_SCALAR_FIELD(useHashTable);
346 COMPARE_SCALAR_FIELD(unknownEqFalse);
347 COMPARE_NODE_FIELD(setParam);
348 COMPARE_NODE_FIELD(parParam);
349 COMPARE_NODE_FIELD(args);
350 COMPARE_SCALAR_FIELD(startup_cost);
351 COMPARE_SCALAR_FIELD(per_call_cost);
353 return true;
356 static bool
357 _equalAlternativeSubPlan(AlternativeSubPlan *a, AlternativeSubPlan *b)
359 COMPARE_NODE_FIELD(subplans);
361 return true;
364 static bool
365 _equalFieldSelect(FieldSelect *a, FieldSelect *b)
367 COMPARE_NODE_FIELD(arg);
368 COMPARE_SCALAR_FIELD(fieldnum);
369 COMPARE_SCALAR_FIELD(resulttype);
370 COMPARE_SCALAR_FIELD(resulttypmod);
372 return true;
375 static bool
376 _equalFieldStore(FieldStore *a, FieldStore *b)
378 COMPARE_NODE_FIELD(arg);
379 COMPARE_NODE_FIELD(newvals);
380 COMPARE_NODE_FIELD(fieldnums);
381 COMPARE_SCALAR_FIELD(resulttype);
383 return true;
386 static bool
387 _equalRelabelType(RelabelType *a, RelabelType *b)
389 COMPARE_NODE_FIELD(arg);
390 COMPARE_SCALAR_FIELD(resulttype);
391 COMPARE_SCALAR_FIELD(resulttypmod);
394 * Special-case COERCE_DONTCARE, so that planner can build coercion nodes
395 * that are equal() to both explicit and implicit coercions.
397 if (a->relabelformat != b->relabelformat &&
398 a->relabelformat != COERCE_DONTCARE &&
399 b->relabelformat != COERCE_DONTCARE)
400 return false;
402 COMPARE_LOCATION_FIELD(location);
404 return true;
407 static bool
408 _equalCoerceViaIO(CoerceViaIO *a, CoerceViaIO *b)
410 COMPARE_NODE_FIELD(arg);
411 COMPARE_SCALAR_FIELD(resulttype);
414 * Special-case COERCE_DONTCARE, so that planner can build coercion nodes
415 * that are equal() to both explicit and implicit coercions.
417 if (a->coerceformat != b->coerceformat &&
418 a->coerceformat != COERCE_DONTCARE &&
419 b->coerceformat != COERCE_DONTCARE)
420 return false;
422 COMPARE_LOCATION_FIELD(location);
424 return true;
427 static bool
428 _equalArrayCoerceExpr(ArrayCoerceExpr *a, ArrayCoerceExpr *b)
430 COMPARE_NODE_FIELD(arg);
431 COMPARE_SCALAR_FIELD(elemfuncid);
432 COMPARE_SCALAR_FIELD(resulttype);
433 COMPARE_SCALAR_FIELD(resulttypmod);
434 COMPARE_SCALAR_FIELD(isExplicit);
437 * Special-case COERCE_DONTCARE, so that planner can build coercion nodes
438 * that are equal() to both explicit and implicit coercions.
440 if (a->coerceformat != b->coerceformat &&
441 a->coerceformat != COERCE_DONTCARE &&
442 b->coerceformat != COERCE_DONTCARE)
443 return false;
445 COMPARE_LOCATION_FIELD(location);
447 return true;
450 static bool
451 _equalConvertRowtypeExpr(ConvertRowtypeExpr *a, ConvertRowtypeExpr *b)
453 COMPARE_NODE_FIELD(arg);
454 COMPARE_SCALAR_FIELD(resulttype);
457 * Special-case COERCE_DONTCARE, so that planner can build coercion nodes
458 * that are equal() to both explicit and implicit coercions.
460 if (a->convertformat != b->convertformat &&
461 a->convertformat != COERCE_DONTCARE &&
462 b->convertformat != COERCE_DONTCARE)
463 return false;
465 COMPARE_LOCATION_FIELD(location);
467 return true;
470 static bool
471 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
473 COMPARE_SCALAR_FIELD(casetype);
474 COMPARE_NODE_FIELD(arg);
475 COMPARE_NODE_FIELD(args);
476 COMPARE_NODE_FIELD(defresult);
477 COMPARE_LOCATION_FIELD(location);
479 return true;
482 static bool
483 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
485 COMPARE_NODE_FIELD(expr);
486 COMPARE_NODE_FIELD(result);
487 COMPARE_LOCATION_FIELD(location);
489 return true;
492 static bool
493 _equalCaseTestExpr(CaseTestExpr *a, CaseTestExpr *b)
495 COMPARE_SCALAR_FIELD(typeId);
496 COMPARE_SCALAR_FIELD(typeMod);
498 return true;
501 static bool
502 _equalArrayExpr(ArrayExpr *a, ArrayExpr *b)
504 COMPARE_SCALAR_FIELD(array_typeid);
505 COMPARE_SCALAR_FIELD(element_typeid);
506 COMPARE_NODE_FIELD(elements);
507 COMPARE_SCALAR_FIELD(multidims);
508 COMPARE_LOCATION_FIELD(location);
510 return true;
513 static bool
514 _equalRowExpr(RowExpr *a, RowExpr *b)
516 COMPARE_NODE_FIELD(args);
517 COMPARE_SCALAR_FIELD(row_typeid);
520 * Special-case COERCE_DONTCARE, so that planner can build coercion nodes
521 * that are equal() to both explicit and implicit coercions.
523 if (a->row_format != b->row_format &&
524 a->row_format != COERCE_DONTCARE &&
525 b->row_format != COERCE_DONTCARE)
526 return false;
528 COMPARE_NODE_FIELD(colnames);
529 COMPARE_LOCATION_FIELD(location);
531 return true;
534 static bool
535 _equalRowCompareExpr(RowCompareExpr *a, RowCompareExpr *b)
537 COMPARE_SCALAR_FIELD(rctype);
538 COMPARE_NODE_FIELD(opnos);
539 COMPARE_NODE_FIELD(opfamilies);
540 COMPARE_NODE_FIELD(largs);
541 COMPARE_NODE_FIELD(rargs);
543 return true;
546 static bool
547 _equalCoalesceExpr(CoalesceExpr *a, CoalesceExpr *b)
549 COMPARE_SCALAR_FIELD(coalescetype);
550 COMPARE_NODE_FIELD(args);
551 COMPARE_LOCATION_FIELD(location);
553 return true;
556 static bool
557 _equalMinMaxExpr(MinMaxExpr *a, MinMaxExpr *b)
559 COMPARE_SCALAR_FIELD(minmaxtype);
560 COMPARE_SCALAR_FIELD(op);
561 COMPARE_NODE_FIELD(args);
562 COMPARE_LOCATION_FIELD(location);
564 return true;
567 static bool
568 _equalXmlExpr(XmlExpr *a, XmlExpr *b)
570 COMPARE_SCALAR_FIELD(op);
571 COMPARE_STRING_FIELD(name);
572 COMPARE_NODE_FIELD(named_args);
573 COMPARE_NODE_FIELD(arg_names);
574 COMPARE_NODE_FIELD(args);
575 COMPARE_SCALAR_FIELD(xmloption);
576 COMPARE_SCALAR_FIELD(type);
577 COMPARE_SCALAR_FIELD(typmod);
578 COMPARE_LOCATION_FIELD(location);
580 return true;
583 static bool
584 _equalNullIfExpr(NullIfExpr *a, NullIfExpr *b)
586 COMPARE_SCALAR_FIELD(opno);
589 * Special-case opfuncid: it is allowable for it to differ if one node
590 * contains zero and the other doesn't. This just means that the one node
591 * isn't as far along in the parse/plan pipeline and hasn't had the
592 * opfuncid cache filled yet.
594 if (a->opfuncid != b->opfuncid &&
595 a->opfuncid != 0 &&
596 b->opfuncid != 0)
597 return false;
599 COMPARE_SCALAR_FIELD(opresulttype);
600 COMPARE_SCALAR_FIELD(opretset);
601 COMPARE_NODE_FIELD(args);
602 COMPARE_LOCATION_FIELD(location);
604 return true;
607 static bool
608 _equalNullTest(NullTest *a, NullTest *b)
610 COMPARE_NODE_FIELD(arg);
611 COMPARE_SCALAR_FIELD(nulltesttype);
613 return true;
616 static bool
617 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
619 COMPARE_NODE_FIELD(arg);
620 COMPARE_SCALAR_FIELD(booltesttype);
622 return true;
625 static bool
626 _equalCoerceToDomain(CoerceToDomain *a, CoerceToDomain *b)
628 COMPARE_NODE_FIELD(arg);
629 COMPARE_SCALAR_FIELD(resulttype);
630 COMPARE_SCALAR_FIELD(resulttypmod);
633 * Special-case COERCE_DONTCARE, so that planner can build coercion nodes
634 * that are equal() to both explicit and implicit coercions.
636 if (a->coercionformat != b->coercionformat &&
637 a->coercionformat != COERCE_DONTCARE &&
638 b->coercionformat != COERCE_DONTCARE)
639 return false;
641 COMPARE_LOCATION_FIELD(location);
643 return true;
646 static bool
647 _equalCoerceToDomainValue(CoerceToDomainValue *a, CoerceToDomainValue *b)
649 COMPARE_SCALAR_FIELD(typeId);
650 COMPARE_SCALAR_FIELD(typeMod);
651 COMPARE_LOCATION_FIELD(location);
653 return true;
656 static bool
657 _equalSetToDefault(SetToDefault *a, SetToDefault *b)
659 COMPARE_SCALAR_FIELD(typeId);
660 COMPARE_SCALAR_FIELD(typeMod);
661 COMPARE_LOCATION_FIELD(location);
663 return true;
666 static bool
667 _equalCurrentOfExpr(CurrentOfExpr *a, CurrentOfExpr *b)
669 COMPARE_SCALAR_FIELD(cvarno);
670 COMPARE_STRING_FIELD(cursor_name);
671 COMPARE_SCALAR_FIELD(cursor_param);
673 return true;
676 static bool
677 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
679 COMPARE_NODE_FIELD(expr);
680 COMPARE_SCALAR_FIELD(resno);
681 COMPARE_STRING_FIELD(resname);
682 COMPARE_SCALAR_FIELD(ressortgroupref);
683 COMPARE_SCALAR_FIELD(resorigtbl);
684 COMPARE_SCALAR_FIELD(resorigcol);
685 COMPARE_SCALAR_FIELD(resjunk);
687 return true;
690 static bool
691 _equalRangeTblRef(RangeTblRef *a, RangeTblRef *b)
693 COMPARE_SCALAR_FIELD(rtindex);
695 return true;
698 static bool
699 _equalJoinExpr(JoinExpr *a, JoinExpr *b)
701 COMPARE_SCALAR_FIELD(jointype);
702 COMPARE_SCALAR_FIELD(isNatural);
703 COMPARE_NODE_FIELD(larg);
704 COMPARE_NODE_FIELD(rarg);
705 COMPARE_NODE_FIELD(using);
706 COMPARE_NODE_FIELD(quals);
707 COMPARE_NODE_FIELD(alias);
708 COMPARE_SCALAR_FIELD(rtindex);
710 return true;
713 static bool
714 _equalFromExpr(FromExpr *a, FromExpr *b)
716 COMPARE_NODE_FIELD(fromlist);
717 COMPARE_NODE_FIELD(quals);
719 return true;
724 * Stuff from relation.h
727 static bool
728 _equalPathKey(PathKey *a, PathKey *b)
731 * This is normally used on non-canonicalized PathKeys, so must chase up
732 * to the topmost merged EquivalenceClass and see if those are the same
733 * (by pointer equality).
735 EquivalenceClass *a_eclass;
736 EquivalenceClass *b_eclass;
738 a_eclass = a->pk_eclass;
739 while (a_eclass->ec_merged)
740 a_eclass = a_eclass->ec_merged;
741 b_eclass = b->pk_eclass;
742 while (b_eclass->ec_merged)
743 b_eclass = b_eclass->ec_merged;
744 if (a_eclass != b_eclass)
745 return false;
746 COMPARE_SCALAR_FIELD(pk_opfamily);
747 COMPARE_SCALAR_FIELD(pk_strategy);
748 COMPARE_SCALAR_FIELD(pk_nulls_first);
750 return true;
753 static bool
754 _equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
756 COMPARE_NODE_FIELD(clause);
757 COMPARE_SCALAR_FIELD(is_pushed_down);
758 COMPARE_SCALAR_FIELD(outerjoin_delayed);
759 COMPARE_BITMAPSET_FIELD(required_relids);
762 * We ignore all the remaining fields, since they may not be set yet, and
763 * should be derivable from the clause anyway.
766 return true;
769 static bool
770 _equalPlaceHolderVar(PlaceHolderVar *a, PlaceHolderVar *b)
773 * We intentionally do not compare phexpr. Two PlaceHolderVars with the
774 * same ID and levelsup should be considered equal even if the contained
775 * expressions have managed to mutate to different states. One way in
776 * which that can happen is that initplan sublinks would get replaced by
777 * differently-numbered Params when sublink folding is done. (The end
778 * result of such a situation would be some unreferenced initplans, which
779 * is annoying but not really a problem.)
781 * COMPARE_NODE_FIELD(phexpr);
783 COMPARE_BITMAPSET_FIELD(phrels);
784 COMPARE_SCALAR_FIELD(phid);
785 COMPARE_SCALAR_FIELD(phlevelsup);
787 return true;
790 static bool
791 _equalSpecialJoinInfo(SpecialJoinInfo *a, SpecialJoinInfo *b)
793 COMPARE_BITMAPSET_FIELD(min_lefthand);
794 COMPARE_BITMAPSET_FIELD(min_righthand);
795 COMPARE_BITMAPSET_FIELD(syn_lefthand);
796 COMPARE_BITMAPSET_FIELD(syn_righthand);
797 COMPARE_SCALAR_FIELD(jointype);
798 COMPARE_SCALAR_FIELD(lhs_strict);
799 COMPARE_SCALAR_FIELD(delay_upper_joins);
800 COMPARE_NODE_FIELD(join_quals);
802 return true;
805 static bool
806 _equalAppendRelInfo(AppendRelInfo *a, AppendRelInfo *b)
808 COMPARE_SCALAR_FIELD(parent_relid);
809 COMPARE_SCALAR_FIELD(child_relid);
810 COMPARE_SCALAR_FIELD(parent_reltype);
811 COMPARE_SCALAR_FIELD(child_reltype);
812 COMPARE_NODE_FIELD(translated_vars);
813 COMPARE_SCALAR_FIELD(parent_reloid);
815 return true;
818 static bool
819 _equalPlaceHolderInfo(PlaceHolderInfo *a, PlaceHolderInfo *b)
821 COMPARE_SCALAR_FIELD(phid);
822 COMPARE_NODE_FIELD(ph_var);
823 COMPARE_BITMAPSET_FIELD(ph_eval_at);
824 COMPARE_BITMAPSET_FIELD(ph_needed);
825 COMPARE_SCALAR_FIELD(ph_width);
827 return true;
832 * Stuff from parsenodes.h
835 static bool
836 _equalQuery(Query *a, Query *b)
838 COMPARE_SCALAR_FIELD(commandType);
839 COMPARE_SCALAR_FIELD(querySource);
840 COMPARE_SCALAR_FIELD(canSetTag);
841 COMPARE_NODE_FIELD(utilityStmt);
842 COMPARE_SCALAR_FIELD(resultRelation);
843 COMPARE_NODE_FIELD(intoClause);
844 COMPARE_SCALAR_FIELD(hasAggs);
845 COMPARE_SCALAR_FIELD(hasWindowFuncs);
846 COMPARE_SCALAR_FIELD(hasSubLinks);
847 COMPARE_SCALAR_FIELD(hasDistinctOn);
848 COMPARE_SCALAR_FIELD(hasRecursive);
849 COMPARE_NODE_FIELD(cteList);
850 COMPARE_NODE_FIELD(rtable);
851 COMPARE_NODE_FIELD(jointree);
852 COMPARE_NODE_FIELD(targetList);
853 COMPARE_NODE_FIELD(returningList);
854 COMPARE_NODE_FIELD(groupClause);
855 COMPARE_NODE_FIELD(havingQual);
856 COMPARE_NODE_FIELD(windowClause);
857 COMPARE_NODE_FIELD(distinctClause);
858 COMPARE_NODE_FIELD(sortClause);
859 COMPARE_NODE_FIELD(limitOffset);
860 COMPARE_NODE_FIELD(limitCount);
861 COMPARE_NODE_FIELD(rowMarks);
862 COMPARE_NODE_FIELD(setOperations);
864 return true;
867 static bool
868 _equalInsertStmt(InsertStmt *a, InsertStmt *b)
870 COMPARE_NODE_FIELD(relation);
871 COMPARE_NODE_FIELD(cols);
872 COMPARE_NODE_FIELD(selectStmt);
873 COMPARE_NODE_FIELD(returningList);
875 return true;
878 static bool
879 _equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
881 COMPARE_NODE_FIELD(relation);
882 COMPARE_NODE_FIELD(usingClause);
883 COMPARE_NODE_FIELD(whereClause);
884 COMPARE_NODE_FIELD(returningList);
886 return true;
889 static bool
890 _equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
892 COMPARE_NODE_FIELD(relation);
893 COMPARE_NODE_FIELD(targetList);
894 COMPARE_NODE_FIELD(whereClause);
895 COMPARE_NODE_FIELD(fromClause);
896 COMPARE_NODE_FIELD(returningList);
898 return true;
901 static bool
902 _equalSelectStmt(SelectStmt *a, SelectStmt *b)
904 COMPARE_NODE_FIELD(distinctClause);
905 COMPARE_NODE_FIELD(intoClause);
906 COMPARE_NODE_FIELD(targetList);
907 COMPARE_NODE_FIELD(fromClause);
908 COMPARE_NODE_FIELD(whereClause);
909 COMPARE_NODE_FIELD(groupClause);
910 COMPARE_NODE_FIELD(havingClause);
911 COMPARE_NODE_FIELD(windowClause);
912 COMPARE_NODE_FIELD(withClause);
913 COMPARE_NODE_FIELD(valuesLists);
914 COMPARE_NODE_FIELD(sortClause);
915 COMPARE_NODE_FIELD(limitOffset);
916 COMPARE_NODE_FIELD(limitCount);
917 COMPARE_NODE_FIELD(lockingClause);
918 COMPARE_SCALAR_FIELD(op);
919 COMPARE_SCALAR_FIELD(all);
920 COMPARE_NODE_FIELD(larg);
921 COMPARE_NODE_FIELD(rarg);
923 return true;
926 static bool
927 _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
929 COMPARE_SCALAR_FIELD(op);
930 COMPARE_SCALAR_FIELD(all);
931 COMPARE_NODE_FIELD(larg);
932 COMPARE_NODE_FIELD(rarg);
933 COMPARE_NODE_FIELD(colTypes);
934 COMPARE_NODE_FIELD(colTypmods);
935 COMPARE_NODE_FIELD(groupClauses);
937 return true;
940 static bool
941 _equalAlterTableStmt(AlterTableStmt *a, AlterTableStmt *b)
943 COMPARE_NODE_FIELD(relation);
944 COMPARE_NODE_FIELD(cmds);
945 COMPARE_SCALAR_FIELD(relkind);
947 return true;
950 static bool
951 _equalAlterTableCmd(AlterTableCmd *a, AlterTableCmd *b)
953 COMPARE_SCALAR_FIELD(subtype);
954 COMPARE_STRING_FIELD(name);
955 COMPARE_NODE_FIELD(def);
956 COMPARE_NODE_FIELD(transform);
957 COMPARE_SCALAR_FIELD(behavior);
959 return true;
962 static bool
963 _equalAlterDomainStmt(AlterDomainStmt *a, AlterDomainStmt *b)
965 COMPARE_SCALAR_FIELD(subtype);
966 COMPARE_NODE_FIELD(typename);
967 COMPARE_STRING_FIELD(name);
968 COMPARE_NODE_FIELD(def);
969 COMPARE_SCALAR_FIELD(behavior);
971 return true;
974 static bool
975 _equalGrantStmt(GrantStmt *a, GrantStmt *b)
977 COMPARE_SCALAR_FIELD(is_grant);
978 COMPARE_SCALAR_FIELD(objtype);
979 COMPARE_NODE_FIELD(objects);
980 COMPARE_NODE_FIELD(privileges);
981 COMPARE_NODE_FIELD(grantees);
982 COMPARE_SCALAR_FIELD(grant_option);
983 COMPARE_SCALAR_FIELD(behavior);
985 return true;
988 static bool
989 _equalPrivGrantee(PrivGrantee *a, PrivGrantee *b)
991 COMPARE_STRING_FIELD(rolname);
993 return true;
996 static bool
997 _equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
999 COMPARE_NODE_FIELD(funcname);
1000 COMPARE_NODE_FIELD(funcargs);
1002 return true;
1005 static bool
1006 _equalAccessPriv(AccessPriv *a, AccessPriv *b)
1008 COMPARE_STRING_FIELD(priv_name);
1009 COMPARE_NODE_FIELD(cols);
1011 return true;
1014 static bool
1015 _equalGrantRoleStmt(GrantRoleStmt *a, GrantRoleStmt *b)
1017 COMPARE_NODE_FIELD(granted_roles);
1018 COMPARE_NODE_FIELD(grantee_roles);
1019 COMPARE_SCALAR_FIELD(is_grant);
1020 COMPARE_SCALAR_FIELD(admin_opt);
1021 COMPARE_STRING_FIELD(grantor);
1022 COMPARE_SCALAR_FIELD(behavior);
1024 return true;
1027 static bool
1028 _equalDeclareCursorStmt(DeclareCursorStmt *a, DeclareCursorStmt *b)
1030 COMPARE_STRING_FIELD(portalname);
1031 COMPARE_SCALAR_FIELD(options);
1032 COMPARE_NODE_FIELD(query);
1034 return true;
1037 static bool
1038 _equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
1040 COMPARE_STRING_FIELD(portalname);
1042 return true;
1045 static bool
1046 _equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
1048 COMPARE_NODE_FIELD(relation);
1049 COMPARE_STRING_FIELD(indexname);
1050 COMPARE_SCALAR_FIELD(verbose);
1052 return true;
1055 static bool
1056 _equalCopyStmt(CopyStmt *a, CopyStmt *b)
1058 COMPARE_NODE_FIELD(relation);
1059 COMPARE_NODE_FIELD(query);
1060 COMPARE_NODE_FIELD(attlist);
1061 COMPARE_SCALAR_FIELD(is_from);
1062 COMPARE_STRING_FIELD(filename);
1063 COMPARE_NODE_FIELD(options);
1065 return true;
1068 static bool
1069 _equalCreateStmt(CreateStmt *a, CreateStmt *b)
1071 COMPARE_NODE_FIELD(relation);
1072 COMPARE_NODE_FIELD(tableElts);
1073 COMPARE_NODE_FIELD(inhRelations);
1074 COMPARE_NODE_FIELD(constraints);
1075 COMPARE_NODE_FIELD(options);
1076 COMPARE_SCALAR_FIELD(oncommit);
1077 COMPARE_STRING_FIELD(tablespacename);
1079 return true;
1082 static bool
1083 _equalInhRelation(InhRelation *a, InhRelation *b)
1085 COMPARE_NODE_FIELD(relation);
1086 COMPARE_NODE_FIELD(options);
1088 return true;
1091 static bool
1092 _equalDefineStmt(DefineStmt *a, DefineStmt *b)
1094 COMPARE_SCALAR_FIELD(kind);
1095 COMPARE_SCALAR_FIELD(oldstyle);
1096 COMPARE_NODE_FIELD(defnames);
1097 COMPARE_NODE_FIELD(args);
1098 COMPARE_NODE_FIELD(definition);
1100 return true;
1103 static bool
1104 _equalDropStmt(DropStmt *a, DropStmt *b)
1106 COMPARE_NODE_FIELD(objects);
1107 COMPARE_SCALAR_FIELD(removeType);
1108 COMPARE_SCALAR_FIELD(behavior);
1109 COMPARE_SCALAR_FIELD(missing_ok);
1111 return true;
1114 static bool
1115 _equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
1117 COMPARE_NODE_FIELD(relations);
1118 COMPARE_SCALAR_FIELD(restart_seqs);
1119 COMPARE_SCALAR_FIELD(behavior);
1121 return true;
1124 static bool
1125 _equalCommentStmt(CommentStmt *a, CommentStmt *b)
1127 COMPARE_SCALAR_FIELD(objtype);
1128 COMPARE_NODE_FIELD(objname);
1129 COMPARE_NODE_FIELD(objargs);
1130 COMPARE_STRING_FIELD(comment);
1132 return true;
1135 static bool
1136 _equalFetchStmt(FetchStmt *a, FetchStmt *b)
1138 COMPARE_SCALAR_FIELD(direction);
1139 COMPARE_SCALAR_FIELD(howMany);
1140 COMPARE_STRING_FIELD(portalname);
1141 COMPARE_SCALAR_FIELD(ismove);
1143 return true;
1146 static bool
1147 _equalIndexStmt(IndexStmt *a, IndexStmt *b)
1149 COMPARE_STRING_FIELD(idxname);
1150 COMPARE_NODE_FIELD(relation);
1151 COMPARE_STRING_FIELD(accessMethod);
1152 COMPARE_STRING_FIELD(tableSpace);
1153 COMPARE_NODE_FIELD(indexParams);
1154 COMPARE_NODE_FIELD(options);
1155 COMPARE_NODE_FIELD(whereClause);
1156 COMPARE_SCALAR_FIELD(unique);
1157 COMPARE_SCALAR_FIELD(primary);
1158 COMPARE_SCALAR_FIELD(isconstraint);
1159 COMPARE_SCALAR_FIELD(concurrent);
1161 return true;
1164 static bool
1165 _equalCreateFunctionStmt(CreateFunctionStmt *a, CreateFunctionStmt *b)
1167 COMPARE_SCALAR_FIELD(replace);
1168 COMPARE_NODE_FIELD(funcname);
1169 COMPARE_NODE_FIELD(parameters);
1170 COMPARE_NODE_FIELD(returnType);
1171 COMPARE_NODE_FIELD(options);
1172 COMPARE_NODE_FIELD(withClause);
1174 return true;
1177 static bool
1178 _equalFunctionParameter(FunctionParameter *a, FunctionParameter *b)
1180 COMPARE_STRING_FIELD(name);
1181 COMPARE_NODE_FIELD(argType);
1182 COMPARE_SCALAR_FIELD(mode);
1183 COMPARE_NODE_FIELD(defexpr);
1185 return true;
1188 static bool
1189 _equalAlterFunctionStmt(AlterFunctionStmt *a, AlterFunctionStmt *b)
1191 COMPARE_NODE_FIELD(func);
1192 COMPARE_NODE_FIELD(actions);
1194 return true;
1197 static bool
1198 _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
1200 COMPARE_SCALAR_FIELD(kind);
1201 COMPARE_NODE_FIELD(name);
1202 COMPARE_NODE_FIELD(args);
1203 COMPARE_SCALAR_FIELD(behavior);
1204 COMPARE_SCALAR_FIELD(missing_ok);
1206 return true;
1209 static bool
1210 _equalRemoveOpClassStmt(RemoveOpClassStmt *a, RemoveOpClassStmt *b)
1212 COMPARE_NODE_FIELD(opclassname);
1213 COMPARE_STRING_FIELD(amname);
1214 COMPARE_SCALAR_FIELD(behavior);
1215 COMPARE_SCALAR_FIELD(missing_ok);
1217 return true;
1220 static bool
1221 _equalRemoveOpFamilyStmt(RemoveOpFamilyStmt *a, RemoveOpFamilyStmt *b)
1223 COMPARE_NODE_FIELD(opfamilyname);
1224 COMPARE_STRING_FIELD(amname);
1225 COMPARE_SCALAR_FIELD(behavior);
1226 COMPARE_SCALAR_FIELD(missing_ok);
1228 return true;
1231 static bool
1232 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
1234 COMPARE_SCALAR_FIELD(renameType);
1235 COMPARE_NODE_FIELD(relation);
1236 COMPARE_NODE_FIELD(object);
1237 COMPARE_NODE_FIELD(objarg);
1238 COMPARE_STRING_FIELD(subname);
1239 COMPARE_STRING_FIELD(newname);
1241 return true;
1244 static bool
1245 _equalAlterObjectSchemaStmt(AlterObjectSchemaStmt *a, AlterObjectSchemaStmt *b)
1247 COMPARE_SCALAR_FIELD(objectType);
1248 COMPARE_NODE_FIELD(relation);
1249 COMPARE_NODE_FIELD(object);
1250 COMPARE_NODE_FIELD(objarg);
1251 COMPARE_STRING_FIELD(addname);
1252 COMPARE_STRING_FIELD(newschema);
1254 return true;
1257 static bool
1258 _equalAlterOwnerStmt(AlterOwnerStmt *a, AlterOwnerStmt *b)
1260 COMPARE_SCALAR_FIELD(objectType);
1261 COMPARE_NODE_FIELD(relation);
1262 COMPARE_NODE_FIELD(object);
1263 COMPARE_NODE_FIELD(objarg);
1264 COMPARE_STRING_FIELD(addname);
1265 COMPARE_STRING_FIELD(newowner);
1267 return true;
1270 static bool
1271 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
1273 COMPARE_NODE_FIELD(relation);
1274 COMPARE_STRING_FIELD(rulename);
1275 COMPARE_NODE_FIELD(whereClause);
1276 COMPARE_SCALAR_FIELD(event);
1277 COMPARE_SCALAR_FIELD(instead);
1278 COMPARE_NODE_FIELD(actions);
1279 COMPARE_SCALAR_FIELD(replace);
1281 return true;
1284 static bool
1285 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1287 COMPARE_STRING_FIELD(conditionname);
1289 return true;
1292 static bool
1293 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1295 COMPARE_STRING_FIELD(conditionname);
1297 return true;
1300 static bool
1301 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1303 COMPARE_STRING_FIELD(conditionname);
1305 return true;
1308 static bool
1309 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1311 COMPARE_SCALAR_FIELD(kind);
1312 COMPARE_NODE_FIELD(options);
1313 COMPARE_STRING_FIELD(gid);
1315 return true;
1318 static bool
1319 _equalCompositeTypeStmt(CompositeTypeStmt *a, CompositeTypeStmt *b)
1321 COMPARE_NODE_FIELD(typevar);
1322 COMPARE_NODE_FIELD(coldeflist);
1324 return true;
1327 static bool
1328 _equalCreateEnumStmt(CreateEnumStmt *a, CreateEnumStmt *b)
1330 COMPARE_NODE_FIELD(typename);
1331 COMPARE_NODE_FIELD(vals);
1333 return true;
1336 static bool
1337 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1339 COMPARE_NODE_FIELD(view);
1340 COMPARE_NODE_FIELD(aliases);
1341 COMPARE_NODE_FIELD(query);
1342 COMPARE_SCALAR_FIELD(replace);
1344 return true;
1347 static bool
1348 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1350 COMPARE_STRING_FIELD(filename);
1352 return true;
1355 static bool
1356 _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
1358 COMPARE_NODE_FIELD(domainname);
1359 COMPARE_NODE_FIELD(typename);
1360 COMPARE_NODE_FIELD(constraints);
1362 return true;
1365 static bool
1366 _equalCreateOpClassStmt(CreateOpClassStmt *a, CreateOpClassStmt *b)
1368 COMPARE_NODE_FIELD(opclassname);
1369 COMPARE_NODE_FIELD(opfamilyname);
1370 COMPARE_STRING_FIELD(amname);
1371 COMPARE_NODE_FIELD(datatype);
1372 COMPARE_NODE_FIELD(items);
1373 COMPARE_SCALAR_FIELD(isDefault);
1375 return true;
1378 static bool
1379 _equalCreateOpClassItem(CreateOpClassItem *a, CreateOpClassItem *b)
1381 COMPARE_SCALAR_FIELD(itemtype);
1382 COMPARE_NODE_FIELD(name);
1383 COMPARE_NODE_FIELD(args);
1384 COMPARE_SCALAR_FIELD(number);
1385 COMPARE_NODE_FIELD(class_args);
1386 COMPARE_NODE_FIELD(storedtype);
1388 return true;
1391 static bool
1392 _equalCreateOpFamilyStmt(CreateOpFamilyStmt *a, CreateOpFamilyStmt *b)
1394 COMPARE_NODE_FIELD(opfamilyname);
1395 COMPARE_STRING_FIELD(amname);
1397 return true;
1400 static bool
1401 _equalAlterOpFamilyStmt(AlterOpFamilyStmt *a, AlterOpFamilyStmt *b)
1403 COMPARE_NODE_FIELD(opfamilyname);
1404 COMPARE_STRING_FIELD(amname);
1405 COMPARE_SCALAR_FIELD(isDrop);
1406 COMPARE_NODE_FIELD(items);
1408 return true;
1411 static bool
1412 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1414 COMPARE_STRING_FIELD(dbname);
1415 COMPARE_NODE_FIELD(options);
1417 return true;
1420 static bool
1421 _equalAlterDatabaseStmt(AlterDatabaseStmt *a, AlterDatabaseStmt *b)
1423 COMPARE_STRING_FIELD(dbname);
1424 COMPARE_NODE_FIELD(options);
1426 return true;
1429 static bool
1430 _equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
1432 COMPARE_STRING_FIELD(dbname);
1433 COMPARE_NODE_FIELD(setstmt);
1435 return true;
1438 static bool
1439 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1441 COMPARE_STRING_FIELD(dbname);
1442 COMPARE_SCALAR_FIELD(missing_ok);
1444 return true;
1447 static bool
1448 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1450 COMPARE_SCALAR_FIELD(vacuum);
1451 COMPARE_SCALAR_FIELD(full);
1452 COMPARE_SCALAR_FIELD(analyze);
1453 COMPARE_SCALAR_FIELD(verbose);
1454 COMPARE_SCALAR_FIELD(freeze_min_age);
1455 COMPARE_SCALAR_FIELD(freeze_table_age);
1456 COMPARE_NODE_FIELD(relation);
1457 COMPARE_NODE_FIELD(va_cols);
1459 return true;
1462 static bool
1463 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1465 COMPARE_NODE_FIELD(query);
1466 COMPARE_SCALAR_FIELD(verbose);
1467 COMPARE_SCALAR_FIELD(analyze);
1469 return true;
1472 static bool
1473 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1475 COMPARE_NODE_FIELD(sequence);
1476 COMPARE_NODE_FIELD(options);
1478 return true;
1481 static bool
1482 _equalAlterSeqStmt(AlterSeqStmt *a, AlterSeqStmt *b)
1484 COMPARE_NODE_FIELD(sequence);
1485 COMPARE_NODE_FIELD(options);
1487 return true;
1490 static bool
1491 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1493 COMPARE_SCALAR_FIELD(kind);
1494 COMPARE_STRING_FIELD(name);
1495 COMPARE_NODE_FIELD(args);
1496 COMPARE_SCALAR_FIELD(is_local);
1498 return true;
1501 static bool
1502 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1504 COMPARE_STRING_FIELD(name);
1506 return true;
1509 static bool
1510 _equalDiscardStmt(DiscardStmt *a, DiscardStmt *b)
1512 COMPARE_SCALAR_FIELD(target);
1514 return true;
1517 static bool
1518 _equalCreateTableSpaceStmt(CreateTableSpaceStmt *a, CreateTableSpaceStmt *b)
1520 COMPARE_STRING_FIELD(tablespacename);
1521 COMPARE_STRING_FIELD(owner);
1522 COMPARE_STRING_FIELD(location);
1524 return true;
1527 static bool
1528 _equalDropTableSpaceStmt(DropTableSpaceStmt *a, DropTableSpaceStmt *b)
1530 COMPARE_STRING_FIELD(tablespacename);
1531 COMPARE_SCALAR_FIELD(missing_ok);
1533 return true;
1536 static bool
1537 _equalCreateFdwStmt(CreateFdwStmt *a, CreateFdwStmt *b)
1539 COMPARE_STRING_FIELD(fdwname);
1540 COMPARE_NODE_FIELD(validator);
1541 COMPARE_NODE_FIELD(options);
1543 return true;
1546 static bool
1547 _equalAlterFdwStmt(AlterFdwStmt *a, AlterFdwStmt *b)
1549 COMPARE_STRING_FIELD(fdwname);
1550 COMPARE_NODE_FIELD(validator);
1551 COMPARE_SCALAR_FIELD(change_validator);
1552 COMPARE_NODE_FIELD(options);
1554 return true;
1557 static bool
1558 _equalDropFdwStmt(DropFdwStmt *a, DropFdwStmt *b)
1560 COMPARE_STRING_FIELD(fdwname);
1561 COMPARE_SCALAR_FIELD(missing_ok);
1562 COMPARE_SCALAR_FIELD(behavior);
1564 return true;
1567 static bool
1568 _equalCreateForeignServerStmt(CreateForeignServerStmt *a, CreateForeignServerStmt *b)
1570 COMPARE_STRING_FIELD(servername);
1571 COMPARE_STRING_FIELD(servertype);
1572 COMPARE_STRING_FIELD(version);
1573 COMPARE_STRING_FIELD(fdwname);
1574 COMPARE_NODE_FIELD(options);
1576 return true;
1579 static bool
1580 _equalAlterForeignServerStmt(AlterForeignServerStmt *a, AlterForeignServerStmt *b)
1582 COMPARE_STRING_FIELD(servername);
1583 COMPARE_STRING_FIELD(version);
1584 COMPARE_NODE_FIELD(options);
1585 COMPARE_SCALAR_FIELD(has_version);
1587 return true;
1590 static bool
1591 _equalDropForeignServerStmt(DropForeignServerStmt *a, DropForeignServerStmt *b)
1593 COMPARE_STRING_FIELD(servername);
1594 COMPARE_SCALAR_FIELD(missing_ok);
1595 COMPARE_SCALAR_FIELD(behavior);
1597 return true;
1600 static bool
1601 _equalCreateUserMappingStmt(CreateUserMappingStmt *a, CreateUserMappingStmt *b)
1603 COMPARE_STRING_FIELD(username);
1604 COMPARE_STRING_FIELD(servername);
1605 COMPARE_NODE_FIELD(options);
1607 return true;
1610 static bool
1611 _equalAlterUserMappingStmt(AlterUserMappingStmt *a, AlterUserMappingStmt *b)
1613 COMPARE_STRING_FIELD(username);
1614 COMPARE_STRING_FIELD(servername);
1615 COMPARE_NODE_FIELD(options);
1617 return true;
1620 static bool
1621 _equalDropUserMappingStmt(DropUserMappingStmt *a, DropUserMappingStmt *b)
1623 COMPARE_STRING_FIELD(username);
1624 COMPARE_STRING_FIELD(servername);
1625 COMPARE_SCALAR_FIELD(missing_ok);
1627 return true;
1630 static bool
1631 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1633 COMPARE_STRING_FIELD(trigname);
1634 COMPARE_NODE_FIELD(relation);
1635 COMPARE_NODE_FIELD(funcname);
1636 COMPARE_NODE_FIELD(args);
1637 COMPARE_SCALAR_FIELD(before);
1638 COMPARE_SCALAR_FIELD(row);
1639 if (strcmp(a->actions, b->actions) != 0) /* in-line string field */
1640 return false;
1641 COMPARE_SCALAR_FIELD(isconstraint);
1642 COMPARE_SCALAR_FIELD(deferrable);
1643 COMPARE_SCALAR_FIELD(initdeferred);
1644 COMPARE_NODE_FIELD(constrrel);
1646 return true;
1649 static bool
1650 _equalDropPropertyStmt(DropPropertyStmt *a, DropPropertyStmt *b)
1652 COMPARE_NODE_FIELD(relation);
1653 COMPARE_STRING_FIELD(property);
1654 COMPARE_SCALAR_FIELD(removeType);
1655 COMPARE_SCALAR_FIELD(behavior);
1656 COMPARE_SCALAR_FIELD(missing_ok);
1658 return true;
1661 static bool
1662 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1664 COMPARE_STRING_FIELD(plname);
1665 COMPARE_NODE_FIELD(plhandler);
1666 COMPARE_NODE_FIELD(plvalidator);
1667 COMPARE_SCALAR_FIELD(pltrusted);
1669 return true;
1672 static bool
1673 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1675 COMPARE_STRING_FIELD(plname);
1676 COMPARE_SCALAR_FIELD(behavior);
1677 COMPARE_SCALAR_FIELD(missing_ok);
1679 return true;
1682 static bool
1683 _equalCreateRoleStmt(CreateRoleStmt *a, CreateRoleStmt *b)
1685 COMPARE_SCALAR_FIELD(stmt_type);
1686 COMPARE_STRING_FIELD(role);
1687 COMPARE_NODE_FIELD(options);
1689 return true;
1692 static bool
1693 _equalAlterRoleStmt(AlterRoleStmt *a, AlterRoleStmt *b)
1695 COMPARE_STRING_FIELD(role);
1696 COMPARE_NODE_FIELD(options);
1697 COMPARE_SCALAR_FIELD(action);
1699 return true;
1702 static bool
1703 _equalAlterRoleSetStmt(AlterRoleSetStmt *a, AlterRoleSetStmt *b)
1705 COMPARE_STRING_FIELD(role);
1706 COMPARE_NODE_FIELD(setstmt);
1708 return true;
1711 static bool
1712 _equalDropRoleStmt(DropRoleStmt *a, DropRoleStmt *b)
1714 COMPARE_NODE_FIELD(roles);
1715 COMPARE_SCALAR_FIELD(missing_ok);
1717 return true;
1720 static bool
1721 _equalLockStmt(LockStmt *a, LockStmt *b)
1723 COMPARE_NODE_FIELD(relations);
1724 COMPARE_SCALAR_FIELD(mode);
1725 COMPARE_SCALAR_FIELD(nowait);
1727 return true;
1730 static bool
1731 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1733 COMPARE_NODE_FIELD(constraints);
1734 COMPARE_SCALAR_FIELD(deferred);
1736 return true;
1739 static bool
1740 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1742 COMPARE_SCALAR_FIELD(kind);
1743 COMPARE_NODE_FIELD(relation);
1744 COMPARE_STRING_FIELD(name);
1745 COMPARE_SCALAR_FIELD(do_system);
1746 COMPARE_SCALAR_FIELD(do_user);
1748 return true;
1751 static bool
1752 _equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
1754 COMPARE_STRING_FIELD(schemaname);
1755 COMPARE_STRING_FIELD(authid);
1756 COMPARE_NODE_FIELD(schemaElts);
1758 return true;
1761 static bool
1762 _equalCreateConversionStmt(CreateConversionStmt *a, CreateConversionStmt *b)
1764 COMPARE_NODE_FIELD(conversion_name);
1765 COMPARE_STRING_FIELD(for_encoding_name);
1766 COMPARE_STRING_FIELD(to_encoding_name);
1767 COMPARE_NODE_FIELD(func_name);
1768 COMPARE_SCALAR_FIELD(def);
1770 return true;
1773 static bool
1774 _equalCreateCastStmt(CreateCastStmt *a, CreateCastStmt *b)
1776 COMPARE_NODE_FIELD(sourcetype);
1777 COMPARE_NODE_FIELD(targettype);
1778 COMPARE_NODE_FIELD(func);
1779 COMPARE_SCALAR_FIELD(context);
1780 COMPARE_SCALAR_FIELD(inout);
1782 return true;
1785 static bool
1786 _equalDropCastStmt(DropCastStmt *a, DropCastStmt *b)
1788 COMPARE_NODE_FIELD(sourcetype);
1789 COMPARE_NODE_FIELD(targettype);
1790 COMPARE_SCALAR_FIELD(behavior);
1791 COMPARE_SCALAR_FIELD(missing_ok);
1793 return true;
1796 static bool
1797 _equalPrepareStmt(PrepareStmt *a, PrepareStmt *b)
1799 COMPARE_STRING_FIELD(name);
1800 COMPARE_NODE_FIELD(argtypes);
1801 COMPARE_NODE_FIELD(query);
1803 return true;
1806 static bool
1807 _equalExecuteStmt(ExecuteStmt *a, ExecuteStmt *b)
1809 COMPARE_STRING_FIELD(name);
1810 COMPARE_NODE_FIELD(into);
1811 COMPARE_NODE_FIELD(params);
1813 return true;
1816 static bool
1817 _equalDeallocateStmt(DeallocateStmt *a, DeallocateStmt *b)
1819 COMPARE_STRING_FIELD(name);
1821 return true;
1824 static bool
1825 _equalDropOwnedStmt(DropOwnedStmt *a, DropOwnedStmt *b)
1827 COMPARE_NODE_FIELD(roles);
1828 COMPARE_SCALAR_FIELD(behavior);
1830 return true;
1833 static bool
1834 _equalReassignOwnedStmt(ReassignOwnedStmt *a, ReassignOwnedStmt *b)
1836 COMPARE_NODE_FIELD(roles);
1837 COMPARE_NODE_FIELD(newrole);
1839 return true;
1842 static bool
1843 _equalAlterTSDictionaryStmt(AlterTSDictionaryStmt *a, AlterTSDictionaryStmt *b)
1845 COMPARE_NODE_FIELD(dictname);
1846 COMPARE_NODE_FIELD(options);
1848 return true;
1851 static bool
1852 _equalAlterTSConfigurationStmt(AlterTSConfigurationStmt *a,
1853 AlterTSConfigurationStmt *b)
1855 COMPARE_NODE_FIELD(cfgname);
1856 COMPARE_NODE_FIELD(tokentype);
1857 COMPARE_NODE_FIELD(dicts);
1858 COMPARE_SCALAR_FIELD(override);
1859 COMPARE_SCALAR_FIELD(replace);
1860 COMPARE_SCALAR_FIELD(missing_ok);
1862 return true;
1865 static bool
1866 _equalAExpr(A_Expr *a, A_Expr *b)
1868 COMPARE_SCALAR_FIELD(kind);
1869 COMPARE_NODE_FIELD(name);
1870 COMPARE_NODE_FIELD(lexpr);
1871 COMPARE_NODE_FIELD(rexpr);
1872 COMPARE_LOCATION_FIELD(location);
1874 return true;
1877 static bool
1878 _equalColumnRef(ColumnRef *a, ColumnRef *b)
1880 COMPARE_NODE_FIELD(fields);
1881 COMPARE_LOCATION_FIELD(location);
1883 return true;
1886 static bool
1887 _equalParamRef(ParamRef *a, ParamRef *b)
1889 COMPARE_SCALAR_FIELD(number);
1890 COMPARE_LOCATION_FIELD(location);
1892 return true;
1895 static bool
1896 _equalAConst(A_Const *a, A_Const *b)
1898 if (!equal(&a->val, &b->val)) /* hack for in-line Value field */
1899 return false;
1900 COMPARE_LOCATION_FIELD(location);
1902 return true;
1905 static bool
1906 _equalFuncCall(FuncCall *a, FuncCall *b)
1908 COMPARE_NODE_FIELD(funcname);
1909 COMPARE_NODE_FIELD(args);
1910 COMPARE_SCALAR_FIELD(agg_star);
1911 COMPARE_SCALAR_FIELD(agg_distinct);
1912 COMPARE_SCALAR_FIELD(func_variadic);
1913 COMPARE_NODE_FIELD(over);
1914 COMPARE_LOCATION_FIELD(location);
1916 return true;
1919 static bool
1920 _equalAStar(A_Star *a, A_Star *b)
1922 return true;
1925 static bool
1926 _equalAIndices(A_Indices *a, A_Indices *b)
1928 COMPARE_NODE_FIELD(lidx);
1929 COMPARE_NODE_FIELD(uidx);
1931 return true;
1934 static bool
1935 _equalA_Indirection(A_Indirection *a, A_Indirection *b)
1937 COMPARE_NODE_FIELD(arg);
1938 COMPARE_NODE_FIELD(indirection);
1940 return true;
1943 static bool
1944 _equalA_ArrayExpr(A_ArrayExpr *a, A_ArrayExpr *b)
1946 COMPARE_NODE_FIELD(elements);
1947 COMPARE_LOCATION_FIELD(location);
1949 return true;
1952 static bool
1953 _equalResTarget(ResTarget *a, ResTarget *b)
1955 COMPARE_STRING_FIELD(name);
1956 COMPARE_NODE_FIELD(indirection);
1957 COMPARE_NODE_FIELD(val);
1958 COMPARE_LOCATION_FIELD(location);
1960 return true;
1963 static bool
1964 _equalTypeName(TypeName *a, TypeName *b)
1966 COMPARE_NODE_FIELD(names);
1967 COMPARE_SCALAR_FIELD(typeid);
1968 COMPARE_SCALAR_FIELD(setof);
1969 COMPARE_SCALAR_FIELD(pct_type);
1970 COMPARE_NODE_FIELD(typmods);
1971 COMPARE_SCALAR_FIELD(typemod);
1972 COMPARE_NODE_FIELD(arrayBounds);
1973 COMPARE_LOCATION_FIELD(location);
1975 return true;
1978 static bool
1979 _equalTypeCast(TypeCast *a, TypeCast *b)
1981 COMPARE_NODE_FIELD(arg);
1982 COMPARE_NODE_FIELD(typename);
1983 COMPARE_LOCATION_FIELD(location);
1985 return true;
1988 static bool
1989 _equalSortBy(SortBy *a, SortBy *b)
1991 COMPARE_NODE_FIELD(node);
1992 COMPARE_SCALAR_FIELD(sortby_dir);
1993 COMPARE_SCALAR_FIELD(sortby_nulls);
1994 COMPARE_NODE_FIELD(useOp);
1995 COMPARE_LOCATION_FIELD(location);
1997 return true;
2000 static bool
2001 _equalWindowDef(WindowDef *a, WindowDef *b)
2003 COMPARE_STRING_FIELD(name);
2004 COMPARE_STRING_FIELD(refname);
2005 COMPARE_NODE_FIELD(partitionClause);
2006 COMPARE_NODE_FIELD(orderClause);
2007 COMPARE_SCALAR_FIELD(frameOptions);
2008 COMPARE_LOCATION_FIELD(location);
2010 return true;
2013 static bool
2014 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
2016 COMPARE_NODE_FIELD(subquery);
2017 COMPARE_NODE_FIELD(alias);
2019 return true;
2022 static bool
2023 _equalRangeFunction(RangeFunction *a, RangeFunction *b)
2025 COMPARE_NODE_FIELD(funccallnode);
2026 COMPARE_NODE_FIELD(alias);
2027 COMPARE_NODE_FIELD(coldeflist);
2029 return true;
2032 static bool
2033 _equalIndexElem(IndexElem *a, IndexElem *b)
2035 COMPARE_STRING_FIELD(name);
2036 COMPARE_NODE_FIELD(expr);
2037 COMPARE_NODE_FIELD(opclass);
2038 COMPARE_SCALAR_FIELD(ordering);
2039 COMPARE_SCALAR_FIELD(nulls_ordering);
2041 return true;
2044 static bool
2045 _equalColumnDef(ColumnDef *a, ColumnDef *b)
2047 COMPARE_STRING_FIELD(colname);
2048 COMPARE_NODE_FIELD(typename);
2049 COMPARE_SCALAR_FIELD(inhcount);
2050 COMPARE_SCALAR_FIELD(is_local);
2051 COMPARE_SCALAR_FIELD(is_not_null);
2052 COMPARE_NODE_FIELD(raw_default);
2053 COMPARE_STRING_FIELD(cooked_default);
2054 COMPARE_NODE_FIELD(constraints);
2056 return true;
2059 static bool
2060 _equalConstraint(Constraint *a, Constraint *b)
2062 COMPARE_SCALAR_FIELD(contype);
2063 COMPARE_STRING_FIELD(name);
2064 COMPARE_NODE_FIELD(raw_expr);
2065 COMPARE_STRING_FIELD(cooked_expr);
2066 COMPARE_NODE_FIELD(keys);
2067 COMPARE_NODE_FIELD(options);
2068 COMPARE_STRING_FIELD(indexspace);
2070 return true;
2073 static bool
2074 _equalDefElem(DefElem *a, DefElem *b)
2076 COMPARE_STRING_FIELD(defname);
2077 COMPARE_NODE_FIELD(arg);
2079 return true;
2082 static bool
2083 _equalOptionDefElem(OptionDefElem *a, OptionDefElem *b)
2085 COMPARE_SCALAR_FIELD(alter_op);
2086 COMPARE_NODE_FIELD(def);
2088 return true;
2091 static bool
2092 _equalReloptElem(ReloptElem *a, ReloptElem *b)
2094 COMPARE_STRING_FIELD(nmspc);
2095 COMPARE_STRING_FIELD(optname);
2096 COMPARE_NODE_FIELD(arg);
2098 return true;
2101 static bool
2102 _equalLockingClause(LockingClause *a, LockingClause *b)
2104 COMPARE_NODE_FIELD(lockedRels);
2105 COMPARE_SCALAR_FIELD(forUpdate);
2106 COMPARE_SCALAR_FIELD(noWait);
2108 return true;
2111 static bool
2112 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
2114 COMPARE_SCALAR_FIELD(rtekind);
2115 COMPARE_SCALAR_FIELD(relid);
2116 COMPARE_NODE_FIELD(subquery);
2117 COMPARE_SCALAR_FIELD(jointype);
2118 COMPARE_NODE_FIELD(joinaliasvars);
2119 COMPARE_NODE_FIELD(funcexpr);
2120 COMPARE_NODE_FIELD(funccoltypes);
2121 COMPARE_NODE_FIELD(funccoltypmods);
2122 COMPARE_NODE_FIELD(values_lists);
2123 COMPARE_STRING_FIELD(ctename);
2124 COMPARE_SCALAR_FIELD(ctelevelsup);
2125 COMPARE_SCALAR_FIELD(self_reference);
2126 COMPARE_NODE_FIELD(ctecoltypes);
2127 COMPARE_NODE_FIELD(ctecoltypmods);
2128 COMPARE_NODE_FIELD(alias);
2129 COMPARE_NODE_FIELD(eref);
2130 COMPARE_SCALAR_FIELD(inh);
2131 COMPARE_SCALAR_FIELD(inFromCl);
2132 COMPARE_SCALAR_FIELD(requiredPerms);
2133 COMPARE_SCALAR_FIELD(checkAsUser);
2134 COMPARE_BITMAPSET_FIELD(selectedCols);
2135 COMPARE_BITMAPSET_FIELD(modifiedCols);
2137 return true;
2140 static bool
2141 _equalSortGroupClause(SortGroupClause *a, SortGroupClause *b)
2143 COMPARE_SCALAR_FIELD(tleSortGroupRef);
2144 COMPARE_SCALAR_FIELD(eqop);
2145 COMPARE_SCALAR_FIELD(sortop);
2146 COMPARE_SCALAR_FIELD(nulls_first);
2148 return true;
2151 static bool
2152 _equalWindowClause(WindowClause *a, WindowClause *b)
2154 COMPARE_STRING_FIELD(name);
2155 COMPARE_STRING_FIELD(refname);
2156 COMPARE_NODE_FIELD(partitionClause);
2157 COMPARE_NODE_FIELD(orderClause);
2158 COMPARE_SCALAR_FIELD(frameOptions);
2159 COMPARE_SCALAR_FIELD(winref);
2160 COMPARE_SCALAR_FIELD(copiedOrder);
2162 return true;
2165 static bool
2166 _equalRowMarkClause(RowMarkClause *a, RowMarkClause *b)
2168 COMPARE_SCALAR_FIELD(rti);
2169 COMPARE_SCALAR_FIELD(prti);
2170 COMPARE_SCALAR_FIELD(forUpdate);
2171 COMPARE_SCALAR_FIELD(noWait);
2172 COMPARE_SCALAR_FIELD(isParent);
2174 return true;
2177 static bool
2178 _equalWithClause(WithClause *a, WithClause *b)
2180 COMPARE_NODE_FIELD(ctes);
2181 COMPARE_SCALAR_FIELD(recursive);
2182 COMPARE_LOCATION_FIELD(location);
2184 return true;
2187 static bool
2188 _equalCommonTableExpr(CommonTableExpr *a, CommonTableExpr *b)
2190 COMPARE_STRING_FIELD(ctename);
2191 COMPARE_NODE_FIELD(aliascolnames);
2192 COMPARE_NODE_FIELD(ctequery);
2193 COMPARE_LOCATION_FIELD(location);
2194 COMPARE_SCALAR_FIELD(cterecursive);
2195 COMPARE_SCALAR_FIELD(cterefcount);
2196 COMPARE_NODE_FIELD(ctecolnames);
2197 COMPARE_NODE_FIELD(ctecoltypes);
2198 COMPARE_NODE_FIELD(ctecoltypmods);
2200 return true;
2203 static bool
2204 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
2206 COMPARE_STRING_FIELD(constr_name);
2207 COMPARE_NODE_FIELD(pktable);
2208 COMPARE_NODE_FIELD(fk_attrs);
2209 COMPARE_NODE_FIELD(pk_attrs);
2210 COMPARE_SCALAR_FIELD(fk_matchtype);
2211 COMPARE_SCALAR_FIELD(fk_upd_action);
2212 COMPARE_SCALAR_FIELD(fk_del_action);
2213 COMPARE_SCALAR_FIELD(deferrable);
2214 COMPARE_SCALAR_FIELD(initdeferred);
2215 COMPARE_SCALAR_FIELD(skip_validation);
2217 return true;
2220 static bool
2221 _equalXmlSerialize(XmlSerialize *a, XmlSerialize *b)
2223 COMPARE_SCALAR_FIELD(xmloption);
2224 COMPARE_NODE_FIELD(expr);
2225 COMPARE_NODE_FIELD(typename);
2226 COMPARE_LOCATION_FIELD(location);
2228 return true;
2232 * Stuff from pg_list.h
2235 static bool
2236 _equalList(List *a, List *b)
2238 ListCell *item_a;
2239 ListCell *item_b;
2242 * Try to reject by simple scalar checks before grovelling through all the
2243 * list elements...
2245 COMPARE_SCALAR_FIELD(type);
2246 COMPARE_SCALAR_FIELD(length);
2249 * We place the switch outside the loop for the sake of efficiency; this
2250 * may not be worth doing...
2252 switch (a->type)
2254 case T_List:
2255 forboth(item_a, a, item_b, b)
2257 if (!equal(lfirst(item_a), lfirst(item_b)))
2258 return false;
2260 break;
2261 case T_IntList:
2262 forboth(item_a, a, item_b, b)
2264 if (lfirst_int(item_a) != lfirst_int(item_b))
2265 return false;
2267 break;
2268 case T_OidList:
2269 forboth(item_a, a, item_b, b)
2271 if (lfirst_oid(item_a) != lfirst_oid(item_b))
2272 return false;
2274 break;
2275 default:
2276 elog(ERROR, "unrecognized list node type: %d",
2277 (int) a->type);
2278 return false; /* keep compiler quiet */
2282 * If we got here, we should have run out of elements of both lists
2284 Assert(item_a == NULL);
2285 Assert(item_b == NULL);
2287 return true;
2291 * Stuff from value.h
2294 static bool
2295 _equalValue(Value *a, Value *b)
2297 COMPARE_SCALAR_FIELD(type);
2299 switch (a->type)
2301 case T_Integer:
2302 COMPARE_SCALAR_FIELD(val.ival);
2303 break;
2304 case T_Float:
2305 case T_String:
2306 case T_BitString:
2307 COMPARE_STRING_FIELD(val.str);
2308 break;
2309 case T_Null:
2310 /* nothing to do */
2311 break;
2312 default:
2313 elog(ERROR, "unrecognized node type: %d", (int) a->type);
2314 break;
2317 return true;
2321 * equal
2322 * returns whether two nodes are equal
2324 bool
2325 equal(void *a, void *b)
2327 bool retval;
2329 if (a == b)
2330 return true;
2333 * note that a!=b, so only one of them can be NULL
2335 if (a == NULL || b == NULL)
2336 return false;
2339 * are they the same type of nodes?
2341 if (nodeTag(a) != nodeTag(b))
2342 return false;
2344 switch (nodeTag(a))
2347 * PRIMITIVE NODES
2349 case T_Alias:
2350 retval = _equalAlias(a, b);
2351 break;
2352 case T_RangeVar:
2353 retval = _equalRangeVar(a, b);
2354 break;
2355 case T_IntoClause:
2356 retval = _equalIntoClause(a, b);
2357 break;
2358 case T_Var:
2359 retval = _equalVar(a, b);
2360 break;
2361 case T_Const:
2362 retval = _equalConst(a, b);
2363 break;
2364 case T_Param:
2365 retval = _equalParam(a, b);
2366 break;
2367 case T_Aggref:
2368 retval = _equalAggref(a, b);
2369 break;
2370 case T_WindowFunc:
2371 retval = _equalWindowFunc(a, b);
2372 break;
2373 case T_ArrayRef:
2374 retval = _equalArrayRef(a, b);
2375 break;
2376 case T_FuncExpr:
2377 retval = _equalFuncExpr(a, b);
2378 break;
2379 case T_OpExpr:
2380 retval = _equalOpExpr(a, b);
2381 break;
2382 case T_DistinctExpr:
2383 retval = _equalDistinctExpr(a, b);
2384 break;
2385 case T_ScalarArrayOpExpr:
2386 retval = _equalScalarArrayOpExpr(a, b);
2387 break;
2388 case T_BoolExpr:
2389 retval = _equalBoolExpr(a, b);
2390 break;
2391 case T_SubLink:
2392 retval = _equalSubLink(a, b);
2393 break;
2394 case T_SubPlan:
2395 retval = _equalSubPlan(a, b);
2396 break;
2397 case T_AlternativeSubPlan:
2398 retval = _equalAlternativeSubPlan(a, b);
2399 break;
2400 case T_FieldSelect:
2401 retval = _equalFieldSelect(a, b);
2402 break;
2403 case T_FieldStore:
2404 retval = _equalFieldStore(a, b);
2405 break;
2406 case T_RelabelType:
2407 retval = _equalRelabelType(a, b);
2408 break;
2409 case T_CoerceViaIO:
2410 retval = _equalCoerceViaIO(a, b);
2411 break;
2412 case T_ArrayCoerceExpr:
2413 retval = _equalArrayCoerceExpr(a, b);
2414 break;
2415 case T_ConvertRowtypeExpr:
2416 retval = _equalConvertRowtypeExpr(a, b);
2417 break;
2418 case T_CaseExpr:
2419 retval = _equalCaseExpr(a, b);
2420 break;
2421 case T_CaseWhen:
2422 retval = _equalCaseWhen(a, b);
2423 break;
2424 case T_CaseTestExpr:
2425 retval = _equalCaseTestExpr(a, b);
2426 break;
2427 case T_ArrayExpr:
2428 retval = _equalArrayExpr(a, b);
2429 break;
2430 case T_RowExpr:
2431 retval = _equalRowExpr(a, b);
2432 break;
2433 case T_RowCompareExpr:
2434 retval = _equalRowCompareExpr(a, b);
2435 break;
2436 case T_CoalesceExpr:
2437 retval = _equalCoalesceExpr(a, b);
2438 break;
2439 case T_MinMaxExpr:
2440 retval = _equalMinMaxExpr(a, b);
2441 break;
2442 case T_XmlExpr:
2443 retval = _equalXmlExpr(a, b);
2444 break;
2445 case T_NullIfExpr:
2446 retval = _equalNullIfExpr(a, b);
2447 break;
2448 case T_NullTest:
2449 retval = _equalNullTest(a, b);
2450 break;
2451 case T_BooleanTest:
2452 retval = _equalBooleanTest(a, b);
2453 break;
2454 case T_CoerceToDomain:
2455 retval = _equalCoerceToDomain(a, b);
2456 break;
2457 case T_CoerceToDomainValue:
2458 retval = _equalCoerceToDomainValue(a, b);
2459 break;
2460 case T_SetToDefault:
2461 retval = _equalSetToDefault(a, b);
2462 break;
2463 case T_CurrentOfExpr:
2464 retval = _equalCurrentOfExpr(a, b);
2465 break;
2466 case T_TargetEntry:
2467 retval = _equalTargetEntry(a, b);
2468 break;
2469 case T_RangeTblRef:
2470 retval = _equalRangeTblRef(a, b);
2471 break;
2472 case T_FromExpr:
2473 retval = _equalFromExpr(a, b);
2474 break;
2475 case T_JoinExpr:
2476 retval = _equalJoinExpr(a, b);
2477 break;
2480 * RELATION NODES
2482 case T_PathKey:
2483 retval = _equalPathKey(a, b);
2484 break;
2485 case T_RestrictInfo:
2486 retval = _equalRestrictInfo(a, b);
2487 break;
2488 case T_PlaceHolderVar:
2489 retval = _equalPlaceHolderVar(a, b);
2490 break;
2491 case T_SpecialJoinInfo:
2492 retval = _equalSpecialJoinInfo(a, b);
2493 break;
2494 case T_AppendRelInfo:
2495 retval = _equalAppendRelInfo(a, b);
2496 break;
2497 case T_PlaceHolderInfo:
2498 retval = _equalPlaceHolderInfo(a, b);
2499 break;
2501 case T_List:
2502 case T_IntList:
2503 case T_OidList:
2504 retval = _equalList(a, b);
2505 break;
2507 case T_Integer:
2508 case T_Float:
2509 case T_String:
2510 case T_BitString:
2511 case T_Null:
2512 retval = _equalValue(a, b);
2513 break;
2516 * PARSE NODES
2518 case T_Query:
2519 retval = _equalQuery(a, b);
2520 break;
2521 case T_InsertStmt:
2522 retval = _equalInsertStmt(a, b);
2523 break;
2524 case T_DeleteStmt:
2525 retval = _equalDeleteStmt(a, b);
2526 break;
2527 case T_UpdateStmt:
2528 retval = _equalUpdateStmt(a, b);
2529 break;
2530 case T_SelectStmt:
2531 retval = _equalSelectStmt(a, b);
2532 break;
2533 case T_SetOperationStmt:
2534 retval = _equalSetOperationStmt(a, b);
2535 break;
2536 case T_AlterTableStmt:
2537 retval = _equalAlterTableStmt(a, b);
2538 break;
2539 case T_AlterTableCmd:
2540 retval = _equalAlterTableCmd(a, b);
2541 break;
2542 case T_AlterDomainStmt:
2543 retval = _equalAlterDomainStmt(a, b);
2544 break;
2545 case T_GrantStmt:
2546 retval = _equalGrantStmt(a, b);
2547 break;
2548 case T_GrantRoleStmt:
2549 retval = _equalGrantRoleStmt(a, b);
2550 break;
2551 case T_DeclareCursorStmt:
2552 retval = _equalDeclareCursorStmt(a, b);
2553 break;
2554 case T_ClosePortalStmt:
2555 retval = _equalClosePortalStmt(a, b);
2556 break;
2557 case T_ClusterStmt:
2558 retval = _equalClusterStmt(a, b);
2559 break;
2560 case T_CopyStmt:
2561 retval = _equalCopyStmt(a, b);
2562 break;
2563 case T_CreateStmt:
2564 retval = _equalCreateStmt(a, b);
2565 break;
2566 case T_InhRelation:
2567 retval = _equalInhRelation(a, b);
2568 break;
2569 case T_DefineStmt:
2570 retval = _equalDefineStmt(a, b);
2571 break;
2572 case T_DropStmt:
2573 retval = _equalDropStmt(a, b);
2574 break;
2575 case T_TruncateStmt:
2576 retval = _equalTruncateStmt(a, b);
2577 break;
2578 case T_CommentStmt:
2579 retval = _equalCommentStmt(a, b);
2580 break;
2581 case T_FetchStmt:
2582 retval = _equalFetchStmt(a, b);
2583 break;
2584 case T_IndexStmt:
2585 retval = _equalIndexStmt(a, b);
2586 break;
2587 case T_CreateFunctionStmt:
2588 retval = _equalCreateFunctionStmt(a, b);
2589 break;
2590 case T_FunctionParameter:
2591 retval = _equalFunctionParameter(a, b);
2592 break;
2593 case T_AlterFunctionStmt:
2594 retval = _equalAlterFunctionStmt(a, b);
2595 break;
2596 case T_RemoveFuncStmt:
2597 retval = _equalRemoveFuncStmt(a, b);
2598 break;
2599 case T_RemoveOpClassStmt:
2600 retval = _equalRemoveOpClassStmt(a, b);
2601 break;
2602 case T_RemoveOpFamilyStmt:
2603 retval = _equalRemoveOpFamilyStmt(a, b);
2604 break;
2605 case T_RenameStmt:
2606 retval = _equalRenameStmt(a, b);
2607 break;
2608 case T_AlterObjectSchemaStmt:
2609 retval = _equalAlterObjectSchemaStmt(a, b);
2610 break;
2611 case T_AlterOwnerStmt:
2612 retval = _equalAlterOwnerStmt(a, b);
2613 break;
2614 case T_RuleStmt:
2615 retval = _equalRuleStmt(a, b);
2616 break;
2617 case T_NotifyStmt:
2618 retval = _equalNotifyStmt(a, b);
2619 break;
2620 case T_ListenStmt:
2621 retval = _equalListenStmt(a, b);
2622 break;
2623 case T_UnlistenStmt:
2624 retval = _equalUnlistenStmt(a, b);
2625 break;
2626 case T_TransactionStmt:
2627 retval = _equalTransactionStmt(a, b);
2628 break;
2629 case T_CompositeTypeStmt:
2630 retval = _equalCompositeTypeStmt(a, b);
2631 break;
2632 case T_CreateEnumStmt:
2633 retval = _equalCreateEnumStmt(a, b);
2634 break;
2635 case T_ViewStmt:
2636 retval = _equalViewStmt(a, b);
2637 break;
2638 case T_LoadStmt:
2639 retval = _equalLoadStmt(a, b);
2640 break;
2641 case T_CreateDomainStmt:
2642 retval = _equalCreateDomainStmt(a, b);
2643 break;
2644 case T_CreateOpClassStmt:
2645 retval = _equalCreateOpClassStmt(a, b);
2646 break;
2647 case T_CreateOpClassItem:
2648 retval = _equalCreateOpClassItem(a, b);
2649 break;
2650 case T_CreateOpFamilyStmt:
2651 retval = _equalCreateOpFamilyStmt(a, b);
2652 break;
2653 case T_AlterOpFamilyStmt:
2654 retval = _equalAlterOpFamilyStmt(a, b);
2655 break;
2656 case T_CreatedbStmt:
2657 retval = _equalCreatedbStmt(a, b);
2658 break;
2659 case T_AlterDatabaseStmt:
2660 retval = _equalAlterDatabaseStmt(a, b);
2661 break;
2662 case T_AlterDatabaseSetStmt:
2663 retval = _equalAlterDatabaseSetStmt(a, b);
2664 break;
2665 case T_DropdbStmt:
2666 retval = _equalDropdbStmt(a, b);
2667 break;
2668 case T_VacuumStmt:
2669 retval = _equalVacuumStmt(a, b);
2670 break;
2671 case T_ExplainStmt:
2672 retval = _equalExplainStmt(a, b);
2673 break;
2674 case T_CreateSeqStmt:
2675 retval = _equalCreateSeqStmt(a, b);
2676 break;
2677 case T_AlterSeqStmt:
2678 retval = _equalAlterSeqStmt(a, b);
2679 break;
2680 case T_VariableSetStmt:
2681 retval = _equalVariableSetStmt(a, b);
2682 break;
2683 case T_VariableShowStmt:
2684 retval = _equalVariableShowStmt(a, b);
2685 break;
2686 case T_DiscardStmt:
2687 retval = _equalDiscardStmt(a, b);
2688 break;
2689 case T_CreateTableSpaceStmt:
2690 retval = _equalCreateTableSpaceStmt(a, b);
2691 break;
2692 case T_DropTableSpaceStmt:
2693 retval = _equalDropTableSpaceStmt(a, b);
2694 break;
2695 case T_CreateFdwStmt:
2696 retval = _equalCreateFdwStmt(a, b);
2697 break;
2698 case T_AlterFdwStmt:
2699 retval = _equalAlterFdwStmt(a, b);
2700 break;
2701 case T_DropFdwStmt:
2702 retval = _equalDropFdwStmt(a, b);
2703 break;
2704 case T_CreateForeignServerStmt:
2705 retval = _equalCreateForeignServerStmt(a, b);
2706 break;
2707 case T_AlterForeignServerStmt:
2708 retval = _equalAlterForeignServerStmt(a, b);
2709 break;
2710 case T_DropForeignServerStmt:
2711 retval = _equalDropForeignServerStmt(a, b);
2712 break;
2713 case T_CreateUserMappingStmt:
2714 retval = _equalCreateUserMappingStmt(a, b);
2715 break;
2716 case T_AlterUserMappingStmt:
2717 retval = _equalAlterUserMappingStmt(a, b);
2718 break;
2719 case T_DropUserMappingStmt:
2720 retval = _equalDropUserMappingStmt(a, b);
2721 break;
2722 case T_CreateTrigStmt:
2723 retval = _equalCreateTrigStmt(a, b);
2724 break;
2725 case T_DropPropertyStmt:
2726 retval = _equalDropPropertyStmt(a, b);
2727 break;
2728 case T_CreatePLangStmt:
2729 retval = _equalCreatePLangStmt(a, b);
2730 break;
2731 case T_DropPLangStmt:
2732 retval = _equalDropPLangStmt(a, b);
2733 break;
2734 case T_CreateRoleStmt:
2735 retval = _equalCreateRoleStmt(a, b);
2736 break;
2737 case T_AlterRoleStmt:
2738 retval = _equalAlterRoleStmt(a, b);
2739 break;
2740 case T_AlterRoleSetStmt:
2741 retval = _equalAlterRoleSetStmt(a, b);
2742 break;
2743 case T_DropRoleStmt:
2744 retval = _equalDropRoleStmt(a, b);
2745 break;
2746 case T_LockStmt:
2747 retval = _equalLockStmt(a, b);
2748 break;
2749 case T_ConstraintsSetStmt:
2750 retval = _equalConstraintsSetStmt(a, b);
2751 break;
2752 case T_ReindexStmt:
2753 retval = _equalReindexStmt(a, b);
2754 break;
2755 case T_CheckPointStmt:
2756 retval = true;
2757 break;
2758 case T_CreateSchemaStmt:
2759 retval = _equalCreateSchemaStmt(a, b);
2760 break;
2761 case T_CreateConversionStmt:
2762 retval = _equalCreateConversionStmt(a, b);
2763 break;
2764 case T_CreateCastStmt:
2765 retval = _equalCreateCastStmt(a, b);
2766 break;
2767 case T_DropCastStmt:
2768 retval = _equalDropCastStmt(a, b);
2769 break;
2770 case T_PrepareStmt:
2771 retval = _equalPrepareStmt(a, b);
2772 break;
2773 case T_ExecuteStmt:
2774 retval = _equalExecuteStmt(a, b);
2775 break;
2776 case T_DeallocateStmt:
2777 retval = _equalDeallocateStmt(a, b);
2778 break;
2779 case T_DropOwnedStmt:
2780 retval = _equalDropOwnedStmt(a, b);
2781 break;
2782 case T_ReassignOwnedStmt:
2783 retval = _equalReassignOwnedStmt(a, b);
2784 break;
2785 case T_AlterTSDictionaryStmt:
2786 retval = _equalAlterTSDictionaryStmt(a, b);
2787 break;
2788 case T_AlterTSConfigurationStmt:
2789 retval = _equalAlterTSConfigurationStmt(a, b);
2790 break;
2792 case T_A_Expr:
2793 retval = _equalAExpr(a, b);
2794 break;
2795 case T_ColumnRef:
2796 retval = _equalColumnRef(a, b);
2797 break;
2798 case T_ParamRef:
2799 retval = _equalParamRef(a, b);
2800 break;
2801 case T_A_Const:
2802 retval = _equalAConst(a, b);
2803 break;
2804 case T_FuncCall:
2805 retval = _equalFuncCall(a, b);
2806 break;
2807 case T_A_Star:
2808 retval = _equalAStar(a, b);
2809 break;
2810 case T_A_Indices:
2811 retval = _equalAIndices(a, b);
2812 break;
2813 case T_A_Indirection:
2814 retval = _equalA_Indirection(a, b);
2815 break;
2816 case T_A_ArrayExpr:
2817 retval = _equalA_ArrayExpr(a, b);
2818 break;
2819 case T_ResTarget:
2820 retval = _equalResTarget(a, b);
2821 break;
2822 case T_TypeCast:
2823 retval = _equalTypeCast(a, b);
2824 break;
2825 case T_SortBy:
2826 retval = _equalSortBy(a, b);
2827 break;
2828 case T_WindowDef:
2829 retval = _equalWindowDef(a, b);
2830 break;
2831 case T_RangeSubselect:
2832 retval = _equalRangeSubselect(a, b);
2833 break;
2834 case T_RangeFunction:
2835 retval = _equalRangeFunction(a, b);
2836 break;
2837 case T_TypeName:
2838 retval = _equalTypeName(a, b);
2839 break;
2840 case T_IndexElem:
2841 retval = _equalIndexElem(a, b);
2842 break;
2843 case T_ColumnDef:
2844 retval = _equalColumnDef(a, b);
2845 break;
2846 case T_Constraint:
2847 retval = _equalConstraint(a, b);
2848 break;
2849 case T_DefElem:
2850 retval = _equalDefElem(a, b);
2851 break;
2852 case T_OptionDefElem:
2853 retval = _equalOptionDefElem(a, b);
2854 break;
2855 case T_ReloptElem:
2856 retval = _equalReloptElem(a, b);
2857 break;
2858 case T_LockingClause:
2859 retval = _equalLockingClause(a, b);
2860 break;
2861 case T_RangeTblEntry:
2862 retval = _equalRangeTblEntry(a, b);
2863 break;
2864 case T_SortGroupClause:
2865 retval = _equalSortGroupClause(a, b);
2866 break;
2867 case T_WindowClause:
2868 retval = _equalWindowClause(a, b);
2869 break;
2870 case T_RowMarkClause:
2871 retval = _equalRowMarkClause(a, b);
2872 break;
2873 case T_WithClause:
2874 retval = _equalWithClause(a, b);
2875 break;
2876 case T_CommonTableExpr:
2877 retval = _equalCommonTableExpr(a, b);
2878 break;
2879 case T_FkConstraint:
2880 retval = _equalFkConstraint(a, b);
2881 break;
2882 case T_PrivGrantee:
2883 retval = _equalPrivGrantee(a, b);
2884 break;
2885 case T_FuncWithArgs:
2886 retval = _equalFuncWithArgs(a, b);
2887 break;
2888 case T_AccessPriv:
2889 retval = _equalAccessPriv(a, b);
2890 break;
2891 case T_XmlSerialize:
2892 retval = _equalXmlSerialize(a, b);
2893 break;
2895 default:
2896 elog(ERROR, "unrecognized node type: %d",
2897 (int) nodeTag(a));
2898 retval = false; /* keep compiler quiet */
2899 break;
2902 return retval;