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-2001, 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.129 2002/04/24 02:48:54 momjian Exp $
25 *-------------------------------------------------------------------------
30 #include "nodes/plannodes.h"
31 #include "nodes/relation.h"
32 #include "utils/datum.h"
35 /* Macro for comparing string fields that might be NULL */
36 #define equalstr(a, b) \
37 (((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
41 * Stuff from primnodes.h
45 _equalResdom(Resdom *a, Resdom *b)
47 if (a->resno != b->resno)
49 if (a->restype != b->restype)
51 if (a->restypmod != b->restypmod)
53 if (!equalstr(a->resname, b->resname))
55 if (a->ressortgroupref != b->ressortgroupref)
57 if (a->reskey != b->reskey)
59 if (a->reskeyop != b->reskeyop)
61 /* we ignore resjunk flag ... is this correct? */
67 _equalFjoin(Fjoin *a, Fjoin *b)
71 if (a->fj_initialized != b->fj_initialized)
73 if (a->fj_nNodes != b->fj_nNodes)
75 if (!equal(a->fj_innerNode, b->fj_innerNode))
78 nNodes = a->fj_nNodes;
79 if (memcmp(a->fj_results, b->fj_results, nNodes * sizeof(Datum)) != 0)
81 if (memcmp(a->fj_alwaysDone, b->fj_alwaysDone, nNodes * sizeof(bool)) != 0)
88 _equalExpr(Expr *a, Expr *b)
91 * We do not examine typeOid, since the optimizer often doesn't bother
92 * to set it in created nodes, and it is logically a derivative of the
95 if (a->opType != b->opType)
97 if (!equal(a->oper, b->oper))
99 if (!equal(a->args, b->args))
106 _equalVar(Var *a, Var *b)
108 if (a->varno != b->varno)
110 if (a->varattno != b->varattno)
112 if (a->vartype != b->vartype)
114 if (a->vartypmod != b->vartypmod)
116 if (a->varlevelsup != b->varlevelsup)
118 if (a->varnoold != b->varnoold)
120 if (a->varoattno != b->varoattno)
127 _equalOper(Oper *a, Oper *b)
129 if (a->opno != b->opno)
131 if (a->opresulttype != b->opresulttype)
135 * We do not examine opid or op_fcache, since these are logically
136 * derived from opno, and they may not be set yet depending on how far
137 * along the node is in the parse/plan pipeline.
139 * (Besides, op_fcache is executor state, which we don't check --- see
140 * notes at head of file.)
142 * It's probably not really necessary to check opresulttype either...
149 _equalConst(Const *a, Const *b)
151 if (a->consttype != b->consttype)
153 if (a->constlen != b->constlen)
155 if (a->constisnull != b->constisnull)
157 if (a->constbyval != b->constbyval)
159 /* XXX What about constisset and constiscast? */
162 * We treat all NULL constants of the same type as equal. Someday this
163 * might need to change? But datumIsEqual doesn't work on nulls,
168 return datumIsEqual(a->constvalue, b->constvalue,
169 a->constbyval, a->constlen);
173 _equalParam(Param *a, Param *b)
175 if (a->paramkind != b->paramkind)
177 if (a->paramtype != b->paramtype)
180 switch (a->paramkind)
185 if (strcmp(a->paramname, b->paramname) != 0)
190 if (a->paramid != b->paramid)
196 * XXX: Hmmm... What are we supposed to return in this case ??
201 elog(ERROR, "_equalParam: Invalid paramkind value: %d",
209 _equalFunc(Func *a, Func *b)
211 if (a->funcid != b->funcid)
213 if (a->functype != b->functype)
215 /* Note we do not look at func_fcache; see notes for _equalOper */
221 _equalAggref(Aggref *a, Aggref *b)
223 if (a->aggfnoid != b->aggfnoid)
225 if (a->aggtype != b->aggtype)
227 if (!equal(a->target, b->target))
229 if (a->aggstar != b->aggstar)
231 if (a->aggdistinct != b->aggdistinct)
233 /* ignore aggno, which is only a private field for the executor */
238 _equalSubLink(SubLink *a, SubLink *b)
240 if (a->subLinkType != b->subLinkType)
242 if (a->useor != b->useor)
244 if (!equal(a->lefthand, b->lefthand))
246 if (!equal(a->oper, b->oper))
248 if (!equal(a->subselect, b->subselect))
254 _equalArrayRef(ArrayRef *a, ArrayRef *b)
256 if (a->refelemtype != b->refelemtype)
258 if (a->refattrlength != b->refattrlength)
260 if (a->refelemlength != b->refelemlength)
262 if (a->refelembyval != b->refelembyval)
264 if (!equal(a->refupperindexpr, b->refupperindexpr))
266 if (!equal(a->reflowerindexpr, b->reflowerindexpr))
268 if (!equal(a->refexpr, b->refexpr))
270 return equal(a->refassgnexpr, b->refassgnexpr);
274 _equalFieldSelect(FieldSelect *a, FieldSelect *b)
276 if (!equal(a->arg, b->arg))
278 if (a->fieldnum != b->fieldnum)
280 if (a->resulttype != b->resulttype)
282 if (a->resulttypmod != b->resulttypmod)
288 _equalRelabelType(RelabelType *a, RelabelType *b)
290 if (!equal(a->arg, b->arg))
292 if (a->resulttype != b->resulttype)
294 if (a->resulttypmod != b->resulttypmod)
300 _equalRangeTblRef(RangeTblRef *a, RangeTblRef *b)
302 if (a->rtindex != b->rtindex)
309 _equalFromExpr(FromExpr *a, FromExpr *b)
311 if (!equal(a->fromlist, b->fromlist))
313 if (!equal(a->quals, b->quals))
320 _equalJoinExpr(JoinExpr *a, JoinExpr *b)
322 if (a->jointype != b->jointype)
324 if (a->isNatural != b->isNatural)
326 if (!equal(a->larg, b->larg))
328 if (!equal(a->rarg, b->rarg))
330 if (!equal(a->using, b->using))
332 if (!equal(a->quals, b->quals))
334 if (!equal(a->alias, b->alias))
336 if (a->rtindex != b->rtindex)
343 * Stuff from relation.h
347 _equalRelOptInfo(RelOptInfo *a, RelOptInfo *b)
350 * We treat RelOptInfos as equal if they refer to the same base rels
351 * joined in the same order. Is this appropriate/sufficient?
353 return equali(a->relids, b->relids);
357 _equalIndexOptInfo(IndexOptInfo *a, IndexOptInfo *b)
360 * We treat IndexOptInfos as equal if they refer to the same index. Is
363 if (a->indexoid != b->indexoid)
369 _equalPathKeyItem(PathKeyItem *a, PathKeyItem *b)
371 if (a->sortop != b->sortop)
373 if (!equal(a->key, b->key))
379 _equalPath(Path *a, Path *b)
381 if (a->pathtype != b->pathtype)
383 if (!equal(a->parent, b->parent))
387 * do not check path costs, since they may not be set yet, and being
388 * float values there are roundoff error issues anyway...
390 if (!equal(a->pathkeys, b->pathkeys))
396 _equalIndexPath(IndexPath *a, IndexPath *b)
398 if (!_equalPath((Path *) a, (Path *) b))
400 if (!equal(a->indexinfo, b->indexinfo))
402 if (!equal(a->indexqual, b->indexqual))
404 if (a->indexscandir != b->indexscandir)
406 if (!equali(a->joinrelids, b->joinrelids))
408 if (a->alljoinquals != b->alljoinquals)
412 * Skip 'rows' because of possibility of floating-point roundoff
413 * error. It should be derivable from the other fields anyway.
419 _equalTidPath(TidPath *a, TidPath *b)
421 if (!_equalPath((Path *) a, (Path *) b))
423 if (!equal(a->tideval, b->tideval))
425 if (!equali(a->unjoined_relids, b->unjoined_relids))
431 _equalAppendPath(AppendPath *a, AppendPath *b)
433 if (!_equalPath((Path *) a, (Path *) b))
435 if (!equal(a->subpaths, b->subpaths))
441 _equalJoinPath(JoinPath *a, JoinPath *b)
443 if (!_equalPath((Path *) a, (Path *) b))
445 if (a->jointype != b->jointype)
447 if (!equal(a->outerjoinpath, b->outerjoinpath))
449 if (!equal(a->innerjoinpath, b->innerjoinpath))
451 if (!equal(a->joinrestrictinfo, b->joinrestrictinfo))
457 _equalNestPath(NestPath *a, NestPath *b)
459 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
465 _equalMergePath(MergePath *a, MergePath *b)
467 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
469 if (!equal(a->path_mergeclauses, b->path_mergeclauses))
471 if (!equal(a->outersortkeys, b->outersortkeys))
473 if (!equal(a->innersortkeys, b->innersortkeys))
479 _equalHashPath(HashPath *a, HashPath *b)
481 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
483 if (!equal(a->path_hashclauses, b->path_hashclauses))
489 _equalSubPlan(SubPlan *a, SubPlan *b)
491 /* should compare plans, but have to settle for comparing plan IDs */
492 if (a->plan_id != b->plan_id)
495 if (!equal(a->rtable, b->rtable))
498 if (!equal(a->sublink, b->sublink))
505 _equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
507 if (!equal(a->clause, b->clause))
509 if (a->ispusheddown != b->ispusheddown)
513 * We ignore eval_cost, this_selec, left/right_pathkey, and
514 * left/right_bucketsize, since they may not be set yet, and should be
515 * derivable from the clause anyway. Probably it's not really
516 * necessary to compare any of these remaining fields ...
518 if (!equal(a->subclauseindices, b->subclauseindices))
520 if (a->mergejoinoperator != b->mergejoinoperator)
522 if (a->left_sortop != b->left_sortop)
524 if (a->right_sortop != b->right_sortop)
526 if (a->hashjoinoperator != b->hashjoinoperator)
532 _equalJoinInfo(JoinInfo *a, JoinInfo *b)
534 if (!equali(a->unjoined_relids, b->unjoined_relids))
536 if (!equal(a->jinfo_restrictinfo, b->jinfo_restrictinfo))
542 _equalIter(Iter *a, Iter *b)
544 return equal(a->iterexpr, b->iterexpr);
548 _equalStream(Stream *a, Stream *b)
550 if (a->clausetype != b->clausetype)
552 if (a->groupup != b->groupup)
554 if (a->groupcost != b->groupcost)
556 if (a->groupsel != b->groupsel)
558 if (!equal(a->pathptr, b->pathptr))
560 if (!equal(a->cinfo, b->cinfo))
562 if (!equal(a->upstream, b->upstream))
564 return equal(a->downstream, b->downstream);
568 * Stuff from parsenodes.h
572 _equalQuery(Query *a, Query *b)
574 if (a->commandType != b->commandType)
576 if (!equal(a->utilityStmt, b->utilityStmt))
578 if (a->resultRelation != b->resultRelation)
580 if (!equal(a->into, b->into))
582 if (a->isPortal != b->isPortal)
584 if (a->isBinary != b->isBinary)
586 if (a->hasAggs != b->hasAggs)
588 if (a->hasSubLinks != b->hasSubLinks)
590 /* we deliberately ignore originalQuery */
591 if (!equal(a->rtable, b->rtable))
593 if (!equal(a->jointree, b->jointree))
595 if (!equali(a->rowMarks, b->rowMarks))
597 if (!equal(a->targetList, b->targetList))
599 if (!equal(a->groupClause, b->groupClause))
601 if (!equal(a->havingQual, b->havingQual))
603 if (!equal(a->distinctClause, b->distinctClause))
605 if (!equal(a->sortClause, b->sortClause))
607 if (!equal(a->limitOffset, b->limitOffset))
609 if (!equal(a->limitCount, b->limitCount))
611 if (!equal(a->setOperations, b->setOperations))
613 if (!equali(a->resultRelations, b->resultRelations))
617 * We do not check the internal-to-the-planner fields: base_rel_list,
618 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. They
619 * might not be set yet, and in any case they should be derivable from
626 _equalInsertStmt(InsertStmt *a, InsertStmt *b)
628 if (!equal(a->relation, b->relation))
630 if (!equal(a->cols, b->cols))
632 if (!equal(a->targetList, b->targetList))
634 if (!equal(a->selectStmt, b->selectStmt))
641 _equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
643 if (!equal(a->relation, b->relation))
645 if (!equal(a->whereClause, b->whereClause))
652 _equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
654 if (!equal(a->relation, b->relation))
656 if (!equal(a->targetList, b->targetList))
658 if (!equal(a->whereClause, b->whereClause))
660 if (!equal(a->fromClause, b->fromClause))
667 _equalSelectStmt(SelectStmt *a, SelectStmt *b)
669 if (!equal(a->distinctClause, b->distinctClause))
671 if (!equal(a->into, b->into))
673 if (!equal(a->intoColNames, b->intoColNames))
675 if (!equal(a->targetList, b->targetList))
677 if (!equal(a->fromClause, b->fromClause))
679 if (!equal(a->whereClause, b->whereClause))
681 if (!equal(a->groupClause, b->groupClause))
683 if (!equal(a->havingClause, b->havingClause))
685 if (!equal(a->sortClause, b->sortClause))
687 if (!equalstr(a->portalname, b->portalname))
689 if (a->binary != b->binary)
691 if (!equal(a->limitOffset, b->limitOffset))
693 if (!equal(a->limitCount, b->limitCount))
695 if (!equal(a->forUpdate, b->forUpdate))
699 if (a->all != b->all)
701 if (!equal(a->larg, b->larg))
703 if (!equal(a->rarg, b->rarg))
710 _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
714 if (a->all != b->all)
716 if (!equal(a->larg, b->larg))
718 if (!equal(a->rarg, b->rarg))
720 if (!equali(a->colTypes, b->colTypes))
727 _equalAlterTableStmt(AlterTableStmt *a, AlterTableStmt *b)
729 if (a->subtype != b->subtype)
731 if (!equal(a->relation, b->relation))
733 if (!equalstr(a->name, b->name))
735 if (!equal(a->def, b->def))
737 if (a->behavior != b->behavior)
744 _equalGrantStmt(GrantStmt *a, GrantStmt *b)
746 if (a->is_grant != b->is_grant)
748 if (a->objtype != b->objtype)
750 if (!equal(a->objects, b->objects))
752 if (!equali(a->privileges, b->privileges))
754 if (!equal(a->grantees, b->grantees))
761 _equalPrivGrantee(PrivGrantee *a, PrivGrantee *b)
763 return equalstr(a->username, b->username)
764 && equalstr(a->groupname, b->groupname);
768 _equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
770 return equal(a->funcname, b->funcname)
771 && equal(a->funcargs, b->funcargs);
775 _equalInsertDefault(InsertDefault *a, InsertDefault *b)
781 _equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
783 if (!equalstr(a->portalname, b->portalname))
790 _equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
792 if (!equal(a->relation, b->relation))
794 if (!equalstr(a->indexname, b->indexname))
801 _equalCopyStmt(CopyStmt *a, CopyStmt *b)
803 if (a->binary != b->binary)
805 if (!equal(a->relation, b->relation))
807 if (a->oids != b->oids)
809 if (a->direction != b->direction)
811 if (!equalstr(a->filename, b->filename))
813 if (!equalstr(a->delimiter, b->delimiter))
815 if (!equalstr(a->null_print, b->null_print))
822 _equalCreateStmt(CreateStmt *a, CreateStmt *b)
824 if (!equal(a->relation, b->relation))
826 if (!equal(a->tableElts, b->tableElts))
828 if (!equal(a->inhRelations, b->inhRelations))
830 if (!equal(a->constraints, b->constraints))
832 if (a->hasoids != b->hasoids)
839 _equalDefineStmt(DefineStmt *a, DefineStmt *b)
841 if (a->defType != b->defType)
843 if (!equal(a->defnames, b->defnames))
845 if (!equal(a->definition, b->definition))
852 _equalDropStmt(DropStmt *a, DropStmt *b)
854 if (!equal(a->objects, b->objects))
856 if (a->removeType != b->removeType)
858 if (a->behavior != b->behavior)
865 _equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
867 if (!equal(a->relation, b->relation))
874 _equalCommentStmt(CommentStmt *a, CommentStmt *b)
876 if (a->objtype != b->objtype)
878 if (!equal(a->objname, b->objname))
880 if (!equal(a->objargs, b->objargs))
882 if (!equalstr(a->comment, b->comment))
889 _equalFetchStmt(FetchStmt *a, FetchStmt *b)
891 if (a->direction != b->direction)
893 if (a->howMany != b->howMany)
895 if (!equalstr(a->portalname, b->portalname))
897 if (a->ismove != b->ismove)
904 _equalIndexStmt(IndexStmt *a, IndexStmt *b)
906 if (!equalstr(a->idxname, b->idxname))
908 if (!equal(a->relation, b->relation))
910 if (!equalstr(a->accessMethod, b->accessMethod))
912 if (!equal(a->indexParams, b->indexParams))
914 if (!equal(a->whereClause, b->whereClause))
916 if (!equal(a->rangetable, b->rangetable))
918 if (a->unique != b->unique)
920 if (a->primary != b->primary)
927 _equalProcedureStmt(ProcedureStmt *a, ProcedureStmt *b)
929 if (a->replace != b->replace)
931 if (!equal(a->funcname, b->funcname))
933 if (!equal(a->argTypes, b->argTypes))
935 if (!equal(a->returnType, b->returnType))
937 if (!equal(a->withClause, b->withClause))
939 if (!equal(a->as, b->as))
941 if (!equalstr(a->language, b->language))
948 _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
950 if (!equal(a->aggname, b->aggname))
952 if (!equal(a->aggtype, b->aggtype))
959 _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
961 if (!equal(a->funcname, b->funcname))
963 if (!equal(a->args, b->args))
970 _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
972 if (!equal(a->opname, b->opname))
974 if (!equal(a->args, b->args))
982 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
984 if (!equal(a->relation, b->relation))
986 if (!equalstr(a->oldname, b->oldname))
988 if (!equalstr(a->newname, b->newname))
990 if (a->renameType != b->renameType)
997 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
999 if (!equal(a->relation, b->relation))
1001 if (!equalstr(a->rulename, b->rulename))
1003 if (!equal(a->whereClause, b->whereClause))
1005 if (a->event != b->event)
1007 if (a->instead != b->instead)
1009 if (!equal(a->actions, b->actions))
1016 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1018 if (!equal(a->relation, b->relation))
1025 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1027 if (!equal(a->relation, b->relation))
1034 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1036 if (!equal(a->relation, b->relation))
1043 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1045 if (a->command != b->command)
1052 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1054 if (!equal(a->view, b->view))
1056 if (!equal(a->aliases, b->aliases))
1058 if (!equal(a->query, b->query))
1065 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1067 if (!equalstr(a->filename, b->filename))
1074 _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
1076 if (!equal(a->domainname, b->domainname))
1078 if (!equal(a->typename, b->typename))
1080 if (!equal(a->constraints, b->constraints))
1087 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1089 if (!equalstr(a->dbname, b->dbname))
1091 if (!equalstr(a->dbowner, b->dbowner))
1093 if (!equalstr(a->dbpath, b->dbpath))
1095 if (!equalstr(a->dbtemplate, b->dbtemplate))
1097 if (a->encoding != b->encoding)
1104 _equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
1106 if (!equalstr(a->dbname, b->dbname))
1108 if (!equalstr(a->variable, b->variable))
1110 if (!equal(a->value, b->value))
1117 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1119 if (!equalstr(a->dbname, b->dbname))
1126 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1128 if (a->vacuum != b->vacuum)
1130 if (a->full != b->full)
1132 if (a->analyze != b->analyze)
1134 if (a->freeze != b->freeze)
1136 if (a->verbose != b->verbose)
1138 if (!equal(a->relation, b->relation))
1140 if (!equal(a->va_cols, b->va_cols))
1147 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1149 if (!equal(a->query, b->query))
1151 if (a->verbose != b->verbose)
1153 if (a->analyze != b->analyze)
1160 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1162 if (!equal(a->sequence, b->sequence))
1164 if (!equal(a->options, b->options))
1171 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1173 if (!equalstr(a->name, b->name))
1175 if (!equal(a->args, b->args))
1182 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1184 if (!equalstr(a->name, b->name))
1191 _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
1193 if (!equalstr(a->name, b->name))
1200 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1202 if (!equalstr(a->trigname, b->trigname))
1204 if (!equal(a->relation, b->relation))
1206 if (!equal(a->funcname, b->funcname))
1208 if (!equal(a->args, b->args))
1210 if (a->before != b->before)
1212 if (a->row != b->row)
1214 if (strcmp(a->actions, b->actions) != 0)
1216 if (!equalstr(a->lang, b->lang))
1218 if (!equalstr(a->text, b->text))
1220 if (!equal(a->attr, b->attr))
1222 if (!equalstr(a->when, b->when))
1224 if (a->isconstraint != b->isconstraint)
1226 if (a->deferrable != b->deferrable)
1228 if (a->initdeferred != b->initdeferred)
1230 if (!equal(a->constrrel, b->constrrel))
1237 _equalDropPropertyStmt(DropPropertyStmt *a, DropPropertyStmt *b)
1239 if (!equal(a->relation, b->relation))
1241 if (!equalstr(a->property, b->property))
1243 if (a->removeType != b->removeType)
1250 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1252 if (!equalstr(a->plname, b->plname))
1254 if (!equal(a->plhandler, b->plhandler))
1256 if (!equalstr(a->plcompiler, b->plcompiler))
1258 if (a->pltrusted != b->pltrusted)
1265 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1267 if (!equalstr(a->plname, b->plname))
1274 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1276 if (!equalstr(a->user, b->user))
1278 if (!equal(a->options, b->options))
1285 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1287 if (!equalstr(a->user, b->user))
1289 if (!equal(a->options, b->options))
1296 _equalAlterUserSetStmt(AlterUserSetStmt *a, AlterUserSetStmt *b)
1298 if (!equalstr(a->user, b->user))
1300 if (!equalstr(a->variable, b->variable))
1302 if (!equal(a->value, b->value))
1309 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1311 if (!equal(a->users, b->users))
1318 _equalLockStmt(LockStmt *a, LockStmt *b)
1320 if (!equal(a->relations, b->relations))
1322 if (a->mode != b->mode)
1329 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1331 if (!equal(a->constraints, b->constraints))
1333 if (a->deferred != b->deferred)
1340 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1342 if (!equalstr(a->name, b->name))
1344 if (!equal(a->options, b->options))
1351 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1353 if (!equalstr(a->name, b->name))
1355 if (a->action != b->action)
1357 if (!equal(a->listUsers, b->listUsers))
1364 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1366 if (!equalstr(a->name, b->name))
1373 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1375 if (a->reindexType != b->reindexType)
1377 if (!equal(a->relation, b->relation))
1379 if (!equalstr(a->name, b->name))
1381 if (a->force != b->force)
1383 if (a->all != b->all)
1390 _equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
1392 if (!equalstr(a->schemaname, b->schemaname))
1394 if (!equalstr(a->authid, b->authid))
1396 if (!equal(a->schemaElts, b->schemaElts))
1403 _equalAExpr(A_Expr *a, A_Expr *b)
1405 if (a->oper != b->oper)
1407 if (!equal(a->name, b->name))
1409 if (!equal(a->lexpr, b->lexpr))
1411 if (!equal(a->rexpr, b->rexpr))
1418 _equalColumnRef(ColumnRef *a, ColumnRef *b)
1420 if (!equal(a->fields, b->fields))
1422 if (!equal(a->indirection, b->indirection))
1429 _equalParamRef(ParamRef *a, ParamRef *b)
1431 if (a->number != b->number)
1433 if (!equal(a->fields, b->fields))
1435 if (!equal(a->indirection, b->indirection))
1442 _equalAConst(A_Const *a, A_Const *b)
1444 if (!equal(&a->val, &b->val))
1446 if (!equal(a->typename, b->typename))
1453 _equalIdent(Ident *a, Ident *b)
1455 if (!equalstr(a->name, b->name))
1462 _equalFuncCall(FuncCall *a, FuncCall *b)
1464 if (!equal(a->funcname, b->funcname))
1466 if (!equal(a->args, b->args))
1468 if (a->agg_star != b->agg_star)
1470 if (a->agg_distinct != b->agg_distinct)
1477 _equalAIndices(A_Indices *a, A_Indices *b)
1479 if (!equal(a->lidx, b->lidx))
1481 if (!equal(a->uidx, b->uidx))
1488 _equalExprFieldSelect(ExprFieldSelect *a, ExprFieldSelect *b)
1490 if (!equal(a->arg, b->arg))
1492 if (!equal(a->fields, b->fields))
1494 if (!equal(a->indirection, b->indirection))
1501 _equalResTarget(ResTarget *a, ResTarget *b)
1503 if (!equalstr(a->name, b->name))
1505 if (!equal(a->indirection, b->indirection))
1507 if (!equal(a->val, b->val))
1514 _equalTypeCast(TypeCast *a, TypeCast *b)
1516 if (!equal(a->arg, b->arg))
1518 if (!equal(a->typename, b->typename))
1525 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1527 if (!equal(a->useOp, b->useOp))
1529 if (!equal(a->node, b->node))
1536 _equalAlias(Alias *a, Alias *b)
1538 if (!equalstr(a->aliasname, b->aliasname))
1540 if (!equal(a->colnames, b->colnames))
1547 _equalRangeVar(RangeVar *a, RangeVar *b)
1549 if (!equalstr(a->catalogname, b->catalogname))
1551 if (!equalstr(a->schemaname, b->schemaname))
1553 if (!equalstr(a->relname, b->relname))
1555 if (a->inhOpt != b->inhOpt)
1557 if (a->istemp != b->istemp)
1559 if (!equal(a->alias, b->alias))
1566 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1568 if (!equal(a->subquery, b->subquery))
1570 if (!equal(a->alias, b->alias))
1577 _equalTypeName(TypeName *a, TypeName *b)
1579 if (!equal(a->names, b->names))
1581 if (a->typeid != b->typeid)
1583 if (a->timezone != b->timezone)
1585 if (a->setof != b->setof)
1587 if (a->pct_type != b->pct_type)
1589 if (a->typmod != b->typmod)
1591 if (!equal(a->arrayBounds, b->arrayBounds))
1598 _equalIndexElem(IndexElem *a, IndexElem *b)
1600 if (!equalstr(a->name, b->name))
1602 if (!equal(a->funcname, b->funcname))
1604 if (!equal(a->args, b->args))
1606 if (!equal(a->opclass, b->opclass))
1613 _equalColumnDef(ColumnDef *a, ColumnDef *b)
1615 if (!equalstr(a->colname, b->colname))
1617 if (!equal(a->typename, b->typename))
1619 if (a->is_not_null != b->is_not_null)
1621 if (!equal(a->raw_default, b->raw_default))
1623 if (!equalstr(a->cooked_default, b->cooked_default))
1625 if (!equal(a->constraints, b->constraints))
1632 _equalConstraint(Constraint *a, Constraint *b)
1634 if (a->contype != b->contype)
1636 if (!equalstr(a->name, b->name))
1638 if (!equal(a->raw_expr, b->raw_expr))
1640 if (!equalstr(a->cooked_expr, b->cooked_expr))
1642 if (!equal(a->keys, b->keys))
1649 _equalDefElem(DefElem *a, DefElem *b)
1651 if (!equalstr(a->defname, b->defname))
1653 if (!equal(a->arg, b->arg))
1660 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
1662 if (!equal(a->resdom, b->resdom))
1664 if (!equal(a->fjoin, b->fjoin))
1666 if (!equal(a->expr, b->expr))
1673 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
1675 if (a->rtekind != b->rtekind)
1677 if (a->relid != b->relid)
1679 if (!equal(a->subquery, b->subquery))
1681 if (a->jointype != b->jointype)
1683 if (!equali(a->joincoltypes, b->joincoltypes))
1685 if (!equali(a->joincoltypmods, b->joincoltypmods))
1687 if (!equali(a->joinleftcols, b->joinleftcols))
1689 if (!equali(a->joinrightcols, b->joinrightcols))
1691 if (!equal(a->alias, b->alias))
1693 if (!equal(a->eref, b->eref))
1695 if (a->inh != b->inh)
1697 if (a->inFromCl != b->inFromCl)
1699 if (a->checkForRead != b->checkForRead)
1701 if (a->checkForWrite != b->checkForWrite)
1703 if (a->checkAsUser != b->checkAsUser)
1710 _equalSortClause(SortClause *a, SortClause *b)
1712 if (a->tleSortGroupRef != b->tleSortGroupRef)
1714 if (a->sortop != b->sortop)
1721 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
1723 if (!equalstr(a->constr_name, b->constr_name))
1725 if (!equal(a->pktable, b->pktable))
1727 if (!equal(a->fk_attrs, b->fk_attrs))
1729 if (!equal(a->pk_attrs, b->pk_attrs))
1731 if (!equalstr(a->match_type, b->match_type))
1733 if (a->actions != b->actions)
1735 if (a->deferrable != b->deferrable)
1737 if (a->initdeferred != b->initdeferred)
1744 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
1746 if (a->casetype != b->casetype)
1748 if (!equal(a->arg, b->arg))
1750 if (!equal(a->args, b->args))
1752 if (!equal(a->defresult, b->defresult))
1759 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
1761 if (!equal(a->expr, b->expr))
1763 if (!equal(a->result, b->result))
1770 _equalNullTest(NullTest *a, NullTest *b)
1772 if (!equal(a->arg, b->arg))
1774 if (a->nulltesttype != b->nulltesttype)
1780 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
1782 if (!equal(a->arg, b->arg))
1784 if (a->booltesttype != b->booltesttype)
1790 * Stuff from pg_list.h
1794 _equalValue(Value *a, Value *b)
1796 if (a->type != b->type)
1802 return a->val.ival == b->val.ival;
1806 return strcmp(a->val.str, b->val.str) == 0;
1816 * returns whether two nodes are equal
1819 equal(void *a, void *b)
1821 bool retval = false;
1827 * note that a!=b, so only one of them can be NULL
1829 if (a == NULL || b == NULL)
1833 * are they the same type of nodes?
1835 if (nodeTag(a) != nodeTag(b))
1841 retval = _equalSubPlan(a, b);
1845 retval = _equalResdom(a, b);
1848 retval = _equalFjoin(a, b);
1851 retval = _equalExpr(a, b);
1854 retval = _equalVar(a, b);
1857 retval = _equalOper(a, b);
1860 retval = _equalConst(a, b);
1863 retval = _equalParam(a, b);
1866 retval = _equalAggref(a, b);
1869 retval = _equalSubLink(a, b);
1872 retval = _equalFunc(a, b);
1875 retval = _equalFieldSelect(a, b);
1878 retval = _equalArrayRef(a, b);
1881 retval = _equalIter(a, b);
1884 retval = _equalRelabelType(a, b);
1887 retval = _equalRangeTblRef(a, b);
1890 retval = _equalFromExpr(a, b);
1893 retval = _equalJoinExpr(a, b);
1897 retval = _equalRelOptInfo(a, b);
1900 retval = _equalPath(a, b);
1903 retval = _equalIndexPath(a, b);
1906 retval = _equalNestPath(a, b);
1909 retval = _equalMergePath(a, b);
1912 retval = _equalHashPath(a, b);
1915 retval = _equalPathKeyItem(a, b);
1917 case T_RestrictInfo:
1918 retval = _equalRestrictInfo(a, b);
1921 retval = _equalJoinInfo(a, b);
1924 retval = _equalStream(a, b);
1927 retval = _equalTidPath(a, b);
1930 retval = _equalAppendPath(a, b);
1932 case T_IndexOptInfo:
1933 retval = _equalIndexOptInfo(a, b);
1938 List *la = (List *) a;
1939 List *lb = (List *) b;
1943 * Try to reject by length check before we grovel through
1944 * all the elements...
1946 if (length(la) != length(lb))
1950 if (!equal(lfirst(l), lfirst(lb)))
1961 retval = _equalValue(a, b);
1965 retval = _equalQuery(a, b);
1968 retval = _equalInsertStmt(a, b);
1971 retval = _equalDeleteStmt(a, b);
1974 retval = _equalUpdateStmt(a, b);
1977 retval = _equalSelectStmt(a, b);
1979 case T_SetOperationStmt:
1980 retval = _equalSetOperationStmt(a, b);
1982 case T_AlterTableStmt:
1983 retval = _equalAlterTableStmt(a, b);
1986 retval = _equalGrantStmt(a, b);
1988 case T_ClosePortalStmt:
1989 retval = _equalClosePortalStmt(a, b);
1992 retval = _equalClusterStmt(a, b);
1995 retval = _equalCopyStmt(a, b);
1998 retval = _equalCreateStmt(a, b);
2001 retval = _equalDefineStmt(a, b);
2004 retval = _equalDropStmt(a, b);
2006 case T_TruncateStmt:
2007 retval = _equalTruncateStmt(a, b);
2010 retval = _equalCommentStmt(a, b);
2013 retval = _equalFetchStmt(a, b);
2016 retval = _equalIndexStmt(a, b);
2018 case T_ProcedureStmt:
2019 retval = _equalProcedureStmt(a, b);
2021 case T_RemoveAggrStmt:
2022 retval = _equalRemoveAggrStmt(a, b);
2024 case T_RemoveFuncStmt:
2025 retval = _equalRemoveFuncStmt(a, b);
2027 case T_RemoveOperStmt:
2028 retval = _equalRemoveOperStmt(a, b);
2031 retval = _equalRenameStmt(a, b);
2034 retval = _equalRuleStmt(a, b);
2037 retval = _equalNotifyStmt(a, b);
2040 retval = _equalListenStmt(a, b);
2042 case T_UnlistenStmt:
2043 retval = _equalUnlistenStmt(a, b);
2045 case T_TransactionStmt:
2046 retval = _equalTransactionStmt(a, b);
2049 retval = _equalViewStmt(a, b);
2052 retval = _equalLoadStmt(a, b);
2054 case T_CreateDomainStmt:
2055 retval = _equalCreateDomainStmt(a, b);
2057 case T_CreatedbStmt:
2058 retval = _equalCreatedbStmt(a, b);
2060 case T_AlterDatabaseSetStmt:
2061 retval = _equalAlterDatabaseSetStmt(a, b);
2064 retval = _equalDropdbStmt(a, b);
2067 retval = _equalVacuumStmt(a, b);
2070 retval = _equalExplainStmt(a, b);
2072 case T_CreateSeqStmt:
2073 retval = _equalCreateSeqStmt(a, b);
2075 case T_VariableSetStmt:
2076 retval = _equalVariableSetStmt(a, b);
2078 case T_VariableShowStmt:
2079 retval = _equalVariableShowStmt(a, b);
2081 case T_VariableResetStmt:
2082 retval = _equalVariableResetStmt(a, b);
2084 case T_CreateTrigStmt:
2085 retval = _equalCreateTrigStmt(a, b);
2087 case T_DropPropertyStmt:
2088 retval = _equalDropPropertyStmt(a, b);
2090 case T_CreatePLangStmt:
2091 retval = _equalCreatePLangStmt(a, b);
2093 case T_DropPLangStmt:
2094 retval = _equalDropPLangStmt(a, b);
2096 case T_CreateUserStmt:
2097 retval = _equalCreateUserStmt(a, b);
2099 case T_AlterUserStmt:
2100 retval = _equalAlterUserStmt(a, b);
2102 case T_AlterUserSetStmt:
2103 retval = _equalAlterUserSetStmt(a, b);
2105 case T_DropUserStmt:
2106 retval = _equalDropUserStmt(a, b);
2109 retval = _equalLockStmt(a, b);
2111 case T_ConstraintsSetStmt:
2112 retval = _equalConstraintsSetStmt(a, b);
2114 case T_CreateGroupStmt:
2115 retval = _equalCreateGroupStmt(a, b);
2117 case T_AlterGroupStmt:
2118 retval = _equalAlterGroupStmt(a, b);
2120 case T_DropGroupStmt:
2121 retval = _equalDropGroupStmt(a, b);
2124 retval = _equalReindexStmt(a, b);
2126 case T_CheckPointStmt:
2129 case T_CreateSchemaStmt:
2130 retval = _equalCreateSchemaStmt(a, b);
2134 retval = _equalAExpr(a, b);
2137 retval = _equalColumnRef(a, b);
2140 retval = _equalParamRef(a, b);
2143 retval = _equalAConst(a, b);
2146 retval = _equalIdent(a, b);
2149 retval = _equalFuncCall(a, b);
2152 retval = _equalAIndices(a, b);
2154 case T_ExprFieldSelect:
2155 retval = _equalExprFieldSelect(a, b);
2158 retval = _equalResTarget(a, b);
2161 retval = _equalTypeCast(a, b);
2164 retval = _equalSortGroupBy(a, b);
2167 retval = _equalAlias(a, b);
2170 retval = _equalRangeVar(a, b);
2172 case T_RangeSubselect:
2173 retval = _equalRangeSubselect(a, b);
2176 retval = _equalTypeName(a, b);
2179 retval = _equalIndexElem(a, b);
2182 retval = _equalColumnDef(a, b);
2185 retval = _equalConstraint(a, b);
2188 retval = _equalDefElem(a, b);
2191 retval = _equalTargetEntry(a, b);
2193 case T_RangeTblEntry:
2194 retval = _equalRangeTblEntry(a, b);
2197 retval = _equalSortClause(a, b);
2200 /* GroupClause is equivalent to SortClause */
2201 retval = _equalSortClause(a, b);
2204 retval = _equalCaseExpr(a, b);
2207 retval = _equalCaseWhen(a, b);
2210 retval = _equalNullTest(a, b);
2213 retval = _equalBooleanTest(a, b);
2215 case T_FkConstraint:
2216 retval = _equalFkConstraint(a, b);
2219 retval = _equalPrivGrantee(a, b);
2221 case T_FuncWithArgs:
2222 retval = _equalFuncWithArgs(a, b);
2224 case T_InsertDefault:
2225 retval = _equalInsertDefault(a, b);
2229 elog(WARNING, "equal: don't know whether nodes of type %d are equal",