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.167 2002/11/24 21:52:13 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)
221 * Special-case COERCE_DONTCARE, so that pathkeys can build coercion
222 * nodes that are equal() to both explicit and implicit coercions.
224 if (a->funcformat != b->funcformat &&
225 a->funcformat != COERCE_DONTCARE &&
226 b->funcformat != COERCE_DONTCARE)
229 /* Note we do not look at func_fcache; see notes for _equalOper */
235 _equalAggref(Aggref *a, Aggref *b)
237 if (a->aggfnoid != b->aggfnoid)
239 if (a->aggtype != b->aggtype)
241 if (!equal(a->target, b->target))
243 if (a->aggstar != b->aggstar)
245 if (a->aggdistinct != b->aggdistinct)
247 /* ignore aggno, which is only a private field for the executor */
252 _equalSubLink(SubLink *a, SubLink *b)
254 if (a->subLinkType != b->subLinkType)
256 if (a->useor != b->useor)
258 if (!equal(a->lefthand, b->lefthand))
260 if (!equal(a->oper, b->oper))
262 if (!equal(a->subselect, b->subselect))
268 _equalArrayRef(ArrayRef *a, ArrayRef *b)
270 if (a->refrestype != b->refrestype)
272 if (a->refattrlength != b->refattrlength)
274 if (a->refelemlength != b->refelemlength)
276 if (a->refelembyval != b->refelembyval)
278 if (a->refelemalign != b->refelemalign)
280 if (!equal(a->refupperindexpr, b->refupperindexpr))
282 if (!equal(a->reflowerindexpr, b->reflowerindexpr))
284 if (!equal(a->refexpr, b->refexpr))
286 if (!equal(a->refassgnexpr, b->refassgnexpr))
292 _equalFieldSelect(FieldSelect *a, FieldSelect *b)
294 if (!equal(a->arg, b->arg))
296 if (a->fieldnum != b->fieldnum)
298 if (a->resulttype != b->resulttype)
300 if (a->resulttypmod != b->resulttypmod)
306 _equalRelabelType(RelabelType *a, RelabelType *b)
308 if (!equal(a->arg, b->arg))
310 if (a->resulttype != b->resulttype)
312 if (a->resulttypmod != b->resulttypmod)
315 * Special-case COERCE_DONTCARE, so that pathkeys can build coercion
316 * nodes that are equal() to both explicit and implicit coercions.
318 if (a->relabelformat != b->relabelformat &&
319 a->relabelformat != COERCE_DONTCARE &&
320 b->relabelformat != COERCE_DONTCARE)
326 _equalRangeTblRef(RangeTblRef *a, RangeTblRef *b)
328 if (a->rtindex != b->rtindex)
335 _equalFromExpr(FromExpr *a, FromExpr *b)
337 if (!equal(a->fromlist, b->fromlist))
339 if (!equal(a->quals, b->quals))
346 _equalJoinExpr(JoinExpr *a, JoinExpr *b)
348 if (a->jointype != b->jointype)
350 if (a->isNatural != b->isNatural)
352 if (!equal(a->larg, b->larg))
354 if (!equal(a->rarg, b->rarg))
356 if (!equal(a->using, b->using))
358 if (!equal(a->quals, b->quals))
360 if (!equal(a->alias, b->alias))
362 if (a->rtindex != b->rtindex)
369 * Stuff from relation.h
373 _equalRelOptInfo(RelOptInfo *a, RelOptInfo *b)
376 * We treat RelOptInfos as equal if they refer to the same base rels
377 * joined in the same order. Is this appropriate/sufficient?
379 return equali(a->relids, b->relids);
383 _equalIndexOptInfo(IndexOptInfo *a, IndexOptInfo *b)
386 * We treat IndexOptInfos as equal if they refer to the same index. Is
389 if (a->indexoid != b->indexoid)
395 _equalPathKeyItem(PathKeyItem *a, PathKeyItem *b)
397 if (a->sortop != b->sortop)
399 if (!equal(a->key, b->key))
405 _equalPath(Path *a, Path *b)
407 if (a->pathtype != b->pathtype)
409 if (!equal(a->parent, b->parent))
413 * do not check path costs, since they may not be set yet, and being
414 * float values there are roundoff error issues anyway...
416 if (!equal(a->pathkeys, b->pathkeys))
422 _equalIndexPath(IndexPath *a, IndexPath *b)
424 if (!_equalPath((Path *) a, (Path *) b))
426 if (!equal(a->indexinfo, b->indexinfo))
428 if (!equal(a->indexqual, b->indexqual))
430 if (a->indexscandir != b->indexscandir)
434 * Skip 'rows' because of possibility of floating-point roundoff
435 * error. It should be derivable from the other fields anyway.
441 _equalTidPath(TidPath *a, TidPath *b)
443 if (!_equalPath((Path *) a, (Path *) b))
445 if (!equal(a->tideval, b->tideval))
447 if (!equali(a->unjoined_relids, b->unjoined_relids))
453 _equalAppendPath(AppendPath *a, AppendPath *b)
455 if (!_equalPath((Path *) a, (Path *) b))
457 if (!equal(a->subpaths, b->subpaths))
463 _equalResultPath(ResultPath *a, ResultPath *b)
465 if (!_equalPath((Path *) a, (Path *) b))
467 if (!equal(a->subpath, b->subpath))
469 if (!equal(a->constantqual, b->constantqual))
475 _equalJoinPath(JoinPath *a, JoinPath *b)
477 if (!_equalPath((Path *) a, (Path *) b))
479 if (a->jointype != b->jointype)
481 if (!equal(a->outerjoinpath, b->outerjoinpath))
483 if (!equal(a->innerjoinpath, b->innerjoinpath))
485 if (!equal(a->joinrestrictinfo, b->joinrestrictinfo))
491 _equalNestPath(NestPath *a, NestPath *b)
493 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
499 _equalMergePath(MergePath *a, MergePath *b)
501 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
503 if (!equal(a->path_mergeclauses, b->path_mergeclauses))
505 if (!equal(a->outersortkeys, b->outersortkeys))
507 if (!equal(a->innersortkeys, b->innersortkeys))
513 _equalHashPath(HashPath *a, HashPath *b)
515 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
517 if (!equal(a->path_hashclauses, b->path_hashclauses))
523 _equalSubPlan(SubPlan *a, SubPlan *b)
525 /* should compare plans, but have to settle for comparing plan IDs */
526 if (a->plan_id != b->plan_id)
529 if (!equal(a->rtable, b->rtable))
532 if (!equal(a->sublink, b->sublink))
539 _equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
541 if (!equal(a->clause, b->clause))
543 if (a->ispusheddown != b->ispusheddown)
547 * We ignore subclauseindices, eval_cost, this_selec, left/right_pathkey,
548 * and left/right_bucketsize, since they may not be set yet, and should be
549 * derivable from the clause anyway. Probably it's not really necessary
550 * to compare any of these remaining fields ...
552 if (a->mergejoinoperator != b->mergejoinoperator)
554 if (a->left_sortop != b->left_sortop)
556 if (a->right_sortop != b->right_sortop)
558 if (a->hashjoinoperator != b->hashjoinoperator)
564 _equalJoinInfo(JoinInfo *a, JoinInfo *b)
566 if (!equali(a->unjoined_relids, b->unjoined_relids))
568 if (!equal(a->jinfo_restrictinfo, b->jinfo_restrictinfo))
574 _equalInnerIndexscanInfo(InnerIndexscanInfo *a, InnerIndexscanInfo *b)
576 if (!equali(a->other_relids, b->other_relids))
578 if (a->isouterjoin != b->isouterjoin)
580 if (!equal(a->best_innerpath, b->best_innerpath))
586 * Stuff from parsenodes.h
590 _equalQuery(Query *a, Query *b)
592 if (a->commandType != b->commandType)
594 if (a->querySource != b->querySource)
596 if (!equal(a->utilityStmt, b->utilityStmt))
598 if (a->resultRelation != b->resultRelation)
600 if (!equal(a->into, b->into))
602 if (a->isPortal != b->isPortal)
604 if (a->isBinary != b->isBinary)
606 if (a->hasAggs != b->hasAggs)
608 if (a->hasSubLinks != b->hasSubLinks)
610 if (!equal(a->rtable, b->rtable))
612 if (!equal(a->jointree, b->jointree))
614 if (!equali(a->rowMarks, b->rowMarks))
616 if (!equal(a->targetList, b->targetList))
618 if (!equal(a->groupClause, b->groupClause))
620 if (!equal(a->havingQual, b->havingQual))
622 if (!equal(a->distinctClause, b->distinctClause))
624 if (!equal(a->sortClause, b->sortClause))
626 if (!equal(a->limitOffset, b->limitOffset))
628 if (!equal(a->limitCount, b->limitCount))
630 if (!equal(a->setOperations, b->setOperations))
632 if (!equali(a->resultRelations, b->resultRelations))
636 * We do not check the internal-to-the-planner fields: base_rel_list,
637 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys,
638 * hasJoinRTEs. They might not be set yet, and in any case they should
639 * be derivable from the other fields.
645 _equalInsertStmt(InsertStmt *a, InsertStmt *b)
647 if (!equal(a->relation, b->relation))
649 if (!equal(a->cols, b->cols))
651 if (!equal(a->targetList, b->targetList))
653 if (!equal(a->selectStmt, b->selectStmt))
660 _equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
662 if (!equal(a->relation, b->relation))
664 if (!equal(a->whereClause, b->whereClause))
671 _equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
673 if (!equal(a->relation, b->relation))
675 if (!equal(a->targetList, b->targetList))
677 if (!equal(a->whereClause, b->whereClause))
679 if (!equal(a->fromClause, b->fromClause))
686 _equalSelectStmt(SelectStmt *a, SelectStmt *b)
688 if (!equal(a->distinctClause, b->distinctClause))
690 if (!equal(a->into, b->into))
692 if (!equal(a->intoColNames, b->intoColNames))
694 if (!equal(a->targetList, b->targetList))
696 if (!equal(a->fromClause, b->fromClause))
698 if (!equal(a->whereClause, b->whereClause))
700 if (!equal(a->groupClause, b->groupClause))
702 if (!equal(a->havingClause, b->havingClause))
704 if (!equal(a->sortClause, b->sortClause))
706 if (!equalstr(a->portalname, b->portalname))
708 if (a->binary != b->binary)
710 if (!equal(a->limitOffset, b->limitOffset))
712 if (!equal(a->limitCount, b->limitCount))
714 if (!equal(a->forUpdate, b->forUpdate))
718 if (a->all != b->all)
720 if (!equal(a->larg, b->larg))
722 if (!equal(a->rarg, b->rarg))
729 _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
733 if (a->all != b->all)
735 if (!equal(a->larg, b->larg))
737 if (!equal(a->rarg, b->rarg))
739 if (!equali(a->colTypes, b->colTypes))
746 _equalAlterTableStmt(AlterTableStmt *a, AlterTableStmt *b)
748 if (a->subtype != b->subtype)
750 if (!equal(a->relation, b->relation))
752 if (!equalstr(a->name, b->name))
754 if (!equal(a->def, b->def))
756 if (a->behavior != b->behavior)
763 _equalGrantStmt(GrantStmt *a, GrantStmt *b)
765 if (a->is_grant != b->is_grant)
767 if (a->objtype != b->objtype)
769 if (!equal(a->objects, b->objects))
771 if (!equali(a->privileges, b->privileges))
773 if (!equal(a->grantees, b->grantees))
780 _equalPrivGrantee(PrivGrantee *a, PrivGrantee *b)
782 return equalstr(a->username, b->username)
783 && equalstr(a->groupname, b->groupname);
787 _equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
789 return equal(a->funcname, b->funcname)
790 && equal(a->funcargs, b->funcargs);
794 _equalInsertDefault(InsertDefault *a, InsertDefault *b)
800 _equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
802 if (!equalstr(a->portalname, b->portalname))
809 _equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
811 if (!equal(a->relation, b->relation))
813 if (!equalstr(a->indexname, b->indexname))
820 _equalCopyStmt(CopyStmt *a, CopyStmt *b)
822 if (!equal(a->relation, b->relation))
824 if (!equal(a->attlist, b->attlist))
826 if (a->is_from != b->is_from)
828 if (!equalstr(a->filename, b->filename))
830 if (!equal(a->options, b->options))
837 _equalCreateStmt(CreateStmt *a, CreateStmt *b)
839 if (!equal(a->relation, b->relation))
841 if (!equal(a->tableElts, b->tableElts))
843 if (!equal(a->inhRelations, b->inhRelations))
845 if (!equal(a->constraints, b->constraints))
847 if (a->hasoids != b->hasoids)
849 if (a->oncommit != b->oncommit)
856 _equalDefineStmt(DefineStmt *a, DefineStmt *b)
858 if (a->defType != b->defType)
860 if (!equal(a->defnames, b->defnames))
862 if (!equal(a->definition, b->definition))
869 _equalDropStmt(DropStmt *a, DropStmt *b)
871 if (!equal(a->objects, b->objects))
873 if (a->removeType != b->removeType)
875 if (a->behavior != b->behavior)
882 _equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
884 if (!equal(a->relation, b->relation))
891 _equalCommentStmt(CommentStmt *a, CommentStmt *b)
893 if (a->objtype != b->objtype)
895 if (!equal(a->objname, b->objname))
897 if (!equal(a->objargs, b->objargs))
899 if (!equalstr(a->comment, b->comment))
906 _equalFetchStmt(FetchStmt *a, FetchStmt *b)
908 if (a->direction != b->direction)
910 if (a->howMany != b->howMany)
912 if (!equalstr(a->portalname, b->portalname))
914 if (a->ismove != b->ismove)
921 _equalIndexStmt(IndexStmt *a, IndexStmt *b)
923 if (!equalstr(a->idxname, b->idxname))
925 if (!equal(a->relation, b->relation))
927 if (!equalstr(a->accessMethod, b->accessMethod))
929 if (!equal(a->indexParams, b->indexParams))
931 if (!equal(a->whereClause, b->whereClause))
933 if (!equal(a->rangetable, b->rangetable))
935 if (a->unique != b->unique)
937 if (a->primary != b->primary)
939 if (a->isconstraint != b->isconstraint)
946 _equalCreateFunctionStmt(CreateFunctionStmt *a, CreateFunctionStmt *b)
948 if (a->replace != b->replace)
950 if (!equal(a->funcname, b->funcname))
952 if (!equal(a->argTypes, b->argTypes))
954 if (!equal(a->returnType, b->returnType))
956 if (!equal(a->options, b->options))
958 if (!equal(a->withClause, b->withClause))
965 _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
967 if (!equal(a->aggname, b->aggname))
969 if (!equal(a->aggtype, b->aggtype))
971 if (a->behavior != b->behavior)
978 _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
980 if (!equal(a->funcname, b->funcname))
982 if (!equal(a->args, b->args))
984 if (a->behavior != b->behavior)
991 _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
993 if (!equal(a->opname, b->opname))
995 if (!equal(a->args, b->args))
997 if (a->behavior != b->behavior)
1004 _equalRemoveOpClassStmt(RemoveOpClassStmt *a, RemoveOpClassStmt *b)
1006 if (!equal(a->opclassname, b->opclassname))
1008 if (!equalstr(a->amname, b->amname))
1010 if (a->behavior != b->behavior)
1017 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
1019 if (!equal(a->relation, b->relation))
1021 if (!equalstr(a->oldname, b->oldname))
1023 if (!equalstr(a->newname, b->newname))
1025 if (a->renameType != b->renameType)
1032 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
1034 if (!equal(a->relation, b->relation))
1036 if (!equalstr(a->rulename, b->rulename))
1038 if (!equal(a->whereClause, b->whereClause))
1040 if (a->event != b->event)
1042 if (a->instead != b->instead)
1044 if (a->replace != b->replace)
1046 if (!equal(a->actions, b->actions))
1053 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1055 if (!equal(a->relation, b->relation))
1062 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1064 if (!equal(a->relation, b->relation))
1071 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1073 if (!equal(a->relation, b->relation))
1080 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1082 if (a->command != b->command)
1084 if (!equal(a->options, b->options))
1091 _equalCompositeTypeStmt(CompositeTypeStmt *a, CompositeTypeStmt *b)
1093 if (!equal(a->typevar, b->typevar))
1095 if (!equal(a->coldeflist, b->coldeflist))
1102 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1104 if (!equal(a->view, b->view))
1106 if (!equal(a->aliases, b->aliases))
1108 if (!equal(a->query, b->query))
1110 if (a->replace != b->replace)
1117 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1119 if (!equalstr(a->filename, b->filename))
1126 _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
1128 if (!equal(a->domainname, b->domainname))
1130 if (!equal(a->typename, b->typename))
1132 if (!equal(a->constraints, b->constraints))
1139 _equalCreateOpClassStmt(CreateOpClassStmt *a, CreateOpClassStmt *b)
1141 if (!equal(a->opclassname, b->opclassname))
1143 if (!equalstr(a->amname, b->amname))
1145 if (!equal(a->datatype, b->datatype))
1147 if (!equal(a->items, b->items))
1149 if (a->isDefault != b->isDefault)
1156 _equalCreateOpClassItem(CreateOpClassItem *a, CreateOpClassItem *b)
1158 if (a->itemtype != b->itemtype)
1160 if (!equal(a->name, b->name))
1162 if (!equal(a->args, b->args))
1164 if (a->number != b->number)
1166 if (a->recheck != b->recheck)
1168 if (!equal(a->storedtype, b->storedtype))
1175 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1177 if (!equalstr(a->dbname, b->dbname))
1179 if (!equal(a->options, b->options))
1186 _equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
1188 if (!equalstr(a->dbname, b->dbname))
1190 if (!equalstr(a->variable, b->variable))
1192 if (!equal(a->value, b->value))
1199 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1201 if (!equalstr(a->dbname, b->dbname))
1208 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1210 if (a->vacuum != b->vacuum)
1212 if (a->full != b->full)
1214 if (a->analyze != b->analyze)
1216 if (a->freeze != b->freeze)
1218 if (a->verbose != b->verbose)
1220 if (!equal(a->relation, b->relation))
1222 if (!equal(a->va_cols, b->va_cols))
1229 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1231 if (!equal(a->query, b->query))
1233 if (a->verbose != b->verbose)
1235 if (a->analyze != b->analyze)
1242 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1244 if (!equal(a->sequence, b->sequence))
1246 if (!equal(a->options, b->options))
1253 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1255 if (!equalstr(a->name, b->name))
1257 if (!equal(a->args, b->args))
1259 if (a->is_local != b->is_local)
1266 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1268 if (!equalstr(a->name, b->name))
1275 _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
1277 if (!equalstr(a->name, b->name))
1284 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1286 if (!equalstr(a->trigname, b->trigname))
1288 if (!equal(a->relation, b->relation))
1290 if (!equal(a->funcname, b->funcname))
1292 if (!equal(a->args, b->args))
1294 if (a->before != b->before)
1296 if (a->row != b->row)
1298 if (strcmp(a->actions, b->actions) != 0)
1300 if (a->isconstraint != b->isconstraint)
1302 if (a->deferrable != b->deferrable)
1304 if (a->initdeferred != b->initdeferred)
1306 if (!equal(a->constrrel, b->constrrel))
1313 _equalDropPropertyStmt(DropPropertyStmt *a, DropPropertyStmt *b)
1315 if (!equal(a->relation, b->relation))
1317 if (!equalstr(a->property, b->property))
1319 if (a->removeType != b->removeType)
1321 if (a->behavior != b->behavior)
1328 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1330 if (!equalstr(a->plname, b->plname))
1332 if (!equal(a->plhandler, b->plhandler))
1334 if (!equal(a->plvalidator, b->plvalidator))
1336 if (a->pltrusted != b->pltrusted)
1343 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1345 if (!equalstr(a->plname, b->plname))
1347 if (a->behavior != b->behavior)
1354 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1356 if (!equalstr(a->user, b->user))
1358 if (!equal(a->options, b->options))
1365 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1367 if (!equalstr(a->user, b->user))
1369 if (!equal(a->options, b->options))
1376 _equalAlterUserSetStmt(AlterUserSetStmt *a, AlterUserSetStmt *b)
1378 if (!equalstr(a->user, b->user))
1380 if (!equalstr(a->variable, b->variable))
1382 if (!equal(a->value, b->value))
1389 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1391 if (!equal(a->users, b->users))
1398 _equalLockStmt(LockStmt *a, LockStmt *b)
1400 if (!equal(a->relations, b->relations))
1402 if (a->mode != b->mode)
1409 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1411 if (!equal(a->constraints, b->constraints))
1413 if (a->deferred != b->deferred)
1420 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1422 if (!equalstr(a->name, b->name))
1424 if (!equal(a->options, b->options))
1431 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1433 if (!equalstr(a->name, b->name))
1435 if (a->action != b->action)
1437 if (!equal(a->listUsers, b->listUsers))
1444 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1446 if (!equalstr(a->name, b->name))
1453 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1455 if (a->reindexType != b->reindexType)
1457 if (!equal(a->relation, b->relation))
1459 if (!equalstr(a->name, b->name))
1461 if (a->force != b->force)
1463 if (a->all != b->all)
1470 _equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
1472 if (!equalstr(a->schemaname, b->schemaname))
1474 if (!equalstr(a->authid, b->authid))
1476 if (!equal(a->schemaElts, b->schemaElts))
1483 _equalCreateConversionStmt(CreateConversionStmt *a, CreateConversionStmt *b)
1485 if (!equal(a->conversion_name, b->conversion_name))
1487 if (!equalstr(a->for_encoding_name, b->for_encoding_name))
1489 if (!equalstr(a->to_encoding_name, b->to_encoding_name))
1491 if (!equal(a->func_name, b->func_name))
1493 if (a->def != b->def)
1500 _equalCreateCastStmt(CreateCastStmt *a, CreateCastStmt *b)
1502 if (!equal(a->sourcetype, b->sourcetype))
1504 if (!equal(a->targettype, b->targettype))
1506 if (!equal(a->func, b->func))
1508 if (a->context != b->context)
1515 _equalDropCastStmt(DropCastStmt *a, DropCastStmt *b)
1517 if (!equal(a->sourcetype, b->sourcetype))
1519 if (!equal(a->targettype, b->targettype))
1521 if (a->behavior != b->behavior)
1528 _equalPrepareStmt(PrepareStmt *a, PrepareStmt *b)
1530 if (!equalstr(a->name, b->name))
1532 if (!equal(a->argtypes, b->argtypes))
1534 if (!equali(a->argtype_oids, b->argtype_oids))
1536 if (!equal(a->query, b->query))
1543 _equalExecuteStmt(ExecuteStmt *a, ExecuteStmt *b)
1545 if (!equalstr(a->name, b->name))
1547 if (!equal(a->into, b->into))
1549 if (!equal(a->params, b->params))
1556 _equalDeallocateStmt(DeallocateStmt *a, DeallocateStmt *b)
1558 if (!equalstr(a->name, b->name))
1565 _equalAExpr(A_Expr *a, A_Expr *b)
1567 if (a->oper != b->oper)
1569 if (!equal(a->name, b->name))
1571 if (!equal(a->lexpr, b->lexpr))
1573 if (!equal(a->rexpr, b->rexpr))
1580 _equalColumnRef(ColumnRef *a, ColumnRef *b)
1582 if (!equal(a->fields, b->fields))
1584 if (!equal(a->indirection, b->indirection))
1591 _equalParamRef(ParamRef *a, ParamRef *b)
1593 if (a->number != b->number)
1595 if (!equal(a->fields, b->fields))
1597 if (!equal(a->indirection, b->indirection))
1604 _equalAConst(A_Const *a, A_Const *b)
1606 if (!equal(&a->val, &b->val))
1608 if (!equal(a->typename, b->typename))
1615 _equalFuncCall(FuncCall *a, FuncCall *b)
1617 if (!equal(a->funcname, b->funcname))
1619 if (!equal(a->args, b->args))
1621 if (a->agg_star != b->agg_star)
1623 if (a->agg_distinct != b->agg_distinct)
1630 _equalAIndices(A_Indices *a, A_Indices *b)
1632 if (!equal(a->lidx, b->lidx))
1634 if (!equal(a->uidx, b->uidx))
1641 _equalExprFieldSelect(ExprFieldSelect *a, ExprFieldSelect *b)
1643 if (!equal(a->arg, b->arg))
1645 if (!equal(a->fields, b->fields))
1647 if (!equal(a->indirection, b->indirection))
1654 _equalResTarget(ResTarget *a, ResTarget *b)
1656 if (!equalstr(a->name, b->name))
1658 if (!equal(a->indirection, b->indirection))
1660 if (!equal(a->val, b->val))
1667 _equalTypeCast(TypeCast *a, TypeCast *b)
1669 if (!equal(a->arg, b->arg))
1671 if (!equal(a->typename, b->typename))
1678 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1680 if (!equal(a->useOp, b->useOp))
1682 if (!equal(a->node, b->node))
1689 _equalAlias(Alias *a, Alias *b)
1691 if (!equalstr(a->aliasname, b->aliasname))
1693 if (!equal(a->colnames, b->colnames))
1700 _equalRangeVar(RangeVar *a, RangeVar *b)
1702 if (!equalstr(a->catalogname, b->catalogname))
1704 if (!equalstr(a->schemaname, b->schemaname))
1706 if (!equalstr(a->relname, b->relname))
1708 if (a->inhOpt != b->inhOpt)
1710 if (a->istemp != b->istemp)
1712 if (!equal(a->alias, b->alias))
1719 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1721 if (!equal(a->subquery, b->subquery))
1723 if (!equal(a->alias, b->alias))
1730 _equalRangeFunction(RangeFunction *a, RangeFunction *b)
1732 if (!equal(a->funccallnode, b->funccallnode))
1734 if (!equal(a->alias, b->alias))
1736 if (!equal(a->coldeflist, b->coldeflist))
1743 _equalTypeName(TypeName *a, TypeName *b)
1745 if (!equal(a->names, b->names))
1747 if (a->typeid != b->typeid)
1749 if (a->timezone != b->timezone)
1751 if (a->setof != b->setof)
1753 if (a->pct_type != b->pct_type)
1755 if (a->typmod != b->typmod)
1757 if (!equal(a->arrayBounds, b->arrayBounds))
1764 _equalIndexElem(IndexElem *a, IndexElem *b)
1766 if (!equalstr(a->name, b->name))
1768 if (!equal(a->funcname, b->funcname))
1770 if (!equal(a->args, b->args))
1772 if (!equal(a->opclass, b->opclass))
1779 _equalColumnDef(ColumnDef *a, ColumnDef *b)
1781 if (!equalstr(a->colname, b->colname))
1783 if (!equal(a->typename, b->typename))
1785 if (a->inhcount != b->inhcount)
1787 if (a->is_local != b->is_local)
1789 if (a->is_not_null != b->is_not_null)
1791 if (!equal(a->raw_default, b->raw_default))
1793 if (!equalstr(a->cooked_default, b->cooked_default))
1795 if (!equal(a->constraints, b->constraints))
1797 if (!equal(a->support, b->support))
1804 _equalConstraint(Constraint *a, Constraint *b)
1806 if (a->contype != b->contype)
1808 if (!equalstr(a->name, b->name))
1810 if (!equal(a->raw_expr, b->raw_expr))
1812 if (!equalstr(a->cooked_expr, b->cooked_expr))
1814 if (!equal(a->keys, b->keys))
1821 _equalDefElem(DefElem *a, DefElem *b)
1823 if (!equalstr(a->defname, b->defname))
1825 if (!equal(a->arg, b->arg))
1832 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
1834 if (!equal(a->resdom, b->resdom))
1836 if (!equal(a->fjoin, b->fjoin))
1838 if (!equal(a->expr, b->expr))
1845 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
1847 if (a->rtekind != b->rtekind)
1849 if (a->relid != b->relid)
1851 if (!equal(a->subquery, b->subquery))
1853 if (!equal(a->funcexpr, b->funcexpr))
1855 if (!equal(a->coldeflist, b->coldeflist))
1857 if (a->jointype != b->jointype)
1859 if (!equal(a->joinaliasvars, b->joinaliasvars))
1861 if (!equal(a->alias, b->alias))
1863 if (!equal(a->eref, b->eref))
1865 if (a->inh != b->inh)
1867 if (a->inFromCl != b->inFromCl)
1869 if (a->checkForRead != b->checkForRead)
1871 if (a->checkForWrite != b->checkForWrite)
1873 if (a->checkAsUser != b->checkAsUser)
1880 _equalSortClause(SortClause *a, SortClause *b)
1882 if (a->tleSortGroupRef != b->tleSortGroupRef)
1884 if (a->sortop != b->sortop)
1891 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
1893 if (!equalstr(a->constr_name, b->constr_name))
1895 if (!equal(a->pktable, b->pktable))
1897 if (!equal(a->fk_attrs, b->fk_attrs))
1899 if (!equal(a->pk_attrs, b->pk_attrs))
1901 if (a->fk_matchtype != b->fk_matchtype)
1903 if (a->fk_upd_action != b->fk_upd_action)
1905 if (a->fk_del_action != b->fk_del_action)
1907 if (a->deferrable != b->deferrable)
1909 if (a->initdeferred != b->initdeferred)
1911 if (a->skip_validation != b->skip_validation)
1918 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
1920 if (a->casetype != b->casetype)
1922 if (!equal(a->arg, b->arg))
1924 if (!equal(a->args, b->args))
1926 if (!equal(a->defresult, b->defresult))
1933 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
1935 if (!equal(a->expr, b->expr))
1937 if (!equal(a->result, b->result))
1944 _equalNullTest(NullTest *a, NullTest *b)
1946 if (!equal(a->arg, b->arg))
1948 if (a->nulltesttype != b->nulltesttype)
1954 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
1956 if (!equal(a->arg, b->arg))
1958 if (a->booltesttype != b->booltesttype)
1964 _equalConstraintTest(ConstraintTest *a, ConstraintTest *b)
1966 if (!equal(a->arg, b->arg))
1968 if (a->testtype != b->testtype)
1970 if (!equalstr(a->name, b->name))
1972 if (!equalstr(a->domname, b->domname))
1974 if (!equal(a->check_expr, b->check_expr))
1980 _equalConstraintTestValue(ConstraintTestValue *a, ConstraintTestValue *b)
1982 if (a->typeId != b->typeId)
1984 if (a->typeMod != b->typeMod)
1990 _equalDomainConstraintValue(DomainConstraintValue *a, DomainConstraintValue *b)
1996 * Stuff from pg_list.h
1999 _equalValue(Value *a, Value *b)
2001 if (a->type != b->type)
2007 return a->val.ival == b->val.ival;
2011 return strcmp(a->val.str, b->val.str) == 0;
2016 elog(ERROR, "_equalValue: unknown node type %d", a->type);
2025 * returns whether two nodes are equal
2028 equal(void *a, void *b)
2030 bool retval = false;
2036 * note that a!=b, so only one of them can be NULL
2038 if (a == NULL || b == NULL)
2042 * are they the same type of nodes?
2044 if (nodeTag(a) != nodeTag(b))
2050 retval = _equalSubPlan(a, b);
2054 retval = _equalResdom(a, b);
2057 retval = _equalFjoin(a, b);
2060 retval = _equalExpr(a, b);
2063 retval = _equalVar(a, b);
2066 retval = _equalOper(a, b);
2069 retval = _equalConst(a, b);
2072 retval = _equalParam(a, b);
2075 retval = _equalAggref(a, b);
2078 retval = _equalSubLink(a, b);
2081 retval = _equalFunc(a, b);
2084 retval = _equalFieldSelect(a, b);
2087 retval = _equalArrayRef(a, b);
2090 retval = _equalRelabelType(a, b);
2093 retval = _equalRangeTblRef(a, b);
2096 retval = _equalFromExpr(a, b);
2099 retval = _equalJoinExpr(a, b);
2103 retval = _equalRelOptInfo(a, b);
2106 retval = _equalPath(a, b);
2109 retval = _equalIndexPath(a, b);
2112 retval = _equalNestPath(a, b);
2115 retval = _equalMergePath(a, b);
2118 retval = _equalHashPath(a, b);
2121 retval = _equalPathKeyItem(a, b);
2123 case T_RestrictInfo:
2124 retval = _equalRestrictInfo(a, b);
2127 retval = _equalJoinInfo(a, b);
2129 case T_InnerIndexscanInfo:
2130 retval = _equalInnerIndexscanInfo(a, b);
2133 retval = _equalTidPath(a, b);
2136 retval = _equalAppendPath(a, b);
2139 retval = _equalResultPath(a, b);
2141 case T_IndexOptInfo:
2142 retval = _equalIndexOptInfo(a, b);
2147 List *la = (List *) a;
2148 List *lb = (List *) b;
2152 * Try to reject by length check before we grovel through
2153 * all the elements...
2155 if (length(la) != length(lb))
2159 if (!equal(lfirst(l), lfirst(lb)))
2172 retval = _equalValue(a, b);
2176 retval = _equalQuery(a, b);
2179 retval = _equalInsertStmt(a, b);
2182 retval = _equalDeleteStmt(a, b);
2185 retval = _equalUpdateStmt(a, b);
2188 retval = _equalSelectStmt(a, b);
2190 case T_SetOperationStmt:
2191 retval = _equalSetOperationStmt(a, b);
2193 case T_AlterTableStmt:
2194 retval = _equalAlterTableStmt(a, b);
2197 retval = _equalGrantStmt(a, b);
2199 case T_ClosePortalStmt:
2200 retval = _equalClosePortalStmt(a, b);
2203 retval = _equalClusterStmt(a, b);
2206 retval = _equalCopyStmt(a, b);
2209 retval = _equalCreateStmt(a, b);
2212 retval = _equalDefineStmt(a, b);
2215 retval = _equalDropStmt(a, b);
2217 case T_TruncateStmt:
2218 retval = _equalTruncateStmt(a, b);
2221 retval = _equalCommentStmt(a, b);
2224 retval = _equalFetchStmt(a, b);
2227 retval = _equalIndexStmt(a, b);
2229 case T_CreateFunctionStmt:
2230 retval = _equalCreateFunctionStmt(a, b);
2232 case T_RemoveAggrStmt:
2233 retval = _equalRemoveAggrStmt(a, b);
2235 case T_RemoveFuncStmt:
2236 retval = _equalRemoveFuncStmt(a, b);
2238 case T_RemoveOperStmt:
2239 retval = _equalRemoveOperStmt(a, b);
2241 case T_RemoveOpClassStmt:
2242 retval = _equalRemoveOpClassStmt(a, b);
2245 retval = _equalRenameStmt(a, b);
2248 retval = _equalRuleStmt(a, b);
2251 retval = _equalNotifyStmt(a, b);
2254 retval = _equalListenStmt(a, b);
2256 case T_UnlistenStmt:
2257 retval = _equalUnlistenStmt(a, b);
2259 case T_TransactionStmt:
2260 retval = _equalTransactionStmt(a, b);
2262 case T_CompositeTypeStmt:
2263 retval = _equalCompositeTypeStmt(a, b);
2266 retval = _equalViewStmt(a, b);
2269 retval = _equalLoadStmt(a, b);
2271 case T_CreateDomainStmt:
2272 retval = _equalCreateDomainStmt(a, b);
2274 case T_CreateOpClassStmt:
2275 retval = _equalCreateOpClassStmt(a, b);
2277 case T_CreateOpClassItem:
2278 retval = _equalCreateOpClassItem(a, b);
2280 case T_CreatedbStmt:
2281 retval = _equalCreatedbStmt(a, b);
2283 case T_AlterDatabaseSetStmt:
2284 retval = _equalAlterDatabaseSetStmt(a, b);
2287 retval = _equalDropdbStmt(a, b);
2290 retval = _equalVacuumStmt(a, b);
2293 retval = _equalExplainStmt(a, b);
2295 case T_CreateSeqStmt:
2296 retval = _equalCreateSeqStmt(a, b);
2298 case T_VariableSetStmt:
2299 retval = _equalVariableSetStmt(a, b);
2301 case T_VariableShowStmt:
2302 retval = _equalVariableShowStmt(a, b);
2304 case T_VariableResetStmt:
2305 retval = _equalVariableResetStmt(a, b);
2307 case T_CreateTrigStmt:
2308 retval = _equalCreateTrigStmt(a, b);
2310 case T_DropPropertyStmt:
2311 retval = _equalDropPropertyStmt(a, b);
2313 case T_CreatePLangStmt:
2314 retval = _equalCreatePLangStmt(a, b);
2316 case T_DropPLangStmt:
2317 retval = _equalDropPLangStmt(a, b);
2319 case T_CreateUserStmt:
2320 retval = _equalCreateUserStmt(a, b);
2322 case T_AlterUserStmt:
2323 retval = _equalAlterUserStmt(a, b);
2325 case T_AlterUserSetStmt:
2326 retval = _equalAlterUserSetStmt(a, b);
2328 case T_DropUserStmt:
2329 retval = _equalDropUserStmt(a, b);
2332 retval = _equalLockStmt(a, b);
2334 case T_ConstraintsSetStmt:
2335 retval = _equalConstraintsSetStmt(a, b);
2337 case T_CreateGroupStmt:
2338 retval = _equalCreateGroupStmt(a, b);
2340 case T_AlterGroupStmt:
2341 retval = _equalAlterGroupStmt(a, b);
2343 case T_DropGroupStmt:
2344 retval = _equalDropGroupStmt(a, b);
2347 retval = _equalReindexStmt(a, b);
2349 case T_CheckPointStmt:
2352 case T_CreateSchemaStmt:
2353 retval = _equalCreateSchemaStmt(a, b);
2355 case T_CreateConversionStmt:
2356 retval = _equalCreateConversionStmt(a, b);
2358 case T_CreateCastStmt:
2359 retval = _equalCreateCastStmt(a, b);
2361 case T_DropCastStmt:
2362 retval = _equalDropCastStmt(a, b);
2365 retval = _equalPrepareStmt(a, b);
2368 retval = _equalExecuteStmt(a, b);
2370 case T_DeallocateStmt:
2371 retval = _equalDeallocateStmt(a, b);
2375 retval = _equalAExpr(a, b);
2378 retval = _equalColumnRef(a, b);
2381 retval = _equalParamRef(a, b);
2384 retval = _equalAConst(a, b);
2387 retval = _equalFuncCall(a, b);
2390 retval = _equalAIndices(a, b);
2392 case T_ExprFieldSelect:
2393 retval = _equalExprFieldSelect(a, b);
2396 retval = _equalResTarget(a, b);
2399 retval = _equalTypeCast(a, b);
2402 retval = _equalSortGroupBy(a, b);
2405 retval = _equalAlias(a, b);
2408 retval = _equalRangeVar(a, b);
2410 case T_RangeSubselect:
2411 retval = _equalRangeSubselect(a, b);
2413 case T_RangeFunction:
2414 retval = _equalRangeFunction(a, b);
2417 retval = _equalTypeName(a, b);
2420 retval = _equalIndexElem(a, b);
2423 retval = _equalColumnDef(a, b);
2426 retval = _equalConstraint(a, b);
2429 retval = _equalDefElem(a, b);
2432 retval = _equalTargetEntry(a, b);
2434 case T_RangeTblEntry:
2435 retval = _equalRangeTblEntry(a, b);
2438 retval = _equalSortClause(a, b);
2441 /* GroupClause is equivalent to SortClause */
2442 retval = _equalSortClause(a, b);
2445 retval = _equalCaseExpr(a, b);
2448 retval = _equalCaseWhen(a, b);
2451 retval = _equalNullTest(a, b);
2454 retval = _equalBooleanTest(a, b);
2456 case T_ConstraintTest:
2457 retval = _equalConstraintTest(a, b);
2459 case T_ConstraintTestValue:
2460 retval = _equalConstraintTestValue(a, b);
2462 case T_FkConstraint:
2463 retval = _equalFkConstraint(a, b);
2466 retval = _equalPrivGrantee(a, b);
2468 case T_FuncWithArgs:
2469 retval = _equalFuncWithArgs(a, b);
2471 case T_InsertDefault:
2472 retval = _equalInsertDefault(a, b);
2474 case T_DomainConstraintValue:
2475 retval = _equalDomainConstraintValue(a, b);
2479 elog(WARNING, "equal: don't know whether nodes of type %d are equal",