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.155 2002/08/27 04:55:07 tgl Exp $
25 *-------------------------------------------------------------------------
30 #include "nodes/plannodes.h"
31 #include "nodes/relation.h"
32 #include "utils/datum.h"
35 /* Macro for comparing string fields that might be NULL */
36 #define equalstr(a, b) \
37 (((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
41 * Stuff from primnodes.h
45 _equalResdom(Resdom *a, Resdom *b)
47 if (a->resno != b->resno)
49 if (a->restype != b->restype)
51 if (a->restypmod != b->restypmod)
53 if (!equalstr(a->resname, b->resname))
55 if (a->ressortgroupref != b->ressortgroupref)
57 if (a->reskey != b->reskey)
59 if (a->reskeyop != b->reskeyop)
61 /* we ignore resjunk flag ... is this correct? */
67 _equalFjoin(Fjoin *a, Fjoin *b)
71 if (a->fj_initialized != b->fj_initialized)
73 if (a->fj_nNodes != b->fj_nNodes)
75 if (!equal(a->fj_innerNode, b->fj_innerNode))
78 nNodes = a->fj_nNodes;
79 if (memcmp(a->fj_results, b->fj_results, nNodes * sizeof(Datum)) != 0)
81 if (memcmp(a->fj_alwaysDone, b->fj_alwaysDone, nNodes * sizeof(bool)) != 0)
88 _equalExpr(Expr *a, Expr *b)
91 * We do not examine typeOid, since the optimizer often doesn't bother
92 * to set it in created nodes, and it is logically a derivative of the
95 if (a->opType != b->opType)
97 if (!equal(a->oper, b->oper))
99 if (!equal(a->args, b->args))
106 _equalVar(Var *a, Var *b)
108 if (a->varno != b->varno)
110 if (a->varattno != b->varattno)
112 if (a->vartype != b->vartype)
114 if (a->vartypmod != b->vartypmod)
116 if (a->varlevelsup != b->varlevelsup)
118 if (a->varnoold != b->varnoold)
120 if (a->varoattno != b->varoattno)
127 _equalOper(Oper *a, Oper *b)
129 if (a->opno != b->opno)
131 if (a->opresulttype != b->opresulttype)
133 if (a->opretset != b->opretset)
137 * We do not examine opid or op_fcache, since these are logically
138 * derived from opno, and they may not be set yet depending on how far
139 * along the node is in the parse/plan pipeline.
141 * (Besides, op_fcache is executor state, which we don't check --- see
142 * notes at head of file.)
144 * It's probably not really necessary to check opresulttype or opretset,
152 _equalConst(Const *a, Const *b)
154 if (a->consttype != b->consttype)
156 if (a->constlen != b->constlen)
158 if (a->constisnull != b->constisnull)
160 if (a->constbyval != b->constbyval)
162 /* XXX What about constisset and constiscast? */
165 * We treat all NULL constants of the same type as equal. Someday this
166 * might need to change? But datumIsEqual doesn't work on nulls,
171 return datumIsEqual(a->constvalue, b->constvalue,
172 a->constbyval, a->constlen);
176 _equalParam(Param *a, Param *b)
178 if (a->paramkind != b->paramkind)
180 if (a->paramtype != b->paramtype)
183 switch (a->paramkind)
188 if (strcmp(a->paramname, b->paramname) != 0)
193 if (a->paramid != b->paramid)
199 * XXX: Hmmm... What are we supposed to return in this case ??
204 elog(ERROR, "_equalParam: Invalid paramkind value: %d",
212 _equalFunc(Func *a, Func *b)
214 if (a->funcid != b->funcid)
216 if (a->funcresulttype != b->funcresulttype)
218 if (a->funcretset != b->funcretset)
220 /* Note we do not look at func_fcache; see notes for _equalOper */
226 _equalAggref(Aggref *a, Aggref *b)
228 if (a->aggfnoid != b->aggfnoid)
230 if (a->aggtype != b->aggtype)
232 if (!equal(a->target, b->target))
234 if (a->aggstar != b->aggstar)
236 if (a->aggdistinct != b->aggdistinct)
238 /* ignore aggno, which is only a private field for the executor */
243 _equalSubLink(SubLink *a, SubLink *b)
245 if (a->subLinkType != b->subLinkType)
247 if (a->useor != b->useor)
249 if (!equal(a->lefthand, b->lefthand))
251 if (!equal(a->oper, b->oper))
253 if (!equal(a->subselect, b->subselect))
259 _equalArrayRef(ArrayRef *a, ArrayRef *b)
261 if (a->refrestype != b->refrestype)
263 if (a->refattrlength != b->refattrlength)
265 if (a->refelemlength != b->refelemlength)
267 if (a->refelembyval != b->refelembyval)
269 if (a->refelemalign != b->refelemalign)
271 if (!equal(a->refupperindexpr, b->refupperindexpr))
273 if (!equal(a->reflowerindexpr, b->reflowerindexpr))
275 if (!equal(a->refexpr, b->refexpr))
277 if (!equal(a->refassgnexpr, b->refassgnexpr))
283 _equalFieldSelect(FieldSelect *a, FieldSelect *b)
285 if (!equal(a->arg, b->arg))
287 if (a->fieldnum != b->fieldnum)
289 if (a->resulttype != b->resulttype)
291 if (a->resulttypmod != b->resulttypmod)
297 _equalRelabelType(RelabelType *a, RelabelType *b)
299 if (!equal(a->arg, b->arg))
301 if (a->resulttype != b->resulttype)
303 if (a->resulttypmod != b->resulttypmod)
309 _equalRangeTblRef(RangeTblRef *a, RangeTblRef *b)
311 if (a->rtindex != b->rtindex)
318 _equalFromExpr(FromExpr *a, FromExpr *b)
320 if (!equal(a->fromlist, b->fromlist))
322 if (!equal(a->quals, b->quals))
329 _equalJoinExpr(JoinExpr *a, JoinExpr *b)
331 if (a->jointype != b->jointype)
333 if (a->isNatural != b->isNatural)
335 if (!equal(a->larg, b->larg))
337 if (!equal(a->rarg, b->rarg))
339 if (!equal(a->using, b->using))
341 if (!equal(a->quals, b->quals))
343 if (!equal(a->alias, b->alias))
345 if (a->rtindex != b->rtindex)
352 * Stuff from relation.h
356 _equalRelOptInfo(RelOptInfo *a, RelOptInfo *b)
359 * We treat RelOptInfos as equal if they refer to the same base rels
360 * joined in the same order. Is this appropriate/sufficient?
362 return equali(a->relids, b->relids);
366 _equalIndexOptInfo(IndexOptInfo *a, IndexOptInfo *b)
369 * We treat IndexOptInfos as equal if they refer to the same index. Is
372 if (a->indexoid != b->indexoid)
378 _equalPathKeyItem(PathKeyItem *a, PathKeyItem *b)
380 if (a->sortop != b->sortop)
382 if (!equal(a->key, b->key))
388 _equalPath(Path *a, Path *b)
390 if (a->pathtype != b->pathtype)
392 if (!equal(a->parent, b->parent))
396 * do not check path costs, since they may not be set yet, and being
397 * float values there are roundoff error issues anyway...
399 if (!equal(a->pathkeys, b->pathkeys))
405 _equalIndexPath(IndexPath *a, IndexPath *b)
407 if (!_equalPath((Path *) a, (Path *) b))
409 if (!equal(a->indexinfo, b->indexinfo))
411 if (!equal(a->indexqual, b->indexqual))
413 if (a->indexscandir != b->indexscandir)
415 if (!equali(a->joinrelids, b->joinrelids))
417 if (a->alljoinquals != b->alljoinquals)
421 * Skip 'rows' because of possibility of floating-point roundoff
422 * error. It should be derivable from the other fields anyway.
428 _equalTidPath(TidPath *a, TidPath *b)
430 if (!_equalPath((Path *) a, (Path *) b))
432 if (!equal(a->tideval, b->tideval))
434 if (!equali(a->unjoined_relids, b->unjoined_relids))
440 _equalAppendPath(AppendPath *a, AppendPath *b)
442 if (!_equalPath((Path *) a, (Path *) b))
444 if (!equal(a->subpaths, b->subpaths))
450 _equalJoinPath(JoinPath *a, JoinPath *b)
452 if (!_equalPath((Path *) a, (Path *) b))
454 if (a->jointype != b->jointype)
456 if (!equal(a->outerjoinpath, b->outerjoinpath))
458 if (!equal(a->innerjoinpath, b->innerjoinpath))
460 if (!equal(a->joinrestrictinfo, b->joinrestrictinfo))
466 _equalNestPath(NestPath *a, NestPath *b)
468 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
474 _equalMergePath(MergePath *a, MergePath *b)
476 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
478 if (!equal(a->path_mergeclauses, b->path_mergeclauses))
480 if (!equal(a->outersortkeys, b->outersortkeys))
482 if (!equal(a->innersortkeys, b->innersortkeys))
488 _equalHashPath(HashPath *a, HashPath *b)
490 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
492 if (!equal(a->path_hashclauses, b->path_hashclauses))
498 _equalSubPlan(SubPlan *a, SubPlan *b)
500 /* should compare plans, but have to settle for comparing plan IDs */
501 if (a->plan_id != b->plan_id)
504 if (!equal(a->rtable, b->rtable))
507 if (!equal(a->sublink, b->sublink))
514 _equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
516 if (!equal(a->clause, b->clause))
518 if (a->ispusheddown != b->ispusheddown)
522 * We ignore eval_cost, this_selec, left/right_pathkey, and
523 * left/right_bucketsize, since they may not be set yet, and should be
524 * derivable from the clause anyway. Probably it's not really
525 * necessary to compare any of these remaining fields ...
527 if (!equal(a->subclauseindices, b->subclauseindices))
529 if (a->mergejoinoperator != b->mergejoinoperator)
531 if (a->left_sortop != b->left_sortop)
533 if (a->right_sortop != b->right_sortop)
535 if (a->hashjoinoperator != b->hashjoinoperator)
541 _equalJoinInfo(JoinInfo *a, JoinInfo *b)
543 if (!equali(a->unjoined_relids, b->unjoined_relids))
545 if (!equal(a->jinfo_restrictinfo, b->jinfo_restrictinfo))
551 * Stuff from parsenodes.h
555 _equalQuery(Query *a, Query *b)
557 if (a->commandType != b->commandType)
559 if (!equal(a->utilityStmt, b->utilityStmt))
561 if (a->resultRelation != b->resultRelation)
563 if (!equal(a->into, b->into))
565 if (a->isPortal != b->isPortal)
567 if (a->isBinary != b->isBinary)
569 if (a->hasAggs != b->hasAggs)
571 if (a->hasSubLinks != b->hasSubLinks)
573 /* we deliberately ignore originalQuery */
574 if (!equal(a->rtable, b->rtable))
576 if (!equal(a->jointree, b->jointree))
578 if (!equali(a->rowMarks, b->rowMarks))
580 if (!equal(a->targetList, b->targetList))
582 if (!equal(a->groupClause, b->groupClause))
584 if (!equal(a->havingQual, b->havingQual))
586 if (!equal(a->distinctClause, b->distinctClause))
588 if (!equal(a->sortClause, b->sortClause))
590 if (!equal(a->limitOffset, b->limitOffset))
592 if (!equal(a->limitCount, b->limitCount))
594 if (!equal(a->setOperations, b->setOperations))
596 if (!equali(a->resultRelations, b->resultRelations))
600 * We do not check the internal-to-the-planner fields: base_rel_list,
601 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. They
602 * might not be set yet, and in any case they should be derivable from
609 _equalInsertStmt(InsertStmt *a, InsertStmt *b)
611 if (!equal(a->relation, b->relation))
613 if (!equal(a->cols, b->cols))
615 if (!equal(a->targetList, b->targetList))
617 if (!equal(a->selectStmt, b->selectStmt))
624 _equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
626 if (!equal(a->relation, b->relation))
628 if (!equal(a->whereClause, b->whereClause))
635 _equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
637 if (!equal(a->relation, b->relation))
639 if (!equal(a->targetList, b->targetList))
641 if (!equal(a->whereClause, b->whereClause))
643 if (!equal(a->fromClause, b->fromClause))
650 _equalSelectStmt(SelectStmt *a, SelectStmt *b)
652 if (!equal(a->distinctClause, b->distinctClause))
654 if (!equal(a->into, b->into))
656 if (!equal(a->intoColNames, b->intoColNames))
658 if (!equal(a->targetList, b->targetList))
660 if (!equal(a->fromClause, b->fromClause))
662 if (!equal(a->whereClause, b->whereClause))
664 if (!equal(a->groupClause, b->groupClause))
666 if (!equal(a->havingClause, b->havingClause))
668 if (!equal(a->sortClause, b->sortClause))
670 if (!equalstr(a->portalname, b->portalname))
672 if (a->binary != b->binary)
674 if (!equal(a->limitOffset, b->limitOffset))
676 if (!equal(a->limitCount, b->limitCount))
678 if (!equal(a->forUpdate, b->forUpdate))
682 if (a->all != b->all)
684 if (!equal(a->larg, b->larg))
686 if (!equal(a->rarg, b->rarg))
693 _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
697 if (a->all != b->all)
699 if (!equal(a->larg, b->larg))
701 if (!equal(a->rarg, b->rarg))
703 if (!equali(a->colTypes, b->colTypes))
710 _equalAlterTableStmt(AlterTableStmt *a, AlterTableStmt *b)
712 if (a->subtype != b->subtype)
714 if (!equal(a->relation, b->relation))
716 if (!equalstr(a->name, b->name))
718 if (!equal(a->def, b->def))
720 if (a->behavior != b->behavior)
727 _equalGrantStmt(GrantStmt *a, GrantStmt *b)
729 if (a->is_grant != b->is_grant)
731 if (a->objtype != b->objtype)
733 if (!equal(a->objects, b->objects))
735 if (!equali(a->privileges, b->privileges))
737 if (!equal(a->grantees, b->grantees))
744 _equalPrivGrantee(PrivGrantee *a, PrivGrantee *b)
746 return equalstr(a->username, b->username)
747 && equalstr(a->groupname, b->groupname);
751 _equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
753 return equal(a->funcname, b->funcname)
754 && equal(a->funcargs, b->funcargs);
758 _equalInsertDefault(InsertDefault *a, InsertDefault *b)
764 _equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
766 if (!equalstr(a->portalname, b->portalname))
773 _equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
775 if (!equal(a->relation, b->relation))
777 if (!equalstr(a->indexname, b->indexname))
784 _equalCopyStmt(CopyStmt *a, CopyStmt *b)
786 if (!equal(a->relation, b->relation))
788 if (!equal(a->attlist, b->attlist))
790 if (a->is_from != b->is_from)
792 if (!equalstr(a->filename, b->filename))
794 if (!equal(a->options, b->options))
801 _equalCreateStmt(CreateStmt *a, CreateStmt *b)
803 if (!equal(a->relation, b->relation))
805 if (!equal(a->tableElts, b->tableElts))
807 if (!equal(a->inhRelations, b->inhRelations))
809 if (!equal(a->constraints, b->constraints))
811 if (a->hasoids != b->hasoids)
818 _equalDefineStmt(DefineStmt *a, DefineStmt *b)
820 if (a->defType != b->defType)
822 if (!equal(a->defnames, b->defnames))
824 if (!equal(a->definition, b->definition))
831 _equalDropStmt(DropStmt *a, DropStmt *b)
833 if (!equal(a->objects, b->objects))
835 if (a->removeType != b->removeType)
837 if (a->behavior != b->behavior)
844 _equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
846 if (!equal(a->relation, b->relation))
853 _equalCommentStmt(CommentStmt *a, CommentStmt *b)
855 if (a->objtype != b->objtype)
857 if (!equal(a->objname, b->objname))
859 if (!equal(a->objargs, b->objargs))
861 if (!equalstr(a->comment, b->comment))
868 _equalFetchStmt(FetchStmt *a, FetchStmt *b)
870 if (a->direction != b->direction)
872 if (a->howMany != b->howMany)
874 if (!equalstr(a->portalname, b->portalname))
876 if (a->ismove != b->ismove)
883 _equalIndexStmt(IndexStmt *a, IndexStmt *b)
885 if (!equalstr(a->idxname, b->idxname))
887 if (!equal(a->relation, b->relation))
889 if (!equalstr(a->accessMethod, b->accessMethod))
891 if (!equal(a->indexParams, b->indexParams))
893 if (!equal(a->whereClause, b->whereClause))
895 if (!equal(a->rangetable, b->rangetable))
897 if (a->unique != b->unique)
899 if (a->primary != b->primary)
901 if (a->isconstraint != b->isconstraint)
908 _equalCreateFunctionStmt(CreateFunctionStmt *a, CreateFunctionStmt *b)
910 if (a->replace != b->replace)
912 if (!equal(a->funcname, b->funcname))
914 if (!equal(a->argTypes, b->argTypes))
916 if (!equal(a->returnType, b->returnType))
918 if (!equal(a->options, b->options))
920 if (!equal(a->withClause, b->withClause))
927 _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
929 if (!equal(a->aggname, b->aggname))
931 if (!equal(a->aggtype, b->aggtype))
933 if (a->behavior != b->behavior)
940 _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
942 if (!equal(a->funcname, b->funcname))
944 if (!equal(a->args, b->args))
946 if (a->behavior != b->behavior)
953 _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
955 if (!equal(a->opname, b->opname))
957 if (!equal(a->args, b->args))
959 if (a->behavior != b->behavior)
966 _equalRemoveOpClassStmt(RemoveOpClassStmt *a, RemoveOpClassStmt *b)
968 if (!equal(a->opclassname, b->opclassname))
970 if (!equalstr(a->amname, b->amname))
972 if (a->behavior != b->behavior)
979 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
981 if (!equal(a->relation, b->relation))
983 if (!equalstr(a->oldname, b->oldname))
985 if (!equalstr(a->newname, b->newname))
987 if (a->renameType != b->renameType)
994 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
996 if (!equal(a->relation, b->relation))
998 if (!equalstr(a->rulename, b->rulename))
1000 if (!equal(a->whereClause, b->whereClause))
1002 if (a->event != b->event)
1004 if (a->instead != b->instead)
1006 if (!equal(a->actions, b->actions))
1013 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1015 if (!equal(a->relation, b->relation))
1022 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1024 if (!equal(a->relation, b->relation))
1031 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1033 if (!equal(a->relation, b->relation))
1040 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1042 if (a->command != b->command)
1044 if (!equal(a->options, b->options))
1051 _equalCompositeTypeStmt(CompositeTypeStmt *a, CompositeTypeStmt *b)
1053 if (!equal(a->typevar, b->typevar))
1055 if (!equal(a->coldeflist, b->coldeflist))
1062 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1064 if (!equal(a->view, b->view))
1066 if (!equal(a->aliases, b->aliases))
1068 if (!equal(a->query, b->query))
1075 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1077 if (!equalstr(a->filename, b->filename))
1084 _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
1086 if (!equal(a->domainname, b->domainname))
1088 if (!equal(a->typename, b->typename))
1090 if (!equal(a->constraints, b->constraints))
1097 _equalCreateOpClassStmt(CreateOpClassStmt *a, CreateOpClassStmt *b)
1099 if (!equal(a->opclassname, b->opclassname))
1101 if (!equalstr(a->amname, b->amname))
1103 if (!equal(a->datatype, b->datatype))
1105 if (!equal(a->items, b->items))
1107 if (a->isDefault != b->isDefault)
1114 _equalCreateOpClassItem(CreateOpClassItem *a, CreateOpClassItem *b)
1116 if (a->itemtype != b->itemtype)
1118 if (!equal(a->name, b->name))
1120 if (!equal(a->args, b->args))
1122 if (a->number != b->number)
1124 if (a->recheck != b->recheck)
1126 if (!equal(a->storedtype, b->storedtype))
1133 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1135 if (!equalstr(a->dbname, b->dbname))
1137 if (!equal(a->options, b->options))
1144 _equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
1146 if (!equalstr(a->dbname, b->dbname))
1148 if (!equalstr(a->variable, b->variable))
1150 if (!equal(a->value, b->value))
1157 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1159 if (!equalstr(a->dbname, b->dbname))
1166 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1168 if (a->vacuum != b->vacuum)
1170 if (a->full != b->full)
1172 if (a->analyze != b->analyze)
1174 if (a->freeze != b->freeze)
1176 if (a->verbose != b->verbose)
1178 if (!equal(a->relation, b->relation))
1180 if (!equal(a->va_cols, b->va_cols))
1187 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1189 if (!equal(a->query, b->query))
1191 if (a->verbose != b->verbose)
1193 if (a->analyze != b->analyze)
1200 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1202 if (!equal(a->sequence, b->sequence))
1204 if (!equal(a->options, b->options))
1211 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1213 if (!equalstr(a->name, b->name))
1215 if (!equal(a->args, b->args))
1217 if (a->is_local != b->is_local)
1224 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1226 if (!equalstr(a->name, b->name))
1233 _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
1235 if (!equalstr(a->name, b->name))
1242 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1244 if (!equalstr(a->trigname, b->trigname))
1246 if (!equal(a->relation, b->relation))
1248 if (!equal(a->funcname, b->funcname))
1250 if (!equal(a->args, b->args))
1252 if (a->before != b->before)
1254 if (a->row != b->row)
1256 if (strcmp(a->actions, b->actions) != 0)
1258 if (!equalstr(a->lang, b->lang))
1260 if (!equalstr(a->text, b->text))
1262 if (!equal(a->attr, b->attr))
1264 if (!equalstr(a->when, b->when))
1266 if (a->isconstraint != b->isconstraint)
1268 if (a->deferrable != b->deferrable)
1270 if (a->initdeferred != b->initdeferred)
1272 if (!equal(a->constrrel, b->constrrel))
1279 _equalDropPropertyStmt(DropPropertyStmt *a, DropPropertyStmt *b)
1281 if (!equal(a->relation, b->relation))
1283 if (!equalstr(a->property, b->property))
1285 if (a->removeType != b->removeType)
1287 if (a->behavior != b->behavior)
1294 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1296 if (!equalstr(a->plname, b->plname))
1298 if (!equal(a->plhandler, b->plhandler))
1300 if (!equal(a->plvalidator, b->plvalidator))
1302 if (a->pltrusted != b->pltrusted)
1309 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1311 if (!equalstr(a->plname, b->plname))
1313 if (a->behavior != b->behavior)
1320 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1322 if (!equalstr(a->user, b->user))
1324 if (!equal(a->options, b->options))
1331 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1333 if (!equalstr(a->user, b->user))
1335 if (!equal(a->options, b->options))
1342 _equalAlterUserSetStmt(AlterUserSetStmt *a, AlterUserSetStmt *b)
1344 if (!equalstr(a->user, b->user))
1346 if (!equalstr(a->variable, b->variable))
1348 if (!equal(a->value, b->value))
1355 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1357 if (!equal(a->users, b->users))
1364 _equalLockStmt(LockStmt *a, LockStmt *b)
1366 if (!equal(a->relations, b->relations))
1368 if (a->mode != b->mode)
1375 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1377 if (!equal(a->constraints, b->constraints))
1379 if (a->deferred != b->deferred)
1386 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1388 if (!equalstr(a->name, b->name))
1390 if (!equal(a->options, b->options))
1397 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1399 if (!equalstr(a->name, b->name))
1401 if (a->action != b->action)
1403 if (!equal(a->listUsers, b->listUsers))
1410 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1412 if (!equalstr(a->name, b->name))
1419 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1421 if (a->reindexType != b->reindexType)
1423 if (!equal(a->relation, b->relation))
1425 if (!equalstr(a->name, b->name))
1427 if (a->force != b->force)
1429 if (a->all != b->all)
1436 _equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
1438 if (!equalstr(a->schemaname, b->schemaname))
1440 if (!equalstr(a->authid, b->authid))
1442 if (!equal(a->schemaElts, b->schemaElts))
1449 _equalCreateConversionStmt(CreateConversionStmt *a, CreateConversionStmt *b)
1451 if (!equal(a->conversion_name, b->conversion_name))
1453 if (!equalstr(a->for_encoding_name, b->for_encoding_name))
1455 if (!equalstr(a->to_encoding_name, b->to_encoding_name))
1457 if (!equal(a->func_name, b->func_name))
1459 if (a->def != b->def)
1466 _equalCreateCastStmt(CreateCastStmt *a, CreateCastStmt *b)
1468 if (!equal(a->sourcetype, b->sourcetype))
1470 if (!equal(a->targettype, b->targettype))
1472 if (!equal(a->func, b->func))
1474 if (a->implicit != b->implicit)
1481 _equalDropCastStmt(DropCastStmt *a, DropCastStmt *b)
1483 if (!equal(a->sourcetype, b->sourcetype))
1485 if (!equal(a->targettype, b->targettype))
1487 if (a->behavior != b->behavior)
1494 _equalPrepareStmt(PrepareStmt *a, PrepareStmt *b)
1496 if (!equalstr(a->name, b->name))
1498 if (!equal(a->argtypes, b->argtypes))
1500 if (!equali(a->argtype_oids, b->argtype_oids))
1502 if (!equal(a->query, b->query))
1509 _equalExecuteStmt(ExecuteStmt *a, ExecuteStmt *b)
1511 if (!equalstr(a->name, b->name))
1513 if (!equal(a->into, b->into))
1515 if (!equal(a->params, b->params))
1522 _equalDeallocateStmt(DeallocateStmt *a, DeallocateStmt *b)
1524 if (!equalstr(a->name, b->name))
1531 _equalAExpr(A_Expr *a, A_Expr *b)
1533 if (a->oper != b->oper)
1535 if (!equal(a->name, b->name))
1537 if (!equal(a->lexpr, b->lexpr))
1539 if (!equal(a->rexpr, b->rexpr))
1546 _equalColumnRef(ColumnRef *a, ColumnRef *b)
1548 if (!equal(a->fields, b->fields))
1550 if (!equal(a->indirection, b->indirection))
1557 _equalParamRef(ParamRef *a, ParamRef *b)
1559 if (a->number != b->number)
1561 if (!equal(a->fields, b->fields))
1563 if (!equal(a->indirection, b->indirection))
1570 _equalAConst(A_Const *a, A_Const *b)
1572 if (!equal(&a->val, &b->val))
1574 if (!equal(a->typename, b->typename))
1581 _equalFuncCall(FuncCall *a, FuncCall *b)
1583 if (!equal(a->funcname, b->funcname))
1585 if (!equal(a->args, b->args))
1587 if (a->agg_star != b->agg_star)
1589 if (a->agg_distinct != b->agg_distinct)
1596 _equalAIndices(A_Indices *a, A_Indices *b)
1598 if (!equal(a->lidx, b->lidx))
1600 if (!equal(a->uidx, b->uidx))
1607 _equalExprFieldSelect(ExprFieldSelect *a, ExprFieldSelect *b)
1609 if (!equal(a->arg, b->arg))
1611 if (!equal(a->fields, b->fields))
1613 if (!equal(a->indirection, b->indirection))
1620 _equalResTarget(ResTarget *a, ResTarget *b)
1622 if (!equalstr(a->name, b->name))
1624 if (!equal(a->indirection, b->indirection))
1626 if (!equal(a->val, b->val))
1633 _equalTypeCast(TypeCast *a, TypeCast *b)
1635 if (!equal(a->arg, b->arg))
1637 if (!equal(a->typename, b->typename))
1644 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1646 if (!equal(a->useOp, b->useOp))
1648 if (!equal(a->node, b->node))
1655 _equalAlias(Alias *a, Alias *b)
1657 if (!equalstr(a->aliasname, b->aliasname))
1659 if (!equal(a->colnames, b->colnames))
1666 _equalRangeVar(RangeVar *a, RangeVar *b)
1668 if (!equalstr(a->catalogname, b->catalogname))
1670 if (!equalstr(a->schemaname, b->schemaname))
1672 if (!equalstr(a->relname, b->relname))
1674 if (a->inhOpt != b->inhOpt)
1676 if (a->istemp != b->istemp)
1678 if (!equal(a->alias, b->alias))
1685 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1687 if (!equal(a->subquery, b->subquery))
1689 if (!equal(a->alias, b->alias))
1696 _equalRangeFunction(RangeFunction *a, RangeFunction *b)
1698 if (!equal(a->funccallnode, b->funccallnode))
1700 if (!equal(a->alias, b->alias))
1702 if (!equal(a->coldeflist, b->coldeflist))
1709 _equalTypeName(TypeName *a, TypeName *b)
1711 if (!equal(a->names, b->names))
1713 if (a->typeid != b->typeid)
1715 if (a->timezone != b->timezone)
1717 if (a->setof != b->setof)
1719 if (a->pct_type != b->pct_type)
1721 if (a->typmod != b->typmod)
1723 if (!equal(a->arrayBounds, b->arrayBounds))
1730 _equalIndexElem(IndexElem *a, IndexElem *b)
1732 if (!equalstr(a->name, b->name))
1734 if (!equal(a->funcname, b->funcname))
1736 if (!equal(a->args, b->args))
1738 if (!equal(a->opclass, b->opclass))
1745 _equalColumnDef(ColumnDef *a, ColumnDef *b)
1747 if (!equalstr(a->colname, b->colname))
1749 if (!equal(a->typename, b->typename))
1751 if (a->is_not_null != b->is_not_null)
1753 if (!equal(a->raw_default, b->raw_default))
1755 if (!equalstr(a->cooked_default, b->cooked_default))
1757 if (!equal(a->constraints, b->constraints))
1759 if (!equal(a->support, b->support))
1766 _equalConstraint(Constraint *a, Constraint *b)
1768 if (a->contype != b->contype)
1770 if (!equalstr(a->name, b->name))
1772 if (!equal(a->raw_expr, b->raw_expr))
1774 if (!equalstr(a->cooked_expr, b->cooked_expr))
1776 if (!equal(a->keys, b->keys))
1783 _equalDefElem(DefElem *a, DefElem *b)
1785 if (!equalstr(a->defname, b->defname))
1787 if (!equal(a->arg, b->arg))
1794 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
1796 if (!equal(a->resdom, b->resdom))
1798 if (!equal(a->fjoin, b->fjoin))
1800 if (!equal(a->expr, b->expr))
1807 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
1809 if (a->rtekind != b->rtekind)
1811 if (a->relid != b->relid)
1813 if (!equal(a->subquery, b->subquery))
1815 if (!equal(a->funcexpr, b->funcexpr))
1817 if (!equal(a->coldeflist, b->coldeflist))
1819 if (a->jointype != b->jointype)
1821 if (!equal(a->joinaliasvars, b->joinaliasvars))
1823 if (!equal(a->alias, b->alias))
1825 if (!equal(a->eref, b->eref))
1827 if (a->inh != b->inh)
1829 if (a->inFromCl != b->inFromCl)
1831 if (a->checkForRead != b->checkForRead)
1833 if (a->checkForWrite != b->checkForWrite)
1835 if (a->checkAsUser != b->checkAsUser)
1842 _equalSortClause(SortClause *a, SortClause *b)
1844 if (a->tleSortGroupRef != b->tleSortGroupRef)
1846 if (a->sortop != b->sortop)
1853 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
1855 if (!equalstr(a->constr_name, b->constr_name))
1857 if (!equal(a->pktable, b->pktable))
1859 if (!equal(a->fk_attrs, b->fk_attrs))
1861 if (!equal(a->pk_attrs, b->pk_attrs))
1863 if (a->fk_matchtype != b->fk_matchtype)
1865 if (a->fk_upd_action != b->fk_upd_action)
1867 if (a->fk_del_action != b->fk_del_action)
1869 if (a->deferrable != b->deferrable)
1871 if (a->initdeferred != b->initdeferred)
1873 if (a->skip_validation != b->skip_validation)
1880 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
1882 if (a->casetype != b->casetype)
1884 if (!equal(a->arg, b->arg))
1886 if (!equal(a->args, b->args))
1888 if (!equal(a->defresult, b->defresult))
1895 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
1897 if (!equal(a->expr, b->expr))
1899 if (!equal(a->result, b->result))
1906 _equalNullTest(NullTest *a, NullTest *b)
1908 if (!equal(a->arg, b->arg))
1910 if (a->nulltesttype != b->nulltesttype)
1916 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
1918 if (!equal(a->arg, b->arg))
1920 if (a->booltesttype != b->booltesttype)
1926 * Stuff from pg_list.h
1930 _equalValue(Value *a, Value *b)
1932 if (a->type != b->type)
1938 return a->val.ival == b->val.ival;
1942 return strcmp(a->val.str, b->val.str) == 0;
1947 elog(ERROR, "_equalValue: unknown node type %d", a->type);
1956 * returns whether two nodes are equal
1959 equal(void *a, void *b)
1961 bool retval = false;
1967 * note that a!=b, so only one of them can be NULL
1969 if (a == NULL || b == NULL)
1973 * are they the same type of nodes?
1975 if (nodeTag(a) != nodeTag(b))
1981 retval = _equalSubPlan(a, b);
1985 retval = _equalResdom(a, b);
1988 retval = _equalFjoin(a, b);
1991 retval = _equalExpr(a, b);
1994 retval = _equalVar(a, b);
1997 retval = _equalOper(a, b);
2000 retval = _equalConst(a, b);
2003 retval = _equalParam(a, b);
2006 retval = _equalAggref(a, b);
2009 retval = _equalSubLink(a, b);
2012 retval = _equalFunc(a, b);
2015 retval = _equalFieldSelect(a, b);
2018 retval = _equalArrayRef(a, b);
2021 retval = _equalRelabelType(a, b);
2024 retval = _equalRangeTblRef(a, b);
2027 retval = _equalFromExpr(a, b);
2030 retval = _equalJoinExpr(a, b);
2034 retval = _equalRelOptInfo(a, b);
2037 retval = _equalPath(a, b);
2040 retval = _equalIndexPath(a, b);
2043 retval = _equalNestPath(a, b);
2046 retval = _equalMergePath(a, b);
2049 retval = _equalHashPath(a, b);
2052 retval = _equalPathKeyItem(a, b);
2054 case T_RestrictInfo:
2055 retval = _equalRestrictInfo(a, b);
2058 retval = _equalJoinInfo(a, b);
2061 retval = _equalTidPath(a, b);
2064 retval = _equalAppendPath(a, b);
2066 case T_IndexOptInfo:
2067 retval = _equalIndexOptInfo(a, b);
2072 List *la = (List *) a;
2073 List *lb = (List *) b;
2077 * Try to reject by length check before we grovel through
2078 * all the elements...
2080 if (length(la) != length(lb))
2084 if (!equal(lfirst(l), lfirst(lb)))
2097 retval = _equalValue(a, b);
2101 retval = _equalQuery(a, b);
2104 retval = _equalInsertStmt(a, b);
2107 retval = _equalDeleteStmt(a, b);
2110 retval = _equalUpdateStmt(a, b);
2113 retval = _equalSelectStmt(a, b);
2115 case T_SetOperationStmt:
2116 retval = _equalSetOperationStmt(a, b);
2118 case T_AlterTableStmt:
2119 retval = _equalAlterTableStmt(a, b);
2122 retval = _equalGrantStmt(a, b);
2124 case T_ClosePortalStmt:
2125 retval = _equalClosePortalStmt(a, b);
2128 retval = _equalClusterStmt(a, b);
2131 retval = _equalCopyStmt(a, b);
2134 retval = _equalCreateStmt(a, b);
2137 retval = _equalDefineStmt(a, b);
2140 retval = _equalDropStmt(a, b);
2142 case T_TruncateStmt:
2143 retval = _equalTruncateStmt(a, b);
2146 retval = _equalCommentStmt(a, b);
2149 retval = _equalFetchStmt(a, b);
2152 retval = _equalIndexStmt(a, b);
2154 case T_CreateFunctionStmt:
2155 retval = _equalCreateFunctionStmt(a, b);
2157 case T_RemoveAggrStmt:
2158 retval = _equalRemoveAggrStmt(a, b);
2160 case T_RemoveFuncStmt:
2161 retval = _equalRemoveFuncStmt(a, b);
2163 case T_RemoveOperStmt:
2164 retval = _equalRemoveOperStmt(a, b);
2166 case T_RemoveOpClassStmt:
2167 retval = _equalRemoveOpClassStmt(a, b);
2170 retval = _equalRenameStmt(a, b);
2173 retval = _equalRuleStmt(a, b);
2176 retval = _equalNotifyStmt(a, b);
2179 retval = _equalListenStmt(a, b);
2181 case T_UnlistenStmt:
2182 retval = _equalUnlistenStmt(a, b);
2184 case T_TransactionStmt:
2185 retval = _equalTransactionStmt(a, b);
2187 case T_CompositeTypeStmt:
2188 retval = _equalCompositeTypeStmt(a, b);
2191 retval = _equalViewStmt(a, b);
2194 retval = _equalLoadStmt(a, b);
2196 case T_CreateDomainStmt:
2197 retval = _equalCreateDomainStmt(a, b);
2199 case T_CreateOpClassStmt:
2200 retval = _equalCreateOpClassStmt(a, b);
2202 case T_CreateOpClassItem:
2203 retval = _equalCreateOpClassItem(a, b);
2205 case T_CreatedbStmt:
2206 retval = _equalCreatedbStmt(a, b);
2208 case T_AlterDatabaseSetStmt:
2209 retval = _equalAlterDatabaseSetStmt(a, b);
2212 retval = _equalDropdbStmt(a, b);
2215 retval = _equalVacuumStmt(a, b);
2218 retval = _equalExplainStmt(a, b);
2220 case T_CreateSeqStmt:
2221 retval = _equalCreateSeqStmt(a, b);
2223 case T_VariableSetStmt:
2224 retval = _equalVariableSetStmt(a, b);
2226 case T_VariableShowStmt:
2227 retval = _equalVariableShowStmt(a, b);
2229 case T_VariableResetStmt:
2230 retval = _equalVariableResetStmt(a, b);
2232 case T_CreateTrigStmt:
2233 retval = _equalCreateTrigStmt(a, b);
2235 case T_DropPropertyStmt:
2236 retval = _equalDropPropertyStmt(a, b);
2238 case T_CreatePLangStmt:
2239 retval = _equalCreatePLangStmt(a, b);
2241 case T_DropPLangStmt:
2242 retval = _equalDropPLangStmt(a, b);
2244 case T_CreateUserStmt:
2245 retval = _equalCreateUserStmt(a, b);
2247 case T_AlterUserStmt:
2248 retval = _equalAlterUserStmt(a, b);
2250 case T_AlterUserSetStmt:
2251 retval = _equalAlterUserSetStmt(a, b);
2253 case T_DropUserStmt:
2254 retval = _equalDropUserStmt(a, b);
2257 retval = _equalLockStmt(a, b);
2259 case T_ConstraintsSetStmt:
2260 retval = _equalConstraintsSetStmt(a, b);
2262 case T_CreateGroupStmt:
2263 retval = _equalCreateGroupStmt(a, b);
2265 case T_AlterGroupStmt:
2266 retval = _equalAlterGroupStmt(a, b);
2268 case T_DropGroupStmt:
2269 retval = _equalDropGroupStmt(a, b);
2272 retval = _equalReindexStmt(a, b);
2274 case T_CheckPointStmt:
2277 case T_CreateSchemaStmt:
2278 retval = _equalCreateSchemaStmt(a, b);
2280 case T_CreateConversionStmt:
2281 retval = _equalCreateConversionStmt(a, b);
2283 case T_CreateCastStmt:
2284 retval = _equalCreateCastStmt(a, b);
2286 case T_DropCastStmt:
2287 retval = _equalDropCastStmt(a, b);
2290 retval = _equalPrepareStmt(a, b);
2293 retval = _equalExecuteStmt(a, b);
2295 case T_DeallocateStmt:
2296 retval = _equalDeallocateStmt(a, b);
2300 retval = _equalAExpr(a, b);
2303 retval = _equalColumnRef(a, b);
2306 retval = _equalParamRef(a, b);
2309 retval = _equalAConst(a, b);
2312 retval = _equalFuncCall(a, b);
2315 retval = _equalAIndices(a, b);
2317 case T_ExprFieldSelect:
2318 retval = _equalExprFieldSelect(a, b);
2321 retval = _equalResTarget(a, b);
2324 retval = _equalTypeCast(a, b);
2327 retval = _equalSortGroupBy(a, b);
2330 retval = _equalAlias(a, b);
2333 retval = _equalRangeVar(a, b);
2335 case T_RangeSubselect:
2336 retval = _equalRangeSubselect(a, b);
2338 case T_RangeFunction:
2339 retval = _equalRangeFunction(a, b);
2342 retval = _equalTypeName(a, b);
2345 retval = _equalIndexElem(a, b);
2348 retval = _equalColumnDef(a, b);
2351 retval = _equalConstraint(a, b);
2354 retval = _equalDefElem(a, b);
2357 retval = _equalTargetEntry(a, b);
2359 case T_RangeTblEntry:
2360 retval = _equalRangeTblEntry(a, b);
2363 retval = _equalSortClause(a, b);
2366 /* GroupClause is equivalent to SortClause */
2367 retval = _equalSortClause(a, b);
2370 retval = _equalCaseExpr(a, b);
2373 retval = _equalCaseWhen(a, b);
2376 retval = _equalNullTest(a, b);
2379 retval = _equalBooleanTest(a, b);
2381 case T_FkConstraint:
2382 retval = _equalFkConstraint(a, b);
2385 retval = _equalPrivGrantee(a, b);
2387 case T_FuncWithArgs:
2388 retval = _equalFuncWithArgs(a, b);
2390 case T_InsertDefault:
2391 retval = _equalInsertDefault(a, b);
2395 elog(WARNING, "equal: don't know whether nodes of type %d are equal",