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.163 2002/11/11 22:19:22 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)
432 if (!equali(a->joinrelids, b->joinrelids))
434 if (a->alljoinquals != b->alljoinquals)
438 * Skip 'rows' because of possibility of floating-point roundoff
439 * error. It should be derivable from the other fields anyway.
445 _equalTidPath(TidPath *a, TidPath *b)
447 if (!_equalPath((Path *) a, (Path *) b))
449 if (!equal(a->tideval, b->tideval))
451 if (!equali(a->unjoined_relids, b->unjoined_relids))
457 _equalAppendPath(AppendPath *a, AppendPath *b)
459 if (!_equalPath((Path *) a, (Path *) b))
461 if (!equal(a->subpaths, b->subpaths))
467 _equalResultPath(ResultPath *a, ResultPath *b)
469 if (!_equalPath((Path *) a, (Path *) b))
471 if (!equal(a->subpath, b->subpath))
473 if (!equal(a->constantqual, b->constantqual))
479 _equalJoinPath(JoinPath *a, JoinPath *b)
481 if (!_equalPath((Path *) a, (Path *) b))
483 if (a->jointype != b->jointype)
485 if (!equal(a->outerjoinpath, b->outerjoinpath))
487 if (!equal(a->innerjoinpath, b->innerjoinpath))
489 if (!equal(a->joinrestrictinfo, b->joinrestrictinfo))
495 _equalNestPath(NestPath *a, NestPath *b)
497 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
503 _equalMergePath(MergePath *a, MergePath *b)
505 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
507 if (!equal(a->path_mergeclauses, b->path_mergeclauses))
509 if (!equal(a->outersortkeys, b->outersortkeys))
511 if (!equal(a->innersortkeys, b->innersortkeys))
517 _equalHashPath(HashPath *a, HashPath *b)
519 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
521 if (!equal(a->path_hashclauses, b->path_hashclauses))
527 _equalSubPlan(SubPlan *a, SubPlan *b)
529 /* should compare plans, but have to settle for comparing plan IDs */
530 if (a->plan_id != b->plan_id)
533 if (!equal(a->rtable, b->rtable))
536 if (!equal(a->sublink, b->sublink))
543 _equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
545 if (!equal(a->clause, b->clause))
547 if (a->ispusheddown != b->ispusheddown)
551 * We ignore eval_cost, this_selec, left/right_pathkey, and
552 * left/right_bucketsize, since they may not be set yet, and should be
553 * derivable from the clause anyway. Probably it's not really
554 * necessary to compare any of these remaining fields ...
556 if (!equal(a->subclauseindices, b->subclauseindices))
558 if (a->mergejoinoperator != b->mergejoinoperator)
560 if (a->left_sortop != b->left_sortop)
562 if (a->right_sortop != b->right_sortop)
564 if (a->hashjoinoperator != b->hashjoinoperator)
570 _equalJoinInfo(JoinInfo *a, JoinInfo *b)
572 if (!equali(a->unjoined_relids, b->unjoined_relids))
574 if (!equal(a->jinfo_restrictinfo, b->jinfo_restrictinfo))
580 * Stuff from parsenodes.h
584 _equalQuery(Query *a, Query *b)
586 if (a->commandType != b->commandType)
588 if (a->querySource != b->querySource)
590 if (!equal(a->utilityStmt, b->utilityStmt))
592 if (a->resultRelation != b->resultRelation)
594 if (!equal(a->into, b->into))
596 if (a->isPortal != b->isPortal)
598 if (a->isBinary != b->isBinary)
600 if (a->hasAggs != b->hasAggs)
602 if (a->hasSubLinks != b->hasSubLinks)
604 if (!equal(a->rtable, b->rtable))
606 if (!equal(a->jointree, b->jointree))
608 if (!equali(a->rowMarks, b->rowMarks))
610 if (!equal(a->targetList, b->targetList))
612 if (!equal(a->groupClause, b->groupClause))
614 if (!equal(a->havingQual, b->havingQual))
616 if (!equal(a->distinctClause, b->distinctClause))
618 if (!equal(a->sortClause, b->sortClause))
620 if (!equal(a->limitOffset, b->limitOffset))
622 if (!equal(a->limitCount, b->limitCount))
624 if (!equal(a->setOperations, b->setOperations))
626 if (!equali(a->resultRelations, b->resultRelations))
630 * We do not check the internal-to-the-planner fields: base_rel_list,
631 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. They
632 * might not be set yet, and in any case they should be derivable from
639 _equalInsertStmt(InsertStmt *a, InsertStmt *b)
641 if (!equal(a->relation, b->relation))
643 if (!equal(a->cols, b->cols))
645 if (!equal(a->targetList, b->targetList))
647 if (!equal(a->selectStmt, b->selectStmt))
654 _equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
656 if (!equal(a->relation, b->relation))
658 if (!equal(a->whereClause, b->whereClause))
665 _equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
667 if (!equal(a->relation, b->relation))
669 if (!equal(a->targetList, b->targetList))
671 if (!equal(a->whereClause, b->whereClause))
673 if (!equal(a->fromClause, b->fromClause))
680 _equalSelectStmt(SelectStmt *a, SelectStmt *b)
682 if (!equal(a->distinctClause, b->distinctClause))
684 if (!equal(a->into, b->into))
686 if (!equal(a->intoColNames, b->intoColNames))
688 if (!equal(a->targetList, b->targetList))
690 if (!equal(a->fromClause, b->fromClause))
692 if (!equal(a->whereClause, b->whereClause))
694 if (!equal(a->groupClause, b->groupClause))
696 if (!equal(a->havingClause, b->havingClause))
698 if (!equal(a->sortClause, b->sortClause))
700 if (!equalstr(a->portalname, b->portalname))
702 if (a->binary != b->binary)
704 if (!equal(a->limitOffset, b->limitOffset))
706 if (!equal(a->limitCount, b->limitCount))
708 if (!equal(a->forUpdate, b->forUpdate))
712 if (a->all != b->all)
714 if (!equal(a->larg, b->larg))
716 if (!equal(a->rarg, b->rarg))
723 _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
727 if (a->all != b->all)
729 if (!equal(a->larg, b->larg))
731 if (!equal(a->rarg, b->rarg))
733 if (!equali(a->colTypes, b->colTypes))
740 _equalAlterTableStmt(AlterTableStmt *a, AlterTableStmt *b)
742 if (a->subtype != b->subtype)
744 if (!equal(a->relation, b->relation))
746 if (!equalstr(a->name, b->name))
748 if (!equal(a->def, b->def))
750 if (a->behavior != b->behavior)
757 _equalGrantStmt(GrantStmt *a, GrantStmt *b)
759 if (a->is_grant != b->is_grant)
761 if (a->objtype != b->objtype)
763 if (!equal(a->objects, b->objects))
765 if (!equali(a->privileges, b->privileges))
767 if (!equal(a->grantees, b->grantees))
774 _equalPrivGrantee(PrivGrantee *a, PrivGrantee *b)
776 return equalstr(a->username, b->username)
777 && equalstr(a->groupname, b->groupname);
781 _equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
783 return equal(a->funcname, b->funcname)
784 && equal(a->funcargs, b->funcargs);
788 _equalInsertDefault(InsertDefault *a, InsertDefault *b)
794 _equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
796 if (!equalstr(a->portalname, b->portalname))
803 _equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
805 if (!equal(a->relation, b->relation))
807 if (!equalstr(a->indexname, b->indexname))
814 _equalCopyStmt(CopyStmt *a, CopyStmt *b)
816 if (!equal(a->relation, b->relation))
818 if (!equal(a->attlist, b->attlist))
820 if (a->is_from != b->is_from)
822 if (!equalstr(a->filename, b->filename))
824 if (!equal(a->options, b->options))
831 _equalCreateStmt(CreateStmt *a, CreateStmt *b)
833 if (!equal(a->relation, b->relation))
835 if (!equal(a->tableElts, b->tableElts))
837 if (!equal(a->inhRelations, b->inhRelations))
839 if (!equal(a->constraints, b->constraints))
841 if (a->hasoids != b->hasoids)
843 if (a->oncommit != b->oncommit)
850 _equalDefineStmt(DefineStmt *a, DefineStmt *b)
852 if (a->defType != b->defType)
854 if (!equal(a->defnames, b->defnames))
856 if (!equal(a->definition, b->definition))
863 _equalDropStmt(DropStmt *a, DropStmt *b)
865 if (!equal(a->objects, b->objects))
867 if (a->removeType != b->removeType)
869 if (a->behavior != b->behavior)
876 _equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
878 if (!equal(a->relation, b->relation))
885 _equalCommentStmt(CommentStmt *a, CommentStmt *b)
887 if (a->objtype != b->objtype)
889 if (!equal(a->objname, b->objname))
891 if (!equal(a->objargs, b->objargs))
893 if (!equalstr(a->comment, b->comment))
900 _equalFetchStmt(FetchStmt *a, FetchStmt *b)
902 if (a->direction != b->direction)
904 if (a->howMany != b->howMany)
906 if (!equalstr(a->portalname, b->portalname))
908 if (a->ismove != b->ismove)
915 _equalIndexStmt(IndexStmt *a, IndexStmt *b)
917 if (!equalstr(a->idxname, b->idxname))
919 if (!equal(a->relation, b->relation))
921 if (!equalstr(a->accessMethod, b->accessMethod))
923 if (!equal(a->indexParams, b->indexParams))
925 if (!equal(a->whereClause, b->whereClause))
927 if (!equal(a->rangetable, b->rangetable))
929 if (a->unique != b->unique)
931 if (a->primary != b->primary)
933 if (a->isconstraint != b->isconstraint)
940 _equalCreateFunctionStmt(CreateFunctionStmt *a, CreateFunctionStmt *b)
942 if (a->replace != b->replace)
944 if (!equal(a->funcname, b->funcname))
946 if (!equal(a->argTypes, b->argTypes))
948 if (!equal(a->returnType, b->returnType))
950 if (!equal(a->options, b->options))
952 if (!equal(a->withClause, b->withClause))
959 _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
961 if (!equal(a->aggname, b->aggname))
963 if (!equal(a->aggtype, b->aggtype))
965 if (a->behavior != b->behavior)
972 _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
974 if (!equal(a->funcname, b->funcname))
976 if (!equal(a->args, b->args))
978 if (a->behavior != b->behavior)
985 _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
987 if (!equal(a->opname, b->opname))
989 if (!equal(a->args, b->args))
991 if (a->behavior != b->behavior)
998 _equalRemoveOpClassStmt(RemoveOpClassStmt *a, RemoveOpClassStmt *b)
1000 if (!equal(a->opclassname, b->opclassname))
1002 if (!equalstr(a->amname, b->amname))
1004 if (a->behavior != b->behavior)
1011 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
1013 if (!equal(a->relation, b->relation))
1015 if (!equalstr(a->oldname, b->oldname))
1017 if (!equalstr(a->newname, b->newname))
1019 if (a->renameType != b->renameType)
1026 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
1028 if (!equal(a->relation, b->relation))
1030 if (!equalstr(a->rulename, b->rulename))
1032 if (!equal(a->whereClause, b->whereClause))
1034 if (a->event != b->event)
1036 if (a->instead != b->instead)
1038 if (a->replace != b->replace)
1040 if (!equal(a->actions, b->actions))
1047 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1049 if (!equal(a->relation, b->relation))
1056 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1058 if (!equal(a->relation, b->relation))
1065 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1067 if (!equal(a->relation, b->relation))
1074 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1076 if (a->command != b->command)
1078 if (!equal(a->options, b->options))
1085 _equalCompositeTypeStmt(CompositeTypeStmt *a, CompositeTypeStmt *b)
1087 if (!equal(a->typevar, b->typevar))
1089 if (!equal(a->coldeflist, b->coldeflist))
1096 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1098 if (!equal(a->view, b->view))
1100 if (!equal(a->aliases, b->aliases))
1102 if (!equal(a->query, b->query))
1104 if (a->replace != b->replace)
1111 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1113 if (!equalstr(a->filename, b->filename))
1120 _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
1122 if (!equal(a->domainname, b->domainname))
1124 if (!equal(a->typename, b->typename))
1126 if (!equal(a->constraints, b->constraints))
1133 _equalCreateOpClassStmt(CreateOpClassStmt *a, CreateOpClassStmt *b)
1135 if (!equal(a->opclassname, b->opclassname))
1137 if (!equalstr(a->amname, b->amname))
1139 if (!equal(a->datatype, b->datatype))
1141 if (!equal(a->items, b->items))
1143 if (a->isDefault != b->isDefault)
1150 _equalCreateOpClassItem(CreateOpClassItem *a, CreateOpClassItem *b)
1152 if (a->itemtype != b->itemtype)
1154 if (!equal(a->name, b->name))
1156 if (!equal(a->args, b->args))
1158 if (a->number != b->number)
1160 if (a->recheck != b->recheck)
1162 if (!equal(a->storedtype, b->storedtype))
1169 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1171 if (!equalstr(a->dbname, b->dbname))
1173 if (!equal(a->options, b->options))
1180 _equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
1182 if (!equalstr(a->dbname, b->dbname))
1184 if (!equalstr(a->variable, b->variable))
1186 if (!equal(a->value, b->value))
1193 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1195 if (!equalstr(a->dbname, b->dbname))
1202 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1204 if (a->vacuum != b->vacuum)
1206 if (a->full != b->full)
1208 if (a->analyze != b->analyze)
1210 if (a->freeze != b->freeze)
1212 if (a->verbose != b->verbose)
1214 if (!equal(a->relation, b->relation))
1216 if (!equal(a->va_cols, b->va_cols))
1223 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1225 if (!equal(a->query, b->query))
1227 if (a->verbose != b->verbose)
1229 if (a->analyze != b->analyze)
1236 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1238 if (!equal(a->sequence, b->sequence))
1240 if (!equal(a->options, b->options))
1247 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1249 if (!equalstr(a->name, b->name))
1251 if (!equal(a->args, b->args))
1253 if (a->is_local != b->is_local)
1260 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1262 if (!equalstr(a->name, b->name))
1269 _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
1271 if (!equalstr(a->name, b->name))
1278 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1280 if (!equalstr(a->trigname, b->trigname))
1282 if (!equal(a->relation, b->relation))
1284 if (!equal(a->funcname, b->funcname))
1286 if (!equal(a->args, b->args))
1288 if (a->before != b->before)
1290 if (a->row != b->row)
1292 if (strcmp(a->actions, b->actions) != 0)
1294 if (!equalstr(a->lang, b->lang))
1296 if (!equalstr(a->text, b->text))
1298 if (!equal(a->attr, b->attr))
1300 if (!equalstr(a->when, b->when))
1302 if (a->isconstraint != b->isconstraint)
1304 if (a->deferrable != b->deferrable)
1306 if (a->initdeferred != b->initdeferred)
1308 if (!equal(a->constrrel, b->constrrel))
1315 _equalDropPropertyStmt(DropPropertyStmt *a, DropPropertyStmt *b)
1317 if (!equal(a->relation, b->relation))
1319 if (!equalstr(a->property, b->property))
1321 if (a->removeType != b->removeType)
1323 if (a->behavior != b->behavior)
1330 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1332 if (!equalstr(a->plname, b->plname))
1334 if (!equal(a->plhandler, b->plhandler))
1336 if (!equal(a->plvalidator, b->plvalidator))
1338 if (a->pltrusted != b->pltrusted)
1345 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1347 if (!equalstr(a->plname, b->plname))
1349 if (a->behavior != b->behavior)
1356 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1358 if (!equalstr(a->user, b->user))
1360 if (!equal(a->options, b->options))
1367 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1369 if (!equalstr(a->user, b->user))
1371 if (!equal(a->options, b->options))
1378 _equalAlterUserSetStmt(AlterUserSetStmt *a, AlterUserSetStmt *b)
1380 if (!equalstr(a->user, b->user))
1382 if (!equalstr(a->variable, b->variable))
1384 if (!equal(a->value, b->value))
1391 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1393 if (!equal(a->users, b->users))
1400 _equalLockStmt(LockStmt *a, LockStmt *b)
1402 if (!equal(a->relations, b->relations))
1404 if (a->mode != b->mode)
1411 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1413 if (!equal(a->constraints, b->constraints))
1415 if (a->deferred != b->deferred)
1422 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1424 if (!equalstr(a->name, b->name))
1426 if (!equal(a->options, b->options))
1433 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1435 if (!equalstr(a->name, b->name))
1437 if (a->action != b->action)
1439 if (!equal(a->listUsers, b->listUsers))
1446 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1448 if (!equalstr(a->name, b->name))
1455 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1457 if (a->reindexType != b->reindexType)
1459 if (!equal(a->relation, b->relation))
1461 if (!equalstr(a->name, b->name))
1463 if (a->force != b->force)
1465 if (a->all != b->all)
1472 _equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
1474 if (!equalstr(a->schemaname, b->schemaname))
1476 if (!equalstr(a->authid, b->authid))
1478 if (!equal(a->schemaElts, b->schemaElts))
1485 _equalCreateConversionStmt(CreateConversionStmt *a, CreateConversionStmt *b)
1487 if (!equal(a->conversion_name, b->conversion_name))
1489 if (!equalstr(a->for_encoding_name, b->for_encoding_name))
1491 if (!equalstr(a->to_encoding_name, b->to_encoding_name))
1493 if (!equal(a->func_name, b->func_name))
1495 if (a->def != b->def)
1502 _equalCreateCastStmt(CreateCastStmt *a, CreateCastStmt *b)
1504 if (!equal(a->sourcetype, b->sourcetype))
1506 if (!equal(a->targettype, b->targettype))
1508 if (!equal(a->func, b->func))
1510 if (a->context != b->context)
1517 _equalDropCastStmt(DropCastStmt *a, DropCastStmt *b)
1519 if (!equal(a->sourcetype, b->sourcetype))
1521 if (!equal(a->targettype, b->targettype))
1523 if (a->behavior != b->behavior)
1530 _equalPrepareStmt(PrepareStmt *a, PrepareStmt *b)
1532 if (!equalstr(a->name, b->name))
1534 if (!equal(a->argtypes, b->argtypes))
1536 if (!equali(a->argtype_oids, b->argtype_oids))
1538 if (!equal(a->query, b->query))
1545 _equalExecuteStmt(ExecuteStmt *a, ExecuteStmt *b)
1547 if (!equalstr(a->name, b->name))
1549 if (!equal(a->into, b->into))
1551 if (!equal(a->params, b->params))
1558 _equalDeallocateStmt(DeallocateStmt *a, DeallocateStmt *b)
1560 if (!equalstr(a->name, b->name))
1567 _equalAExpr(A_Expr *a, A_Expr *b)
1569 if (a->oper != b->oper)
1571 if (!equal(a->name, b->name))
1573 if (!equal(a->lexpr, b->lexpr))
1575 if (!equal(a->rexpr, b->rexpr))
1582 _equalColumnRef(ColumnRef *a, ColumnRef *b)
1584 if (!equal(a->fields, b->fields))
1586 if (!equal(a->indirection, b->indirection))
1593 _equalParamRef(ParamRef *a, ParamRef *b)
1595 if (a->number != b->number)
1597 if (!equal(a->fields, b->fields))
1599 if (!equal(a->indirection, b->indirection))
1606 _equalAConst(A_Const *a, A_Const *b)
1608 if (!equal(&a->val, &b->val))
1610 if (!equal(a->typename, b->typename))
1617 _equalFuncCall(FuncCall *a, FuncCall *b)
1619 if (!equal(a->funcname, b->funcname))
1621 if (!equal(a->args, b->args))
1623 if (a->agg_star != b->agg_star)
1625 if (a->agg_distinct != b->agg_distinct)
1632 _equalAIndices(A_Indices *a, A_Indices *b)
1634 if (!equal(a->lidx, b->lidx))
1636 if (!equal(a->uidx, b->uidx))
1643 _equalExprFieldSelect(ExprFieldSelect *a, ExprFieldSelect *b)
1645 if (!equal(a->arg, b->arg))
1647 if (!equal(a->fields, b->fields))
1649 if (!equal(a->indirection, b->indirection))
1656 _equalResTarget(ResTarget *a, ResTarget *b)
1658 if (!equalstr(a->name, b->name))
1660 if (!equal(a->indirection, b->indirection))
1662 if (!equal(a->val, b->val))
1669 _equalTypeCast(TypeCast *a, TypeCast *b)
1671 if (!equal(a->arg, b->arg))
1673 if (!equal(a->typename, b->typename))
1680 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1682 if (!equal(a->useOp, b->useOp))
1684 if (!equal(a->node, b->node))
1691 _equalAlias(Alias *a, Alias *b)
1693 if (!equalstr(a->aliasname, b->aliasname))
1695 if (!equal(a->colnames, b->colnames))
1702 _equalRangeVar(RangeVar *a, RangeVar *b)
1704 if (!equalstr(a->catalogname, b->catalogname))
1706 if (!equalstr(a->schemaname, b->schemaname))
1708 if (!equalstr(a->relname, b->relname))
1710 if (a->inhOpt != b->inhOpt)
1712 if (a->istemp != b->istemp)
1714 if (!equal(a->alias, b->alias))
1721 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1723 if (!equal(a->subquery, b->subquery))
1725 if (!equal(a->alias, b->alias))
1732 _equalRangeFunction(RangeFunction *a, RangeFunction *b)
1734 if (!equal(a->funccallnode, b->funccallnode))
1736 if (!equal(a->alias, b->alias))
1738 if (!equal(a->coldeflist, b->coldeflist))
1745 _equalTypeName(TypeName *a, TypeName *b)
1747 if (!equal(a->names, b->names))
1749 if (a->typeid != b->typeid)
1751 if (a->timezone != b->timezone)
1753 if (a->setof != b->setof)
1755 if (a->pct_type != b->pct_type)
1757 if (a->typmod != b->typmod)
1759 if (!equal(a->arrayBounds, b->arrayBounds))
1766 _equalIndexElem(IndexElem *a, IndexElem *b)
1768 if (!equalstr(a->name, b->name))
1770 if (!equal(a->funcname, b->funcname))
1772 if (!equal(a->args, b->args))
1774 if (!equal(a->opclass, b->opclass))
1781 _equalColumnDef(ColumnDef *a, ColumnDef *b)
1783 if (!equalstr(a->colname, b->colname))
1785 if (!equal(a->typename, b->typename))
1787 if (a->inhcount != b->inhcount)
1789 if (a->is_local != b->is_local)
1791 if (a->is_not_null != b->is_not_null)
1793 if (!equal(a->raw_default, b->raw_default))
1795 if (!equalstr(a->cooked_default, b->cooked_default))
1797 if (!equal(a->constraints, b->constraints))
1799 if (!equal(a->support, b->support))
1806 _equalConstraint(Constraint *a, Constraint *b)
1808 if (a->contype != b->contype)
1810 if (!equalstr(a->name, b->name))
1812 if (!equal(a->raw_expr, b->raw_expr))
1814 if (!equalstr(a->cooked_expr, b->cooked_expr))
1816 if (!equal(a->keys, b->keys))
1823 _equalDefElem(DefElem *a, DefElem *b)
1825 if (!equalstr(a->defname, b->defname))
1827 if (!equal(a->arg, b->arg))
1834 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
1836 if (!equal(a->resdom, b->resdom))
1838 if (!equal(a->fjoin, b->fjoin))
1840 if (!equal(a->expr, b->expr))
1847 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
1849 if (a->rtekind != b->rtekind)
1851 if (a->relid != b->relid)
1853 if (!equal(a->subquery, b->subquery))
1855 if (!equal(a->funcexpr, b->funcexpr))
1857 if (!equal(a->coldeflist, b->coldeflist))
1859 if (a->jointype != b->jointype)
1861 if (!equal(a->joinaliasvars, b->joinaliasvars))
1863 if (!equal(a->alias, b->alias))
1865 if (!equal(a->eref, b->eref))
1867 if (a->inh != b->inh)
1869 if (a->inFromCl != b->inFromCl)
1871 if (a->checkForRead != b->checkForRead)
1873 if (a->checkForWrite != b->checkForWrite)
1875 if (a->checkAsUser != b->checkAsUser)
1882 _equalSortClause(SortClause *a, SortClause *b)
1884 if (a->tleSortGroupRef != b->tleSortGroupRef)
1886 if (a->sortop != b->sortop)
1893 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
1895 if (!equalstr(a->constr_name, b->constr_name))
1897 if (!equal(a->pktable, b->pktable))
1899 if (!equal(a->fk_attrs, b->fk_attrs))
1901 if (!equal(a->pk_attrs, b->pk_attrs))
1903 if (a->fk_matchtype != b->fk_matchtype)
1905 if (a->fk_upd_action != b->fk_upd_action)
1907 if (a->fk_del_action != b->fk_del_action)
1909 if (a->deferrable != b->deferrable)
1911 if (a->initdeferred != b->initdeferred)
1913 if (a->skip_validation != b->skip_validation)
1920 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
1922 if (a->casetype != b->casetype)
1924 if (!equal(a->arg, b->arg))
1926 if (!equal(a->args, b->args))
1928 if (!equal(a->defresult, b->defresult))
1935 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
1937 if (!equal(a->expr, b->expr))
1939 if (!equal(a->result, b->result))
1946 _equalNullTest(NullTest *a, NullTest *b)
1948 if (!equal(a->arg, b->arg))
1950 if (a->nulltesttype != b->nulltesttype)
1956 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
1958 if (!equal(a->arg, b->arg))
1960 if (a->booltesttype != b->booltesttype)
1966 _equalConstraintTest(ConstraintTest *a, ConstraintTest *b)
1968 if (!equal(a->arg, b->arg))
1970 if (a->testtype != b->testtype)
1972 if (!equalstr(a->name, b->name))
1974 if (!equal(a->check_expr, b->check_expr))
1980 * Stuff from pg_list.h
1984 _equalValue(Value *a, Value *b)
1986 if (a->type != b->type)
1992 return a->val.ival == b->val.ival;
1996 return strcmp(a->val.str, b->val.str) == 0;
2001 elog(ERROR, "_equalValue: unknown node type %d", a->type);
2010 * returns whether two nodes are equal
2013 equal(void *a, void *b)
2015 bool retval = false;
2021 * note that a!=b, so only one of them can be NULL
2023 if (a == NULL || b == NULL)
2027 * are they the same type of nodes?
2029 if (nodeTag(a) != nodeTag(b))
2035 retval = _equalSubPlan(a, b);
2039 retval = _equalResdom(a, b);
2042 retval = _equalFjoin(a, b);
2045 retval = _equalExpr(a, b);
2048 retval = _equalVar(a, b);
2051 retval = _equalOper(a, b);
2054 retval = _equalConst(a, b);
2057 retval = _equalParam(a, b);
2060 retval = _equalAggref(a, b);
2063 retval = _equalSubLink(a, b);
2066 retval = _equalFunc(a, b);
2069 retval = _equalFieldSelect(a, b);
2072 retval = _equalArrayRef(a, b);
2075 retval = _equalRelabelType(a, b);
2078 retval = _equalRangeTblRef(a, b);
2081 retval = _equalFromExpr(a, b);
2084 retval = _equalJoinExpr(a, b);
2088 retval = _equalRelOptInfo(a, b);
2091 retval = _equalPath(a, b);
2094 retval = _equalIndexPath(a, b);
2097 retval = _equalNestPath(a, b);
2100 retval = _equalMergePath(a, b);
2103 retval = _equalHashPath(a, b);
2106 retval = _equalPathKeyItem(a, b);
2108 case T_RestrictInfo:
2109 retval = _equalRestrictInfo(a, b);
2112 retval = _equalJoinInfo(a, b);
2115 retval = _equalTidPath(a, b);
2118 retval = _equalAppendPath(a, b);
2121 retval = _equalResultPath(a, b);
2123 case T_IndexOptInfo:
2124 retval = _equalIndexOptInfo(a, b);
2129 List *la = (List *) a;
2130 List *lb = (List *) b;
2134 * Try to reject by length check before we grovel through
2135 * all the elements...
2137 if (length(la) != length(lb))
2141 if (!equal(lfirst(l), lfirst(lb)))
2154 retval = _equalValue(a, b);
2158 retval = _equalQuery(a, b);
2161 retval = _equalInsertStmt(a, b);
2164 retval = _equalDeleteStmt(a, b);
2167 retval = _equalUpdateStmt(a, b);
2170 retval = _equalSelectStmt(a, b);
2172 case T_SetOperationStmt:
2173 retval = _equalSetOperationStmt(a, b);
2175 case T_AlterTableStmt:
2176 retval = _equalAlterTableStmt(a, b);
2179 retval = _equalGrantStmt(a, b);
2181 case T_ClosePortalStmt:
2182 retval = _equalClosePortalStmt(a, b);
2185 retval = _equalClusterStmt(a, b);
2188 retval = _equalCopyStmt(a, b);
2191 retval = _equalCreateStmt(a, b);
2194 retval = _equalDefineStmt(a, b);
2197 retval = _equalDropStmt(a, b);
2199 case T_TruncateStmt:
2200 retval = _equalTruncateStmt(a, b);
2203 retval = _equalCommentStmt(a, b);
2206 retval = _equalFetchStmt(a, b);
2209 retval = _equalIndexStmt(a, b);
2211 case T_CreateFunctionStmt:
2212 retval = _equalCreateFunctionStmt(a, b);
2214 case T_RemoveAggrStmt:
2215 retval = _equalRemoveAggrStmt(a, b);
2217 case T_RemoveFuncStmt:
2218 retval = _equalRemoveFuncStmt(a, b);
2220 case T_RemoveOperStmt:
2221 retval = _equalRemoveOperStmt(a, b);
2223 case T_RemoveOpClassStmt:
2224 retval = _equalRemoveOpClassStmt(a, b);
2227 retval = _equalRenameStmt(a, b);
2230 retval = _equalRuleStmt(a, b);
2233 retval = _equalNotifyStmt(a, b);
2236 retval = _equalListenStmt(a, b);
2238 case T_UnlistenStmt:
2239 retval = _equalUnlistenStmt(a, b);
2241 case T_TransactionStmt:
2242 retval = _equalTransactionStmt(a, b);
2244 case T_CompositeTypeStmt:
2245 retval = _equalCompositeTypeStmt(a, b);
2248 retval = _equalViewStmt(a, b);
2251 retval = _equalLoadStmt(a, b);
2253 case T_CreateDomainStmt:
2254 retval = _equalCreateDomainStmt(a, b);
2256 case T_CreateOpClassStmt:
2257 retval = _equalCreateOpClassStmt(a, b);
2259 case T_CreateOpClassItem:
2260 retval = _equalCreateOpClassItem(a, b);
2262 case T_CreatedbStmt:
2263 retval = _equalCreatedbStmt(a, b);
2265 case T_AlterDatabaseSetStmt:
2266 retval = _equalAlterDatabaseSetStmt(a, b);
2269 retval = _equalDropdbStmt(a, b);
2272 retval = _equalVacuumStmt(a, b);
2275 retval = _equalExplainStmt(a, b);
2277 case T_CreateSeqStmt:
2278 retval = _equalCreateSeqStmt(a, b);
2280 case T_VariableSetStmt:
2281 retval = _equalVariableSetStmt(a, b);
2283 case T_VariableShowStmt:
2284 retval = _equalVariableShowStmt(a, b);
2286 case T_VariableResetStmt:
2287 retval = _equalVariableResetStmt(a, b);
2289 case T_CreateTrigStmt:
2290 retval = _equalCreateTrigStmt(a, b);
2292 case T_DropPropertyStmt:
2293 retval = _equalDropPropertyStmt(a, b);
2295 case T_CreatePLangStmt:
2296 retval = _equalCreatePLangStmt(a, b);
2298 case T_DropPLangStmt:
2299 retval = _equalDropPLangStmt(a, b);
2301 case T_CreateUserStmt:
2302 retval = _equalCreateUserStmt(a, b);
2304 case T_AlterUserStmt:
2305 retval = _equalAlterUserStmt(a, b);
2307 case T_AlterUserSetStmt:
2308 retval = _equalAlterUserSetStmt(a, b);
2310 case T_DropUserStmt:
2311 retval = _equalDropUserStmt(a, b);
2314 retval = _equalLockStmt(a, b);
2316 case T_ConstraintsSetStmt:
2317 retval = _equalConstraintsSetStmt(a, b);
2319 case T_CreateGroupStmt:
2320 retval = _equalCreateGroupStmt(a, b);
2322 case T_AlterGroupStmt:
2323 retval = _equalAlterGroupStmt(a, b);
2325 case T_DropGroupStmt:
2326 retval = _equalDropGroupStmt(a, b);
2329 retval = _equalReindexStmt(a, b);
2331 case T_CheckPointStmt:
2334 case T_CreateSchemaStmt:
2335 retval = _equalCreateSchemaStmt(a, b);
2337 case T_CreateConversionStmt:
2338 retval = _equalCreateConversionStmt(a, b);
2340 case T_CreateCastStmt:
2341 retval = _equalCreateCastStmt(a, b);
2343 case T_DropCastStmt:
2344 retval = _equalDropCastStmt(a, b);
2347 retval = _equalPrepareStmt(a, b);
2350 retval = _equalExecuteStmt(a, b);
2352 case T_DeallocateStmt:
2353 retval = _equalDeallocateStmt(a, b);
2357 retval = _equalAExpr(a, b);
2360 retval = _equalColumnRef(a, b);
2363 retval = _equalParamRef(a, b);
2366 retval = _equalAConst(a, b);
2369 retval = _equalFuncCall(a, b);
2372 retval = _equalAIndices(a, b);
2374 case T_ExprFieldSelect:
2375 retval = _equalExprFieldSelect(a, b);
2378 retval = _equalResTarget(a, b);
2381 retval = _equalTypeCast(a, b);
2384 retval = _equalSortGroupBy(a, b);
2387 retval = _equalAlias(a, b);
2390 retval = _equalRangeVar(a, b);
2392 case T_RangeSubselect:
2393 retval = _equalRangeSubselect(a, b);
2395 case T_RangeFunction:
2396 retval = _equalRangeFunction(a, b);
2399 retval = _equalTypeName(a, b);
2402 retval = _equalIndexElem(a, b);
2405 retval = _equalColumnDef(a, b);
2408 retval = _equalConstraint(a, b);
2411 retval = _equalDefElem(a, b);
2414 retval = _equalTargetEntry(a, b);
2416 case T_RangeTblEntry:
2417 retval = _equalRangeTblEntry(a, b);
2420 retval = _equalSortClause(a, b);
2423 /* GroupClause is equivalent to SortClause */
2424 retval = _equalSortClause(a, b);
2427 retval = _equalCaseExpr(a, b);
2430 retval = _equalCaseWhen(a, b);
2433 retval = _equalNullTest(a, b);
2436 retval = _equalBooleanTest(a, b);
2438 case T_ConstraintTest:
2439 retval = _equalConstraintTest(a, b);
2441 case T_FkConstraint:
2442 retval = _equalFkConstraint(a, b);
2445 retval = _equalPrivGrantee(a, b);
2447 case T_FuncWithArgs:
2448 retval = _equalFuncWithArgs(a, b);
2450 case T_InsertDefault:
2451 retval = _equalInsertDefault(a, b);
2455 elog(WARNING, "equal: don't know whether nodes of type %d are equal",