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.132 2002/05/12 23:43:02 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->refelemtype != b->refelemtype)
263 if (a->refattrlength != b->refattrlength)
265 if (a->refelemlength != b->refelemlength)
267 if (a->refelembyval != b->refelembyval)
269 if (!equal(a->refupperindexpr, b->refupperindexpr))
271 if (!equal(a->reflowerindexpr, b->reflowerindexpr))
273 if (!equal(a->refexpr, b->refexpr))
275 return equal(a->refassgnexpr, b->refassgnexpr);
279 _equalFieldSelect(FieldSelect *a, FieldSelect *b)
281 if (!equal(a->arg, b->arg))
283 if (a->fieldnum != b->fieldnum)
285 if (a->resulttype != b->resulttype)
287 if (a->resulttypmod != b->resulttypmod)
293 _equalRelabelType(RelabelType *a, RelabelType *b)
295 if (!equal(a->arg, b->arg))
297 if (a->resulttype != b->resulttype)
299 if (a->resulttypmod != b->resulttypmod)
305 _equalRangeTblRef(RangeTblRef *a, RangeTblRef *b)
307 if (a->rtindex != b->rtindex)
314 _equalFromExpr(FromExpr *a, FromExpr *b)
316 if (!equal(a->fromlist, b->fromlist))
318 if (!equal(a->quals, b->quals))
325 _equalJoinExpr(JoinExpr *a, JoinExpr *b)
327 if (a->jointype != b->jointype)
329 if (a->isNatural != b->isNatural)
331 if (!equal(a->larg, b->larg))
333 if (!equal(a->rarg, b->rarg))
335 if (!equal(a->using, b->using))
337 if (!equal(a->quals, b->quals))
339 if (!equal(a->alias, b->alias))
341 if (a->rtindex != b->rtindex)
348 * Stuff from relation.h
352 _equalRelOptInfo(RelOptInfo *a, RelOptInfo *b)
355 * We treat RelOptInfos as equal if they refer to the same base rels
356 * joined in the same order. Is this appropriate/sufficient?
358 return equali(a->relids, b->relids);
362 _equalIndexOptInfo(IndexOptInfo *a, IndexOptInfo *b)
365 * We treat IndexOptInfos as equal if they refer to the same index. Is
368 if (a->indexoid != b->indexoid)
374 _equalPathKeyItem(PathKeyItem *a, PathKeyItem *b)
376 if (a->sortop != b->sortop)
378 if (!equal(a->key, b->key))
384 _equalPath(Path *a, Path *b)
386 if (a->pathtype != b->pathtype)
388 if (!equal(a->parent, b->parent))
392 * do not check path costs, since they may not be set yet, and being
393 * float values there are roundoff error issues anyway...
395 if (!equal(a->pathkeys, b->pathkeys))
401 _equalIndexPath(IndexPath *a, IndexPath *b)
403 if (!_equalPath((Path *) a, (Path *) b))
405 if (!equal(a->indexinfo, b->indexinfo))
407 if (!equal(a->indexqual, b->indexqual))
409 if (a->indexscandir != b->indexscandir)
411 if (!equali(a->joinrelids, b->joinrelids))
413 if (a->alljoinquals != b->alljoinquals)
417 * Skip 'rows' because of possibility of floating-point roundoff
418 * error. It should be derivable from the other fields anyway.
424 _equalTidPath(TidPath *a, TidPath *b)
426 if (!_equalPath((Path *) a, (Path *) b))
428 if (!equal(a->tideval, b->tideval))
430 if (!equali(a->unjoined_relids, b->unjoined_relids))
436 _equalAppendPath(AppendPath *a, AppendPath *b)
438 if (!_equalPath((Path *) a, (Path *) b))
440 if (!equal(a->subpaths, b->subpaths))
446 _equalJoinPath(JoinPath *a, JoinPath *b)
448 if (!_equalPath((Path *) a, (Path *) b))
450 if (a->jointype != b->jointype)
452 if (!equal(a->outerjoinpath, b->outerjoinpath))
454 if (!equal(a->innerjoinpath, b->innerjoinpath))
456 if (!equal(a->joinrestrictinfo, b->joinrestrictinfo))
462 _equalNestPath(NestPath *a, NestPath *b)
464 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
470 _equalMergePath(MergePath *a, MergePath *b)
472 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
474 if (!equal(a->path_mergeclauses, b->path_mergeclauses))
476 if (!equal(a->outersortkeys, b->outersortkeys))
478 if (!equal(a->innersortkeys, b->innersortkeys))
484 _equalHashPath(HashPath *a, HashPath *b)
486 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
488 if (!equal(a->path_hashclauses, b->path_hashclauses))
494 _equalSubPlan(SubPlan *a, SubPlan *b)
496 /* should compare plans, but have to settle for comparing plan IDs */
497 if (a->plan_id != b->plan_id)
500 if (!equal(a->rtable, b->rtable))
503 if (!equal(a->sublink, b->sublink))
510 _equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
512 if (!equal(a->clause, b->clause))
514 if (a->ispusheddown != b->ispusheddown)
518 * We ignore eval_cost, this_selec, left/right_pathkey, and
519 * left/right_bucketsize, since they may not be set yet, and should be
520 * derivable from the clause anyway. Probably it's not really
521 * necessary to compare any of these remaining fields ...
523 if (!equal(a->subclauseindices, b->subclauseindices))
525 if (a->mergejoinoperator != b->mergejoinoperator)
527 if (a->left_sortop != b->left_sortop)
529 if (a->right_sortop != b->right_sortop)
531 if (a->hashjoinoperator != b->hashjoinoperator)
537 _equalJoinInfo(JoinInfo *a, JoinInfo *b)
539 if (!equali(a->unjoined_relids, b->unjoined_relids))
541 if (!equal(a->jinfo_restrictinfo, b->jinfo_restrictinfo))
547 _equalStream(Stream *a, Stream *b)
549 if (a->clausetype != b->clausetype)
551 if (a->groupup != b->groupup)
553 if (a->groupcost != b->groupcost)
555 if (a->groupsel != b->groupsel)
557 if (!equal(a->pathptr, b->pathptr))
559 if (!equal(a->cinfo, b->cinfo))
561 if (!equal(a->upstream, b->upstream))
563 return equal(a->downstream, b->downstream);
567 * Stuff from parsenodes.h
571 _equalQuery(Query *a, Query *b)
573 if (a->commandType != b->commandType)
575 if (!equal(a->utilityStmt, b->utilityStmt))
577 if (a->resultRelation != b->resultRelation)
579 if (!equal(a->into, b->into))
581 if (a->isPortal != b->isPortal)
583 if (a->isBinary != b->isBinary)
585 if (a->hasAggs != b->hasAggs)
587 if (a->hasSubLinks != b->hasSubLinks)
589 /* we deliberately ignore originalQuery */
590 if (!equal(a->rtable, b->rtable))
592 if (!equal(a->jointree, b->jointree))
594 if (!equali(a->rowMarks, b->rowMarks))
596 if (!equal(a->targetList, b->targetList))
598 if (!equal(a->groupClause, b->groupClause))
600 if (!equal(a->havingQual, b->havingQual))
602 if (!equal(a->distinctClause, b->distinctClause))
604 if (!equal(a->sortClause, b->sortClause))
606 if (!equal(a->limitOffset, b->limitOffset))
608 if (!equal(a->limitCount, b->limitCount))
610 if (!equal(a->setOperations, b->setOperations))
612 if (!equali(a->resultRelations, b->resultRelations))
616 * We do not check the internal-to-the-planner fields: base_rel_list,
617 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. They
618 * might not be set yet, and in any case they should be derivable from
625 _equalInsertStmt(InsertStmt *a, InsertStmt *b)
627 if (!equal(a->relation, b->relation))
629 if (!equal(a->cols, b->cols))
631 if (!equal(a->targetList, b->targetList))
633 if (!equal(a->selectStmt, b->selectStmt))
640 _equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
642 if (!equal(a->relation, b->relation))
644 if (!equal(a->whereClause, b->whereClause))
651 _equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
653 if (!equal(a->relation, b->relation))
655 if (!equal(a->targetList, b->targetList))
657 if (!equal(a->whereClause, b->whereClause))
659 if (!equal(a->fromClause, b->fromClause))
666 _equalSelectStmt(SelectStmt *a, SelectStmt *b)
668 if (!equal(a->distinctClause, b->distinctClause))
670 if (!equal(a->into, b->into))
672 if (!equal(a->intoColNames, b->intoColNames))
674 if (!equal(a->targetList, b->targetList))
676 if (!equal(a->fromClause, b->fromClause))
678 if (!equal(a->whereClause, b->whereClause))
680 if (!equal(a->groupClause, b->groupClause))
682 if (!equal(a->havingClause, b->havingClause))
684 if (!equal(a->sortClause, b->sortClause))
686 if (!equalstr(a->portalname, b->portalname))
688 if (a->binary != b->binary)
690 if (!equal(a->limitOffset, b->limitOffset))
692 if (!equal(a->limitCount, b->limitCount))
694 if (!equal(a->forUpdate, b->forUpdate))
698 if (a->all != b->all)
700 if (!equal(a->larg, b->larg))
702 if (!equal(a->rarg, b->rarg))
709 _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
713 if (a->all != b->all)
715 if (!equal(a->larg, b->larg))
717 if (!equal(a->rarg, b->rarg))
719 if (!equali(a->colTypes, b->colTypes))
726 _equalAlterTableStmt(AlterTableStmt *a, AlterTableStmt *b)
728 if (a->subtype != b->subtype)
730 if (!equal(a->relation, b->relation))
732 if (!equalstr(a->name, b->name))
734 if (!equal(a->def, b->def))
736 if (a->behavior != b->behavior)
743 _equalGrantStmt(GrantStmt *a, GrantStmt *b)
745 if (a->is_grant != b->is_grant)
747 if (a->objtype != b->objtype)
749 if (!equal(a->objects, b->objects))
751 if (!equali(a->privileges, b->privileges))
753 if (!equal(a->grantees, b->grantees))
760 _equalPrivGrantee(PrivGrantee *a, PrivGrantee *b)
762 return equalstr(a->username, b->username)
763 && equalstr(a->groupname, b->groupname);
767 _equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
769 return equal(a->funcname, b->funcname)
770 && equal(a->funcargs, b->funcargs);
774 _equalInsertDefault(InsertDefault *a, InsertDefault *b)
780 _equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
782 if (!equalstr(a->portalname, b->portalname))
789 _equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
791 if (!equal(a->relation, b->relation))
793 if (!equalstr(a->indexname, b->indexname))
800 _equalCopyStmt(CopyStmt *a, CopyStmt *b)
802 if (a->binary != b->binary)
804 if (!equal(a->relation, b->relation))
806 if (a->oids != b->oids)
808 if (a->direction != b->direction)
810 if (!equalstr(a->filename, b->filename))
812 if (!equalstr(a->delimiter, b->delimiter))
814 if (!equalstr(a->null_print, b->null_print))
821 _equalCreateStmt(CreateStmt *a, CreateStmt *b)
823 if (!equal(a->relation, b->relation))
825 if (!equal(a->tableElts, b->tableElts))
827 if (!equal(a->inhRelations, b->inhRelations))
829 if (!equal(a->constraints, b->constraints))
831 if (a->hasoids != b->hasoids)
838 _equalDefineStmt(DefineStmt *a, DefineStmt *b)
840 if (a->defType != b->defType)
842 if (!equal(a->defnames, b->defnames))
844 if (!equal(a->definition, b->definition))
851 _equalDropStmt(DropStmt *a, DropStmt *b)
853 if (!equal(a->objects, b->objects))
855 if (a->removeType != b->removeType)
857 if (a->behavior != b->behavior)
864 _equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
866 if (!equal(a->relation, b->relation))
873 _equalCommentStmt(CommentStmt *a, CommentStmt *b)
875 if (a->objtype != b->objtype)
877 if (!equal(a->objname, b->objname))
879 if (!equal(a->objargs, b->objargs))
881 if (!equalstr(a->comment, b->comment))
888 _equalFetchStmt(FetchStmt *a, FetchStmt *b)
890 if (a->direction != b->direction)
892 if (a->howMany != b->howMany)
894 if (!equalstr(a->portalname, b->portalname))
896 if (a->ismove != b->ismove)
903 _equalIndexStmt(IndexStmt *a, IndexStmt *b)
905 if (!equalstr(a->idxname, b->idxname))
907 if (!equal(a->relation, b->relation))
909 if (!equalstr(a->accessMethod, b->accessMethod))
911 if (!equal(a->indexParams, b->indexParams))
913 if (!equal(a->whereClause, b->whereClause))
915 if (!equal(a->rangetable, b->rangetable))
917 if (a->unique != b->unique)
919 if (a->primary != b->primary)
926 _equalProcedureStmt(ProcedureStmt *a, ProcedureStmt *b)
928 if (a->replace != b->replace)
930 if (!equal(a->funcname, b->funcname))
932 if (!equal(a->argTypes, b->argTypes))
934 if (!equal(a->returnType, b->returnType))
936 if (!equal(a->withClause, b->withClause))
938 if (!equal(a->as, b->as))
940 if (!equalstr(a->language, b->language))
947 _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
949 if (!equal(a->aggname, b->aggname))
951 if (!equal(a->aggtype, b->aggtype))
958 _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
960 if (!equal(a->funcname, b->funcname))
962 if (!equal(a->args, b->args))
969 _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
971 if (!equal(a->opname, b->opname))
973 if (!equal(a->args, b->args))
981 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
983 if (!equal(a->relation, b->relation))
985 if (!equalstr(a->oldname, b->oldname))
987 if (!equalstr(a->newname, b->newname))
989 if (a->renameType != b->renameType)
996 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
998 if (!equal(a->relation, b->relation))
1000 if (!equalstr(a->rulename, b->rulename))
1002 if (!equal(a->whereClause, b->whereClause))
1004 if (a->event != b->event)
1006 if (a->instead != b->instead)
1008 if (!equal(a->actions, b->actions))
1015 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1017 if (!equal(a->relation, b->relation))
1024 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1026 if (!equal(a->relation, b->relation))
1033 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1035 if (!equal(a->relation, b->relation))
1042 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1044 if (a->command != b->command)
1051 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1053 if (!equal(a->view, b->view))
1055 if (!equal(a->aliases, b->aliases))
1057 if (!equal(a->query, b->query))
1064 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1066 if (!equalstr(a->filename, b->filename))
1073 _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
1075 if (!equal(a->domainname, b->domainname))
1077 if (!equal(a->typename, b->typename))
1079 if (!equal(a->constraints, b->constraints))
1086 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1088 if (!equalstr(a->dbname, b->dbname))
1090 if (!equalstr(a->dbowner, b->dbowner))
1092 if (!equalstr(a->dbpath, b->dbpath))
1094 if (!equalstr(a->dbtemplate, b->dbtemplate))
1096 if (a->encoding != b->encoding)
1103 _equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
1105 if (!equalstr(a->dbname, b->dbname))
1107 if (!equalstr(a->variable, b->variable))
1109 if (!equal(a->value, b->value))
1116 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1118 if (!equalstr(a->dbname, b->dbname))
1125 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1127 if (a->vacuum != b->vacuum)
1129 if (a->full != b->full)
1131 if (a->analyze != b->analyze)
1133 if (a->freeze != b->freeze)
1135 if (a->verbose != b->verbose)
1137 if (!equal(a->relation, b->relation))
1139 if (!equal(a->va_cols, b->va_cols))
1146 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1148 if (!equal(a->query, b->query))
1150 if (a->verbose != b->verbose)
1152 if (a->analyze != b->analyze)
1159 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1161 if (!equal(a->sequence, b->sequence))
1163 if (!equal(a->options, b->options))
1170 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1172 if (!equalstr(a->name, b->name))
1174 if (!equal(a->args, b->args))
1181 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1183 if (!equalstr(a->name, b->name))
1190 _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
1192 if (!equalstr(a->name, b->name))
1199 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1201 if (!equalstr(a->trigname, b->trigname))
1203 if (!equal(a->relation, b->relation))
1205 if (!equal(a->funcname, b->funcname))
1207 if (!equal(a->args, b->args))
1209 if (a->before != b->before)
1211 if (a->row != b->row)
1213 if (strcmp(a->actions, b->actions) != 0)
1215 if (!equalstr(a->lang, b->lang))
1217 if (!equalstr(a->text, b->text))
1219 if (!equal(a->attr, b->attr))
1221 if (!equalstr(a->when, b->when))
1223 if (a->isconstraint != b->isconstraint)
1225 if (a->deferrable != b->deferrable)
1227 if (a->initdeferred != b->initdeferred)
1229 if (!equal(a->constrrel, b->constrrel))
1236 _equalDropPropertyStmt(DropPropertyStmt *a, DropPropertyStmt *b)
1238 if (!equal(a->relation, b->relation))
1240 if (!equalstr(a->property, b->property))
1242 if (a->removeType != b->removeType)
1249 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1251 if (!equalstr(a->plname, b->plname))
1253 if (!equal(a->plhandler, b->plhandler))
1255 if (!equalstr(a->plcompiler, b->plcompiler))
1257 if (a->pltrusted != b->pltrusted)
1264 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1266 if (!equalstr(a->plname, b->plname))
1273 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1275 if (!equalstr(a->user, b->user))
1277 if (!equal(a->options, b->options))
1284 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1286 if (!equalstr(a->user, b->user))
1288 if (!equal(a->options, b->options))
1295 _equalAlterUserSetStmt(AlterUserSetStmt *a, AlterUserSetStmt *b)
1297 if (!equalstr(a->user, b->user))
1299 if (!equalstr(a->variable, b->variable))
1301 if (!equal(a->value, b->value))
1308 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1310 if (!equal(a->users, b->users))
1317 _equalLockStmt(LockStmt *a, LockStmt *b)
1319 if (!equal(a->relations, b->relations))
1321 if (a->mode != b->mode)
1328 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1330 if (!equal(a->constraints, b->constraints))
1332 if (a->deferred != b->deferred)
1339 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1341 if (!equalstr(a->name, b->name))
1343 if (!equal(a->options, b->options))
1350 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1352 if (!equalstr(a->name, b->name))
1354 if (a->action != b->action)
1356 if (!equal(a->listUsers, b->listUsers))
1363 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1365 if (!equalstr(a->name, b->name))
1372 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1374 if (a->reindexType != b->reindexType)
1376 if (!equal(a->relation, b->relation))
1378 if (!equalstr(a->name, b->name))
1380 if (a->force != b->force)
1382 if (a->all != b->all)
1389 _equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
1391 if (!equalstr(a->schemaname, b->schemaname))
1393 if (!equalstr(a->authid, b->authid))
1395 if (!equal(a->schemaElts, b->schemaElts))
1402 _equalAExpr(A_Expr *a, A_Expr *b)
1404 if (a->oper != b->oper)
1406 if (!equal(a->name, b->name))
1408 if (!equal(a->lexpr, b->lexpr))
1410 if (!equal(a->rexpr, b->rexpr))
1417 _equalColumnRef(ColumnRef *a, ColumnRef *b)
1419 if (!equal(a->fields, b->fields))
1421 if (!equal(a->indirection, b->indirection))
1428 _equalParamRef(ParamRef *a, ParamRef *b)
1430 if (a->number != b->number)
1432 if (!equal(a->fields, b->fields))
1434 if (!equal(a->indirection, b->indirection))
1441 _equalAConst(A_Const *a, A_Const *b)
1443 if (!equal(&a->val, &b->val))
1445 if (!equal(a->typename, b->typename))
1452 _equalIdent(Ident *a, Ident *b)
1454 if (!equalstr(a->name, b->name))
1461 _equalFuncCall(FuncCall *a, FuncCall *b)
1463 if (!equal(a->funcname, b->funcname))
1465 if (!equal(a->args, b->args))
1467 if (a->agg_star != b->agg_star)
1469 if (a->agg_distinct != b->agg_distinct)
1476 _equalAIndices(A_Indices *a, A_Indices *b)
1478 if (!equal(a->lidx, b->lidx))
1480 if (!equal(a->uidx, b->uidx))
1487 _equalExprFieldSelect(ExprFieldSelect *a, ExprFieldSelect *b)
1489 if (!equal(a->arg, b->arg))
1491 if (!equal(a->fields, b->fields))
1493 if (!equal(a->indirection, b->indirection))
1500 _equalResTarget(ResTarget *a, ResTarget *b)
1502 if (!equalstr(a->name, b->name))
1504 if (!equal(a->indirection, b->indirection))
1506 if (!equal(a->val, b->val))
1513 _equalTypeCast(TypeCast *a, TypeCast *b)
1515 if (!equal(a->arg, b->arg))
1517 if (!equal(a->typename, b->typename))
1524 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1526 if (!equal(a->useOp, b->useOp))
1528 if (!equal(a->node, b->node))
1535 _equalAlias(Alias *a, Alias *b)
1537 if (!equalstr(a->aliasname, b->aliasname))
1539 if (!equal(a->colnames, b->colnames))
1546 _equalRangeVar(RangeVar *a, RangeVar *b)
1548 if (!equalstr(a->catalogname, b->catalogname))
1550 if (!equalstr(a->schemaname, b->schemaname))
1552 if (!equalstr(a->relname, b->relname))
1554 if (a->inhOpt != b->inhOpt)
1556 if (a->istemp != b->istemp)
1558 if (!equal(a->alias, b->alias))
1565 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1567 if (!equal(a->subquery, b->subquery))
1569 if (!equal(a->alias, b->alias))
1576 _equalRangeFunction(RangeFunction *a, RangeFunction *b)
1578 if (!equal(a->funccallnode, b->funccallnode))
1580 if (!equal(a->alias, b->alias))
1587 _equalTypeName(TypeName *a, TypeName *b)
1589 if (!equal(a->names, b->names))
1591 if (a->typeid != b->typeid)
1593 if (a->timezone != b->timezone)
1595 if (a->setof != b->setof)
1597 if (a->pct_type != b->pct_type)
1599 if (a->typmod != b->typmod)
1601 if (!equal(a->arrayBounds, b->arrayBounds))
1608 _equalIndexElem(IndexElem *a, IndexElem *b)
1610 if (!equalstr(a->name, b->name))
1612 if (!equal(a->funcname, b->funcname))
1614 if (!equal(a->args, b->args))
1616 if (!equal(a->opclass, b->opclass))
1623 _equalColumnDef(ColumnDef *a, ColumnDef *b)
1625 if (!equalstr(a->colname, b->colname))
1627 if (!equal(a->typename, b->typename))
1629 if (a->is_not_null != b->is_not_null)
1631 if (!equal(a->raw_default, b->raw_default))
1633 if (!equalstr(a->cooked_default, b->cooked_default))
1635 if (!equal(a->constraints, b->constraints))
1642 _equalConstraint(Constraint *a, Constraint *b)
1644 if (a->contype != b->contype)
1646 if (!equalstr(a->name, b->name))
1648 if (!equal(a->raw_expr, b->raw_expr))
1650 if (!equalstr(a->cooked_expr, b->cooked_expr))
1652 if (!equal(a->keys, b->keys))
1659 _equalDefElem(DefElem *a, DefElem *b)
1661 if (!equalstr(a->defname, b->defname))
1663 if (!equal(a->arg, b->arg))
1670 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
1672 if (!equal(a->resdom, b->resdom))
1674 if (!equal(a->fjoin, b->fjoin))
1676 if (!equal(a->expr, b->expr))
1683 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
1685 if (a->rtekind != b->rtekind)
1687 if (a->relid != b->relid)
1689 if (!equal(a->subquery, b->subquery))
1691 if (!equal(a->funcexpr, b->funcexpr))
1693 if (a->jointype != b->jointype)
1695 if (!equal(a->joinaliasvars, b->joinaliasvars))
1697 if (!equal(a->alias, b->alias))
1699 if (!equal(a->eref, b->eref))
1701 if (a->inh != b->inh)
1703 if (a->inFromCl != b->inFromCl)
1705 if (a->checkForRead != b->checkForRead)
1707 if (a->checkForWrite != b->checkForWrite)
1709 if (a->checkAsUser != b->checkAsUser)
1716 _equalSortClause(SortClause *a, SortClause *b)
1718 if (a->tleSortGroupRef != b->tleSortGroupRef)
1720 if (a->sortop != b->sortop)
1727 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
1729 if (!equalstr(a->constr_name, b->constr_name))
1731 if (!equal(a->pktable, b->pktable))
1733 if (!equal(a->fk_attrs, b->fk_attrs))
1735 if (!equal(a->pk_attrs, b->pk_attrs))
1737 if (!equalstr(a->match_type, b->match_type))
1739 if (a->actions != b->actions)
1741 if (a->deferrable != b->deferrable)
1743 if (a->initdeferred != b->initdeferred)
1750 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
1752 if (a->casetype != b->casetype)
1754 if (!equal(a->arg, b->arg))
1756 if (!equal(a->args, b->args))
1758 if (!equal(a->defresult, b->defresult))
1765 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
1767 if (!equal(a->expr, b->expr))
1769 if (!equal(a->result, b->result))
1776 _equalNullTest(NullTest *a, NullTest *b)
1778 if (!equal(a->arg, b->arg))
1780 if (a->nulltesttype != b->nulltesttype)
1786 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
1788 if (!equal(a->arg, b->arg))
1790 if (a->booltesttype != b->booltesttype)
1796 * Stuff from pg_list.h
1800 _equalValue(Value *a, Value *b)
1802 if (a->type != b->type)
1808 return a->val.ival == b->val.ival;
1812 return strcmp(a->val.str, b->val.str) == 0;
1822 * returns whether two nodes are equal
1825 equal(void *a, void *b)
1827 bool retval = false;
1833 * note that a!=b, so only one of them can be NULL
1835 if (a == NULL || b == NULL)
1839 * are they the same type of nodes?
1841 if (nodeTag(a) != nodeTag(b))
1847 retval = _equalSubPlan(a, b);
1851 retval = _equalResdom(a, b);
1854 retval = _equalFjoin(a, b);
1857 retval = _equalExpr(a, b);
1860 retval = _equalVar(a, b);
1863 retval = _equalOper(a, b);
1866 retval = _equalConst(a, b);
1869 retval = _equalParam(a, b);
1872 retval = _equalAggref(a, b);
1875 retval = _equalSubLink(a, b);
1878 retval = _equalFunc(a, b);
1881 retval = _equalFieldSelect(a, b);
1884 retval = _equalArrayRef(a, b);
1887 retval = _equalRelabelType(a, b);
1890 retval = _equalRangeTblRef(a, b);
1893 retval = _equalFromExpr(a, b);
1896 retval = _equalJoinExpr(a, b);
1900 retval = _equalRelOptInfo(a, b);
1903 retval = _equalPath(a, b);
1906 retval = _equalIndexPath(a, b);
1909 retval = _equalNestPath(a, b);
1912 retval = _equalMergePath(a, b);
1915 retval = _equalHashPath(a, b);
1918 retval = _equalPathKeyItem(a, b);
1920 case T_RestrictInfo:
1921 retval = _equalRestrictInfo(a, b);
1924 retval = _equalJoinInfo(a, b);
1927 retval = _equalStream(a, b);
1930 retval = _equalTidPath(a, b);
1933 retval = _equalAppendPath(a, b);
1935 case T_IndexOptInfo:
1936 retval = _equalIndexOptInfo(a, b);
1941 List *la = (List *) a;
1942 List *lb = (List *) b;
1946 * Try to reject by length check before we grovel through
1947 * all the elements...
1949 if (length(la) != length(lb))
1953 if (!equal(lfirst(l), lfirst(lb)))
1964 retval = _equalValue(a, b);
1968 retval = _equalQuery(a, b);
1971 retval = _equalInsertStmt(a, b);
1974 retval = _equalDeleteStmt(a, b);
1977 retval = _equalUpdateStmt(a, b);
1980 retval = _equalSelectStmt(a, b);
1982 case T_SetOperationStmt:
1983 retval = _equalSetOperationStmt(a, b);
1985 case T_AlterTableStmt:
1986 retval = _equalAlterTableStmt(a, b);
1989 retval = _equalGrantStmt(a, b);
1991 case T_ClosePortalStmt:
1992 retval = _equalClosePortalStmt(a, b);
1995 retval = _equalClusterStmt(a, b);
1998 retval = _equalCopyStmt(a, b);
2001 retval = _equalCreateStmt(a, b);
2004 retval = _equalDefineStmt(a, b);
2007 retval = _equalDropStmt(a, b);
2009 case T_TruncateStmt:
2010 retval = _equalTruncateStmt(a, b);
2013 retval = _equalCommentStmt(a, b);
2016 retval = _equalFetchStmt(a, b);
2019 retval = _equalIndexStmt(a, b);
2021 case T_ProcedureStmt:
2022 retval = _equalProcedureStmt(a, b);
2024 case T_RemoveAggrStmt:
2025 retval = _equalRemoveAggrStmt(a, b);
2027 case T_RemoveFuncStmt:
2028 retval = _equalRemoveFuncStmt(a, b);
2030 case T_RemoveOperStmt:
2031 retval = _equalRemoveOperStmt(a, b);
2034 retval = _equalRenameStmt(a, b);
2037 retval = _equalRuleStmt(a, b);
2040 retval = _equalNotifyStmt(a, b);
2043 retval = _equalListenStmt(a, b);
2045 case T_UnlistenStmt:
2046 retval = _equalUnlistenStmt(a, b);
2048 case T_TransactionStmt:
2049 retval = _equalTransactionStmt(a, b);
2052 retval = _equalViewStmt(a, b);
2055 retval = _equalLoadStmt(a, b);
2057 case T_CreateDomainStmt:
2058 retval = _equalCreateDomainStmt(a, b);
2060 case T_CreatedbStmt:
2061 retval = _equalCreatedbStmt(a, b);
2063 case T_AlterDatabaseSetStmt:
2064 retval = _equalAlterDatabaseSetStmt(a, b);
2067 retval = _equalDropdbStmt(a, b);
2070 retval = _equalVacuumStmt(a, b);
2073 retval = _equalExplainStmt(a, b);
2075 case T_CreateSeqStmt:
2076 retval = _equalCreateSeqStmt(a, b);
2078 case T_VariableSetStmt:
2079 retval = _equalVariableSetStmt(a, b);
2081 case T_VariableShowStmt:
2082 retval = _equalVariableShowStmt(a, b);
2084 case T_VariableResetStmt:
2085 retval = _equalVariableResetStmt(a, b);
2087 case T_CreateTrigStmt:
2088 retval = _equalCreateTrigStmt(a, b);
2090 case T_DropPropertyStmt:
2091 retval = _equalDropPropertyStmt(a, b);
2093 case T_CreatePLangStmt:
2094 retval = _equalCreatePLangStmt(a, b);
2096 case T_DropPLangStmt:
2097 retval = _equalDropPLangStmt(a, b);
2099 case T_CreateUserStmt:
2100 retval = _equalCreateUserStmt(a, b);
2102 case T_AlterUserStmt:
2103 retval = _equalAlterUserStmt(a, b);
2105 case T_AlterUserSetStmt:
2106 retval = _equalAlterUserSetStmt(a, b);
2108 case T_DropUserStmt:
2109 retval = _equalDropUserStmt(a, b);
2112 retval = _equalLockStmt(a, b);
2114 case T_ConstraintsSetStmt:
2115 retval = _equalConstraintsSetStmt(a, b);
2117 case T_CreateGroupStmt:
2118 retval = _equalCreateGroupStmt(a, b);
2120 case T_AlterGroupStmt:
2121 retval = _equalAlterGroupStmt(a, b);
2123 case T_DropGroupStmt:
2124 retval = _equalDropGroupStmt(a, b);
2127 retval = _equalReindexStmt(a, b);
2129 case T_CheckPointStmt:
2132 case T_CreateSchemaStmt:
2133 retval = _equalCreateSchemaStmt(a, b);
2137 retval = _equalAExpr(a, b);
2140 retval = _equalColumnRef(a, b);
2143 retval = _equalParamRef(a, b);
2146 retval = _equalAConst(a, b);
2149 retval = _equalIdent(a, b);
2152 retval = _equalFuncCall(a, b);
2155 retval = _equalAIndices(a, b);
2157 case T_ExprFieldSelect:
2158 retval = _equalExprFieldSelect(a, b);
2161 retval = _equalResTarget(a, b);
2164 retval = _equalTypeCast(a, b);
2167 retval = _equalSortGroupBy(a, b);
2170 retval = _equalAlias(a, b);
2173 retval = _equalRangeVar(a, b);
2175 case T_RangeSubselect:
2176 retval = _equalRangeSubselect(a, b);
2178 case T_RangeFunction:
2179 retval = _equalRangeFunction(a, b);
2182 retval = _equalTypeName(a, b);
2185 retval = _equalIndexElem(a, b);
2188 retval = _equalColumnDef(a, b);
2191 retval = _equalConstraint(a, b);
2194 retval = _equalDefElem(a, b);
2197 retval = _equalTargetEntry(a, b);
2199 case T_RangeTblEntry:
2200 retval = _equalRangeTblEntry(a, b);
2203 retval = _equalSortClause(a, b);
2206 /* GroupClause is equivalent to SortClause */
2207 retval = _equalSortClause(a, b);
2210 retval = _equalCaseExpr(a, b);
2213 retval = _equalCaseWhen(a, b);
2216 retval = _equalNullTest(a, b);
2219 retval = _equalBooleanTest(a, b);
2221 case T_FkConstraint:
2222 retval = _equalFkConstraint(a, b);
2225 retval = _equalPrivGrantee(a, b);
2227 case T_FuncWithArgs:
2228 retval = _equalFuncWithArgs(a, b);
2230 case T_InsertDefault:
2231 retval = _equalInsertDefault(a, b);
2235 elog(WARNING, "equal: don't know whether nodes of type %d are equal",