1 /*-------------------------------------------------------------------------
4 * Equality functions to compare node trees.
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.
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
19 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
20 * Portions Copyright (c) 1994, Regents of the University of California
23 * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.158 2002/09/02 02:13:01 tgl Exp $
25 *-------------------------------------------------------------------------
30 #include "nodes/plannodes.h"
31 #include "nodes/relation.h"
32 #include "utils/datum.h"
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))
41 * Stuff from primnodes.h
45 _equalResdom(Resdom *a, Resdom *b)
47 if (a->resno != b->resno)
49 if (a->restype != b->restype)
51 if (a->restypmod != b->restypmod)
53 if (!equalstr(a->resname, b->resname))
55 if (a->ressortgroupref != b->ressortgroupref)
57 if (a->reskey != b->reskey)
59 if (a->reskeyop != b->reskeyop)
61 /* we ignore resjunk flag ... is this correct? */
67 _equalFjoin(Fjoin *a, Fjoin *b)
71 if (a->fj_initialized != b->fj_initialized)
73 if (a->fj_nNodes != b->fj_nNodes)
75 if (!equal(a->fj_innerNode, b->fj_innerNode))
78 nNodes = a->fj_nNodes;
79 if (memcmp(a->fj_results, b->fj_results, nNodes * sizeof(Datum)) != 0)
81 if (memcmp(a->fj_alwaysDone, b->fj_alwaysDone, nNodes * sizeof(bool)) != 0)
88 _equalExpr(Expr *a, Expr *b)
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
95 if (a->opType != b->opType)
97 if (!equal(a->oper, b->oper))
99 if (!equal(a->args, b->args))
106 _equalVar(Var *a, Var *b)
108 if (a->varno != b->varno)
110 if (a->varattno != b->varattno)
112 if (a->vartype != b->vartype)
114 if (a->vartypmod != b->vartypmod)
116 if (a->varlevelsup != b->varlevelsup)
118 if (a->varnoold != b->varnoold)
120 if (a->varoattno != b->varoattno)
127 _equalOper(Oper *a, Oper *b)
129 if (a->opno != b->opno)
131 if (a->opresulttype != b->opresulttype)
133 if (a->opretset != b->opretset)
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.
141 * (Besides, op_fcache is executor state, which we don't check --- see
142 * notes at head of file.)
144 * It's probably not really necessary to check opresulttype or opretset,
152 _equalConst(Const *a, Const *b)
154 if (a->consttype != b->consttype)
156 if (a->constlen != b->constlen)
158 if (a->constisnull != b->constisnull)
160 if (a->constbyval != b->constbyval)
162 /* XXX What about constisset and constiscast? */
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,
171 return datumIsEqual(a->constvalue, b->constvalue,
172 a->constbyval, a->constlen);
176 _equalParam(Param *a, Param *b)
178 if (a->paramkind != b->paramkind)
180 if (a->paramtype != b->paramtype)
183 switch (a->paramkind)
188 if (strcmp(a->paramname, b->paramname) != 0)
193 if (a->paramid != b->paramid)
199 * XXX: Hmmm... What are we supposed to return in this case ??
204 elog(ERROR, "_equalParam: Invalid paramkind value: %d",
212 _equalFunc(Func *a, Func *b)
214 if (a->funcid != b->funcid)
216 if (a->funcresulttype != b->funcresulttype)
218 if (a->funcretset != b->funcretset)
220 /* Note we do not look at func_fcache; see notes for _equalOper */
226 _equalAggref(Aggref *a, Aggref *b)
228 if (a->aggfnoid != b->aggfnoid)
230 if (a->aggtype != b->aggtype)
232 if (!equal(a->target, b->target))
234 if (a->aggstar != b->aggstar)
236 if (a->aggdistinct != b->aggdistinct)
238 /* ignore aggno, which is only a private field for the executor */
243 _equalSubLink(SubLink *a, SubLink *b)
245 if (a->subLinkType != b->subLinkType)
247 if (a->useor != b->useor)
249 if (!equal(a->lefthand, b->lefthand))
251 if (!equal(a->oper, b->oper))
253 if (!equal(a->subselect, b->subselect))
259 _equalArrayRef(ArrayRef *a, ArrayRef *b)
261 if (a->refrestype != b->refrestype)
263 if (a->refattrlength != b->refattrlength)
265 if (a->refelemlength != b->refelemlength)
267 if (a->refelembyval != b->refelembyval)
269 if (a->refelemalign != b->refelemalign)
271 if (!equal(a->refupperindexpr, b->refupperindexpr))
273 if (!equal(a->reflowerindexpr, b->reflowerindexpr))
275 if (!equal(a->refexpr, b->refexpr))
277 if (!equal(a->refassgnexpr, b->refassgnexpr))
283 _equalFieldSelect(FieldSelect *a, FieldSelect *b)
285 if (!equal(a->arg, b->arg))
287 if (a->fieldnum != b->fieldnum)
289 if (a->resulttype != b->resulttype)
291 if (a->resulttypmod != b->resulttypmod)
297 _equalRelabelType(RelabelType *a, RelabelType *b)
299 if (!equal(a->arg, b->arg))
301 if (a->resulttype != b->resulttype)
303 if (a->resulttypmod != b->resulttypmod)
309 _equalRangeTblRef(RangeTblRef *a, RangeTblRef *b)
311 if (a->rtindex != b->rtindex)
318 _equalFromExpr(FromExpr *a, FromExpr *b)
320 if (!equal(a->fromlist, b->fromlist))
322 if (!equal(a->quals, b->quals))
329 _equalJoinExpr(JoinExpr *a, JoinExpr *b)
331 if (a->jointype != b->jointype)
333 if (a->isNatural != b->isNatural)
335 if (!equal(a->larg, b->larg))
337 if (!equal(a->rarg, b->rarg))
339 if (!equal(a->using, b->using))
341 if (!equal(a->quals, b->quals))
343 if (!equal(a->alias, b->alias))
345 if (a->rtindex != b->rtindex)
352 * Stuff from relation.h
356 _equalRelOptInfo(RelOptInfo *a, RelOptInfo *b)
359 * We treat RelOptInfos as equal if they refer to the same base rels
360 * joined in the same order. Is this appropriate/sufficient?
362 return equali(a->relids, b->relids);
366 _equalIndexOptInfo(IndexOptInfo *a, IndexOptInfo *b)
369 * We treat IndexOptInfos as equal if they refer to the same index. Is
372 if (a->indexoid != b->indexoid)
378 _equalPathKeyItem(PathKeyItem *a, PathKeyItem *b)
380 if (a->sortop != b->sortop)
382 if (!equal(a->key, b->key))
388 _equalPath(Path *a, Path *b)
390 if (a->pathtype != b->pathtype)
392 if (!equal(a->parent, b->parent))
396 * do not check path costs, since they may not be set yet, and being
397 * float values there are roundoff error issues anyway...
399 if (!equal(a->pathkeys, b->pathkeys))
405 _equalIndexPath(IndexPath *a, IndexPath *b)
407 if (!_equalPath((Path *) a, (Path *) b))
409 if (!equal(a->indexinfo, b->indexinfo))
411 if (!equal(a->indexqual, b->indexqual))
413 if (a->indexscandir != b->indexscandir)
415 if (!equali(a->joinrelids, b->joinrelids))
417 if (a->alljoinquals != b->alljoinquals)
421 * Skip 'rows' because of possibility of floating-point roundoff
422 * error. It should be derivable from the other fields anyway.
428 _equalTidPath(TidPath *a, TidPath *b)
430 if (!_equalPath((Path *) a, (Path *) b))
432 if (!equal(a->tideval, b->tideval))
434 if (!equali(a->unjoined_relids, b->unjoined_relids))
440 _equalAppendPath(AppendPath *a, AppendPath *b)
442 if (!_equalPath((Path *) a, (Path *) b))
444 if (!equal(a->subpaths, b->subpaths))
450 _equalJoinPath(JoinPath *a, JoinPath *b)
452 if (!_equalPath((Path *) a, (Path *) b))
454 if (a->jointype != b->jointype)
456 if (!equal(a->outerjoinpath, b->outerjoinpath))
458 if (!equal(a->innerjoinpath, b->innerjoinpath))
460 if (!equal(a->joinrestrictinfo, b->joinrestrictinfo))
466 _equalNestPath(NestPath *a, NestPath *b)
468 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
474 _equalMergePath(MergePath *a, MergePath *b)
476 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
478 if (!equal(a->path_mergeclauses, b->path_mergeclauses))
480 if (!equal(a->outersortkeys, b->outersortkeys))
482 if (!equal(a->innersortkeys, b->innersortkeys))
488 _equalHashPath(HashPath *a, HashPath *b)
490 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
492 if (!equal(a->path_hashclauses, b->path_hashclauses))
498 _equalSubPlan(SubPlan *a, SubPlan *b)
500 /* should compare plans, but have to settle for comparing plan IDs */
501 if (a->plan_id != b->plan_id)
504 if (!equal(a->rtable, b->rtable))
507 if (!equal(a->sublink, b->sublink))
514 _equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
516 if (!equal(a->clause, b->clause))
518 if (a->ispusheddown != b->ispusheddown)
522 * We ignore eval_cost, this_selec, left/right_pathkey, and
523 * left/right_bucketsize, since they may not be set yet, and should be
524 * derivable from the clause anyway. Probably it's not really
525 * necessary to compare any of these remaining fields ...
527 if (!equal(a->subclauseindices, b->subclauseindices))
529 if (a->mergejoinoperator != b->mergejoinoperator)
531 if (a->left_sortop != b->left_sortop)
533 if (a->right_sortop != b->right_sortop)
535 if (a->hashjoinoperator != b->hashjoinoperator)
541 _equalJoinInfo(JoinInfo *a, JoinInfo *b)
543 if (!equali(a->unjoined_relids, b->unjoined_relids))
545 if (!equal(a->jinfo_restrictinfo, b->jinfo_restrictinfo))
551 * Stuff from parsenodes.h
555 _equalQuery(Query *a, Query *b)
557 if (a->commandType != b->commandType)
559 if (!equal(a->utilityStmt, b->utilityStmt))
561 if (a->resultRelation != b->resultRelation)
563 if (!equal(a->into, b->into))
565 if (a->isPortal != b->isPortal)
567 if (a->isBinary != b->isBinary)
569 if (a->hasAggs != b->hasAggs)
571 if (a->hasSubLinks != b->hasSubLinks)
573 /* we deliberately ignore originalQuery */
574 if (!equal(a->rtable, b->rtable))
576 if (!equal(a->jointree, b->jointree))
578 if (!equali(a->rowMarks, b->rowMarks))
580 if (!equal(a->targetList, b->targetList))
582 if (!equal(a->groupClause, b->groupClause))
584 if (!equal(a->havingQual, b->havingQual))
586 if (!equal(a->distinctClause, b->distinctClause))
588 if (!equal(a->sortClause, b->sortClause))
590 if (!equal(a->limitOffset, b->limitOffset))
592 if (!equal(a->limitCount, b->limitCount))
594 if (!equal(a->setOperations, b->setOperations))
596 if (!equali(a->resultRelations, b->resultRelations))
600 * We do not check the internal-to-the-planner fields: base_rel_list,
601 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. They
602 * might not be set yet, and in any case they should be derivable from
609 _equalInsertStmt(InsertStmt *a, InsertStmt *b)
611 if (!equal(a->relation, b->relation))
613 if (!equal(a->cols, b->cols))
615 if (!equal(a->targetList, b->targetList))
617 if (!equal(a->selectStmt, b->selectStmt))
624 _equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
626 if (!equal(a->relation, b->relation))
628 if (!equal(a->whereClause, b->whereClause))
635 _equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
637 if (!equal(a->relation, b->relation))
639 if (!equal(a->targetList, b->targetList))
641 if (!equal(a->whereClause, b->whereClause))
643 if (!equal(a->fromClause, b->fromClause))
650 _equalSelectStmt(SelectStmt *a, SelectStmt *b)
652 if (!equal(a->distinctClause, b->distinctClause))
654 if (!equal(a->into, b->into))
656 if (!equal(a->intoColNames, b->intoColNames))
658 if (!equal(a->targetList, b->targetList))
660 if (!equal(a->fromClause, b->fromClause))
662 if (!equal(a->whereClause, b->whereClause))
664 if (!equal(a->groupClause, b->groupClause))
666 if (!equal(a->havingClause, b->havingClause))
668 if (!equal(a->sortClause, b->sortClause))
670 if (!equalstr(a->portalname, b->portalname))
672 if (a->binary != b->binary)
674 if (!equal(a->limitOffset, b->limitOffset))
676 if (!equal(a->limitCount, b->limitCount))
678 if (!equal(a->forUpdate, b->forUpdate))
682 if (a->all != b->all)
684 if (!equal(a->larg, b->larg))
686 if (!equal(a->rarg, b->rarg))
693 _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
697 if (a->all != b->all)
699 if (!equal(a->larg, b->larg))
701 if (!equal(a->rarg, b->rarg))
703 if (!equali(a->colTypes, b->colTypes))
710 _equalAlterTableStmt(AlterTableStmt *a, AlterTableStmt *b)
712 if (a->subtype != b->subtype)
714 if (!equal(a->relation, b->relation))
716 if (!equalstr(a->name, b->name))
718 if (!equal(a->def, b->def))
720 if (a->behavior != b->behavior)
727 _equalGrantStmt(GrantStmt *a, GrantStmt *b)
729 if (a->is_grant != b->is_grant)
731 if (a->objtype != b->objtype)
733 if (!equal(a->objects, b->objects))
735 if (!equali(a->privileges, b->privileges))
737 if (!equal(a->grantees, b->grantees))
744 _equalPrivGrantee(PrivGrantee *a, PrivGrantee *b)
746 return equalstr(a->username, b->username)
747 && equalstr(a->groupname, b->groupname);
751 _equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
753 return equal(a->funcname, b->funcname)
754 && equal(a->funcargs, b->funcargs);
758 _equalInsertDefault(InsertDefault *a, InsertDefault *b)
764 _equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
766 if (!equalstr(a->portalname, b->portalname))
773 _equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
775 if (!equal(a->relation, b->relation))
777 if (!equalstr(a->indexname, b->indexname))
784 _equalCopyStmt(CopyStmt *a, CopyStmt *b)
786 if (!equal(a->relation, b->relation))
788 if (!equal(a->attlist, b->attlist))
790 if (a->is_from != b->is_from)
792 if (!equalstr(a->filename, b->filename))
794 if (!equal(a->options, b->options))
801 _equalCreateStmt(CreateStmt *a, CreateStmt *b)
803 if (!equal(a->relation, b->relation))
805 if (!equal(a->tableElts, b->tableElts))
807 if (!equal(a->inhRelations, b->inhRelations))
809 if (!equal(a->constraints, b->constraints))
811 if (a->hasoids != b->hasoids)
818 _equalDefineStmt(DefineStmt *a, DefineStmt *b)
820 if (a->defType != b->defType)
822 if (!equal(a->defnames, b->defnames))
824 if (!equal(a->definition, b->definition))
831 _equalDropStmt(DropStmt *a, DropStmt *b)
833 if (!equal(a->objects, b->objects))
835 if (a->removeType != b->removeType)
837 if (a->behavior != b->behavior)
844 _equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
846 if (!equal(a->relation, b->relation))
853 _equalCommentStmt(CommentStmt *a, CommentStmt *b)
855 if (a->objtype != b->objtype)
857 if (!equal(a->objname, b->objname))
859 if (!equal(a->objargs, b->objargs))
861 if (!equalstr(a->comment, b->comment))
868 _equalFetchStmt(FetchStmt *a, FetchStmt *b)
870 if (a->direction != b->direction)
872 if (a->howMany != b->howMany)
874 if (!equalstr(a->portalname, b->portalname))
876 if (a->ismove != b->ismove)
883 _equalIndexStmt(IndexStmt *a, IndexStmt *b)
885 if (!equalstr(a->idxname, b->idxname))
887 if (!equal(a->relation, b->relation))
889 if (!equalstr(a->accessMethod, b->accessMethod))
891 if (!equal(a->indexParams, b->indexParams))
893 if (!equal(a->whereClause, b->whereClause))
895 if (!equal(a->rangetable, b->rangetable))
897 if (a->unique != b->unique)
899 if (a->primary != b->primary)
901 if (a->isconstraint != b->isconstraint)
908 _equalCreateFunctionStmt(CreateFunctionStmt *a, CreateFunctionStmt *b)
910 if (a->replace != b->replace)
912 if (!equal(a->funcname, b->funcname))
914 if (!equal(a->argTypes, b->argTypes))
916 if (!equal(a->returnType, b->returnType))
918 if (!equal(a->options, b->options))
920 if (!equal(a->withClause, b->withClause))
927 _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
929 if (!equal(a->aggname, b->aggname))
931 if (!equal(a->aggtype, b->aggtype))
933 if (a->behavior != b->behavior)
940 _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
942 if (!equal(a->funcname, b->funcname))
944 if (!equal(a->args, b->args))
946 if (a->behavior != b->behavior)
953 _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
955 if (!equal(a->opname, b->opname))
957 if (!equal(a->args, b->args))
959 if (a->behavior != b->behavior)
966 _equalRemoveOpClassStmt(RemoveOpClassStmt *a, RemoveOpClassStmt *b)
968 if (!equal(a->opclassname, b->opclassname))
970 if (!equalstr(a->amname, b->amname))
972 if (a->behavior != b->behavior)
979 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
981 if (!equal(a->relation, b->relation))
983 if (!equalstr(a->oldname, b->oldname))
985 if (!equalstr(a->newname, b->newname))
987 if (a->renameType != b->renameType)
994 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
996 if (!equal(a->relation, b->relation))
998 if (!equalstr(a->rulename, b->rulename))
1000 if (!equal(a->whereClause, b->whereClause))
1002 if (a->event != b->event)
1004 if (a->instead != b->instead)
1006 if (a->replace != b->replace)
1008 if (!equal(a->actions, b->actions))
1015 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1017 if (!equal(a->relation, b->relation))
1024 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1026 if (!equal(a->relation, b->relation))
1033 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1035 if (!equal(a->relation, b->relation))
1042 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1044 if (a->command != b->command)
1046 if (!equal(a->options, b->options))
1053 _equalCompositeTypeStmt(CompositeTypeStmt *a, CompositeTypeStmt *b)
1055 if (!equal(a->typevar, b->typevar))
1057 if (!equal(a->coldeflist, b->coldeflist))
1064 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1066 if (!equal(a->view, b->view))
1068 if (!equal(a->aliases, b->aliases))
1070 if (!equal(a->query, b->query))
1072 if (a->replace != b->replace)
1079 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1081 if (!equalstr(a->filename, b->filename))
1088 _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
1090 if (!equal(a->domainname, b->domainname))
1092 if (!equal(a->typename, b->typename))
1094 if (!equal(a->constraints, b->constraints))
1101 _equalCreateOpClassStmt(CreateOpClassStmt *a, CreateOpClassStmt *b)
1103 if (!equal(a->opclassname, b->opclassname))
1105 if (!equalstr(a->amname, b->amname))
1107 if (!equal(a->datatype, b->datatype))
1109 if (!equal(a->items, b->items))
1111 if (a->isDefault != b->isDefault)
1118 _equalCreateOpClassItem(CreateOpClassItem *a, CreateOpClassItem *b)
1120 if (a->itemtype != b->itemtype)
1122 if (!equal(a->name, b->name))
1124 if (!equal(a->args, b->args))
1126 if (a->number != b->number)
1128 if (a->recheck != b->recheck)
1130 if (!equal(a->storedtype, b->storedtype))
1137 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1139 if (!equalstr(a->dbname, b->dbname))
1141 if (!equal(a->options, b->options))
1148 _equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
1150 if (!equalstr(a->dbname, b->dbname))
1152 if (!equalstr(a->variable, b->variable))
1154 if (!equal(a->value, b->value))
1161 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1163 if (!equalstr(a->dbname, b->dbname))
1170 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1172 if (a->vacuum != b->vacuum)
1174 if (a->full != b->full)
1176 if (a->analyze != b->analyze)
1178 if (a->freeze != b->freeze)
1180 if (a->verbose != b->verbose)
1182 if (!equal(a->relation, b->relation))
1184 if (!equal(a->va_cols, b->va_cols))
1191 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1193 if (!equal(a->query, b->query))
1195 if (a->verbose != b->verbose)
1197 if (a->analyze != b->analyze)
1204 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1206 if (!equal(a->sequence, b->sequence))
1208 if (!equal(a->options, b->options))
1215 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1217 if (!equalstr(a->name, b->name))
1219 if (!equal(a->args, b->args))
1221 if (a->is_local != b->is_local)
1228 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1230 if (!equalstr(a->name, b->name))
1237 _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
1239 if (!equalstr(a->name, b->name))
1246 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1248 if (!equalstr(a->trigname, b->trigname))
1250 if (!equal(a->relation, b->relation))
1252 if (!equal(a->funcname, b->funcname))
1254 if (!equal(a->args, b->args))
1256 if (a->before != b->before)
1258 if (a->row != b->row)
1260 if (strcmp(a->actions, b->actions) != 0)
1262 if (!equalstr(a->lang, b->lang))
1264 if (!equalstr(a->text, b->text))
1266 if (!equal(a->attr, b->attr))
1268 if (!equalstr(a->when, b->when))
1270 if (a->isconstraint != b->isconstraint)
1272 if (a->deferrable != b->deferrable)
1274 if (a->initdeferred != b->initdeferred)
1276 if (!equal(a->constrrel, b->constrrel))
1283 _equalDropPropertyStmt(DropPropertyStmt *a, DropPropertyStmt *b)
1285 if (!equal(a->relation, b->relation))
1287 if (!equalstr(a->property, b->property))
1289 if (a->removeType != b->removeType)
1291 if (a->behavior != b->behavior)
1298 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1300 if (!equalstr(a->plname, b->plname))
1302 if (!equal(a->plhandler, b->plhandler))
1304 if (!equal(a->plvalidator, b->plvalidator))
1306 if (a->pltrusted != b->pltrusted)
1313 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1315 if (!equalstr(a->plname, b->plname))
1317 if (a->behavior != b->behavior)
1324 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1326 if (!equalstr(a->user, b->user))
1328 if (!equal(a->options, b->options))
1335 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1337 if (!equalstr(a->user, b->user))
1339 if (!equal(a->options, b->options))
1346 _equalAlterUserSetStmt(AlterUserSetStmt *a, AlterUserSetStmt *b)
1348 if (!equalstr(a->user, b->user))
1350 if (!equalstr(a->variable, b->variable))
1352 if (!equal(a->value, b->value))
1359 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1361 if (!equal(a->users, b->users))
1368 _equalLockStmt(LockStmt *a, LockStmt *b)
1370 if (!equal(a->relations, b->relations))
1372 if (a->mode != b->mode)
1379 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1381 if (!equal(a->constraints, b->constraints))
1383 if (a->deferred != b->deferred)
1390 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1392 if (!equalstr(a->name, b->name))
1394 if (!equal(a->options, b->options))
1401 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1403 if (!equalstr(a->name, b->name))
1405 if (a->action != b->action)
1407 if (!equal(a->listUsers, b->listUsers))
1414 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1416 if (!equalstr(a->name, b->name))
1423 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1425 if (a->reindexType != b->reindexType)
1427 if (!equal(a->relation, b->relation))
1429 if (!equalstr(a->name, b->name))
1431 if (a->force != b->force)
1433 if (a->all != b->all)
1440 _equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
1442 if (!equalstr(a->schemaname, b->schemaname))
1444 if (!equalstr(a->authid, b->authid))
1446 if (!equal(a->schemaElts, b->schemaElts))
1453 _equalCreateConversionStmt(CreateConversionStmt *a, CreateConversionStmt *b)
1455 if (!equal(a->conversion_name, b->conversion_name))
1457 if (!equalstr(a->for_encoding_name, b->for_encoding_name))
1459 if (!equalstr(a->to_encoding_name, b->to_encoding_name))
1461 if (!equal(a->func_name, b->func_name))
1463 if (a->def != b->def)
1470 _equalCreateCastStmt(CreateCastStmt *a, CreateCastStmt *b)
1472 if (!equal(a->sourcetype, b->sourcetype))
1474 if (!equal(a->targettype, b->targettype))
1476 if (!equal(a->func, b->func))
1478 if (a->implicit != b->implicit)
1485 _equalDropCastStmt(DropCastStmt *a, DropCastStmt *b)
1487 if (!equal(a->sourcetype, b->sourcetype))
1489 if (!equal(a->targettype, b->targettype))
1491 if (a->behavior != b->behavior)
1498 _equalPrepareStmt(PrepareStmt *a, PrepareStmt *b)
1500 if (!equalstr(a->name, b->name))
1502 if (!equal(a->argtypes, b->argtypes))
1504 if (!equali(a->argtype_oids, b->argtype_oids))
1506 if (!equal(a->query, b->query))
1513 _equalExecuteStmt(ExecuteStmt *a, ExecuteStmt *b)
1515 if (!equalstr(a->name, b->name))
1517 if (!equal(a->into, b->into))
1519 if (!equal(a->params, b->params))
1526 _equalDeallocateStmt(DeallocateStmt *a, DeallocateStmt *b)
1528 if (!equalstr(a->name, b->name))
1535 _equalAExpr(A_Expr *a, A_Expr *b)
1537 if (a->oper != b->oper)
1539 if (!equal(a->name, b->name))
1541 if (!equal(a->lexpr, b->lexpr))
1543 if (!equal(a->rexpr, b->rexpr))
1550 _equalColumnRef(ColumnRef *a, ColumnRef *b)
1552 if (!equal(a->fields, b->fields))
1554 if (!equal(a->indirection, b->indirection))
1561 _equalParamRef(ParamRef *a, ParamRef *b)
1563 if (a->number != b->number)
1565 if (!equal(a->fields, b->fields))
1567 if (!equal(a->indirection, b->indirection))
1574 _equalAConst(A_Const *a, A_Const *b)
1576 if (!equal(&a->val, &b->val))
1578 if (!equal(a->typename, b->typename))
1585 _equalFuncCall(FuncCall *a, FuncCall *b)
1587 if (!equal(a->funcname, b->funcname))
1589 if (!equal(a->args, b->args))
1591 if (a->agg_star != b->agg_star)
1593 if (a->agg_distinct != b->agg_distinct)
1600 _equalAIndices(A_Indices *a, A_Indices *b)
1602 if (!equal(a->lidx, b->lidx))
1604 if (!equal(a->uidx, b->uidx))
1611 _equalExprFieldSelect(ExprFieldSelect *a, ExprFieldSelect *b)
1613 if (!equal(a->arg, b->arg))
1615 if (!equal(a->fields, b->fields))
1617 if (!equal(a->indirection, b->indirection))
1624 _equalResTarget(ResTarget *a, ResTarget *b)
1626 if (!equalstr(a->name, b->name))
1628 if (!equal(a->indirection, b->indirection))
1630 if (!equal(a->val, b->val))
1637 _equalTypeCast(TypeCast *a, TypeCast *b)
1639 if (!equal(a->arg, b->arg))
1641 if (!equal(a->typename, b->typename))
1648 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1650 if (!equal(a->useOp, b->useOp))
1652 if (!equal(a->node, b->node))
1659 _equalAlias(Alias *a, Alias *b)
1661 if (!equalstr(a->aliasname, b->aliasname))
1663 if (!equal(a->colnames, b->colnames))
1670 _equalRangeVar(RangeVar *a, RangeVar *b)
1672 if (!equalstr(a->catalogname, b->catalogname))
1674 if (!equalstr(a->schemaname, b->schemaname))
1676 if (!equalstr(a->relname, b->relname))
1678 if (a->inhOpt != b->inhOpt)
1680 if (a->istemp != b->istemp)
1682 if (!equal(a->alias, b->alias))
1689 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1691 if (!equal(a->subquery, b->subquery))
1693 if (!equal(a->alias, b->alias))
1700 _equalRangeFunction(RangeFunction *a, RangeFunction *b)
1702 if (!equal(a->funccallnode, b->funccallnode))
1704 if (!equal(a->alias, b->alias))
1706 if (!equal(a->coldeflist, b->coldeflist))
1713 _equalTypeName(TypeName *a, TypeName *b)
1715 if (!equal(a->names, b->names))
1717 if (a->typeid != b->typeid)
1719 if (a->timezone != b->timezone)
1721 if (a->setof != b->setof)
1723 if (a->pct_type != b->pct_type)
1725 if (a->typmod != b->typmod)
1727 if (!equal(a->arrayBounds, b->arrayBounds))
1734 _equalIndexElem(IndexElem *a, IndexElem *b)
1736 if (!equalstr(a->name, b->name))
1738 if (!equal(a->funcname, b->funcname))
1740 if (!equal(a->args, b->args))
1742 if (!equal(a->opclass, b->opclass))
1749 _equalColumnDef(ColumnDef *a, ColumnDef *b)
1751 if (!equalstr(a->colname, b->colname))
1753 if (!equal(a->typename, b->typename))
1755 if (a->is_inherited != b->is_inherited)
1757 if (a->is_not_null != b->is_not_null)
1759 if (!equal(a->raw_default, b->raw_default))
1761 if (!equalstr(a->cooked_default, b->cooked_default))
1763 if (!equal(a->constraints, b->constraints))
1765 if (!equal(a->support, b->support))
1772 _equalConstraint(Constraint *a, Constraint *b)
1774 if (a->contype != b->contype)
1776 if (!equalstr(a->name, b->name))
1778 if (!equal(a->raw_expr, b->raw_expr))
1780 if (!equalstr(a->cooked_expr, b->cooked_expr))
1782 if (!equal(a->keys, b->keys))
1789 _equalDefElem(DefElem *a, DefElem *b)
1791 if (!equalstr(a->defname, b->defname))
1793 if (!equal(a->arg, b->arg))
1800 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
1802 if (!equal(a->resdom, b->resdom))
1804 if (!equal(a->fjoin, b->fjoin))
1806 if (!equal(a->expr, b->expr))
1813 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
1815 if (a->rtekind != b->rtekind)
1817 if (a->relid != b->relid)
1819 if (!equal(a->subquery, b->subquery))
1821 if (!equal(a->funcexpr, b->funcexpr))
1823 if (!equal(a->coldeflist, b->coldeflist))
1825 if (a->jointype != b->jointype)
1827 if (!equal(a->joinaliasvars, b->joinaliasvars))
1829 if (!equal(a->alias, b->alias))
1831 if (!equal(a->eref, b->eref))
1833 if (a->inh != b->inh)
1835 if (a->inFromCl != b->inFromCl)
1837 if (a->checkForRead != b->checkForRead)
1839 if (a->checkForWrite != b->checkForWrite)
1841 if (a->checkAsUser != b->checkAsUser)
1848 _equalSortClause(SortClause *a, SortClause *b)
1850 if (a->tleSortGroupRef != b->tleSortGroupRef)
1852 if (a->sortop != b->sortop)
1859 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
1861 if (!equalstr(a->constr_name, b->constr_name))
1863 if (!equal(a->pktable, b->pktable))
1865 if (!equal(a->fk_attrs, b->fk_attrs))
1867 if (!equal(a->pk_attrs, b->pk_attrs))
1869 if (a->fk_matchtype != b->fk_matchtype)
1871 if (a->fk_upd_action != b->fk_upd_action)
1873 if (a->fk_del_action != b->fk_del_action)
1875 if (a->deferrable != b->deferrable)
1877 if (a->initdeferred != b->initdeferred)
1879 if (a->skip_validation != b->skip_validation)
1886 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
1888 if (a->casetype != b->casetype)
1890 if (!equal(a->arg, b->arg))
1892 if (!equal(a->args, b->args))
1894 if (!equal(a->defresult, b->defresult))
1901 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
1903 if (!equal(a->expr, b->expr))
1905 if (!equal(a->result, b->result))
1912 _equalNullTest(NullTest *a, NullTest *b)
1914 if (!equal(a->arg, b->arg))
1916 if (a->nulltesttype != b->nulltesttype)
1922 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
1924 if (!equal(a->arg, b->arg))
1926 if (a->booltesttype != b->booltesttype)
1932 _equalConstraintTest(ConstraintTest *a, ConstraintTest *b)
1934 if (!equal(a->arg, b->arg))
1936 if (a->testtype != b->testtype)
1938 if (!equalstr(a->name, b->name))
1940 if (!equal(a->check_expr, b->check_expr))
1946 * Stuff from pg_list.h
1950 _equalValue(Value *a, Value *b)
1952 if (a->type != b->type)
1958 return a->val.ival == b->val.ival;
1962 return strcmp(a->val.str, b->val.str) == 0;
1967 elog(ERROR, "_equalValue: unknown node type %d", a->type);
1976 * returns whether two nodes are equal
1979 equal(void *a, void *b)
1981 bool retval = false;
1987 * note that a!=b, so only one of them can be NULL
1989 if (a == NULL || b == NULL)
1993 * are they the same type of nodes?
1995 if (nodeTag(a) != nodeTag(b))
2001 retval = _equalSubPlan(a, b);
2005 retval = _equalResdom(a, b);
2008 retval = _equalFjoin(a, b);
2011 retval = _equalExpr(a, b);
2014 retval = _equalVar(a, b);
2017 retval = _equalOper(a, b);
2020 retval = _equalConst(a, b);
2023 retval = _equalParam(a, b);
2026 retval = _equalAggref(a, b);
2029 retval = _equalSubLink(a, b);
2032 retval = _equalFunc(a, b);
2035 retval = _equalFieldSelect(a, b);
2038 retval = _equalArrayRef(a, b);
2041 retval = _equalRelabelType(a, b);
2044 retval = _equalRangeTblRef(a, b);
2047 retval = _equalFromExpr(a, b);
2050 retval = _equalJoinExpr(a, b);
2054 retval = _equalRelOptInfo(a, b);
2057 retval = _equalPath(a, b);
2060 retval = _equalIndexPath(a, b);
2063 retval = _equalNestPath(a, b);
2066 retval = _equalMergePath(a, b);
2069 retval = _equalHashPath(a, b);
2072 retval = _equalPathKeyItem(a, b);
2074 case T_RestrictInfo:
2075 retval = _equalRestrictInfo(a, b);
2078 retval = _equalJoinInfo(a, b);
2081 retval = _equalTidPath(a, b);
2084 retval = _equalAppendPath(a, b);
2086 case T_IndexOptInfo:
2087 retval = _equalIndexOptInfo(a, b);
2092 List *la = (List *) a;
2093 List *lb = (List *) b;
2097 * Try to reject by length check before we grovel through
2098 * all the elements...
2100 if (length(la) != length(lb))
2104 if (!equal(lfirst(l), lfirst(lb)))
2117 retval = _equalValue(a, b);
2121 retval = _equalQuery(a, b);
2124 retval = _equalInsertStmt(a, b);
2127 retval = _equalDeleteStmt(a, b);
2130 retval = _equalUpdateStmt(a, b);
2133 retval = _equalSelectStmt(a, b);
2135 case T_SetOperationStmt:
2136 retval = _equalSetOperationStmt(a, b);
2138 case T_AlterTableStmt:
2139 retval = _equalAlterTableStmt(a, b);
2142 retval = _equalGrantStmt(a, b);
2144 case T_ClosePortalStmt:
2145 retval = _equalClosePortalStmt(a, b);
2148 retval = _equalClusterStmt(a, b);
2151 retval = _equalCopyStmt(a, b);
2154 retval = _equalCreateStmt(a, b);
2157 retval = _equalDefineStmt(a, b);
2160 retval = _equalDropStmt(a, b);
2162 case T_TruncateStmt:
2163 retval = _equalTruncateStmt(a, b);
2166 retval = _equalCommentStmt(a, b);
2169 retval = _equalFetchStmt(a, b);
2172 retval = _equalIndexStmt(a, b);
2174 case T_CreateFunctionStmt:
2175 retval = _equalCreateFunctionStmt(a, b);
2177 case T_RemoveAggrStmt:
2178 retval = _equalRemoveAggrStmt(a, b);
2180 case T_RemoveFuncStmt:
2181 retval = _equalRemoveFuncStmt(a, b);
2183 case T_RemoveOperStmt:
2184 retval = _equalRemoveOperStmt(a, b);
2186 case T_RemoveOpClassStmt:
2187 retval = _equalRemoveOpClassStmt(a, b);
2190 retval = _equalRenameStmt(a, b);
2193 retval = _equalRuleStmt(a, b);
2196 retval = _equalNotifyStmt(a, b);
2199 retval = _equalListenStmt(a, b);
2201 case T_UnlistenStmt:
2202 retval = _equalUnlistenStmt(a, b);
2204 case T_TransactionStmt:
2205 retval = _equalTransactionStmt(a, b);
2207 case T_CompositeTypeStmt:
2208 retval = _equalCompositeTypeStmt(a, b);
2211 retval = _equalViewStmt(a, b);
2214 retval = _equalLoadStmt(a, b);
2216 case T_CreateDomainStmt:
2217 retval = _equalCreateDomainStmt(a, b);
2219 case T_CreateOpClassStmt:
2220 retval = _equalCreateOpClassStmt(a, b);
2222 case T_CreateOpClassItem:
2223 retval = _equalCreateOpClassItem(a, b);
2225 case T_CreatedbStmt:
2226 retval = _equalCreatedbStmt(a, b);
2228 case T_AlterDatabaseSetStmt:
2229 retval = _equalAlterDatabaseSetStmt(a, b);
2232 retval = _equalDropdbStmt(a, b);
2235 retval = _equalVacuumStmt(a, b);
2238 retval = _equalExplainStmt(a, b);
2240 case T_CreateSeqStmt:
2241 retval = _equalCreateSeqStmt(a, b);
2243 case T_VariableSetStmt:
2244 retval = _equalVariableSetStmt(a, b);
2246 case T_VariableShowStmt:
2247 retval = _equalVariableShowStmt(a, b);
2249 case T_VariableResetStmt:
2250 retval = _equalVariableResetStmt(a, b);
2252 case T_CreateTrigStmt:
2253 retval = _equalCreateTrigStmt(a, b);
2255 case T_DropPropertyStmt:
2256 retval = _equalDropPropertyStmt(a, b);
2258 case T_CreatePLangStmt:
2259 retval = _equalCreatePLangStmt(a, b);
2261 case T_DropPLangStmt:
2262 retval = _equalDropPLangStmt(a, b);
2264 case T_CreateUserStmt:
2265 retval = _equalCreateUserStmt(a, b);
2267 case T_AlterUserStmt:
2268 retval = _equalAlterUserStmt(a, b);
2270 case T_AlterUserSetStmt:
2271 retval = _equalAlterUserSetStmt(a, b);
2273 case T_DropUserStmt:
2274 retval = _equalDropUserStmt(a, b);
2277 retval = _equalLockStmt(a, b);
2279 case T_ConstraintsSetStmt:
2280 retval = _equalConstraintsSetStmt(a, b);
2282 case T_CreateGroupStmt:
2283 retval = _equalCreateGroupStmt(a, b);
2285 case T_AlterGroupStmt:
2286 retval = _equalAlterGroupStmt(a, b);
2288 case T_DropGroupStmt:
2289 retval = _equalDropGroupStmt(a, b);
2292 retval = _equalReindexStmt(a, b);
2294 case T_CheckPointStmt:
2297 case T_CreateSchemaStmt:
2298 retval = _equalCreateSchemaStmt(a, b);
2300 case T_CreateConversionStmt:
2301 retval = _equalCreateConversionStmt(a, b);
2303 case T_CreateCastStmt:
2304 retval = _equalCreateCastStmt(a, b);
2306 case T_DropCastStmt:
2307 retval = _equalDropCastStmt(a, b);
2310 retval = _equalPrepareStmt(a, b);
2313 retval = _equalExecuteStmt(a, b);
2315 case T_DeallocateStmt:
2316 retval = _equalDeallocateStmt(a, b);
2320 retval = _equalAExpr(a, b);
2323 retval = _equalColumnRef(a, b);
2326 retval = _equalParamRef(a, b);
2329 retval = _equalAConst(a, b);
2332 retval = _equalFuncCall(a, b);
2335 retval = _equalAIndices(a, b);
2337 case T_ExprFieldSelect:
2338 retval = _equalExprFieldSelect(a, b);
2341 retval = _equalResTarget(a, b);
2344 retval = _equalTypeCast(a, b);
2347 retval = _equalSortGroupBy(a, b);
2350 retval = _equalAlias(a, b);
2353 retval = _equalRangeVar(a, b);
2355 case T_RangeSubselect:
2356 retval = _equalRangeSubselect(a, b);
2358 case T_RangeFunction:
2359 retval = _equalRangeFunction(a, b);
2362 retval = _equalTypeName(a, b);
2365 retval = _equalIndexElem(a, b);
2368 retval = _equalColumnDef(a, b);
2371 retval = _equalConstraint(a, b);
2374 retval = _equalDefElem(a, b);
2377 retval = _equalTargetEntry(a, b);
2379 case T_RangeTblEntry:
2380 retval = _equalRangeTblEntry(a, b);
2383 retval = _equalSortClause(a, b);
2386 /* GroupClause is equivalent to SortClause */
2387 retval = _equalSortClause(a, b);
2390 retval = _equalCaseExpr(a, b);
2393 retval = _equalCaseWhen(a, b);
2396 retval = _equalNullTest(a, b);
2399 retval = _equalBooleanTest(a, b);
2401 case T_ConstraintTest:
2402 retval = _equalConstraintTest(a, b);
2404 case T_FkConstraint:
2405 retval = _equalFkConstraint(a, b);
2408 retval = _equalPrivGrantee(a, b);
2410 case T_FuncWithArgs:
2411 retval = _equalFuncWithArgs(a, b);
2413 case T_InsertDefault:
2414 retval = _equalInsertDefault(a, b);
2418 elog(WARNING, "equal: don't know whether nodes of type %d are equal",