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.126 2002/04/16 23:08:10 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)
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->column, b->column))
988 if (!equalstr(a->newname, b->newname))
995 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
997 if (!equal(a->relation, b->relation))
999 if (!equalstr(a->rulename, b->rulename))
1001 if (!equal(a->whereClause, b->whereClause))
1003 if (a->event != b->event)
1005 if (a->instead != b->instead)
1007 if (!equal(a->actions, b->actions))
1014 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1016 if (!equal(a->relation, b->relation))
1023 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1025 if (!equal(a->relation, b->relation))
1032 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1034 if (!equal(a->relation, b->relation))
1041 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1043 if (a->command != b->command)
1050 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1052 if (!equal(a->view, b->view))
1054 if (!equal(a->aliases, b->aliases))
1056 if (!equal(a->query, b->query))
1063 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1065 if (!equalstr(a->filename, b->filename))
1072 _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
1074 if (!equal(a->domainname, b->domainname))
1076 if (!equal(a->typename, b->typename))
1078 if (!equal(a->constraints, b->constraints))
1085 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1087 if (!equalstr(a->dbname, b->dbname))
1089 if (!equalstr(a->dbowner, b->dbowner))
1091 if (!equalstr(a->dbpath, b->dbpath))
1093 if (!equalstr(a->dbtemplate, b->dbtemplate))
1095 if (a->encoding != b->encoding)
1102 _equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
1104 if (!equalstr(a->dbname, b->dbname))
1106 if (!equalstr(a->variable, b->variable))
1108 if (!equal(a->value, b->value))
1115 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1117 if (!equalstr(a->dbname, b->dbname))
1124 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1126 if (a->vacuum != b->vacuum)
1128 if (a->full != b->full)
1130 if (a->analyze != b->analyze)
1132 if (a->freeze != b->freeze)
1134 if (a->verbose != b->verbose)
1136 if (!equal(a->relation, b->relation))
1138 if (!equal(a->va_cols, b->va_cols))
1145 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1147 if (!equal(a->query, b->query))
1149 if (a->verbose != b->verbose)
1151 if (a->analyze != b->analyze)
1158 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1160 if (!equal(a->sequence, b->sequence))
1162 if (!equal(a->options, b->options))
1169 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1171 if (!equalstr(a->name, b->name))
1173 if (!equal(a->args, b->args))
1180 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1182 if (!equalstr(a->name, b->name))
1189 _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
1191 if (!equalstr(a->name, b->name))
1198 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1200 if (!equalstr(a->trigname, b->trigname))
1202 if (!equal(a->relation, b->relation))
1204 if (!equal(a->funcname, b->funcname))
1206 if (!equal(a->args, b->args))
1208 if (a->before != b->before)
1210 if (a->row != b->row)
1212 if (strcmp(a->actions, b->actions) != 0)
1214 if (!equalstr(a->lang, b->lang))
1216 if (!equalstr(a->text, b->text))
1218 if (!equal(a->attr, b->attr))
1220 if (!equalstr(a->when, b->when))
1222 if (a->isconstraint != b->isconstraint)
1224 if (a->deferrable != b->deferrable)
1226 if (a->initdeferred != b->initdeferred)
1228 if (!equal(a->constrrel, b->constrrel))
1235 _equalDropTrigStmt(DropTrigStmt *a, DropTrigStmt *b)
1237 if (!equalstr(a->trigname, b->trigname))
1239 if (!equal(a->relation, b->relation))
1246 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1248 if (!equalstr(a->plname, b->plname))
1250 if (!equal(a->plhandler, b->plhandler))
1252 if (!equalstr(a->plcompiler, b->plcompiler))
1254 if (a->pltrusted != b->pltrusted)
1261 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1263 if (!equalstr(a->plname, b->plname))
1270 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1272 if (!equalstr(a->user, b->user))
1274 if (!equal(a->options, b->options))
1281 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1283 if (!equalstr(a->user, b->user))
1285 if (!equal(a->options, b->options))
1292 _equalAlterUserSetStmt(AlterUserSetStmt *a, AlterUserSetStmt *b)
1294 if (!equalstr(a->user, b->user))
1296 if (!equalstr(a->variable, b->variable))
1298 if (!equal(a->value, b->value))
1305 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1307 if (!equal(a->users, b->users))
1314 _equalLockStmt(LockStmt *a, LockStmt *b)
1316 if (!equal(a->relations, b->relations))
1318 if (a->mode != b->mode)
1325 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1327 if (!equal(a->constraints, b->constraints))
1329 if (a->deferred != b->deferred)
1336 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1338 if (!equalstr(a->name, b->name))
1340 if (!equal(a->options, b->options))
1347 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1349 if (!equalstr(a->name, b->name))
1351 if (a->action != b->action)
1353 if (!equal(a->listUsers, b->listUsers))
1360 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1362 if (!equalstr(a->name, b->name))
1369 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1371 if (a->reindexType != b->reindexType)
1373 if (!equal(a->relation, b->relation))
1375 if (!equalstr(a->name, b->name))
1377 if (a->force != b->force)
1379 if (a->all != b->all)
1386 _equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
1388 if (!equalstr(a->schemaname, b->schemaname))
1390 if (!equalstr(a->authid, b->authid))
1392 if (!equal(a->schemaElts, b->schemaElts))
1399 _equalAExpr(A_Expr *a, A_Expr *b)
1401 if (a->oper != b->oper)
1403 if (!equal(a->name, b->name))
1405 if (!equal(a->lexpr, b->lexpr))
1407 if (!equal(a->rexpr, b->rexpr))
1414 _equalColumnRef(ColumnRef *a, ColumnRef *b)
1416 if (!equal(a->fields, b->fields))
1418 if (!equal(a->indirection, b->indirection))
1425 _equalParamRef(ParamRef *a, ParamRef *b)
1427 if (a->number != b->number)
1429 if (!equal(a->fields, b->fields))
1431 if (!equal(a->indirection, b->indirection))
1438 _equalAConst(A_Const *a, A_Const *b)
1440 if (!equal(&a->val, &b->val))
1442 if (!equal(a->typename, b->typename))
1449 _equalIdent(Ident *a, Ident *b)
1451 if (!equalstr(a->name, b->name))
1458 _equalFuncCall(FuncCall *a, FuncCall *b)
1460 if (!equal(a->funcname, b->funcname))
1462 if (!equal(a->args, b->args))
1464 if (a->agg_star != b->agg_star)
1466 if (a->agg_distinct != b->agg_distinct)
1473 _equalAIndices(A_Indices *a, A_Indices *b)
1475 if (!equal(a->lidx, b->lidx))
1477 if (!equal(a->uidx, b->uidx))
1484 _equalExprFieldSelect(ExprFieldSelect *a, ExprFieldSelect *b)
1486 if (!equal(a->arg, b->arg))
1488 if (!equal(a->fields, b->fields))
1490 if (!equal(a->indirection, b->indirection))
1497 _equalResTarget(ResTarget *a, ResTarget *b)
1499 if (!equalstr(a->name, b->name))
1501 if (!equal(a->indirection, b->indirection))
1503 if (!equal(a->val, b->val))
1510 _equalTypeCast(TypeCast *a, TypeCast *b)
1512 if (!equal(a->arg, b->arg))
1514 if (!equal(a->typename, b->typename))
1521 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1523 if (!equal(a->useOp, b->useOp))
1525 if (!equal(a->node, b->node))
1532 _equalAlias(Alias *a, Alias *b)
1534 if (!equalstr(a->aliasname, b->aliasname))
1536 if (!equal(a->colnames, b->colnames))
1543 _equalRangeVar(RangeVar *a, RangeVar *b)
1545 if (!equalstr(a->catalogname, b->catalogname))
1547 if (!equalstr(a->schemaname, b->schemaname))
1549 if (!equalstr(a->relname, b->relname))
1551 if (a->inhOpt != b->inhOpt)
1553 if (a->istemp != b->istemp)
1555 if (!equal(a->alias, b->alias))
1562 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1564 if (!equal(a->subquery, b->subquery))
1566 if (!equal(a->alias, b->alias))
1573 _equalTypeName(TypeName *a, TypeName *b)
1575 if (!equal(a->names, b->names))
1577 if (a->typeid != b->typeid)
1579 if (a->timezone != b->timezone)
1581 if (a->setof != b->setof)
1583 if (a->pct_type != b->pct_type)
1585 if (a->typmod != b->typmod)
1587 if (!equal(a->arrayBounds, b->arrayBounds))
1594 _equalIndexElem(IndexElem *a, IndexElem *b)
1596 if (!equalstr(a->name, b->name))
1598 if (!equal(a->funcname, b->funcname))
1600 if (!equal(a->args, b->args))
1602 if (!equalstr(a->class, b->class))
1609 _equalColumnDef(ColumnDef *a, ColumnDef *b)
1611 if (!equalstr(a->colname, b->colname))
1613 if (!equal(a->typename, b->typename))
1615 if (a->is_not_null != b->is_not_null)
1617 if (!equal(a->raw_default, b->raw_default))
1619 if (!equalstr(a->cooked_default, b->cooked_default))
1621 if (!equal(a->constraints, b->constraints))
1628 _equalConstraint(Constraint *a, Constraint *b)
1630 if (a->contype != b->contype)
1632 if (!equalstr(a->name, b->name))
1634 if (!equal(a->raw_expr, b->raw_expr))
1636 if (!equalstr(a->cooked_expr, b->cooked_expr))
1638 if (!equal(a->keys, b->keys))
1645 _equalDefElem(DefElem *a, DefElem *b)
1647 if (!equalstr(a->defname, b->defname))
1649 if (!equal(a->arg, b->arg))
1656 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
1658 if (!equal(a->resdom, b->resdom))
1660 if (!equal(a->fjoin, b->fjoin))
1662 if (!equal(a->expr, b->expr))
1669 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
1671 if (a->rtekind != b->rtekind)
1673 if (a->relid != b->relid)
1675 if (!equal(a->subquery, b->subquery))
1677 if (a->jointype != b->jointype)
1679 if (!equali(a->joincoltypes, b->joincoltypes))
1681 if (!equali(a->joincoltypmods, b->joincoltypmods))
1683 if (!equali(a->joinleftcols, b->joinleftcols))
1685 if (!equali(a->joinrightcols, b->joinrightcols))
1687 if (!equal(a->alias, b->alias))
1689 if (!equal(a->eref, b->eref))
1691 if (a->inh != b->inh)
1693 if (a->inFromCl != b->inFromCl)
1695 if (a->checkForRead != b->checkForRead)
1697 if (a->checkForWrite != b->checkForWrite)
1699 if (a->checkAsUser != b->checkAsUser)
1706 _equalSortClause(SortClause *a, SortClause *b)
1708 if (a->tleSortGroupRef != b->tleSortGroupRef)
1710 if (a->sortop != b->sortop)
1717 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
1719 if (!equalstr(a->constr_name, b->constr_name))
1721 if (!equal(a->pktable, b->pktable))
1723 if (!equal(a->fk_attrs, b->fk_attrs))
1725 if (!equal(a->pk_attrs, b->pk_attrs))
1727 if (!equalstr(a->match_type, b->match_type))
1729 if (a->actions != b->actions)
1731 if (a->deferrable != b->deferrable)
1733 if (a->initdeferred != b->initdeferred)
1740 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
1742 if (a->casetype != b->casetype)
1744 if (!equal(a->arg, b->arg))
1746 if (!equal(a->args, b->args))
1748 if (!equal(a->defresult, b->defresult))
1755 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
1757 if (!equal(a->expr, b->expr))
1759 if (!equal(a->result, b->result))
1766 _equalNullTest(NullTest *a, NullTest *b)
1768 if (!equal(a->arg, b->arg))
1770 if (a->nulltesttype != b->nulltesttype)
1776 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
1778 if (!equal(a->arg, b->arg))
1780 if (a->booltesttype != b->booltesttype)
1786 * Stuff from pg_list.h
1790 _equalValue(Value *a, Value *b)
1792 if (a->type != b->type)
1798 return a->val.ival == b->val.ival;
1802 return strcmp(a->val.str, b->val.str) == 0;
1812 * returns whether two nodes are equal
1815 equal(void *a, void *b)
1817 bool retval = false;
1823 * note that a!=b, so only one of them can be NULL
1825 if (a == NULL || b == NULL)
1829 * are they the same type of nodes?
1831 if (nodeTag(a) != nodeTag(b))
1837 retval = _equalSubPlan(a, b);
1841 retval = _equalResdom(a, b);
1844 retval = _equalFjoin(a, b);
1847 retval = _equalExpr(a, b);
1850 retval = _equalVar(a, b);
1853 retval = _equalOper(a, b);
1856 retval = _equalConst(a, b);
1859 retval = _equalParam(a, b);
1862 retval = _equalAggref(a, b);
1865 retval = _equalSubLink(a, b);
1868 retval = _equalFunc(a, b);
1871 retval = _equalFieldSelect(a, b);
1874 retval = _equalArrayRef(a, b);
1877 retval = _equalIter(a, b);
1880 retval = _equalRelabelType(a, b);
1883 retval = _equalRangeTblRef(a, b);
1886 retval = _equalFromExpr(a, b);
1889 retval = _equalJoinExpr(a, b);
1893 retval = _equalRelOptInfo(a, b);
1896 retval = _equalPath(a, b);
1899 retval = _equalIndexPath(a, b);
1902 retval = _equalNestPath(a, b);
1905 retval = _equalMergePath(a, b);
1908 retval = _equalHashPath(a, b);
1911 retval = _equalPathKeyItem(a, b);
1913 case T_RestrictInfo:
1914 retval = _equalRestrictInfo(a, b);
1917 retval = _equalJoinInfo(a, b);
1920 retval = _equalStream(a, b);
1923 retval = _equalTidPath(a, b);
1926 retval = _equalAppendPath(a, b);
1928 case T_IndexOptInfo:
1929 retval = _equalIndexOptInfo(a, b);
1934 List *la = (List *) a;
1935 List *lb = (List *) b;
1939 * Try to reject by length check before we grovel through
1940 * all the elements...
1942 if (length(la) != length(lb))
1946 if (!equal(lfirst(l), lfirst(lb)))
1957 retval = _equalValue(a, b);
1961 retval = _equalQuery(a, b);
1964 retval = _equalInsertStmt(a, b);
1967 retval = _equalDeleteStmt(a, b);
1970 retval = _equalUpdateStmt(a, b);
1973 retval = _equalSelectStmt(a, b);
1975 case T_SetOperationStmt:
1976 retval = _equalSetOperationStmt(a, b);
1978 case T_AlterTableStmt:
1979 retval = _equalAlterTableStmt(a, b);
1982 retval = _equalGrantStmt(a, b);
1984 case T_ClosePortalStmt:
1985 retval = _equalClosePortalStmt(a, b);
1988 retval = _equalClusterStmt(a, b);
1991 retval = _equalCopyStmt(a, b);
1994 retval = _equalCreateStmt(a, b);
1997 retval = _equalDefineStmt(a, b);
2000 retval = _equalDropStmt(a, b);
2002 case T_TruncateStmt:
2003 retval = _equalTruncateStmt(a, b);
2006 retval = _equalCommentStmt(a, b);
2009 retval = _equalFetchStmt(a, b);
2012 retval = _equalIndexStmt(a, b);
2014 case T_ProcedureStmt:
2015 retval = _equalProcedureStmt(a, b);
2017 case T_RemoveAggrStmt:
2018 retval = _equalRemoveAggrStmt(a, b);
2020 case T_RemoveFuncStmt:
2021 retval = _equalRemoveFuncStmt(a, b);
2023 case T_RemoveOperStmt:
2024 retval = _equalRemoveOperStmt(a, b);
2027 retval = _equalRenameStmt(a, b);
2030 retval = _equalRuleStmt(a, b);
2033 retval = _equalNotifyStmt(a, b);
2036 retval = _equalListenStmt(a, b);
2038 case T_UnlistenStmt:
2039 retval = _equalUnlistenStmt(a, b);
2041 case T_TransactionStmt:
2042 retval = _equalTransactionStmt(a, b);
2045 retval = _equalViewStmt(a, b);
2048 retval = _equalLoadStmt(a, b);
2050 case T_CreateDomainStmt:
2051 retval = _equalCreateDomainStmt(a, b);
2053 case T_CreatedbStmt:
2054 retval = _equalCreatedbStmt(a, b);
2056 case T_AlterDatabaseSetStmt:
2057 retval = _equalAlterDatabaseSetStmt(a, b);
2060 retval = _equalDropdbStmt(a, b);
2063 retval = _equalVacuumStmt(a, b);
2066 retval = _equalExplainStmt(a, b);
2068 case T_CreateSeqStmt:
2069 retval = _equalCreateSeqStmt(a, b);
2071 case T_VariableSetStmt:
2072 retval = _equalVariableSetStmt(a, b);
2074 case T_VariableShowStmt:
2075 retval = _equalVariableShowStmt(a, b);
2077 case T_VariableResetStmt:
2078 retval = _equalVariableResetStmt(a, b);
2080 case T_CreateTrigStmt:
2081 retval = _equalCreateTrigStmt(a, b);
2083 case T_DropTrigStmt:
2084 retval = _equalDropTrigStmt(a, b);
2086 case T_CreatePLangStmt:
2087 retval = _equalCreatePLangStmt(a, b);
2089 case T_DropPLangStmt:
2090 retval = _equalDropPLangStmt(a, b);
2092 case T_CreateUserStmt:
2093 retval = _equalCreateUserStmt(a, b);
2095 case T_AlterUserStmt:
2096 retval = _equalAlterUserStmt(a, b);
2098 case T_AlterUserSetStmt:
2099 retval = _equalAlterUserSetStmt(a, b);
2101 case T_DropUserStmt:
2102 retval = _equalDropUserStmt(a, b);
2105 retval = _equalLockStmt(a, b);
2107 case T_ConstraintsSetStmt:
2108 retval = _equalConstraintsSetStmt(a, b);
2110 case T_CreateGroupStmt:
2111 retval = _equalCreateGroupStmt(a, b);
2113 case T_AlterGroupStmt:
2114 retval = _equalAlterGroupStmt(a, b);
2116 case T_DropGroupStmt:
2117 retval = _equalDropGroupStmt(a, b);
2120 retval = _equalReindexStmt(a, b);
2122 case T_CheckPointStmt:
2125 case T_CreateSchemaStmt:
2126 retval = _equalCreateSchemaStmt(a, b);
2130 retval = _equalAExpr(a, b);
2133 retval = _equalColumnRef(a, b);
2136 retval = _equalParamRef(a, b);
2139 retval = _equalAConst(a, b);
2142 retval = _equalIdent(a, b);
2145 retval = _equalFuncCall(a, b);
2148 retval = _equalAIndices(a, b);
2150 case T_ExprFieldSelect:
2151 retval = _equalExprFieldSelect(a, b);
2154 retval = _equalResTarget(a, b);
2157 retval = _equalTypeCast(a, b);
2160 retval = _equalSortGroupBy(a, b);
2163 retval = _equalAlias(a, b);
2166 retval = _equalRangeVar(a, b);
2168 case T_RangeSubselect:
2169 retval = _equalRangeSubselect(a, b);
2172 retval = _equalTypeName(a, b);
2175 retval = _equalIndexElem(a, b);
2178 retval = _equalColumnDef(a, b);
2181 retval = _equalConstraint(a, b);
2184 retval = _equalDefElem(a, b);
2187 retval = _equalTargetEntry(a, b);
2189 case T_RangeTblEntry:
2190 retval = _equalRangeTblEntry(a, b);
2193 retval = _equalSortClause(a, b);
2196 /* GroupClause is equivalent to SortClause */
2197 retval = _equalSortClause(a, b);
2200 retval = _equalCaseExpr(a, b);
2203 retval = _equalCaseWhen(a, b);
2206 retval = _equalNullTest(a, b);
2209 retval = _equalBooleanTest(a, b);
2211 case T_FkConstraint:
2212 retval = _equalFkConstraint(a, b);
2215 retval = _equalPrivGrantee(a, b);
2217 case T_FuncWithArgs:
2218 retval = _equalFuncWithArgs(a, b);
2220 case T_InsertDefault:
2221 retval = _equalInsertDefault(a, b);
2225 elog(WARNING, "equal: don't know whether nodes of type %d are equal",