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.138 2002/06/20 20:29:29 momjian 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->refelemtype != b->refelemtype)
263 if (a->refattrlength != b->refattrlength)
265 if (a->refelemlength != b->refelemlength)
267 if (a->refelembyval != b->refelembyval)
269 if (!equal(a->refupperindexpr, b->refupperindexpr))
271 if (!equal(a->reflowerindexpr, b->reflowerindexpr))
273 if (!equal(a->refexpr, b->refexpr))
275 return equal(a->refassgnexpr, b->refassgnexpr);
279 _equalFieldSelect(FieldSelect *a, FieldSelect *b)
281 if (!equal(a->arg, b->arg))
283 if (a->fieldnum != b->fieldnum)
285 if (a->resulttype != b->resulttype)
287 if (a->resulttypmod != b->resulttypmod)
293 _equalRelabelType(RelabelType *a, RelabelType *b)
295 if (!equal(a->arg, b->arg))
297 if (a->resulttype != b->resulttype)
299 if (a->resulttypmod != b->resulttypmod)
305 _equalRangeTblRef(RangeTblRef *a, RangeTblRef *b)
307 if (a->rtindex != b->rtindex)
314 _equalFromExpr(FromExpr *a, FromExpr *b)
316 if (!equal(a->fromlist, b->fromlist))
318 if (!equal(a->quals, b->quals))
325 _equalJoinExpr(JoinExpr *a, JoinExpr *b)
327 if (a->jointype != b->jointype)
329 if (a->isNatural != b->isNatural)
331 if (!equal(a->larg, b->larg))
333 if (!equal(a->rarg, b->rarg))
335 if (!equal(a->using, b->using))
337 if (!equal(a->quals, b->quals))
339 if (!equal(a->alias, b->alias))
341 if (a->rtindex != b->rtindex)
348 * Stuff from relation.h
352 _equalRelOptInfo(RelOptInfo *a, RelOptInfo *b)
355 * We treat RelOptInfos as equal if they refer to the same base rels
356 * joined in the same order. Is this appropriate/sufficient?
358 return equali(a->relids, b->relids);
362 _equalIndexOptInfo(IndexOptInfo *a, IndexOptInfo *b)
365 * We treat IndexOptInfos as equal if they refer to the same index. Is
368 if (a->indexoid != b->indexoid)
374 _equalPathKeyItem(PathKeyItem *a, PathKeyItem *b)
376 if (a->sortop != b->sortop)
378 if (!equal(a->key, b->key))
384 _equalPath(Path *a, Path *b)
386 if (a->pathtype != b->pathtype)
388 if (!equal(a->parent, b->parent))
392 * do not check path costs, since they may not be set yet, and being
393 * float values there are roundoff error issues anyway...
395 if (!equal(a->pathkeys, b->pathkeys))
401 _equalIndexPath(IndexPath *a, IndexPath *b)
403 if (!_equalPath((Path *) a, (Path *) b))
405 if (!equal(a->indexinfo, b->indexinfo))
407 if (!equal(a->indexqual, b->indexqual))
409 if (a->indexscandir != b->indexscandir)
411 if (!equali(a->joinrelids, b->joinrelids))
413 if (a->alljoinquals != b->alljoinquals)
417 * Skip 'rows' because of possibility of floating-point roundoff
418 * error. It should be derivable from the other fields anyway.
424 _equalTidPath(TidPath *a, TidPath *b)
426 if (!_equalPath((Path *) a, (Path *) b))
428 if (!equal(a->tideval, b->tideval))
430 if (!equali(a->unjoined_relids, b->unjoined_relids))
436 _equalAppendPath(AppendPath *a, AppendPath *b)
438 if (!_equalPath((Path *) a, (Path *) b))
440 if (!equal(a->subpaths, b->subpaths))
446 _equalJoinPath(JoinPath *a, JoinPath *b)
448 if (!_equalPath((Path *) a, (Path *) b))
450 if (a->jointype != b->jointype)
452 if (!equal(a->outerjoinpath, b->outerjoinpath))
454 if (!equal(a->innerjoinpath, b->innerjoinpath))
456 if (!equal(a->joinrestrictinfo, b->joinrestrictinfo))
462 _equalNestPath(NestPath *a, NestPath *b)
464 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
470 _equalMergePath(MergePath *a, MergePath *b)
472 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
474 if (!equal(a->path_mergeclauses, b->path_mergeclauses))
476 if (!equal(a->outersortkeys, b->outersortkeys))
478 if (!equal(a->innersortkeys, b->innersortkeys))
484 _equalHashPath(HashPath *a, HashPath *b)
486 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
488 if (!equal(a->path_hashclauses, b->path_hashclauses))
494 _equalSubPlan(SubPlan *a, SubPlan *b)
496 /* should compare plans, but have to settle for comparing plan IDs */
497 if (a->plan_id != b->plan_id)
500 if (!equal(a->rtable, b->rtable))
503 if (!equal(a->sublink, b->sublink))
510 _equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
512 if (!equal(a->clause, b->clause))
514 if (a->ispusheddown != b->ispusheddown)
518 * We ignore eval_cost, this_selec, left/right_pathkey, and
519 * left/right_bucketsize, since they may not be set yet, and should be
520 * derivable from the clause anyway. Probably it's not really
521 * necessary to compare any of these remaining fields ...
523 if (!equal(a->subclauseindices, b->subclauseindices))
525 if (a->mergejoinoperator != b->mergejoinoperator)
527 if (a->left_sortop != b->left_sortop)
529 if (a->right_sortop != b->right_sortop)
531 if (a->hashjoinoperator != b->hashjoinoperator)
537 _equalJoinInfo(JoinInfo *a, JoinInfo *b)
539 if (!equali(a->unjoined_relids, b->unjoined_relids))
541 if (!equal(a->jinfo_restrictinfo, b->jinfo_restrictinfo))
547 _equalStream(Stream *a, Stream *b)
549 if (a->clausetype != b->clausetype)
551 if (a->groupup != b->groupup)
553 if (a->groupcost != b->groupcost)
555 if (a->groupsel != b->groupsel)
557 if (!equal(a->pathptr, b->pathptr))
559 if (!equal(a->cinfo, b->cinfo))
561 if (!equal(a->upstream, b->upstream))
563 return equal(a->downstream, b->downstream);
567 * Stuff from parsenodes.h
571 _equalQuery(Query *a, Query *b)
573 if (a->commandType != b->commandType)
575 if (!equal(a->utilityStmt, b->utilityStmt))
577 if (a->resultRelation != b->resultRelation)
579 if (!equal(a->into, b->into))
581 if (a->isPortal != b->isPortal)
583 if (a->isBinary != b->isBinary)
585 if (a->hasAggs != b->hasAggs)
587 if (a->hasSubLinks != b->hasSubLinks)
589 /* we deliberately ignore originalQuery */
590 if (!equal(a->rtable, b->rtable))
592 if (!equal(a->jointree, b->jointree))
594 if (!equali(a->rowMarks, b->rowMarks))
596 if (!equal(a->targetList, b->targetList))
598 if (!equal(a->groupClause, b->groupClause))
600 if (!equal(a->havingQual, b->havingQual))
602 if (!equal(a->distinctClause, b->distinctClause))
604 if (!equal(a->sortClause, b->sortClause))
606 if (!equal(a->limitOffset, b->limitOffset))
608 if (!equal(a->limitCount, b->limitCount))
610 if (!equal(a->setOperations, b->setOperations))
612 if (!equali(a->resultRelations, b->resultRelations))
616 * We do not check the internal-to-the-planner fields: base_rel_list,
617 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. They
618 * might not be set yet, and in any case they should be derivable from
625 _equalInsertStmt(InsertStmt *a, InsertStmt *b)
627 if (!equal(a->relation, b->relation))
629 if (!equal(a->cols, b->cols))
631 if (!equal(a->targetList, b->targetList))
633 if (!equal(a->selectStmt, b->selectStmt))
640 _equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
642 if (!equal(a->relation, b->relation))
644 if (!equal(a->whereClause, b->whereClause))
651 _equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
653 if (!equal(a->relation, b->relation))
655 if (!equal(a->targetList, b->targetList))
657 if (!equal(a->whereClause, b->whereClause))
659 if (!equal(a->fromClause, b->fromClause))
666 _equalSelectStmt(SelectStmt *a, SelectStmt *b)
668 if (!equal(a->distinctClause, b->distinctClause))
670 if (!equal(a->into, b->into))
672 if (!equal(a->intoColNames, b->intoColNames))
674 if (!equal(a->targetList, b->targetList))
676 if (!equal(a->fromClause, b->fromClause))
678 if (!equal(a->whereClause, b->whereClause))
680 if (!equal(a->groupClause, b->groupClause))
682 if (!equal(a->havingClause, b->havingClause))
684 if (!equal(a->sortClause, b->sortClause))
686 if (!equalstr(a->portalname, b->portalname))
688 if (a->binary != b->binary)
690 if (!equal(a->limitOffset, b->limitOffset))
692 if (!equal(a->limitCount, b->limitCount))
694 if (!equal(a->forUpdate, b->forUpdate))
698 if (a->all != b->all)
700 if (!equal(a->larg, b->larg))
702 if (!equal(a->rarg, b->rarg))
709 _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
713 if (a->all != b->all)
715 if (!equal(a->larg, b->larg))
717 if (!equal(a->rarg, b->rarg))
719 if (!equali(a->colTypes, b->colTypes))
726 _equalAlterTableStmt(AlterTableStmt *a, AlterTableStmt *b)
728 if (a->subtype != b->subtype)
730 if (!equal(a->relation, b->relation))
732 if (!equalstr(a->name, b->name))
734 if (!equal(a->def, b->def))
736 if (a->behavior != b->behavior)
743 _equalGrantStmt(GrantStmt *a, GrantStmt *b)
745 if (a->is_grant != b->is_grant)
747 if (a->objtype != b->objtype)
749 if (!equal(a->objects, b->objects))
751 if (!equali(a->privileges, b->privileges))
753 if (!equal(a->grantees, b->grantees))
760 _equalPrivGrantee(PrivGrantee *a, PrivGrantee *b)
762 return equalstr(a->username, b->username)
763 && equalstr(a->groupname, b->groupname);
767 _equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
769 return equal(a->funcname, b->funcname)
770 && equal(a->funcargs, b->funcargs);
774 _equalInsertDefault(InsertDefault *a, InsertDefault *b)
780 _equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
782 if (!equalstr(a->portalname, b->portalname))
789 _equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
791 if (!equal(a->relation, b->relation))
793 if (!equalstr(a->indexname, b->indexname))
800 _equalCopyStmt(CopyStmt *a, CopyStmt *b)
802 if (!equal(a->relation, b->relation))
804 if (a->is_from != b->is_from)
806 if (!equalstr(a->filename, b->filename))
808 if (!equal(a->options, b->options))
815 _equalCreateStmt(CreateStmt *a, CreateStmt *b)
817 if (!equal(a->relation, b->relation))
819 if (!equal(a->tableElts, b->tableElts))
821 if (!equal(a->inhRelations, b->inhRelations))
823 if (!equal(a->constraints, b->constraints))
825 if (a->hasoids != b->hasoids)
832 _equalDefineStmt(DefineStmt *a, DefineStmt *b)
834 if (a->defType != b->defType)
836 if (!equal(a->defnames, b->defnames))
838 if (!equal(a->definition, b->definition))
845 _equalDropStmt(DropStmt *a, DropStmt *b)
847 if (!equal(a->objects, b->objects))
849 if (a->removeType != b->removeType)
851 if (a->behavior != b->behavior)
858 _equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
860 if (!equal(a->relation, b->relation))
867 _equalCommentStmt(CommentStmt *a, CommentStmt *b)
869 if (a->objtype != b->objtype)
871 if (!equal(a->objname, b->objname))
873 if (!equal(a->objargs, b->objargs))
875 if (!equalstr(a->comment, b->comment))
882 _equalFetchStmt(FetchStmt *a, FetchStmt *b)
884 if (a->direction != b->direction)
886 if (a->howMany != b->howMany)
888 if (!equalstr(a->portalname, b->portalname))
890 if (a->ismove != b->ismove)
897 _equalIndexStmt(IndexStmt *a, IndexStmt *b)
899 if (!equalstr(a->idxname, b->idxname))
901 if (!equal(a->relation, b->relation))
903 if (!equalstr(a->accessMethod, b->accessMethod))
905 if (!equal(a->indexParams, b->indexParams))
907 if (!equal(a->whereClause, b->whereClause))
909 if (!equal(a->rangetable, b->rangetable))
911 if (a->unique != b->unique)
913 if (a->primary != b->primary)
920 _equalCreateFunctionStmt(CreateFunctionStmt *a, CreateFunctionStmt *b)
922 if (a->replace != b->replace)
924 if (!equal(a->funcname, b->funcname))
926 if (!equal(a->argTypes, b->argTypes))
928 if (!equal(a->returnType, b->returnType))
930 if (!equal(a->options, b->options))
932 if (!equal(a->withClause, b->withClause))
939 _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
941 if (!equal(a->aggname, b->aggname))
943 if (!equal(a->aggtype, b->aggtype))
950 _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
952 if (!equal(a->funcname, b->funcname))
954 if (!equal(a->args, b->args))
961 _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
963 if (!equal(a->opname, b->opname))
965 if (!equal(a->args, b->args))
973 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
975 if (!equal(a->relation, b->relation))
977 if (!equalstr(a->oldname, b->oldname))
979 if (!equalstr(a->newname, b->newname))
981 if (a->renameType != b->renameType)
988 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
990 if (!equal(a->relation, b->relation))
992 if (!equalstr(a->rulename, b->rulename))
994 if (!equal(a->whereClause, b->whereClause))
996 if (a->event != b->event)
998 if (a->instead != b->instead)
1000 if (!equal(a->actions, b->actions))
1007 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1009 if (!equal(a->relation, b->relation))
1016 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1018 if (!equal(a->relation, b->relation))
1025 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1027 if (!equal(a->relation, b->relation))
1034 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1036 if (a->command != b->command)
1043 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1045 if (!equal(a->view, b->view))
1047 if (!equal(a->aliases, b->aliases))
1049 if (!equal(a->query, b->query))
1056 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1058 if (!equalstr(a->filename, b->filename))
1065 _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
1067 if (!equal(a->domainname, b->domainname))
1069 if (!equal(a->typename, b->typename))
1071 if (!equal(a->constraints, b->constraints))
1078 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1080 if (!equalstr(a->dbname, b->dbname))
1082 if (!equal(a->options, b->options))
1089 _equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
1091 if (!equalstr(a->dbname, b->dbname))
1093 if (!equalstr(a->variable, b->variable))
1095 if (!equal(a->value, b->value))
1102 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1104 if (!equalstr(a->dbname, b->dbname))
1111 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1113 if (a->vacuum != b->vacuum)
1115 if (a->full != b->full)
1117 if (a->analyze != b->analyze)
1119 if (a->freeze != b->freeze)
1121 if (a->verbose != b->verbose)
1123 if (!equal(a->relation, b->relation))
1125 if (!equal(a->va_cols, b->va_cols))
1132 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1134 if (!equal(a->query, b->query))
1136 if (a->verbose != b->verbose)
1138 if (a->analyze != b->analyze)
1145 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1147 if (!equal(a->sequence, b->sequence))
1149 if (!equal(a->options, b->options))
1156 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1158 if (!equalstr(a->name, b->name))
1160 if (!equal(a->args, b->args))
1162 if (a->is_local != b->is_local)
1169 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1171 if (!equalstr(a->name, b->name))
1178 _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
1180 if (!equalstr(a->name, b->name))
1187 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1189 if (!equalstr(a->trigname, b->trigname))
1191 if (!equal(a->relation, b->relation))
1193 if (!equal(a->funcname, b->funcname))
1195 if (!equal(a->args, b->args))
1197 if (a->before != b->before)
1199 if (a->row != b->row)
1201 if (strcmp(a->actions, b->actions) != 0)
1203 if (!equalstr(a->lang, b->lang))
1205 if (!equalstr(a->text, b->text))
1207 if (!equal(a->attr, b->attr))
1209 if (!equalstr(a->when, b->when))
1211 if (a->isconstraint != b->isconstraint)
1213 if (a->deferrable != b->deferrable)
1215 if (a->initdeferred != b->initdeferred)
1217 if (!equal(a->constrrel, b->constrrel))
1224 _equalDropPropertyStmt(DropPropertyStmt *a, DropPropertyStmt *b)
1226 if (!equal(a->relation, b->relation))
1228 if (!equalstr(a->property, b->property))
1230 if (a->removeType != b->removeType)
1237 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1239 if (!equalstr(a->plname, b->plname))
1241 if (!equal(a->plhandler, b->plhandler))
1243 if (!equal(a->plvalidator, b->plvalidator))
1245 if (!equalstr(a->plcompiler, b->plcompiler))
1247 if (a->pltrusted != b->pltrusted)
1254 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1256 if (!equalstr(a->plname, b->plname))
1263 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1265 if (!equalstr(a->user, b->user))
1267 if (!equal(a->options, b->options))
1274 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1276 if (!equalstr(a->user, b->user))
1278 if (!equal(a->options, b->options))
1285 _equalAlterUserSetStmt(AlterUserSetStmt *a, AlterUserSetStmt *b)
1287 if (!equalstr(a->user, b->user))
1289 if (!equalstr(a->variable, b->variable))
1291 if (!equal(a->value, b->value))
1298 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1300 if (!equal(a->users, b->users))
1307 _equalLockStmt(LockStmt *a, LockStmt *b)
1309 if (!equal(a->relations, b->relations))
1311 if (a->mode != b->mode)
1318 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1320 if (!equal(a->constraints, b->constraints))
1322 if (a->deferred != b->deferred)
1329 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1331 if (!equalstr(a->name, b->name))
1333 if (!equal(a->options, b->options))
1340 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1342 if (!equalstr(a->name, b->name))
1344 if (a->action != b->action)
1346 if (!equal(a->listUsers, b->listUsers))
1353 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1355 if (!equalstr(a->name, b->name))
1362 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1364 if (a->reindexType != b->reindexType)
1366 if (!equal(a->relation, b->relation))
1368 if (!equalstr(a->name, b->name))
1370 if (a->force != b->force)
1372 if (a->all != b->all)
1379 _equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
1381 if (!equalstr(a->schemaname, b->schemaname))
1383 if (!equalstr(a->authid, b->authid))
1385 if (!equal(a->schemaElts, b->schemaElts))
1392 _equalAExpr(A_Expr *a, A_Expr *b)
1394 if (a->oper != b->oper)
1396 if (!equal(a->name, b->name))
1398 if (!equal(a->lexpr, b->lexpr))
1400 if (!equal(a->rexpr, b->rexpr))
1407 _equalColumnRef(ColumnRef *a, ColumnRef *b)
1409 if (!equal(a->fields, b->fields))
1411 if (!equal(a->indirection, b->indirection))
1418 _equalParamRef(ParamRef *a, ParamRef *b)
1420 if (a->number != b->number)
1422 if (!equal(a->fields, b->fields))
1424 if (!equal(a->indirection, b->indirection))
1431 _equalAConst(A_Const *a, A_Const *b)
1433 if (!equal(&a->val, &b->val))
1435 if (!equal(a->typename, b->typename))
1442 _equalIdent(Ident *a, Ident *b)
1444 if (!equalstr(a->name, b->name))
1451 _equalFuncCall(FuncCall *a, FuncCall *b)
1453 if (!equal(a->funcname, b->funcname))
1455 if (!equal(a->args, b->args))
1457 if (a->agg_star != b->agg_star)
1459 if (a->agg_distinct != b->agg_distinct)
1466 _equalAIndices(A_Indices *a, A_Indices *b)
1468 if (!equal(a->lidx, b->lidx))
1470 if (!equal(a->uidx, b->uidx))
1477 _equalExprFieldSelect(ExprFieldSelect *a, ExprFieldSelect *b)
1479 if (!equal(a->arg, b->arg))
1481 if (!equal(a->fields, b->fields))
1483 if (!equal(a->indirection, b->indirection))
1490 _equalResTarget(ResTarget *a, ResTarget *b)
1492 if (!equalstr(a->name, b->name))
1494 if (!equal(a->indirection, b->indirection))
1496 if (!equal(a->val, b->val))
1503 _equalTypeCast(TypeCast *a, TypeCast *b)
1505 if (!equal(a->arg, b->arg))
1507 if (!equal(a->typename, b->typename))
1514 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1516 if (!equal(a->useOp, b->useOp))
1518 if (!equal(a->node, b->node))
1525 _equalAlias(Alias *a, Alias *b)
1527 if (!equalstr(a->aliasname, b->aliasname))
1529 if (!equal(a->colnames, b->colnames))
1536 _equalRangeVar(RangeVar *a, RangeVar *b)
1538 if (!equalstr(a->catalogname, b->catalogname))
1540 if (!equalstr(a->schemaname, b->schemaname))
1542 if (!equalstr(a->relname, b->relname))
1544 if (a->inhOpt != b->inhOpt)
1546 if (a->istemp != b->istemp)
1548 if (!equal(a->alias, b->alias))
1555 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1557 if (!equal(a->subquery, b->subquery))
1559 if (!equal(a->alias, b->alias))
1566 _equalRangeFunction(RangeFunction *a, RangeFunction *b)
1568 if (!equal(a->funccallnode, b->funccallnode))
1570 if (!equal(a->alias, b->alias))
1577 _equalTypeName(TypeName *a, TypeName *b)
1579 if (!equal(a->names, b->names))
1581 if (a->typeid != b->typeid)
1583 if (a->timezone != b->timezone)
1585 if (a->setof != b->setof)
1587 if (a->pct_type != b->pct_type)
1589 if (a->typmod != b->typmod)
1591 if (!equal(a->arrayBounds, b->arrayBounds))
1598 _equalIndexElem(IndexElem *a, IndexElem *b)
1600 if (!equalstr(a->name, b->name))
1602 if (!equal(a->funcname, b->funcname))
1604 if (!equal(a->args, b->args))
1606 if (!equal(a->opclass, b->opclass))
1613 _equalColumnDef(ColumnDef *a, ColumnDef *b)
1615 if (!equalstr(a->colname, b->colname))
1617 if (!equal(a->typename, b->typename))
1619 if (a->is_not_null != b->is_not_null)
1621 if (!equal(a->raw_default, b->raw_default))
1623 if (!equalstr(a->cooked_default, b->cooked_default))
1625 if (!equal(a->constraints, b->constraints))
1632 _equalConstraint(Constraint *a, Constraint *b)
1634 if (a->contype != b->contype)
1636 if (!equalstr(a->name, b->name))
1638 if (!equal(a->raw_expr, b->raw_expr))
1640 if (!equalstr(a->cooked_expr, b->cooked_expr))
1642 if (!equal(a->keys, b->keys))
1649 _equalDefElem(DefElem *a, DefElem *b)
1651 if (!equalstr(a->defname, b->defname))
1653 if (!equal(a->arg, b->arg))
1660 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
1662 if (!equal(a->resdom, b->resdom))
1664 if (!equal(a->fjoin, b->fjoin))
1666 if (!equal(a->expr, b->expr))
1673 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
1675 if (a->rtekind != b->rtekind)
1677 if (a->relid != b->relid)
1679 if (!equal(a->subquery, b->subquery))
1681 if (!equal(a->funcexpr, b->funcexpr))
1683 if (a->jointype != b->jointype)
1685 if (!equal(a->joinaliasvars, b->joinaliasvars))
1687 if (!equal(a->alias, b->alias))
1689 if (!equal(a->eref, b->eref))
1691 if (a->inh != b->inh)
1693 if (a->inFromCl != b->inFromCl)
1695 if (a->checkForRead != b->checkForRead)
1697 if (a->checkForWrite != b->checkForWrite)
1699 if (a->checkAsUser != b->checkAsUser)
1706 _equalSortClause(SortClause *a, SortClause *b)
1708 if (a->tleSortGroupRef != b->tleSortGroupRef)
1710 if (a->sortop != b->sortop)
1717 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
1719 if (!equalstr(a->constr_name, b->constr_name))
1721 if (!equal(a->pktable, b->pktable))
1723 if (!equal(a->fk_attrs, b->fk_attrs))
1725 if (!equal(a->pk_attrs, b->pk_attrs))
1727 if (!equalstr(a->match_type, b->match_type))
1729 if (a->actions != b->actions)
1731 if (a->deferrable != b->deferrable)
1733 if (a->initdeferred != b->initdeferred)
1740 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
1742 if (a->casetype != b->casetype)
1744 if (!equal(a->arg, b->arg))
1746 if (!equal(a->args, b->args))
1748 if (!equal(a->defresult, b->defresult))
1755 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
1757 if (!equal(a->expr, b->expr))
1759 if (!equal(a->result, b->result))
1766 _equalNullTest(NullTest *a, NullTest *b)
1768 if (!equal(a->arg, b->arg))
1770 if (a->nulltesttype != b->nulltesttype)
1776 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
1778 if (!equal(a->arg, b->arg))
1780 if (a->booltesttype != b->booltesttype)
1786 * Stuff from pg_list.h
1790 _equalValue(Value *a, Value *b)
1792 if (a->type != b->type)
1798 return a->val.ival == b->val.ival;
1802 return strcmp(a->val.str, b->val.str) == 0;
1812 * returns whether two nodes are equal
1815 equal(void *a, void *b)
1817 bool retval = false;
1823 * note that a!=b, so only one of them can be NULL
1825 if (a == NULL || b == NULL)
1829 * are they the same type of nodes?
1831 if (nodeTag(a) != nodeTag(b))
1837 retval = _equalSubPlan(a, b);
1841 retval = _equalResdom(a, b);
1844 retval = _equalFjoin(a, b);
1847 retval = _equalExpr(a, b);
1850 retval = _equalVar(a, b);
1853 retval = _equalOper(a, b);
1856 retval = _equalConst(a, b);
1859 retval = _equalParam(a, b);
1862 retval = _equalAggref(a, b);
1865 retval = _equalSubLink(a, b);
1868 retval = _equalFunc(a, b);
1871 retval = _equalFieldSelect(a, b);
1874 retval = _equalArrayRef(a, b);
1877 retval = _equalRelabelType(a, b);
1880 retval = _equalRangeTblRef(a, b);
1883 retval = _equalFromExpr(a, b);
1886 retval = _equalJoinExpr(a, b);
1890 retval = _equalRelOptInfo(a, b);
1893 retval = _equalPath(a, b);
1896 retval = _equalIndexPath(a, b);
1899 retval = _equalNestPath(a, b);
1902 retval = _equalMergePath(a, b);
1905 retval = _equalHashPath(a, b);
1908 retval = _equalPathKeyItem(a, b);
1910 case T_RestrictInfo:
1911 retval = _equalRestrictInfo(a, b);
1914 retval = _equalJoinInfo(a, b);
1917 retval = _equalStream(a, b);
1920 retval = _equalTidPath(a, b);
1923 retval = _equalAppendPath(a, b);
1925 case T_IndexOptInfo:
1926 retval = _equalIndexOptInfo(a, b);
1931 List *la = (List *) a;
1932 List *lb = (List *) b;
1936 * Try to reject by length check before we grovel through
1937 * all the elements...
1939 if (length(la) != length(lb))
1943 if (!equal(lfirst(l), lfirst(lb)))
1954 retval = _equalValue(a, b);
1958 retval = _equalQuery(a, b);
1961 retval = _equalInsertStmt(a, b);
1964 retval = _equalDeleteStmt(a, b);
1967 retval = _equalUpdateStmt(a, b);
1970 retval = _equalSelectStmt(a, b);
1972 case T_SetOperationStmt:
1973 retval = _equalSetOperationStmt(a, b);
1975 case T_AlterTableStmt:
1976 retval = _equalAlterTableStmt(a, b);
1979 retval = _equalGrantStmt(a, b);
1981 case T_ClosePortalStmt:
1982 retval = _equalClosePortalStmt(a, b);
1985 retval = _equalClusterStmt(a, b);
1988 retval = _equalCopyStmt(a, b);
1991 retval = _equalCreateStmt(a, b);
1994 retval = _equalDefineStmt(a, b);
1997 retval = _equalDropStmt(a, b);
1999 case T_TruncateStmt:
2000 retval = _equalTruncateStmt(a, b);
2003 retval = _equalCommentStmt(a, b);
2006 retval = _equalFetchStmt(a, b);
2009 retval = _equalIndexStmt(a, b);
2011 case T_CreateFunctionStmt:
2012 retval = _equalCreateFunctionStmt(a, b);
2014 case T_RemoveAggrStmt:
2015 retval = _equalRemoveAggrStmt(a, b);
2017 case T_RemoveFuncStmt:
2018 retval = _equalRemoveFuncStmt(a, b);
2020 case T_RemoveOperStmt:
2021 retval = _equalRemoveOperStmt(a, b);
2024 retval = _equalRenameStmt(a, b);
2027 retval = _equalRuleStmt(a, b);
2030 retval = _equalNotifyStmt(a, b);
2033 retval = _equalListenStmt(a, b);
2035 case T_UnlistenStmt:
2036 retval = _equalUnlistenStmt(a, b);
2038 case T_TransactionStmt:
2039 retval = _equalTransactionStmt(a, b);
2042 retval = _equalViewStmt(a, b);
2045 retval = _equalLoadStmt(a, b);
2047 case T_CreateDomainStmt:
2048 retval = _equalCreateDomainStmt(a, b);
2050 case T_CreatedbStmt:
2051 retval = _equalCreatedbStmt(a, b);
2053 case T_AlterDatabaseSetStmt:
2054 retval = _equalAlterDatabaseSetStmt(a, b);
2057 retval = _equalDropdbStmt(a, b);
2060 retval = _equalVacuumStmt(a, b);
2063 retval = _equalExplainStmt(a, b);
2065 case T_CreateSeqStmt:
2066 retval = _equalCreateSeqStmt(a, b);
2068 case T_VariableSetStmt:
2069 retval = _equalVariableSetStmt(a, b);
2071 case T_VariableShowStmt:
2072 retval = _equalVariableShowStmt(a, b);
2074 case T_VariableResetStmt:
2075 retval = _equalVariableResetStmt(a, b);
2077 case T_CreateTrigStmt:
2078 retval = _equalCreateTrigStmt(a, b);
2080 case T_DropPropertyStmt:
2081 retval = _equalDropPropertyStmt(a, b);
2083 case T_CreatePLangStmt:
2084 retval = _equalCreatePLangStmt(a, b);
2086 case T_DropPLangStmt:
2087 retval = _equalDropPLangStmt(a, b);
2089 case T_CreateUserStmt:
2090 retval = _equalCreateUserStmt(a, b);
2092 case T_AlterUserStmt:
2093 retval = _equalAlterUserStmt(a, b);
2095 case T_AlterUserSetStmt:
2096 retval = _equalAlterUserSetStmt(a, b);
2098 case T_DropUserStmt:
2099 retval = _equalDropUserStmt(a, b);
2102 retval = _equalLockStmt(a, b);
2104 case T_ConstraintsSetStmt:
2105 retval = _equalConstraintsSetStmt(a, b);
2107 case T_CreateGroupStmt:
2108 retval = _equalCreateGroupStmt(a, b);
2110 case T_AlterGroupStmt:
2111 retval = _equalAlterGroupStmt(a, b);
2113 case T_DropGroupStmt:
2114 retval = _equalDropGroupStmt(a, b);
2117 retval = _equalReindexStmt(a, b);
2119 case T_CheckPointStmt:
2122 case T_CreateSchemaStmt:
2123 retval = _equalCreateSchemaStmt(a, b);
2127 retval = _equalAExpr(a, b);
2130 retval = _equalColumnRef(a, b);
2133 retval = _equalParamRef(a, b);
2136 retval = _equalAConst(a, b);
2139 retval = _equalIdent(a, b);
2142 retval = _equalFuncCall(a, b);
2145 retval = _equalAIndices(a, b);
2147 case T_ExprFieldSelect:
2148 retval = _equalExprFieldSelect(a, b);
2151 retval = _equalResTarget(a, b);
2154 retval = _equalTypeCast(a, b);
2157 retval = _equalSortGroupBy(a, b);
2160 retval = _equalAlias(a, b);
2163 retval = _equalRangeVar(a, b);
2165 case T_RangeSubselect:
2166 retval = _equalRangeSubselect(a, b);
2168 case T_RangeFunction:
2169 retval = _equalRangeFunction(a, b);
2172 retval = _equalTypeName(a, b);
2175 retval = _equalIndexElem(a, b);
2178 retval = _equalColumnDef(a, b);
2181 retval = _equalConstraint(a, b);
2184 retval = _equalDefElem(a, b);
2187 retval = _equalTargetEntry(a, b);
2189 case T_RangeTblEntry:
2190 retval = _equalRangeTblEntry(a, b);
2193 retval = _equalSortClause(a, b);
2196 /* GroupClause is equivalent to SortClause */
2197 retval = _equalSortClause(a, b);
2200 retval = _equalCaseExpr(a, b);
2203 retval = _equalCaseWhen(a, b);
2206 retval = _equalNullTest(a, b);
2209 retval = _equalBooleanTest(a, b);
2211 case T_FkConstraint:
2212 retval = _equalFkConstraint(a, b);
2215 retval = _equalPrivGrantee(a, b);
2217 case T_FuncWithArgs:
2218 retval = _equalFuncWithArgs(a, b);
2220 case T_InsertDefault:
2221 retval = _equalInsertDefault(a, b);
2225 elog(WARNING, "equal: don't know whether nodes of type %d are equal",