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.120 2002/03/21 16:00:39 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 (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 _equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
779 if (!equalstr(a->portalname, b->portalname))
786 _equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
788 if (!equal(a->relation, b->relation))
790 if (!equalstr(a->indexname, b->indexname))
797 _equalCopyStmt(CopyStmt *a, CopyStmt *b)
799 if (a->binary != b->binary)
801 if (!equal(a->relation, b->relation))
803 if (a->oids != b->oids)
805 if (a->direction != b->direction)
807 if (!equalstr(a->filename, b->filename))
809 if (!equalstr(a->delimiter, b->delimiter))
811 if (!equalstr(a->null_print, b->null_print))
818 _equalCreateStmt(CreateStmt *a, CreateStmt *b)
820 if (!equal(a->relation, b->relation))
822 if (!equal(a->tableElts, b->tableElts))
824 if (!equal(a->inhRelations, b->inhRelations))
826 if (!equal(a->constraints, b->constraints))
828 if (a->hasoids != b->hasoids)
835 _equalVersionStmt(VersionStmt *a, VersionStmt *b)
837 if (!equalstr(a->relname, b->relname))
839 if (a->direction != b->direction)
841 if (!equalstr(a->fromRelname, b->fromRelname))
843 if (!equalstr(a->date, b->date))
850 _equalDefineStmt(DefineStmt *a, DefineStmt *b)
852 if (a->defType != b->defType)
854 if (!equalstr(a->defname, b->defname))
856 if (!equal(a->definition, b->definition))
863 _equalDropStmt(DropStmt *a, DropStmt *b)
865 if (!equal(a->objects, b->objects))
867 if (a->removeType != b->removeType)
869 if (a->behavior != b->behavior)
876 _equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
878 if (!equal(a->relation, b->relation))
885 _equalCommentStmt(CommentStmt *a, CommentStmt *b)
887 if (a->objtype != b->objtype)
889 if (!equalstr(a->objname, b->objname))
891 if (!equalstr(a->objschema, b->objschema))
893 if (!equalstr(a->objproperty, b->objproperty))
895 if (!equal(a->objlist, b->objlist))
897 if (!equalstr(a->comment, b->comment))
904 _equalFetchStmt(FetchStmt *a, FetchStmt *b)
906 if (a->direction != b->direction)
908 if (a->howMany != b->howMany)
910 if (!equalstr(a->portalname, b->portalname))
912 if (a->ismove != b->ismove)
919 _equalIndexStmt(IndexStmt *a, IndexStmt *b)
921 if (!equalstr(a->idxname, b->idxname))
923 if (!equal(a->relation, b->relation))
925 if (!equalstr(a->accessMethod, b->accessMethod))
927 if (!equal(a->indexParams, b->indexParams))
929 if (!equal(a->whereClause, b->whereClause))
931 if (!equal(a->rangetable, b->rangetable))
933 if (a->unique != b->unique)
935 if (a->primary != b->primary)
942 _equalProcedureStmt(ProcedureStmt *a, ProcedureStmt *b)
944 if (a->replace != b->replace)
946 if (!equalstr(a->funcname, b->funcname))
948 if (!equal(a->argTypes, b->argTypes))
950 if (!equal(a->returnType, b->returnType))
952 if (!equal(a->withClause, b->withClause))
954 if (!equal(a->as, b->as))
956 if (!equalstr(a->language, b->language))
963 _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
965 if (!equalstr(a->aggname, b->aggname))
967 if (!equal(a->aggtype, b->aggtype))
974 _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
976 if (!equalstr(a->funcname, b->funcname))
978 if (!equal(a->args, b->args))
985 _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
987 if (!equalstr(a->opname, b->opname))
989 if (!equal(a->args, b->args))
997 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
999 if (!equal(a->relation, b->relation))
1001 if (!equalstr(a->column, b->column))
1003 if (!equalstr(a->newname, b->newname))
1010 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
1012 if (!equal(a->relation, b->relation))
1014 if (!equalstr(a->rulename, b->rulename))
1016 if (!equal(a->whereClause, b->whereClause))
1018 if (a->event != b->event)
1020 if (a->instead != b->instead)
1022 if (!equal(a->actions, b->actions))
1029 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1031 if (!equal(a->relation, b->relation))
1038 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1040 if (!equal(a->relation, b->relation))
1047 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1049 if (!equal(a->relation, b->relation))
1056 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1058 if (a->command != b->command)
1065 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1067 if (!equal(a->view, b->view))
1069 if (!equal(a->aliases, b->aliases))
1071 if (!equal(a->query, b->query))
1078 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1080 if (!equalstr(a->filename, b->filename))
1087 _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
1089 if (!equalstr(a->domainname, b->domainname))
1091 if (!equal(a->typename, b->typename))
1093 if (!equal(a->constraints, b->constraints))
1100 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1102 if (!equalstr(a->dbname, b->dbname))
1104 if (!equalstr(a->dbowner, b->dbowner))
1106 if (!equalstr(a->dbpath, b->dbpath))
1108 if (!equalstr(a->dbtemplate, b->dbtemplate))
1110 if (a->encoding != b->encoding)
1117 _equalAlterDatabaseSetStmt(AlterDatabaseSetStmt *a, AlterDatabaseSetStmt *b)
1119 if (!equalstr(a->dbname, b->dbname))
1121 if (!equalstr(a->variable, b->variable))
1123 if (!equal(a->value, b->value))
1130 _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
1132 if (!equalstr(a->dbname, b->dbname))
1139 _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
1141 if (a->vacuum != b->vacuum)
1143 if (a->full != b->full)
1145 if (a->analyze != b->analyze)
1147 if (a->freeze != b->freeze)
1149 if (a->verbose != b->verbose)
1151 if (!equal(a->relation, b->relation))
1153 if (!equal(a->va_cols, b->va_cols))
1160 _equalExplainStmt(ExplainStmt *a, ExplainStmt *b)
1162 if (!equal(a->query, b->query))
1164 if (a->verbose != b->verbose)
1166 if (a->analyze != b->analyze)
1173 _equalCreateSeqStmt(CreateSeqStmt *a, CreateSeqStmt *b)
1175 if (!equal(a->sequence, b->sequence))
1177 if (!equal(a->options, b->options))
1184 _equalVariableSetStmt(VariableSetStmt *a, VariableSetStmt *b)
1186 if (!equalstr(a->name, b->name))
1188 if (!equal(a->args, b->args))
1195 _equalVariableShowStmt(VariableShowStmt *a, VariableShowStmt *b)
1197 if (!equalstr(a->name, b->name))
1204 _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
1206 if (!equalstr(a->name, b->name))
1213 _equalCreateTrigStmt(CreateTrigStmt *a, CreateTrigStmt *b)
1215 if (!equalstr(a->trigname, b->trigname))
1217 if (!equal(a->relation, b->relation))
1219 if (!equalstr(a->funcname, b->funcname))
1221 if (!equal(a->args, b->args))
1223 if (a->before != b->before)
1225 if (a->row != b->row)
1227 if (strcmp(a->actions, b->actions) != 0)
1229 if (!equalstr(a->lang, b->lang))
1231 if (!equalstr(a->text, b->text))
1233 if (!equal(a->attr, b->attr))
1235 if (!equalstr(a->when, b->when))
1237 if (a->isconstraint != b->isconstraint)
1239 if (a->deferrable != b->deferrable)
1241 if (a->initdeferred != b->initdeferred)
1243 if (!equal(a->constrrel, b->constrrel))
1250 _equalDropTrigStmt(DropTrigStmt *a, DropTrigStmt *b)
1252 if (!equalstr(a->trigname, b->trigname))
1254 if (!equal(a->relation, b->relation))
1261 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1263 if (!equalstr(a->plname, b->plname))
1265 if (!equalstr(a->plhandler, b->plhandler))
1267 if (!equalstr(a->plcompiler, b->plcompiler))
1269 if (a->pltrusted != b->pltrusted)
1276 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1278 if (!equalstr(a->plname, b->plname))
1285 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1287 if (!equalstr(a->user, b->user))
1289 if (!equal(a->options, b->options))
1296 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1298 if (!equalstr(a->user, b->user))
1300 if (!equal(a->options, b->options))
1307 _equalAlterUserSetStmt(AlterUserSetStmt *a, AlterUserSetStmt *b)
1309 if (!equalstr(a->user, b->user))
1311 if (!equalstr(a->variable, b->variable))
1313 if (!equal(a->value, b->value))
1320 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1322 if (!equal(a->users, b->users))
1329 _equalLockStmt(LockStmt *a, LockStmt *b)
1331 if (!equal(a->relations, b->relations))
1333 if (a->mode != b->mode)
1340 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1342 if (!equal(a->constraints, b->constraints))
1344 if (a->deferred != b->deferred)
1351 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1353 if (!equalstr(a->name, b->name))
1355 if (!equal(a->options, b->options))
1362 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1364 if (!equalstr(a->name, b->name))
1366 if (a->action != b->action)
1368 if (!equal(a->listUsers, b->listUsers))
1375 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1377 if (!equalstr(a->name, b->name))
1384 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1386 if (a->reindexType != b->reindexType)
1388 if (!equal(a->relation, b->relation))
1390 if (!equalstr(a->name, b->name))
1392 if (a->force != b->force)
1394 if (a->all != b->all)
1401 _equalCreateSchemaStmt(CreateSchemaStmt *a, CreateSchemaStmt *b)
1403 if (!equalstr(a->schemaname, b->schemaname))
1405 if (!equalstr(a->authid, b->authid))
1407 if (!equal(a->schemaElts, b->schemaElts))
1414 _equalAExpr(A_Expr *a, A_Expr *b)
1416 if (a->oper != b->oper)
1418 if (!equalstr(a->opname, b->opname))
1420 if (!equal(a->lexpr, b->lexpr))
1422 if (!equal(a->rexpr, b->rexpr))
1429 _equalColumnRef(ColumnRef *a, ColumnRef *b)
1431 if (!equal(a->fields, b->fields))
1433 if (!equal(a->indirection, b->indirection))
1440 _equalParamRef(ParamRef *a, ParamRef *b)
1442 if (a->number != b->number)
1444 if (!equal(a->fields, b->fields))
1446 if (!equal(a->indirection, b->indirection))
1453 _equalAConst(A_Const *a, A_Const *b)
1455 if (!equal(&a->val, &b->val))
1457 if (!equal(a->typename, b->typename))
1464 _equalIdent(Ident *a, Ident *b)
1466 if (!equalstr(a->name, b->name))
1473 _equalFuncCall(FuncCall *a, FuncCall *b)
1475 if (!equalstr(a->funcname, b->funcname))
1477 if (!equal(a->args, b->args))
1479 if (a->agg_star != b->agg_star)
1481 if (a->agg_distinct != b->agg_distinct)
1488 _equalAIndices(A_Indices *a, A_Indices *b)
1490 if (!equal(a->lidx, b->lidx))
1492 if (!equal(a->uidx, b->uidx))
1499 _equalExprFieldSelect(ExprFieldSelect *a, ExprFieldSelect *b)
1501 if (!equal(a->arg, b->arg))
1503 if (!equal(a->fields, b->fields))
1505 if (!equal(a->indirection, b->indirection))
1512 _equalResTarget(ResTarget *a, ResTarget *b)
1514 if (!equalstr(a->name, b->name))
1516 if (!equal(a->indirection, b->indirection))
1518 if (!equal(a->val, b->val))
1525 _equalTypeCast(TypeCast *a, TypeCast *b)
1527 if (!equal(a->arg, b->arg))
1529 if (!equal(a->typename, b->typename))
1536 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1538 if (!equalstr(a->useOp, b->useOp))
1540 if (!equal(a->node, b->node))
1547 _equalAlias(Alias *a, Alias *b)
1549 if (!equalstr(a->aliasname, b->aliasname))
1551 if (!equal(a->colnames, b->colnames))
1558 _equalRangeVar(RangeVar *a, RangeVar *b)
1560 if (!equalstr(a->catalogname, b->catalogname))
1562 if (!equalstr(a->schemaname, b->schemaname))
1564 if (!equalstr(a->relname, b->relname))
1566 if (a->inhOpt != b->inhOpt)
1568 if (a->istemp != b->istemp)
1570 if (!equal(a->alias, b->alias))
1577 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1579 if (!equal(a->subquery, b->subquery))
1581 if (!equal(a->alias, b->alias))
1588 _equalTypeName(TypeName *a, TypeName *b)
1590 if (!equalstr(a->name, b->name))
1592 if (a->timezone != b->timezone)
1594 if (a->setof != b->setof)
1596 if (a->typmod != b->typmod)
1598 if (!equal(a->arrayBounds, b->arrayBounds))
1605 _equalIndexElem(IndexElem *a, IndexElem *b)
1607 if (!equalstr(a->name, b->name))
1609 if (!equal(a->args, b->args))
1611 if (!equalstr(a->class, b->class))
1618 _equalColumnDef(ColumnDef *a, ColumnDef *b)
1620 if (!equalstr(a->colname, b->colname))
1622 if (!equal(a->typename, b->typename))
1624 if (a->is_not_null != b->is_not_null)
1626 if (!equal(a->raw_default, b->raw_default))
1628 if (!equalstr(a->cooked_default, b->cooked_default))
1630 if (!equal(a->constraints, b->constraints))
1637 _equalConstraint(Constraint *a, Constraint *b)
1639 if (a->contype != b->contype)
1641 if (!equalstr(a->name, b->name))
1643 if (!equal(a->raw_expr, b->raw_expr))
1645 if (!equalstr(a->cooked_expr, b->cooked_expr))
1647 if (!equal(a->keys, b->keys))
1654 _equalDefElem(DefElem *a, DefElem *b)
1656 if (!equalstr(a->defname, b->defname))
1658 if (!equal(a->arg, b->arg))
1665 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
1667 if (!equal(a->resdom, b->resdom))
1669 if (!equal(a->fjoin, b->fjoin))
1671 if (!equal(a->expr, b->expr))
1678 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
1680 if (a->rtekind != b->rtekind)
1682 if (!equalstr(a->relname, b->relname))
1684 if (a->relid != b->relid)
1686 if (!equal(a->subquery, b->subquery))
1688 if (a->jointype != b->jointype)
1690 if (!equali(a->joincoltypes, b->joincoltypes))
1692 if (!equali(a->joincoltypmods, b->joincoltypmods))
1694 if (!equali(a->joinleftcols, b->joinleftcols))
1696 if (!equali(a->joinrightcols, b->joinrightcols))
1698 if (!equal(a->alias, b->alias))
1700 if (!equal(a->eref, b->eref))
1702 if (a->inh != b->inh)
1704 if (a->inFromCl != b->inFromCl)
1706 if (a->checkForRead != b->checkForRead)
1708 if (a->checkForWrite != b->checkForWrite)
1710 if (a->checkAsUser != b->checkAsUser)
1717 _equalSortClause(SortClause *a, SortClause *b)
1719 if (a->tleSortGroupRef != b->tleSortGroupRef)
1721 if (a->sortop != b->sortop)
1728 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
1730 if (!equalstr(a->constr_name, b->constr_name))
1732 if (!equal(a->pktable, b->pktable))
1734 if (!equal(a->fk_attrs, b->fk_attrs))
1736 if (!equal(a->pk_attrs, b->pk_attrs))
1738 if (!equalstr(a->match_type, b->match_type))
1740 if (a->actions != b->actions)
1742 if (a->deferrable != b->deferrable)
1744 if (a->initdeferred != b->initdeferred)
1751 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
1753 if (a->casetype != b->casetype)
1755 if (!equal(a->arg, b->arg))
1757 if (!equal(a->args, b->args))
1759 if (!equal(a->defresult, b->defresult))
1766 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
1768 if (!equal(a->expr, b->expr))
1770 if (!equal(a->result, b->result))
1777 _equalNullTest(NullTest *a, NullTest *b)
1779 if (!equal(a->arg, b->arg))
1781 if (a->nulltesttype != b->nulltesttype)
1787 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
1789 if (!equal(a->arg, b->arg))
1791 if (a->booltesttype != b->booltesttype)
1797 * Stuff from pg_list.h
1801 _equalValue(Value *a, Value *b)
1803 if (a->type != b->type)
1809 return a->val.ival == b->val.ival;
1813 return strcmp(a->val.str, b->val.str) == 0;
1823 * returns whether two nodes are equal
1826 equal(void *a, void *b)
1828 bool retval = false;
1834 * note that a!=b, so only one of them can be NULL
1836 if (a == NULL || b == NULL)
1840 * are they the same type of nodes?
1842 if (nodeTag(a) != nodeTag(b))
1848 retval = _equalSubPlan(a, b);
1852 retval = _equalResdom(a, b);
1855 retval = _equalFjoin(a, b);
1858 retval = _equalExpr(a, b);
1861 retval = _equalVar(a, b);
1864 retval = _equalOper(a, b);
1867 retval = _equalConst(a, b);
1870 retval = _equalParam(a, b);
1873 retval = _equalAggref(a, b);
1876 retval = _equalSubLink(a, b);
1879 retval = _equalFunc(a, b);
1882 retval = _equalFieldSelect(a, b);
1885 retval = _equalArrayRef(a, b);
1888 retval = _equalIter(a, b);
1891 retval = _equalRelabelType(a, b);
1894 retval = _equalRangeTblRef(a, b);
1897 retval = _equalFromExpr(a, b);
1900 retval = _equalJoinExpr(a, b);
1904 retval = _equalRelOptInfo(a, b);
1907 retval = _equalPath(a, b);
1910 retval = _equalIndexPath(a, b);
1913 retval = _equalNestPath(a, b);
1916 retval = _equalMergePath(a, b);
1919 retval = _equalHashPath(a, b);
1922 retval = _equalPathKeyItem(a, b);
1924 case T_RestrictInfo:
1925 retval = _equalRestrictInfo(a, b);
1928 retval = _equalJoinInfo(a, b);
1931 retval = _equalStream(a, b);
1934 retval = _equalTidPath(a, b);
1937 retval = _equalAppendPath(a, b);
1939 case T_IndexOptInfo:
1940 retval = _equalIndexOptInfo(a, b);
1945 List *la = (List *) a;
1946 List *lb = (List *) b;
1950 * Try to reject by length check before we grovel through
1951 * all the elements...
1953 if (length(la) != length(lb))
1957 if (!equal(lfirst(l), lfirst(lb)))
1968 retval = _equalValue(a, b);
1972 retval = _equalQuery(a, b);
1975 retval = _equalInsertStmt(a, b);
1978 retval = _equalDeleteStmt(a, b);
1981 retval = _equalUpdateStmt(a, b);
1984 retval = _equalSelectStmt(a, b);
1986 case T_SetOperationStmt:
1987 retval = _equalSetOperationStmt(a, b);
1989 case T_AlterTableStmt:
1990 retval = _equalAlterTableStmt(a, b);
1993 retval = _equalGrantStmt(a, b);
1995 case T_ClosePortalStmt:
1996 retval = _equalClosePortalStmt(a, b);
1999 retval = _equalClusterStmt(a, b);
2002 retval = _equalCopyStmt(a, b);
2005 retval = _equalCreateStmt(a, b);
2008 retval = _equalVersionStmt(a, b);
2011 retval = _equalDefineStmt(a, b);
2014 retval = _equalDropStmt(a, b);
2016 case T_TruncateStmt:
2017 retval = _equalTruncateStmt(a, b);
2020 retval = _equalCommentStmt(a, b);
2023 retval = _equalFetchStmt(a, b);
2026 retval = _equalIndexStmt(a, b);
2028 case T_ProcedureStmt:
2029 retval = _equalProcedureStmt(a, b);
2031 case T_RemoveAggrStmt:
2032 retval = _equalRemoveAggrStmt(a, b);
2034 case T_RemoveFuncStmt:
2035 retval = _equalRemoveFuncStmt(a, b);
2037 case T_RemoveOperStmt:
2038 retval = _equalRemoveOperStmt(a, b);
2041 retval = _equalRenameStmt(a, b);
2044 retval = _equalRuleStmt(a, b);
2047 retval = _equalNotifyStmt(a, b);
2050 retval = _equalListenStmt(a, b);
2052 case T_UnlistenStmt:
2053 retval = _equalUnlistenStmt(a, b);
2055 case T_TransactionStmt:
2056 retval = _equalTransactionStmt(a, b);
2059 retval = _equalViewStmt(a, b);
2062 retval = _equalLoadStmt(a, b);
2064 case T_CreateDomainStmt:
2065 retval = _equalCreateDomainStmt(a, b);
2067 case T_CreatedbStmt:
2068 retval = _equalCreatedbStmt(a, b);
2070 case T_AlterDatabaseSetStmt:
2071 retval = _equalAlterDatabaseSetStmt(a, b);
2074 retval = _equalDropdbStmt(a, b);
2077 retval = _equalVacuumStmt(a, b);
2080 retval = _equalExplainStmt(a, b);
2082 case T_CreateSeqStmt:
2083 retval = _equalCreateSeqStmt(a, b);
2085 case T_VariableSetStmt:
2086 retval = _equalVariableSetStmt(a, b);
2088 case T_VariableShowStmt:
2089 retval = _equalVariableShowStmt(a, b);
2091 case T_VariableResetStmt:
2092 retval = _equalVariableResetStmt(a, b);
2094 case T_CreateTrigStmt:
2095 retval = _equalCreateTrigStmt(a, b);
2097 case T_DropTrigStmt:
2098 retval = _equalDropTrigStmt(a, b);
2100 case T_CreatePLangStmt:
2101 retval = _equalCreatePLangStmt(a, b);
2103 case T_DropPLangStmt:
2104 retval = _equalDropPLangStmt(a, b);
2106 case T_CreateUserStmt:
2107 retval = _equalCreateUserStmt(a, b);
2109 case T_AlterUserStmt:
2110 retval = _equalAlterUserStmt(a, b);
2112 case T_AlterUserSetStmt:
2113 retval = _equalAlterUserSetStmt(a, b);
2115 case T_DropUserStmt:
2116 retval = _equalDropUserStmt(a, b);
2119 retval = _equalLockStmt(a, b);
2121 case T_ConstraintsSetStmt:
2122 retval = _equalConstraintsSetStmt(a, b);
2124 case T_CreateGroupStmt:
2125 retval = _equalCreateGroupStmt(a, b);
2127 case T_AlterGroupStmt:
2128 retval = _equalAlterGroupStmt(a, b);
2130 case T_DropGroupStmt:
2131 retval = _equalDropGroupStmt(a, b);
2134 retval = _equalReindexStmt(a, b);
2136 case T_CheckPointStmt:
2139 case T_CreateSchemaStmt:
2140 retval = _equalCreateSchemaStmt(a, b);
2144 retval = _equalAExpr(a, b);
2147 retval = _equalColumnRef(a, b);
2150 retval = _equalParamRef(a, b);
2153 retval = _equalAConst(a, b);
2156 retval = _equalIdent(a, b);
2159 retval = _equalFuncCall(a, b);
2162 retval = _equalAIndices(a, b);
2164 case T_ExprFieldSelect:
2165 retval = _equalExprFieldSelect(a, b);
2168 retval = _equalResTarget(a, b);
2171 retval = _equalTypeCast(a, b);
2174 retval = _equalSortGroupBy(a, b);
2177 retval = _equalAlias(a, b);
2180 retval = _equalRangeVar(a, b);
2182 case T_RangeSubselect:
2183 retval = _equalRangeSubselect(a, b);
2186 retval = _equalTypeName(a, b);
2189 retval = _equalIndexElem(a, b);
2192 retval = _equalColumnDef(a, b);
2195 retval = _equalConstraint(a, b);
2198 retval = _equalDefElem(a, b);
2201 retval = _equalTargetEntry(a, b);
2203 case T_RangeTblEntry:
2204 retval = _equalRangeTblEntry(a, b);
2207 retval = _equalSortClause(a, b);
2210 /* GroupClause is equivalent to SortClause */
2211 retval = _equalSortClause(a, b);
2214 retval = _equalCaseExpr(a, b);
2217 retval = _equalCaseWhen(a, b);
2220 retval = _equalNullTest(a, b);
2223 retval = _equalBooleanTest(a, b);
2225 case T_FkConstraint:
2226 retval = _equalFkConstraint(a, b);
2229 retval = _equalPrivGrantee(a, b);
2231 case T_FuncWithArgs:
2232 retval = _equalFuncWithArgs(a, b);
2236 elog(WARNING, "equal: don't know whether nodes of type %d are equal",