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.147 2002/08/04 19:48:09 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)
915 if (a->isconstraint != b->isconstraint)
922 _equalCreateFunctionStmt(CreateFunctionStmt *a, CreateFunctionStmt *b)
924 if (a->replace != b->replace)
926 if (!equal(a->funcname, b->funcname))
928 if (!equal(a->argTypes, b->argTypes))
930 if (!equal(a->returnType, b->returnType))
932 if (!equal(a->options, b->options))
934 if (!equal(a->withClause, b->withClause))
941 _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
943 if (!equal(a->aggname, b->aggname))
945 if (!equal(a->aggtype, b->aggtype))
947 if (a->behavior != b->behavior)
954 _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
956 if (!equal(a->funcname, b->funcname))
958 if (!equal(a->args, b->args))
960 if (a->behavior != b->behavior)
967 _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
969 if (!equal(a->opname, b->opname))
971 if (!equal(a->args, b->args))
973 if (a->behavior != b->behavior)
980 _equalRemoveOpClassStmt(RemoveOpClassStmt *a, RemoveOpClassStmt *b)
982 if (!equal(a->opclassname, b->opclassname))
984 if (!equalstr(a->amname, b->amname))
986 if (a->behavior != b->behavior)
993 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
995 if (!equal(a->relation, b->relation))
997 if (!equalstr(a->oldname, b->oldname))
999 if (!equalstr(a->newname, b->newname))
1001 if (a->renameType != b->renameType)
1008 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
1010 if (!equal(a->relation, b->relation))
1012 if (!equalstr(a->rulename, b->rulename))
1014 if (!equal(a->whereClause, b->whereClause))
1016 if (a->event != b->event)
1018 if (a->instead != b->instead)
1020 if (!equal(a->actions, b->actions))
1027 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1029 if (!equal(a->relation, b->relation))
1036 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1038 if (!equal(a->relation, b->relation))
1045 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1047 if (!equal(a->relation, b->relation))
1054 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1056 if (a->command != b->command)
1058 if (!equal(a->options, b->options))
1065 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1067 if (!equal(a->view, b->view))
1069 if (!equal(a->aliases, b->aliases))
1071 if (!equal(a->query, b->query))
1078 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1080 if (!equalstr(a->filename, b->filename))
1087 _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
1089 if (!equal(a->domainname, b->domainname))
1091 if (!equal(a->typename, b->typename))
1093 if (!equal(a->constraints, b->constraints))
1100 _equalCreateOpClassStmt(CreateOpClassStmt *a, CreateOpClassStmt *b)
1102 if (!equal(a->opclassname, b->opclassname))
1104 if (!equalstr(a->amname, b->amname))
1106 if (!equal(a->datatype, b->datatype))
1108 if (!equal(a->items, b->items))
1110 if (a->isDefault != b->isDefault)
1117 _equalCreateOpClassItem(CreateOpClassItem *a, CreateOpClassItem *b)
1119 if (a->itemtype != b->itemtype)
1121 if (!equal(a->name, b->name))
1123 if (!equal(a->args, b->args))
1125 if (a->number != b->number)
1127 if (a->recheck != b->recheck)
1129 if (!equal(a->storedtype, b->storedtype))
1136 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1138 if (!equalstr(a->dbname, b->dbname))
1140 if (!equal(a->options, b->options))
1147 _equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
1149 if (!equalstr(a->dbname, b->dbname))
1151 if (!equalstr(a->variable, b->variable))
1153 if (!equal(a->value, b->value))
1160 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1162 if (!equalstr(a->dbname, b->dbname))
1169 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1171 if (a->vacuum != b->vacuum)
1173 if (a->full != b->full)
1175 if (a->analyze != b->analyze)
1177 if (a->freeze != b->freeze)
1179 if (a->verbose != b->verbose)
1181 if (!equal(a->relation, b->relation))
1183 if (!equal(a->va_cols, b->va_cols))
1190 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1192 if (!equal(a->query, b->query))
1194 if (a->verbose != b->verbose)
1196 if (a->analyze != b->analyze)
1203 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1205 if (!equal(a->sequence, b->sequence))
1207 if (!equal(a->options, b->options))
1214 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1216 if (!equalstr(a->name, b->name))
1218 if (!equal(a->args, b->args))
1220 if (a->is_local != b->is_local)
1227 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1229 if (!equalstr(a->name, b->name))
1236 _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
1238 if (!equalstr(a->name, b->name))
1245 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1247 if (!equalstr(a->trigname, b->trigname))
1249 if (!equal(a->relation, b->relation))
1251 if (!equal(a->funcname, b->funcname))
1253 if (!equal(a->args, b->args))
1255 if (a->before != b->before)
1257 if (a->row != b->row)
1259 if (strcmp(a->actions, b->actions) != 0)
1261 if (!equalstr(a->lang, b->lang))
1263 if (!equalstr(a->text, b->text))
1265 if (!equal(a->attr, b->attr))
1267 if (!equalstr(a->when, b->when))
1269 if (a->isconstraint != b->isconstraint)
1271 if (a->deferrable != b->deferrable)
1273 if (a->initdeferred != b->initdeferred)
1275 if (!equal(a->constrrel, b->constrrel))
1282 _equalDropPropertyStmt(DropPropertyStmt *a, DropPropertyStmt *b)
1284 if (!equal(a->relation, b->relation))
1286 if (!equalstr(a->property, b->property))
1288 if (a->removeType != b->removeType)
1290 if (a->behavior != b->behavior)
1297 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1299 if (!equalstr(a->plname, b->plname))
1301 if (!equal(a->plhandler, b->plhandler))
1303 if (!equal(a->plvalidator, b->plvalidator))
1305 if (a->pltrusted != b->pltrusted)
1312 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1314 if (!equalstr(a->plname, b->plname))
1316 if (a->behavior != b->behavior)
1323 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1325 if (!equalstr(a->user, b->user))
1327 if (!equal(a->options, b->options))
1334 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1336 if (!equalstr(a->user, b->user))
1338 if (!equal(a->options, b->options))
1345 _equalAlterUserSetStmt(AlterUserSetStmt *a, AlterUserSetStmt *b)
1347 if (!equalstr(a->user, b->user))
1349 if (!equalstr(a->variable, b->variable))
1351 if (!equal(a->value, b->value))
1358 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1360 if (!equal(a->users, b->users))
1367 _equalLockStmt(LockStmt *a, LockStmt *b)
1369 if (!equal(a->relations, b->relations))
1371 if (a->mode != b->mode)
1378 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1380 if (!equal(a->constraints, b->constraints))
1382 if (a->deferred != b->deferred)
1389 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1391 if (!equalstr(a->name, b->name))
1393 if (!equal(a->options, b->options))
1400 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1402 if (!equalstr(a->name, b->name))
1404 if (a->action != b->action)
1406 if (!equal(a->listUsers, b->listUsers))
1413 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1415 if (!equalstr(a->name, b->name))
1422 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1424 if (a->reindexType != b->reindexType)
1426 if (!equal(a->relation, b->relation))
1428 if (!equalstr(a->name, b->name))
1430 if (a->force != b->force)
1432 if (a->all != b->all)
1439 _equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
1441 if (!equalstr(a->schemaname, b->schemaname))
1443 if (!equalstr(a->authid, b->authid))
1445 if (!equal(a->schemaElts, b->schemaElts))
1452 _equalAExpr(A_Expr *a, A_Expr *b)
1454 if (a->oper != b->oper)
1456 if (!equal(a->name, b->name))
1458 if (!equal(a->lexpr, b->lexpr))
1460 if (!equal(a->rexpr, b->rexpr))
1467 _equalColumnRef(ColumnRef *a, ColumnRef *b)
1469 if (!equal(a->fields, b->fields))
1471 if (!equal(a->indirection, b->indirection))
1478 _equalParamRef(ParamRef *a, ParamRef *b)
1480 if (a->number != b->number)
1482 if (!equal(a->fields, b->fields))
1484 if (!equal(a->indirection, b->indirection))
1491 _equalAConst(A_Const *a, A_Const *b)
1493 if (!equal(&a->val, &b->val))
1495 if (!equal(a->typename, b->typename))
1502 _equalIdent(Ident *a, Ident *b)
1504 if (!equalstr(a->name, b->name))
1511 _equalFuncCall(FuncCall *a, FuncCall *b)
1513 if (!equal(a->funcname, b->funcname))
1515 if (!equal(a->args, b->args))
1517 if (a->agg_star != b->agg_star)
1519 if (a->agg_distinct != b->agg_distinct)
1526 _equalAIndices(A_Indices *a, A_Indices *b)
1528 if (!equal(a->lidx, b->lidx))
1530 if (!equal(a->uidx, b->uidx))
1537 _equalExprFieldSelect(ExprFieldSelect *a, ExprFieldSelect *b)
1539 if (!equal(a->arg, b->arg))
1541 if (!equal(a->fields, b->fields))
1543 if (!equal(a->indirection, b->indirection))
1550 _equalResTarget(ResTarget *a, ResTarget *b)
1552 if (!equalstr(a->name, b->name))
1554 if (!equal(a->indirection, b->indirection))
1556 if (!equal(a->val, b->val))
1563 _equalTypeCast(TypeCast *a, TypeCast *b)
1565 if (!equal(a->arg, b->arg))
1567 if (!equal(a->typename, b->typename))
1574 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1576 if (!equal(a->useOp, b->useOp))
1578 if (!equal(a->node, b->node))
1585 _equalAlias(Alias *a, Alias *b)
1587 if (!equalstr(a->aliasname, b->aliasname))
1589 if (!equal(a->colnames, b->colnames))
1596 _equalRangeVar(RangeVar *a, RangeVar *b)
1598 if (!equalstr(a->catalogname, b->catalogname))
1600 if (!equalstr(a->schemaname, b->schemaname))
1602 if (!equalstr(a->relname, b->relname))
1604 if (a->inhOpt != b->inhOpt)
1606 if (a->istemp != b->istemp)
1608 if (!equal(a->alias, b->alias))
1610 if (!equal(a->coldeflist, b->coldeflist))
1617 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1619 if (!equal(a->subquery, b->subquery))
1621 if (!equal(a->alias, b->alias))
1628 _equalRangeFunction(RangeFunction *a, RangeFunction *b)
1630 if (!equal(a->funccallnode, b->funccallnode))
1632 if (!equal(a->alias, b->alias))
1639 _equalTypeName(TypeName *a, TypeName *b)
1641 if (!equal(a->names, b->names))
1643 if (a->typeid != b->typeid)
1645 if (a->timezone != b->timezone)
1647 if (a->setof != b->setof)
1649 if (a->pct_type != b->pct_type)
1651 if (a->typmod != b->typmod)
1653 if (!equal(a->arrayBounds, b->arrayBounds))
1660 _equalIndexElem(IndexElem *a, IndexElem *b)
1662 if (!equalstr(a->name, b->name))
1664 if (!equal(a->funcname, b->funcname))
1666 if (!equal(a->args, b->args))
1668 if (!equal(a->opclass, b->opclass))
1675 _equalColumnDef(ColumnDef *a, ColumnDef *b)
1677 if (!equalstr(a->colname, b->colname))
1679 if (!equal(a->typename, b->typename))
1681 if (a->is_not_null != b->is_not_null)
1683 if (!equal(a->raw_default, b->raw_default))
1685 if (!equalstr(a->cooked_default, b->cooked_default))
1687 if (!equal(a->constraints, b->constraints))
1689 if (!equal(a->support, b->support))
1696 _equalConstraint(Constraint *a, Constraint *b)
1698 if (a->contype != b->contype)
1700 if (!equalstr(a->name, b->name))
1702 if (!equal(a->raw_expr, b->raw_expr))
1704 if (!equalstr(a->cooked_expr, b->cooked_expr))
1706 if (!equal(a->keys, b->keys))
1713 _equalDefElem(DefElem *a, DefElem *b)
1715 if (!equalstr(a->defname, b->defname))
1717 if (!equal(a->arg, b->arg))
1724 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
1726 if (!equal(a->resdom, b->resdom))
1728 if (!equal(a->fjoin, b->fjoin))
1730 if (!equal(a->expr, b->expr))
1737 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
1739 if (a->rtekind != b->rtekind)
1741 if (a->relid != b->relid)
1743 if (!equal(a->subquery, b->subquery))
1745 if (!equal(a->funcexpr, b->funcexpr))
1747 if (!equal(a->coldeflist, b->coldeflist))
1749 if (a->jointype != b->jointype)
1751 if (!equal(a->joinaliasvars, b->joinaliasvars))
1753 if (!equal(a->alias, b->alias))
1755 if (!equal(a->eref, b->eref))
1757 if (a->inh != b->inh)
1759 if (a->inFromCl != b->inFromCl)
1761 if (a->checkForRead != b->checkForRead)
1763 if (a->checkForWrite != b->checkForWrite)
1765 if (a->checkAsUser != b->checkAsUser)
1772 _equalSortClause(SortClause *a, SortClause *b)
1774 if (a->tleSortGroupRef != b->tleSortGroupRef)
1776 if (a->sortop != b->sortop)
1783 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
1785 if (!equalstr(a->constr_name, b->constr_name))
1787 if (!equal(a->pktable, b->pktable))
1789 if (!equal(a->fk_attrs, b->fk_attrs))
1791 if (!equal(a->pk_attrs, b->pk_attrs))
1793 if (a->fk_matchtype != b->fk_matchtype)
1795 if (a->fk_upd_action != b->fk_upd_action)
1797 if (a->fk_del_action != b->fk_del_action)
1799 if (a->deferrable != b->deferrable)
1801 if (a->initdeferred != b->initdeferred)
1803 if (a->skip_validation != b->skip_validation)
1810 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
1812 if (a->casetype != b->casetype)
1814 if (!equal(a->arg, b->arg))
1816 if (!equal(a->args, b->args))
1818 if (!equal(a->defresult, b->defresult))
1825 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
1827 if (!equal(a->expr, b->expr))
1829 if (!equal(a->result, b->result))
1836 _equalNullTest(NullTest *a, NullTest *b)
1838 if (!equal(a->arg, b->arg))
1840 if (a->nulltesttype != b->nulltesttype)
1846 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
1848 if (!equal(a->arg, b->arg))
1850 if (a->booltesttype != b->booltesttype)
1856 * Stuff from pg_list.h
1860 _equalValue(Value *a, Value *b)
1862 if (a->type != b->type)
1868 return a->val.ival == b->val.ival;
1872 return strcmp(a->val.str, b->val.str) == 0;
1882 * returns whether two nodes are equal
1885 equal(void *a, void *b)
1887 bool retval = false;
1893 * note that a!=b, so only one of them can be NULL
1895 if (a == NULL || b == NULL)
1899 * are they the same type of nodes?
1901 if (nodeTag(a) != nodeTag(b))
1907 retval = _equalSubPlan(a, b);
1911 retval = _equalResdom(a, b);
1914 retval = _equalFjoin(a, b);
1917 retval = _equalExpr(a, b);
1920 retval = _equalVar(a, b);
1923 retval = _equalOper(a, b);
1926 retval = _equalConst(a, b);
1929 retval = _equalParam(a, b);
1932 retval = _equalAggref(a, b);
1935 retval = _equalSubLink(a, b);
1938 retval = _equalFunc(a, b);
1941 retval = _equalFieldSelect(a, b);
1944 retval = _equalArrayRef(a, b);
1947 retval = _equalRelabelType(a, b);
1950 retval = _equalRangeTblRef(a, b);
1953 retval = _equalFromExpr(a, b);
1956 retval = _equalJoinExpr(a, b);
1960 retval = _equalRelOptInfo(a, b);
1963 retval = _equalPath(a, b);
1966 retval = _equalIndexPath(a, b);
1969 retval = _equalNestPath(a, b);
1972 retval = _equalMergePath(a, b);
1975 retval = _equalHashPath(a, b);
1978 retval = _equalPathKeyItem(a, b);
1980 case T_RestrictInfo:
1981 retval = _equalRestrictInfo(a, b);
1984 retval = _equalJoinInfo(a, b);
1987 retval = _equalStream(a, b);
1990 retval = _equalTidPath(a, b);
1993 retval = _equalAppendPath(a, b);
1995 case T_IndexOptInfo:
1996 retval = _equalIndexOptInfo(a, b);
2001 List *la = (List *) a;
2002 List *lb = (List *) b;
2006 * Try to reject by length check before we grovel through
2007 * all the elements...
2009 if (length(la) != length(lb))
2013 if (!equal(lfirst(l), lfirst(lb)))
2024 retval = _equalValue(a, b);
2028 retval = _equalQuery(a, b);
2031 retval = _equalInsertStmt(a, b);
2034 retval = _equalDeleteStmt(a, b);
2037 retval = _equalUpdateStmt(a, b);
2040 retval = _equalSelectStmt(a, b);
2042 case T_SetOperationStmt:
2043 retval = _equalSetOperationStmt(a, b);
2045 case T_AlterTableStmt:
2046 retval = _equalAlterTableStmt(a, b);
2049 retval = _equalGrantStmt(a, b);
2051 case T_ClosePortalStmt:
2052 retval = _equalClosePortalStmt(a, b);
2055 retval = _equalClusterStmt(a, b);
2058 retval = _equalCopyStmt(a, b);
2061 retval = _equalCreateStmt(a, b);
2064 retval = _equalDefineStmt(a, b);
2067 retval = _equalDropStmt(a, b);
2069 case T_TruncateStmt:
2070 retval = _equalTruncateStmt(a, b);
2073 retval = _equalCommentStmt(a, b);
2076 retval = _equalFetchStmt(a, b);
2079 retval = _equalIndexStmt(a, b);
2081 case T_CreateFunctionStmt:
2082 retval = _equalCreateFunctionStmt(a, b);
2084 case T_RemoveAggrStmt:
2085 retval = _equalRemoveAggrStmt(a, b);
2087 case T_RemoveFuncStmt:
2088 retval = _equalRemoveFuncStmt(a, b);
2090 case T_RemoveOperStmt:
2091 retval = _equalRemoveOperStmt(a, b);
2093 case T_RemoveOpClassStmt:
2094 retval = _equalRemoveOpClassStmt(a, b);
2097 retval = _equalRenameStmt(a, b);
2100 retval = _equalRuleStmt(a, b);
2103 retval = _equalNotifyStmt(a, b);
2106 retval = _equalListenStmt(a, b);
2108 case T_UnlistenStmt:
2109 retval = _equalUnlistenStmt(a, b);
2111 case T_TransactionStmt:
2112 retval = _equalTransactionStmt(a, b);
2115 retval = _equalViewStmt(a, b);
2118 retval = _equalLoadStmt(a, b);
2120 case T_CreateDomainStmt:
2121 retval = _equalCreateDomainStmt(a, b);
2123 case T_CreateOpClassStmt:
2124 retval = _equalCreateOpClassStmt(a, b);
2126 case T_CreateOpClassItem:
2127 retval = _equalCreateOpClassItem(a, b);
2129 case T_CreatedbStmt:
2130 retval = _equalCreatedbStmt(a, b);
2132 case T_AlterDatabaseSetStmt:
2133 retval = _equalAlterDatabaseSetStmt(a, b);
2136 retval = _equalDropdbStmt(a, b);
2139 retval = _equalVacuumStmt(a, b);
2142 retval = _equalExplainStmt(a, b);
2144 case T_CreateSeqStmt:
2145 retval = _equalCreateSeqStmt(a, b);
2147 case T_VariableSetStmt:
2148 retval = _equalVariableSetStmt(a, b);
2150 case T_VariableShowStmt:
2151 retval = _equalVariableShowStmt(a, b);
2153 case T_VariableResetStmt:
2154 retval = _equalVariableResetStmt(a, b);
2156 case T_CreateTrigStmt:
2157 retval = _equalCreateTrigStmt(a, b);
2159 case T_DropPropertyStmt:
2160 retval = _equalDropPropertyStmt(a, b);
2162 case T_CreatePLangStmt:
2163 retval = _equalCreatePLangStmt(a, b);
2165 case T_DropPLangStmt:
2166 retval = _equalDropPLangStmt(a, b);
2168 case T_CreateUserStmt:
2169 retval = _equalCreateUserStmt(a, b);
2171 case T_AlterUserStmt:
2172 retval = _equalAlterUserStmt(a, b);
2174 case T_AlterUserSetStmt:
2175 retval = _equalAlterUserSetStmt(a, b);
2177 case T_DropUserStmt:
2178 retval = _equalDropUserStmt(a, b);
2181 retval = _equalLockStmt(a, b);
2183 case T_ConstraintsSetStmt:
2184 retval = _equalConstraintsSetStmt(a, b);
2186 case T_CreateGroupStmt:
2187 retval = _equalCreateGroupStmt(a, b);
2189 case T_AlterGroupStmt:
2190 retval = _equalAlterGroupStmt(a, b);
2192 case T_DropGroupStmt:
2193 retval = _equalDropGroupStmt(a, b);
2196 retval = _equalReindexStmt(a, b);
2198 case T_CheckPointStmt:
2201 case T_CreateSchemaStmt:
2202 retval = _equalCreateSchemaStmt(a, b);
2206 retval = _equalAExpr(a, b);
2209 retval = _equalColumnRef(a, b);
2212 retval = _equalParamRef(a, b);
2215 retval = _equalAConst(a, b);
2218 retval = _equalIdent(a, b);
2221 retval = _equalFuncCall(a, b);
2224 retval = _equalAIndices(a, b);
2226 case T_ExprFieldSelect:
2227 retval = _equalExprFieldSelect(a, b);
2230 retval = _equalResTarget(a, b);
2233 retval = _equalTypeCast(a, b);
2236 retval = _equalSortGroupBy(a, b);
2239 retval = _equalAlias(a, b);
2242 retval = _equalRangeVar(a, b);
2244 case T_RangeSubselect:
2245 retval = _equalRangeSubselect(a, b);
2247 case T_RangeFunction:
2248 retval = _equalRangeFunction(a, b);
2251 retval = _equalTypeName(a, b);
2254 retval = _equalIndexElem(a, b);
2257 retval = _equalColumnDef(a, b);
2260 retval = _equalConstraint(a, b);
2263 retval = _equalDefElem(a, b);
2266 retval = _equalTargetEntry(a, b);
2268 case T_RangeTblEntry:
2269 retval = _equalRangeTblEntry(a, b);
2272 retval = _equalSortClause(a, b);
2275 /* GroupClause is equivalent to SortClause */
2276 retval = _equalSortClause(a, b);
2279 retval = _equalCaseExpr(a, b);
2282 retval = _equalCaseWhen(a, b);
2285 retval = _equalNullTest(a, b);
2288 retval = _equalBooleanTest(a, b);
2290 case T_FkConstraint:
2291 retval = _equalFkConstraint(a, b);
2294 retval = _equalPrivGrantee(a, b);
2296 case T_FuncWithArgs:
2297 retval = _equalFuncWithArgs(a, b);
2299 case T_InsertDefault:
2300 retval = _equalInsertDefault(a, b);
2304 elog(WARNING, "equal: don't know whether nodes of type %d are equal",