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.123 2002/04/05 11:56:50 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 (strcmp(a->aggname, b->aggname) != 0)
225 if (a->basetype != b->basetype)
227 if (a->aggtype != b->aggtype)
229 if (!equal(a->target, b->target))
231 if (a->aggstar != b->aggstar)
233 if (a->aggdistinct != b->aggdistinct)
235 /* ignore aggno, which is only a private field for the executor */
240 _equalSubLink(SubLink *a, SubLink *b)
242 if (a->subLinkType != b->subLinkType)
244 if (a->useor != b->useor)
246 if (!equal(a->lefthand, b->lefthand))
248 if (!equal(a->oper, b->oper))
250 if (!equal(a->subselect, b->subselect))
256 _equalArrayRef(ArrayRef *a, ArrayRef *b)
258 if (a->refelemtype != b->refelemtype)
260 if (a->refattrlength != b->refattrlength)
262 if (a->refelemlength != b->refelemlength)
264 if (a->refelembyval != b->refelembyval)
266 if (!equal(a->refupperindexpr, b->refupperindexpr))
268 if (!equal(a->reflowerindexpr, b->reflowerindexpr))
270 if (!equal(a->refexpr, b->refexpr))
272 return equal(a->refassgnexpr, b->refassgnexpr);
276 _equalFieldSelect(FieldSelect *a, FieldSelect *b)
278 if (!equal(a->arg, b->arg))
280 if (a->fieldnum != b->fieldnum)
282 if (a->resulttype != b->resulttype)
284 if (a->resulttypmod != b->resulttypmod)
290 _equalRelabelType(RelabelType *a, RelabelType *b)
292 if (!equal(a->arg, b->arg))
294 if (a->resulttype != b->resulttype)
296 if (a->resulttypmod != b->resulttypmod)
302 _equalRangeTblRef(RangeTblRef *a, RangeTblRef *b)
304 if (a->rtindex != b->rtindex)
311 _equalFromExpr(FromExpr *a, FromExpr *b)
313 if (!equal(a->fromlist, b->fromlist))
315 if (!equal(a->quals, b->quals))
322 _equalJoinExpr(JoinExpr *a, JoinExpr *b)
324 if (a->jointype != b->jointype)
326 if (a->isNatural != b->isNatural)
328 if (!equal(a->larg, b->larg))
330 if (!equal(a->rarg, b->rarg))
332 if (!equal(a->using, b->using))
334 if (!equal(a->quals, b->quals))
336 if (!equal(a->alias, b->alias))
338 if (a->rtindex != b->rtindex)
345 * Stuff from relation.h
349 _equalRelOptInfo(RelOptInfo *a, RelOptInfo *b)
352 * We treat RelOptInfos as equal if they refer to the same base rels
353 * joined in the same order. Is this appropriate/sufficient?
355 return equali(a->relids, b->relids);
359 _equalIndexOptInfo(IndexOptInfo *a, IndexOptInfo *b)
362 * We treat IndexOptInfos as equal if they refer to the same index. Is
365 if (a->indexoid != b->indexoid)
371 _equalPathKeyItem(PathKeyItem *a, PathKeyItem *b)
373 if (a->sortop != b->sortop)
375 if (!equal(a->key, b->key))
381 _equalPath(Path *a, Path *b)
383 if (a->pathtype != b->pathtype)
385 if (!equal(a->parent, b->parent))
389 * do not check path costs, since they may not be set yet, and being
390 * float values there are roundoff error issues anyway...
392 if (!equal(a->pathkeys, b->pathkeys))
398 _equalIndexPath(IndexPath *a, IndexPath *b)
400 if (!_equalPath((Path *) a, (Path *) b))
402 if (!equal(a->indexinfo, b->indexinfo))
404 if (!equal(a->indexqual, b->indexqual))
406 if (a->indexscandir != b->indexscandir)
408 if (!equali(a->joinrelids, b->joinrelids))
410 if (a->alljoinquals != b->alljoinquals)
414 * Skip 'rows' because of possibility of floating-point roundoff
415 * error. It should be derivable from the other fields anyway.
421 _equalTidPath(TidPath *a, TidPath *b)
423 if (!_equalPath((Path *) a, (Path *) b))
425 if (!equal(a->tideval, b->tideval))
427 if (!equali(a->unjoined_relids, b->unjoined_relids))
433 _equalAppendPath(AppendPath *a, AppendPath *b)
435 if (!_equalPath((Path *) a, (Path *) b))
437 if (!equal(a->subpaths, b->subpaths))
443 _equalJoinPath(JoinPath *a, JoinPath *b)
445 if (!_equalPath((Path *) a, (Path *) b))
447 if (a->jointype != b->jointype)
449 if (!equal(a->outerjoinpath, b->outerjoinpath))
451 if (!equal(a->innerjoinpath, b->innerjoinpath))
453 if (!equal(a->joinrestrictinfo, b->joinrestrictinfo))
459 _equalNestPath(NestPath *a, NestPath *b)
461 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
467 _equalMergePath(MergePath *a, MergePath *b)
469 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
471 if (!equal(a->path_mergeclauses, b->path_mergeclauses))
473 if (!equal(a->outersortkeys, b->outersortkeys))
475 if (!equal(a->innersortkeys, b->innersortkeys))
481 _equalHashPath(HashPath *a, HashPath *b)
483 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
485 if (!equal(a->path_hashclauses, b->path_hashclauses))
491 _equalSubPlan(SubPlan *a, SubPlan *b)
493 /* should compare plans, but have to settle for comparing plan IDs */
494 if (a->plan_id != b->plan_id)
497 if (!equal(a->rtable, b->rtable))
500 if (!equal(a->sublink, b->sublink))
507 _equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
509 if (!equal(a->clause, b->clause))
511 if (a->ispusheddown != b->ispusheddown)
515 * We ignore eval_cost, this_selec, left/right_pathkey, and
516 * left/right_bucketsize, since they may not be set yet, and should be
517 * derivable from the clause anyway. Probably it's not really
518 * necessary to compare any of these remaining fields ...
520 if (!equal(a->subclauseindices, b->subclauseindices))
522 if (a->mergejoinoperator != b->mergejoinoperator)
524 if (a->left_sortop != b->left_sortop)
526 if (a->right_sortop != b->right_sortop)
528 if (a->hashjoinoperator != b->hashjoinoperator)
534 _equalJoinInfo(JoinInfo *a, JoinInfo *b)
536 if (!equali(a->unjoined_relids, b->unjoined_relids))
538 if (!equal(a->jinfo_restrictinfo, b->jinfo_restrictinfo))
544 _equalIter(Iter *a, Iter *b)
546 return equal(a->iterexpr, b->iterexpr);
550 _equalStream(Stream *a, Stream *b)
552 if (a->clausetype != b->clausetype)
554 if (a->groupup != b->groupup)
556 if (a->groupcost != b->groupcost)
558 if (a->groupsel != b->groupsel)
560 if (!equal(a->pathptr, b->pathptr))
562 if (!equal(a->cinfo, b->cinfo))
564 if (!equal(a->upstream, b->upstream))
566 return equal(a->downstream, b->downstream);
570 * Stuff from parsenodes.h
574 _equalQuery(Query *a, Query *b)
576 if (a->commandType != b->commandType)
578 if (!equal(a->utilityStmt, b->utilityStmt))
580 if (a->resultRelation != b->resultRelation)
582 if (!equal(a->into, b->into))
584 if (a->isPortal != b->isPortal)
586 if (a->isBinary != b->isBinary)
588 if (a->hasAggs != b->hasAggs)
590 if (a->hasSubLinks != b->hasSubLinks)
592 /* we deliberately ignore originalQuery */
593 if (!equal(a->rtable, b->rtable))
595 if (!equal(a->jointree, b->jointree))
597 if (!equali(a->rowMarks, b->rowMarks))
599 if (!equal(a->targetList, b->targetList))
601 if (!equal(a->groupClause, b->groupClause))
603 if (!equal(a->havingQual, b->havingQual))
605 if (!equal(a->distinctClause, b->distinctClause))
607 if (!equal(a->sortClause, b->sortClause))
609 if (!equal(a->limitOffset, b->limitOffset))
611 if (!equal(a->limitCount, b->limitCount))
613 if (!equal(a->setOperations, b->setOperations))
615 if (!equali(a->resultRelations, b->resultRelations))
619 * We do not check the internal-to-the-planner fields: base_rel_list,
620 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. They
621 * might not be set yet, and in any case they should be derivable from
628 _equalInsertStmt(InsertStmt *a, InsertStmt *b)
630 if (!equal(a->relation, b->relation))
632 if (!equal(a->cols, b->cols))
634 if (!equal(a->targetList, b->targetList))
636 if (!equal(a->selectStmt, b->selectStmt))
643 _equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
645 if (!equal(a->relation, b->relation))
647 if (!equal(a->whereClause, b->whereClause))
654 _equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
656 if (!equal(a->relation, b->relation))
658 if (!equal(a->targetList, b->targetList))
660 if (!equal(a->whereClause, b->whereClause))
662 if (!equal(a->fromClause, b->fromClause))
669 _equalSelectStmt(SelectStmt *a, SelectStmt *b)
671 if (!equal(a->distinctClause, b->distinctClause))
673 if (!equal(a->into, b->into))
675 if (!equal(a->intoColNames, b->intoColNames))
677 if (!equal(a->targetList, b->targetList))
679 if (!equal(a->fromClause, b->fromClause))
681 if (!equal(a->whereClause, b->whereClause))
683 if (!equal(a->groupClause, b->groupClause))
685 if (!equal(a->havingClause, b->havingClause))
687 if (!equal(a->sortClause, b->sortClause))
689 if (!equalstr(a->portalname, b->portalname))
691 if (a->binary != b->binary)
693 if (!equal(a->limitOffset, b->limitOffset))
695 if (!equal(a->limitCount, b->limitCount))
697 if (!equal(a->forUpdate, b->forUpdate))
701 if (a->all != b->all)
703 if (!equal(a->larg, b->larg))
705 if (!equal(a->rarg, b->rarg))
712 _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
716 if (a->all != b->all)
718 if (!equal(a->larg, b->larg))
720 if (!equal(a->rarg, b->rarg))
722 if (!equali(a->colTypes, b->colTypes))
729 _equalAlterTableStmt(AlterTableStmt *a, AlterTableStmt *b)
731 if (a->subtype != b->subtype)
733 if (!equal(a->relation, b->relation))
735 if (!equalstr(a->name, b->name))
737 if (!equal(a->def, b->def))
739 if (a->behavior != b->behavior)
746 _equalGrantStmt(GrantStmt *a, GrantStmt *b)
748 if (a->is_grant != b->is_grant)
750 if (a->objtype != b->objtype)
752 if (!equal(a->objects, b->objects))
754 if (!equali(a->privileges, b->privileges))
756 if (!equal(a->grantees, b->grantees))
763 _equalPrivGrantee(PrivGrantee *a, PrivGrantee *b)
765 return equalstr(a->username, b->username)
766 && equalstr(a->groupname, b->groupname);
770 _equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
772 return equalstr(a->funcname, b->funcname)
773 && equal(a->funcargs, b->funcargs);
777 _equalInsertDefault(InsertDefault *a, InsertDefault *b)
783 _equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
785 if (!equalstr(a->portalname, b->portalname))
792 _equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
794 if (!equal(a->relation, b->relation))
796 if (!equalstr(a->indexname, b->indexname))
803 _equalCopyStmt(CopyStmt *a, CopyStmt *b)
805 if (a->binary != b->binary)
807 if (!equal(a->relation, b->relation))
809 if (a->oids != b->oids)
811 if (a->direction != b->direction)
813 if (!equalstr(a->filename, b->filename))
815 if (!equalstr(a->delimiter, b->delimiter))
817 if (!equalstr(a->null_print, b->null_print))
824 _equalCreateStmt(CreateStmt *a, CreateStmt *b)
826 if (!equal(a->relation, b->relation))
828 if (!equal(a->tableElts, b->tableElts))
830 if (!equal(a->inhRelations, b->inhRelations))
832 if (!equal(a->constraints, b->constraints))
834 if (a->hasoids != b->hasoids)
841 _equalDefineStmt(DefineStmt *a, DefineStmt *b)
843 if (a->defType != b->defType)
845 if (!equal(a->defnames, b->defnames))
847 if (!equal(a->definition, b->definition))
854 _equalDropStmt(DropStmt *a, DropStmt *b)
856 if (!equal(a->objects, b->objects))
858 if (a->removeType != b->removeType)
860 if (a->behavior != b->behavior)
867 _equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
869 if (!equal(a->relation, b->relation))
876 _equalCommentStmt(CommentStmt *a, CommentStmt *b)
878 if (a->objtype != b->objtype)
880 if (!equalstr(a->objname, b->objname))
882 if (!equalstr(a->objschema, b->objschema))
884 if (!equalstr(a->objproperty, b->objproperty))
886 if (!equal(a->objlist, b->objlist))
888 if (!equalstr(a->comment, b->comment))
895 _equalFetchStmt(FetchStmt *a, FetchStmt *b)
897 if (a->direction != b->direction)
899 if (a->howMany != b->howMany)
901 if (!equalstr(a->portalname, b->portalname))
903 if (a->ismove != b->ismove)
910 _equalIndexStmt(IndexStmt *a, IndexStmt *b)
912 if (!equalstr(a->idxname, b->idxname))
914 if (!equal(a->relation, b->relation))
916 if (!equalstr(a->accessMethod, b->accessMethod))
918 if (!equal(a->indexParams, b->indexParams))
920 if (!equal(a->whereClause, b->whereClause))
922 if (!equal(a->rangetable, b->rangetable))
924 if (a->unique != b->unique)
926 if (a->primary != b->primary)
933 _equalProcedureStmt(ProcedureStmt *a, ProcedureStmt *b)
935 if (a->replace != b->replace)
937 if (!equal(a->funcname, b->funcname))
939 if (!equal(a->argTypes, b->argTypes))
941 if (!equal(a->returnType, b->returnType))
943 if (!equal(a->withClause, b->withClause))
945 if (!equal(a->as, b->as))
947 if (!equalstr(a->language, b->language))
954 _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
956 if (!equalstr(a->aggname, b->aggname))
958 if (!equal(a->aggtype, b->aggtype))
965 _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
967 if (!equalstr(a->funcname, b->funcname))
969 if (!equal(a->args, b->args))
976 _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
978 if (!equalstr(a->opname, b->opname))
980 if (!equal(a->args, b->args))
988 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
990 if (!equal(a->relation, b->relation))
992 if (!equalstr(a->column, b->column))
994 if (!equalstr(a->newname, b->newname))
1001 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
1003 if (!equal(a->relation, b->relation))
1005 if (!equalstr(a->rulename, b->rulename))
1007 if (!equal(a->whereClause, b->whereClause))
1009 if (a->event != b->event)
1011 if (a->instead != b->instead)
1013 if (!equal(a->actions, b->actions))
1020 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1022 if (!equal(a->relation, b->relation))
1029 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1031 if (!equal(a->relation, b->relation))
1038 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1040 if (!equal(a->relation, b->relation))
1047 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1049 if (a->command != b->command)
1056 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1058 if (!equal(a->view, b->view))
1060 if (!equal(a->aliases, b->aliases))
1062 if (!equal(a->query, b->query))
1069 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1071 if (!equalstr(a->filename, b->filename))
1078 _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
1080 if (!equal(a->domainname, b->domainname))
1082 if (!equal(a->typename, b->typename))
1084 if (!equal(a->constraints, b->constraints))
1091 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1093 if (!equalstr(a->dbname, b->dbname))
1095 if (!equalstr(a->dbowner, b->dbowner))
1097 if (!equalstr(a->dbpath, b->dbpath))
1099 if (!equalstr(a->dbtemplate, b->dbtemplate))
1101 if (a->encoding != b->encoding)
1108 _equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
1110 if (!equalstr(a->dbname, b->dbname))
1112 if (!equalstr(a->variable, b->variable))
1114 if (!equal(a->value, b->value))
1121 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1123 if (!equalstr(a->dbname, b->dbname))
1130 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1132 if (a->vacuum != b->vacuum)
1134 if (a->full != b->full)
1136 if (a->analyze != b->analyze)
1138 if (a->freeze != b->freeze)
1140 if (a->verbose != b->verbose)
1142 if (!equal(a->relation, b->relation))
1144 if (!equal(a->va_cols, b->va_cols))
1151 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1153 if (!equal(a->query, b->query))
1155 if (a->verbose != b->verbose)
1157 if (a->analyze != b->analyze)
1164 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1166 if (!equal(a->sequence, b->sequence))
1168 if (!equal(a->options, b->options))
1175 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1177 if (!equalstr(a->name, b->name))
1179 if (!equal(a->args, b->args))
1186 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1188 if (!equalstr(a->name, b->name))
1195 _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
1197 if (!equalstr(a->name, b->name))
1204 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1206 if (!equalstr(a->trigname, b->trigname))
1208 if (!equal(a->relation, b->relation))
1210 if (!equalstr(a->funcname, b->funcname))
1212 if (!equal(a->args, b->args))
1214 if (a->before != b->before)
1216 if (a->row != b->row)
1218 if (strcmp(a->actions, b->actions) != 0)
1220 if (!equalstr(a->lang, b->lang))
1222 if (!equalstr(a->text, b->text))
1224 if (!equal(a->attr, b->attr))
1226 if (!equalstr(a->when, b->when))
1228 if (a->isconstraint != b->isconstraint)
1230 if (a->deferrable != b->deferrable)
1232 if (a->initdeferred != b->initdeferred)
1234 if (!equal(a->constrrel, b->constrrel))
1241 _equalDropTrigStmt(DropTrigStmt *a, DropTrigStmt *b)
1243 if (!equalstr(a->trigname, b->trigname))
1245 if (!equal(a->relation, b->relation))
1252 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1254 if (!equalstr(a->plname, b->plname))
1256 if (!equalstr(a->plhandler, b->plhandler))
1258 if (!equalstr(a->plcompiler, b->plcompiler))
1260 if (a->pltrusted != b->pltrusted)
1267 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1269 if (!equalstr(a->plname, b->plname))
1276 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1278 if (!equalstr(a->user, b->user))
1280 if (!equal(a->options, b->options))
1287 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1289 if (!equalstr(a->user, b->user))
1291 if (!equal(a->options, b->options))
1298 _equalAlterUserSetStmt(AlterUserSetStmt *a, AlterUserSetStmt *b)
1300 if (!equalstr(a->user, b->user))
1302 if (!equalstr(a->variable, b->variable))
1304 if (!equal(a->value, b->value))
1311 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1313 if (!equal(a->users, b->users))
1320 _equalLockStmt(LockStmt *a, LockStmt *b)
1322 if (!equal(a->relations, b->relations))
1324 if (a->mode != b->mode)
1331 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1333 if (!equal(a->constraints, b->constraints))
1335 if (a->deferred != b->deferred)
1342 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1344 if (!equalstr(a->name, b->name))
1346 if (!equal(a->options, b->options))
1353 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1355 if (!equalstr(a->name, b->name))
1357 if (a->action != b->action)
1359 if (!equal(a->listUsers, b->listUsers))
1366 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1368 if (!equalstr(a->name, b->name))
1375 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1377 if (a->reindexType != b->reindexType)
1379 if (!equal(a->relation, b->relation))
1381 if (!equalstr(a->name, b->name))
1383 if (a->force != b->force)
1385 if (a->all != b->all)
1392 _equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
1394 if (!equalstr(a->schemaname, b->schemaname))
1396 if (!equalstr(a->authid, b->authid))
1398 if (!equal(a->schemaElts, b->schemaElts))
1405 _equalAExpr(A_Expr *a, A_Expr *b)
1407 if (a->oper != b->oper)
1409 if (!equalstr(a->opname, b->opname))
1411 if (!equal(a->lexpr, b->lexpr))
1413 if (!equal(a->rexpr, b->rexpr))
1420 _equalColumnRef(ColumnRef *a, ColumnRef *b)
1422 if (!equal(a->fields, b->fields))
1424 if (!equal(a->indirection, b->indirection))
1431 _equalParamRef(ParamRef *a, ParamRef *b)
1433 if (a->number != b->number)
1435 if (!equal(a->fields, b->fields))
1437 if (!equal(a->indirection, b->indirection))
1444 _equalAConst(A_Const *a, A_Const *b)
1446 if (!equal(&a->val, &b->val))
1448 if (!equal(a->typename, b->typename))
1455 _equalIdent(Ident *a, Ident *b)
1457 if (!equalstr(a->name, b->name))
1464 _equalFuncCall(FuncCall *a, FuncCall *b)
1466 if (!equalstr(a->funcname, b->funcname))
1468 if (!equal(a->args, b->args))
1470 if (a->agg_star != b->agg_star)
1472 if (a->agg_distinct != b->agg_distinct)
1479 _equalAIndices(A_Indices *a, A_Indices *b)
1481 if (!equal(a->lidx, b->lidx))
1483 if (!equal(a->uidx, b->uidx))
1490 _equalExprFieldSelect(ExprFieldSelect *a, ExprFieldSelect *b)
1492 if (!equal(a->arg, b->arg))
1494 if (!equal(a->fields, b->fields))
1496 if (!equal(a->indirection, b->indirection))
1503 _equalResTarget(ResTarget *a, ResTarget *b)
1505 if (!equalstr(a->name, b->name))
1507 if (!equal(a->indirection, b->indirection))
1509 if (!equal(a->val, b->val))
1516 _equalTypeCast(TypeCast *a, TypeCast *b)
1518 if (!equal(a->arg, b->arg))
1520 if (!equal(a->typename, b->typename))
1527 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1529 if (!equalstr(a->useOp, b->useOp))
1531 if (!equal(a->node, b->node))
1538 _equalAlias(Alias *a, Alias *b)
1540 if (!equalstr(a->aliasname, b->aliasname))
1542 if (!equal(a->colnames, b->colnames))
1549 _equalRangeVar(RangeVar *a, RangeVar *b)
1551 if (!equalstr(a->catalogname, b->catalogname))
1553 if (!equalstr(a->schemaname, b->schemaname))
1555 if (!equalstr(a->relname, b->relname))
1557 if (a->inhOpt != b->inhOpt)
1559 if (a->istemp != b->istemp)
1561 if (!equal(a->alias, b->alias))
1568 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1570 if (!equal(a->subquery, b->subquery))
1572 if (!equal(a->alias, b->alias))
1579 _equalTypeName(TypeName *a, TypeName *b)
1581 if (!equal(a->names, b->names))
1583 if (a->typeid != b->typeid)
1585 if (a->timezone != b->timezone)
1587 if (a->setof != b->setof)
1589 if (a->pct_type != b->pct_type)
1591 if (a->typmod != b->typmod)
1593 if (!equal(a->arrayBounds, b->arrayBounds))
1600 _equalIndexElem(IndexElem *a, IndexElem *b)
1602 if (!equalstr(a->name, b->name))
1604 if (!equal(a->args, b->args))
1606 if (!equalstr(a->class, b->class))
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_DropTrigStmt:
2088 retval = _equalDropTrigStmt(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",