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.111 2002/02/26 22:47:05 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 (!equal(a->colnames, b->colnames))
340 if (!equal(a->colvars, b->colvars))
347 * Stuff from relation.h
351 _equalRelOptInfo(RelOptInfo *a, RelOptInfo *b)
354 * We treat RelOptInfos as equal if they refer to the same base rels
355 * joined in the same order. Is this appropriate/sufficient?
357 return equali(a->relids, b->relids);
361 _equalIndexOptInfo(IndexOptInfo *a, IndexOptInfo *b)
364 * We treat IndexOptInfos as equal if they refer to the same index. Is
367 if (a->indexoid != b->indexoid)
373 _equalPathKeyItem(PathKeyItem *a, PathKeyItem *b)
375 if (a->sortop != b->sortop)
377 if (!equal(a->key, b->key))
383 _equalPath(Path *a, Path *b)
385 if (a->pathtype != b->pathtype)
387 if (!equal(a->parent, b->parent))
391 * do not check path costs, since they may not be set yet, and being
392 * float values there are roundoff error issues anyway...
394 if (!equal(a->pathkeys, b->pathkeys))
400 _equalIndexPath(IndexPath *a, IndexPath *b)
402 if (!_equalPath((Path *) a, (Path *) b))
404 if (!equal(a->indexinfo, b->indexinfo))
406 if (!equal(a->indexqual, b->indexqual))
408 if (a->indexscandir != b->indexscandir)
410 if (!equali(a->joinrelids, b->joinrelids))
412 if (a->alljoinquals != b->alljoinquals)
416 * Skip 'rows' because of possibility of floating-point roundoff
417 * error. It should be derivable from the other fields anyway.
423 _equalTidPath(TidPath *a, TidPath *b)
425 if (!_equalPath((Path *) a, (Path *) b))
427 if (!equal(a->tideval, b->tideval))
429 if (!equali(a->unjoined_relids, b->unjoined_relids))
435 _equalAppendPath(AppendPath *a, AppendPath *b)
437 if (!_equalPath((Path *) a, (Path *) b))
439 if (!equal(a->subpaths, b->subpaths))
445 _equalJoinPath(JoinPath *a, JoinPath *b)
447 if (!_equalPath((Path *) a, (Path *) b))
449 if (a->jointype != b->jointype)
451 if (!equal(a->outerjoinpath, b->outerjoinpath))
453 if (!equal(a->innerjoinpath, b->innerjoinpath))
455 if (!equal(a->joinrestrictinfo, b->joinrestrictinfo))
461 _equalNestPath(NestPath *a, NestPath *b)
463 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
469 _equalMergePath(MergePath *a, MergePath *b)
471 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
473 if (!equal(a->path_mergeclauses, b->path_mergeclauses))
475 if (!equal(a->outersortkeys, b->outersortkeys))
477 if (!equal(a->innersortkeys, b->innersortkeys))
483 _equalHashPath(HashPath *a, HashPath *b)
485 if (!_equalJoinPath((JoinPath *) a, (JoinPath *) b))
487 if (!equal(a->path_hashclauses, b->path_hashclauses))
493 _equalSubPlan(SubPlan *a, SubPlan *b)
495 /* should compare plans, but have to settle for comparing plan IDs */
496 if (a->plan_id != b->plan_id)
499 if (!equal(a->rtable, b->rtable))
502 if (!equal(a->sublink, b->sublink))
509 _equalRestrictInfo(RestrictInfo *a, RestrictInfo *b)
511 if (!equal(a->clause, b->clause))
513 if (a->ispusheddown != b->ispusheddown)
517 * We ignore eval_cost, this_selec, left/right_pathkey, and
518 * left/right_bucketsize, since they may not be set yet, and should be
519 * derivable from the clause anyway. Probably it's not really
520 * necessary to compare any of these remaining fields ...
522 if (!equal(a->subclauseindices, b->subclauseindices))
524 if (a->mergejoinoperator != b->mergejoinoperator)
526 if (a->left_sortop != b->left_sortop)
528 if (a->right_sortop != b->right_sortop)
530 if (a->hashjoinoperator != b->hashjoinoperator)
536 _equalJoinInfo(JoinInfo *a, JoinInfo *b)
538 if (!equali(a->unjoined_relids, b->unjoined_relids))
540 if (!equal(a->jinfo_restrictinfo, b->jinfo_restrictinfo))
546 _equalIter(Iter *a, Iter *b)
548 return equal(a->iterexpr, b->iterexpr);
552 _equalStream(Stream *a, Stream *b)
554 if (a->clausetype != b->clausetype)
556 if (a->groupup != b->groupup)
558 if (a->groupcost != b->groupcost)
560 if (a->groupsel != b->groupsel)
562 if (!equal(a->pathptr, b->pathptr))
564 if (!equal(a->cinfo, b->cinfo))
566 if (!equal(a->upstream, b->upstream))
568 return equal(a->downstream, b->downstream);
572 * Stuff from parsenodes.h
576 _equalQuery(Query *a, Query *b)
578 if (a->commandType != b->commandType)
580 if (!equal(a->utilityStmt, b->utilityStmt))
582 if (a->resultRelation != b->resultRelation)
584 if (!equalstr(a->into, b->into))
586 if (a->isPortal != b->isPortal)
588 if (a->isBinary != b->isBinary)
590 if (a->isTemp != b->isTemp)
592 if (a->hasAggs != b->hasAggs)
594 if (a->hasSubLinks != b->hasSubLinks)
596 /* we deliberately ignore originalQuery */
597 if (!equal(a->rtable, b->rtable))
599 if (!equal(a->jointree, b->jointree))
601 if (!equali(a->rowMarks, b->rowMarks))
603 if (!equal(a->targetList, b->targetList))
605 if (!equal(a->groupClause, b->groupClause))
607 if (!equal(a->havingQual, b->havingQual))
609 if (!equal(a->distinctClause, b->distinctClause))
611 if (!equal(a->sortClause, b->sortClause))
613 if (!equal(a->limitOffset, b->limitOffset))
615 if (!equal(a->limitCount, b->limitCount))
617 if (!equal(a->setOperations, b->setOperations))
619 if (!equali(a->resultRelations, b->resultRelations))
623 * We do not check the internal-to-the-planner fields: base_rel_list,
624 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys. They
625 * might not be set yet, and in any case they should be derivable from
632 _equalInsertStmt(InsertStmt *a, InsertStmt *b)
634 if (!equalstr(a->relname, b->relname))
636 if (!equal(a->cols, b->cols))
638 if (!equal(a->targetList, b->targetList))
640 if (!equal(a->selectStmt, b->selectStmt))
647 _equalDeleteStmt(DeleteStmt *a, DeleteStmt *b)
649 if (!equalstr(a->relname, b->relname))
651 if (!equal(a->whereClause, b->whereClause))
653 if (a->inhOpt != b->inhOpt)
660 _equalUpdateStmt(UpdateStmt *a, UpdateStmt *b)
662 if (!equalstr(a->relname, b->relname))
664 if (!equal(a->targetList, b->targetList))
666 if (!equal(a->whereClause, b->whereClause))
668 if (!equal(a->fromClause, b->fromClause))
670 if (a->inhOpt != b->inhOpt)
677 _equalSelectStmt(SelectStmt *a, SelectStmt *b)
679 if (!equal(a->distinctClause, b->distinctClause))
681 if (!equalstr(a->into, b->into))
683 if (a->istemp != b->istemp)
685 if (!equal(a->intoColNames, b->intoColNames))
687 if (!equal(a->targetList, b->targetList))
689 if (!equal(a->fromClause, b->fromClause))
691 if (!equal(a->whereClause, b->whereClause))
693 if (!equal(a->groupClause, b->groupClause))
695 if (!equal(a->havingClause, b->havingClause))
697 if (!equal(a->sortClause, b->sortClause))
699 if (!equalstr(a->portalname, b->portalname))
701 if (a->binary != b->binary)
703 if (!equal(a->limitOffset, b->limitOffset))
705 if (!equal(a->limitCount, b->limitCount))
707 if (!equal(a->forUpdate, b->forUpdate))
711 if (a->all != b->all)
713 if (!equal(a->larg, b->larg))
715 if (!equal(a->rarg, b->rarg))
722 _equalSetOperationStmt(SetOperationStmt *a, SetOperationStmt *b)
726 if (a->all != b->all)
728 if (!equal(a->larg, b->larg))
730 if (!equal(a->rarg, b->rarg))
732 if (!equali(a->colTypes, b->colTypes))
739 _equalAlterTableStmt(AlterTableStmt *a, AlterTableStmt *b)
741 if (a->subtype != b->subtype)
743 if (!equalstr(a->relname, b->relname))
745 if (a->inhOpt != b->inhOpt)
747 if (!equalstr(a->name, b->name))
749 if (!equal(a->def, b->def))
751 if (a->behavior != b->behavior)
758 _equalGrantStmt(GrantStmt *a, GrantStmt *b)
760 if (a->is_grant != b->is_grant)
762 if (a->objtype != b->objtype)
764 if (!equal(a->objects, b->objects))
766 if (!equal(a->privileges, b->privileges))
768 if (!equal(a->grantees, b->grantees))
775 _equalPrivGrantee(PrivGrantee *a, PrivGrantee *b)
777 return equalstr(a->username, b->username)
778 && equalstr(a->groupname, b->groupname);
782 _equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
784 return equalstr(a->funcname, b->funcname)
785 && equal(a->funcargs, b->funcargs);
789 _equalClosePortalStmt(ClosePortalStmt *a, ClosePortalStmt *b)
791 if (!equalstr(a->portalname, b->portalname))
798 _equalClusterStmt(ClusterStmt *a, ClusterStmt *b)
800 if (!equalstr(a->relname, b->relname))
802 if (!equalstr(a->indexname, b->indexname))
809 _equalCopyStmt(CopyStmt *a, CopyStmt *b)
811 if (a->binary != b->binary)
813 if (!equalstr(a->relname, b->relname))
815 if (a->oids != b->oids)
817 if (a->direction != b->direction)
819 if (!equalstr(a->filename, b->filename))
821 if (!equalstr(a->delimiter, b->delimiter))
823 if (!equalstr(a->null_print, b->null_print))
830 _equalCreateStmt(CreateStmt *a, CreateStmt *b)
832 if (!equalstr(a->relname, b->relname))
834 if (!equal(a->tableElts, b->tableElts))
836 if (!equal(a->inhRelnames, b->inhRelnames))
838 if (!equal(a->constraints, b->constraints))
840 if (a->istemp != b->istemp)
842 if (a->hasoids != b->hasoids)
849 _equalVersionStmt(VersionStmt *a, VersionStmt *b)
851 if (!equalstr(a->relname, b->relname))
853 if (a->direction != b->direction)
855 if (!equalstr(a->fromRelname, b->fromRelname))
857 if (!equalstr(a->date, b->date))
864 _equalDefineStmt(DefineStmt *a, DefineStmt *b)
866 if (a->defType != b->defType)
868 if (!equalstr(a->defname, b->defname))
870 if (!equal(a->definition, b->definition))
877 _equalDropStmt(DropStmt *a, DropStmt *b)
879 if (!equal(a->names, b->names))
881 if (a->removeType != b->removeType)
888 _equalTruncateStmt(TruncateStmt *a, TruncateStmt *b)
890 if (!equalstr(a->relName, b->relName))
897 _equalCommentStmt(CommentStmt *a, CommentStmt *b)
899 if (a->objtype != b->objtype)
901 if (!equalstr(a->objname, b->objname))
903 if (!equalstr(a->objproperty, b->objproperty))
905 if (!equal(a->objlist, b->objlist))
907 if (!equalstr(a->comment, b->comment))
914 _equalFetchStmt(FetchStmt *a, FetchStmt *b)
916 if (a->direction != b->direction)
918 if (a->howMany != b->howMany)
920 if (!equalstr(a->portalname, b->portalname))
922 if (a->ismove != b->ismove)
929 _equalIndexStmt(IndexStmt *a, IndexStmt *b)
931 if (!equalstr(a->idxname, b->idxname))
933 if (!equalstr(a->relname, b->relname))
935 if (!equalstr(a->accessMethod, b->accessMethod))
937 if (!equal(a->indexParams, b->indexParams))
939 if (!equal(a->whereClause, b->whereClause))
941 if (!equal(a->rangetable, b->rangetable))
943 if (a->unique != b->unique)
945 if (a->primary != b->primary)
952 _equalProcedureStmt(ProcedureStmt *a, ProcedureStmt *b)
954 if (a->replace != b->replace)
956 if (!equalstr(a->funcname, b->funcname))
958 if (!equal(a->argTypes, b->argTypes))
960 if (!equal(a->returnType, b->returnType))
962 if (!equal(a->withClause, b->withClause))
964 if (!equal(a->as, b->as))
966 if (!equalstr(a->language, b->language))
973 _equalRemoveAggrStmt(RemoveAggrStmt *a, RemoveAggrStmt *b)
975 if (!equalstr(a->aggname, b->aggname))
977 if (!equal(a->aggtype, b->aggtype))
984 _equalRemoveFuncStmt(RemoveFuncStmt *a, RemoveFuncStmt *b)
986 if (!equalstr(a->funcname, b->funcname))
988 if (!equal(a->args, b->args))
995 _equalRemoveOperStmt(RemoveOperStmt *a, RemoveOperStmt *b)
997 if (!equalstr(a->opname, b->opname))
999 if (!equal(a->args, b->args))
1007 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
1009 if (!equalstr(a->relname, b->relname))
1011 if (a->inhOpt != b->inhOpt)
1013 if (!equalstr(a->column, b->column))
1015 if (!equalstr(a->newname, b->newname))
1022 _equalRuleStmt(RuleStmt *a, RuleStmt *b)
1024 if (!equalstr(a->rulename, b->rulename))
1026 if (!equal(a->whereClause, b->whereClause))
1028 if (a->event != b->event)
1030 if (!equal(a->object, b->object))
1032 if (a->instead != b->instead)
1034 if (!equal(a->actions, b->actions))
1041 _equalNotifyStmt(NotifyStmt *a, NotifyStmt *b)
1043 if (!equalstr(a->relname, b->relname))
1050 _equalListenStmt(ListenStmt *a, ListenStmt *b)
1052 if (!equalstr(a->relname, b->relname))
1059 _equalUnlistenStmt(UnlistenStmt *a, UnlistenStmt *b)
1061 if (!equalstr(a->relname, b->relname))
1068 _equalTransactionStmt(TransactionStmt *a, TransactionStmt *b)
1070 if (a->command != b->command)
1077 _equalViewStmt(ViewStmt *a, ViewStmt *b)
1079 if (!equalstr(a->viewname, b->viewname))
1081 if (!equal(a->aliases, b->aliases))
1083 if (!equal(a->query, b->query))
1090 _equalLoadStmt(LoadStmt *a, LoadStmt *b)
1092 if (!equalstr(a->filename, b->filename))
1099 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
1101 if (!equalstr(a->dbname, b->dbname))
1103 if (!equalstr(a->dbowner, b->dbowner))
1105 if (!equalstr(a->dbpath, b->dbpath))
1107 if (!equalstr(a->dbtemplate, b->dbtemplate))
1109 if (a->encoding != b->encoding)
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 (!equalstr(a->vacrel, b->vacrel))
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 (!equalstr(a->seqname, b->seqname))
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 (!equalstr(a->relname, b->relname))
1205 if (!equalstr(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 (!equalstr(a->constrrelname, b->constrrelname))
1236 _equalDropTrigStmt(DropTrigStmt *a, DropTrigStmt *b)
1238 if (!equalstr(a->trigname, b->trigname))
1240 if (!equalstr(a->relname, b->relname))
1247 _equalCreatePLangStmt(CreatePLangStmt *a, CreatePLangStmt *b)
1249 if (!equalstr(a->plname, b->plname))
1251 if (!equalstr(a->plhandler, b->plhandler))
1253 if (!equalstr(a->plcompiler, b->plcompiler))
1255 if (a->pltrusted != b->pltrusted)
1262 _equalDropPLangStmt(DropPLangStmt *a, DropPLangStmt *b)
1264 if (!equalstr(a->plname, b->plname))
1271 _equalCreateUserStmt(CreateUserStmt *a, CreateUserStmt *b)
1273 if (!equalstr(a->user, b->user))
1275 if (!equal(a->options, b->options))
1282 _equalAlterUserStmt(AlterUserStmt *a, AlterUserStmt *b)
1284 if (!equalstr(a->user, b->user))
1286 if (!equal(a->options, b->options))
1293 _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
1295 if (!equal(a->users, b->users))
1302 _equalLockStmt(LockStmt *a, LockStmt *b)
1304 if (!equal(a->rellist, b->rellist))
1306 if (a->mode != b->mode)
1313 _equalConstraintsSetStmt(ConstraintsSetStmt *a, ConstraintsSetStmt *b)
1315 if (!equal(a->constraints, b->constraints))
1317 if (a->deferred != b->deferred)
1324 _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
1326 if (!equalstr(a->name, b->name))
1328 if (!equal(a->options, b->options))
1335 _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
1337 if (!equalstr(a->name, b->name))
1339 if (a->action != b->action)
1341 if (!equal(a->listUsers, b->listUsers))
1348 _equalDropGroupStmt(DropGroupStmt *a, DropGroupStmt *b)
1350 if (!equalstr(a->name, b->name))
1357 _equalReindexStmt(ReindexStmt *a, ReindexStmt *b)
1359 if (a->reindexType != b->reindexType)
1361 if (!equalstr(a->name, b->name))
1363 if (a->force != b->force)
1365 if (a->all != b->all)
1372 _equalAExpr(A_Expr *a, A_Expr *b)
1374 if (a->oper != b->oper)
1376 if (!equalstr(a->opname, b->opname))
1378 if (!equal(a->lexpr, b->lexpr))
1380 if (!equal(a->rexpr, b->rexpr))
1387 _equalAttr(Attr *a, Attr *b)
1389 if (strcmp(a->relname, b->relname) != 0)
1391 if (!equal(a->paramNo, b->paramNo))
1393 if (!equal(a->attrs, b->attrs))
1395 if (!equal(a->indirection, b->indirection))
1402 _equalAConst(A_Const *a, A_Const *b)
1404 if (!equal(&a->val, &b->val))
1406 if (!equal(a->typename, b->typename))
1413 _equalParamNo(ParamNo *a, ParamNo *b)
1415 if (a->number != b->number)
1417 if (!equal(a->typename, b->typename))
1419 if (!equal(a->indirection, b->indirection))
1426 _equalIdent(Ident *a, Ident *b)
1428 if (!equalstr(a->name, b->name))
1430 if (!equal(a->indirection, b->indirection))
1432 if (a->isRel != b->isRel)
1439 _equalFuncCall(FuncCall *a, FuncCall *b)
1441 if (!equalstr(a->funcname, b->funcname))
1443 if (!equal(a->args, b->args))
1445 if (a->agg_star != b->agg_star)
1447 if (a->agg_distinct != b->agg_distinct)
1454 _equalAIndices(A_Indices *a, A_Indices *b)
1456 if (!equal(a->lidx, b->lidx))
1458 if (!equal(a->uidx, b->uidx))
1465 _equalResTarget(ResTarget *a, ResTarget *b)
1467 if (!equalstr(a->name, b->name))
1469 if (!equal(a->indirection, b->indirection))
1471 if (!equal(a->val, b->val))
1478 _equalTypeCast(TypeCast *a, TypeCast *b)
1480 if (!equal(a->arg, b->arg))
1482 if (!equal(a->typename, b->typename))
1489 _equalSortGroupBy(SortGroupBy *a, SortGroupBy *b)
1491 if (!equalstr(a->useOp, b->useOp))
1493 if (!equal(a->node, b->node))
1500 _equalRangeVar(RangeVar *a, RangeVar *b)
1502 if (!equalstr(a->relname, b->relname))
1504 if (a->inhOpt != b->inhOpt)
1506 if (!equal(a->name, b->name))
1513 _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
1515 if (!equal(a->subquery, b->subquery))
1517 if (!equal(a->name, b->name))
1524 _equalTypeName(TypeName *a, TypeName *b)
1526 if (!equalstr(a->name, b->name))
1528 if (a->timezone != b->timezone)
1530 if (a->setof != b->setof)
1532 if (a->typmod != b->typmod)
1534 if (!equal(a->arrayBounds, b->arrayBounds))
1541 _equalIndexElem(IndexElem *a, IndexElem *b)
1543 if (!equalstr(a->name, b->name))
1545 if (!equal(a->args, b->args))
1547 if (!equalstr(a->class, b->class))
1554 _equalColumnDef(ColumnDef *a, ColumnDef *b)
1556 if (!equalstr(a->colname, b->colname))
1558 if (!equal(a->typename, b->typename))
1560 if (a->is_not_null != b->is_not_null)
1562 if (!equal(a->raw_default, b->raw_default))
1564 if (!equalstr(a->cooked_default, b->cooked_default))
1566 if (!equal(a->constraints, b->constraints))
1573 _equalConstraint(Constraint *a, Constraint *b)
1575 if (a->contype != b->contype)
1577 if (!equalstr(a->name, b->name))
1579 if (!equal(a->raw_expr, b->raw_expr))
1581 if (!equalstr(a->cooked_expr, b->cooked_expr))
1583 if (!equal(a->keys, b->keys))
1590 _equalDefElem(DefElem *a, DefElem *b)
1592 if (!equalstr(a->defname, b->defname))
1594 if (!equal(a->arg, b->arg))
1601 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
1603 if (!equal(a->resdom, b->resdom))
1605 if (!equal(a->fjoin, b->fjoin))
1607 if (!equal(a->expr, b->expr))
1614 _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
1616 if (!equalstr(a->relname, b->relname))
1618 if (a->relid != b->relid)
1620 if (!equal(a->subquery, b->subquery))
1622 if (!equal(a->alias, b->alias))
1624 if (!equal(a->eref, b->eref))
1626 if (a->inh != b->inh)
1628 if (a->inFromCl != b->inFromCl)
1630 if (a->checkForRead != b->checkForRead)
1632 if (a->checkForWrite != b->checkForWrite)
1634 if (a->checkAsUser != b->checkAsUser)
1641 _equalSortClause(SortClause *a, SortClause *b)
1643 if (a->tleSortGroupRef != b->tleSortGroupRef)
1645 if (a->sortop != b->sortop)
1652 _equalFkConstraint(FkConstraint *a, FkConstraint *b)
1654 if (!equalstr(a->constr_name, b->constr_name))
1656 if (!equalstr(a->pktable_name, b->pktable_name))
1658 if (!equal(a->fk_attrs, b->fk_attrs))
1660 if (!equal(a->pk_attrs, b->pk_attrs))
1662 if (!equalstr(a->match_type, b->match_type))
1664 if (a->actions != b->actions)
1666 if (a->deferrable != b->deferrable)
1668 if (a->initdeferred != b->initdeferred)
1675 _equalCaseExpr(CaseExpr *a, CaseExpr *b)
1677 if (a->casetype != b->casetype)
1679 if (!equal(a->arg, b->arg))
1681 if (!equal(a->args, b->args))
1683 if (!equal(a->defresult, b->defresult))
1690 _equalCaseWhen(CaseWhen *a, CaseWhen *b)
1692 if (!equal(a->expr, b->expr))
1694 if (!equal(a->result, b->result))
1701 _equalNullTest(NullTest *a, NullTest *b)
1703 if (!equal(a->arg, b->arg))
1705 if (a->nulltesttype != b->nulltesttype)
1711 _equalBooleanTest(BooleanTest *a, BooleanTest *b)
1713 if (!equal(a->arg, b->arg))
1715 if (a->booltesttype != b->booltesttype)
1721 * Stuff from pg_list.h
1725 _equalValue(Value *a, Value *b)
1727 if (a->type != b->type)
1733 return a->val.ival == b->val.ival;
1737 return strcmp(a->val.str, b->val.str) == 0;
1747 * returns whether two nodes are equal
1750 equal(void *a, void *b)
1752 bool retval = false;
1758 * note that a!=b, so only one of them can be NULL
1760 if (a == NULL || b == NULL)
1764 * are they the same type of nodes?
1766 if (nodeTag(a) != nodeTag(b))
1772 retval = _equalSubPlan(a, b);
1776 retval = _equalResdom(a, b);
1779 retval = _equalFjoin(a, b);
1782 retval = _equalExpr(a, b);
1785 retval = _equalVar(a, b);
1788 retval = _equalOper(a, b);
1791 retval = _equalConst(a, b);
1794 retval = _equalParam(a, b);
1797 retval = _equalAggref(a, b);
1800 retval = _equalSubLink(a, b);
1803 retval = _equalFunc(a, b);
1806 retval = _equalFieldSelect(a, b);
1809 retval = _equalArrayRef(a, b);
1812 retval = _equalIter(a, b);
1815 retval = _equalRelabelType(a, b);
1818 retval = _equalRangeTblRef(a, b);
1821 retval = _equalFromExpr(a, b);
1824 retval = _equalJoinExpr(a, b);
1828 retval = _equalRelOptInfo(a, b);
1831 retval = _equalPath(a, b);
1834 retval = _equalIndexPath(a, b);
1837 retval = _equalNestPath(a, b);
1840 retval = _equalMergePath(a, b);
1843 retval = _equalHashPath(a, b);
1846 retval = _equalPathKeyItem(a, b);
1848 case T_RestrictInfo:
1849 retval = _equalRestrictInfo(a, b);
1852 retval = _equalJoinInfo(a, b);
1855 retval = _equalStream(a, b);
1858 retval = _equalTidPath(a, b);
1861 retval = _equalAppendPath(a, b);
1863 case T_IndexOptInfo:
1864 retval = _equalIndexOptInfo(a, b);
1869 List *la = (List *) a;
1870 List *lb = (List *) b;
1874 * Try to reject by length check before we grovel through
1875 * all the elements...
1877 if (length(la) != length(lb))
1881 if (!equal(lfirst(l), lfirst(lb)))
1892 retval = _equalValue(a, b);
1896 retval = _equalQuery(a, b);
1899 retval = _equalInsertStmt(a, b);
1902 retval = _equalDeleteStmt(a, b);
1905 retval = _equalUpdateStmt(a, b);
1908 retval = _equalSelectStmt(a, b);
1910 case T_SetOperationStmt:
1911 retval = _equalSetOperationStmt(a, b);
1913 case T_AlterTableStmt:
1914 retval = _equalAlterTableStmt(a, b);
1917 retval = _equalGrantStmt(a, b);
1919 case T_ClosePortalStmt:
1920 retval = _equalClosePortalStmt(a, b);
1923 retval = _equalClusterStmt(a, b);
1926 retval = _equalCopyStmt(a, b);
1929 retval = _equalCreateStmt(a, b);
1932 retval = _equalVersionStmt(a, b);
1935 retval = _equalDefineStmt(a, b);
1938 retval = _equalDropStmt(a, b);
1940 case T_TruncateStmt:
1941 retval = _equalTruncateStmt(a, b);
1944 retval = _equalCommentStmt(a, b);
1947 retval = _equalFetchStmt(a, b);
1950 retval = _equalIndexStmt(a, b);
1952 case T_ProcedureStmt:
1953 retval = _equalProcedureStmt(a, b);
1955 case T_RemoveAggrStmt:
1956 retval = _equalRemoveAggrStmt(a, b);
1958 case T_RemoveFuncStmt:
1959 retval = _equalRemoveFuncStmt(a, b);
1961 case T_RemoveOperStmt:
1962 retval = _equalRemoveOperStmt(a, b);
1965 retval = _equalRenameStmt(a, b);
1968 retval = _equalRuleStmt(a, b);
1971 retval = _equalNotifyStmt(a, b);
1974 retval = _equalListenStmt(a, b);
1976 case T_UnlistenStmt:
1977 retval = _equalUnlistenStmt(a, b);
1979 case T_TransactionStmt:
1980 retval = _equalTransactionStmt(a, b);
1983 retval = _equalViewStmt(a, b);
1986 retval = _equalLoadStmt(a, b);
1988 case T_CreatedbStmt:
1989 retval = _equalCreatedbStmt(a, b);
1992 retval = _equalDropdbStmt(a, b);
1995 retval = _equalVacuumStmt(a, b);
1998 retval = _equalExplainStmt(a, b);
2000 case T_CreateSeqStmt:
2001 retval = _equalCreateSeqStmt(a, b);
2003 case T_VariableSetStmt:
2004 retval = _equalVariableSetStmt(a, b);
2006 case T_VariableShowStmt:
2007 retval = _equalVariableShowStmt(a, b);
2009 case T_VariableResetStmt:
2010 retval = _equalVariableResetStmt(a, b);
2012 case T_CreateTrigStmt:
2013 retval = _equalCreateTrigStmt(a, b);
2015 case T_DropTrigStmt:
2016 retval = _equalDropTrigStmt(a, b);
2018 case T_CreatePLangStmt:
2019 retval = _equalCreatePLangStmt(a, b);
2021 case T_DropPLangStmt:
2022 retval = _equalDropPLangStmt(a, b);
2024 case T_CreateUserStmt:
2025 retval = _equalCreateUserStmt(a, b);
2027 case T_AlterUserStmt:
2028 retval = _equalAlterUserStmt(a, b);
2030 case T_DropUserStmt:
2031 retval = _equalDropUserStmt(a, b);
2034 retval = _equalLockStmt(a, b);
2036 case T_ConstraintsSetStmt:
2037 retval = _equalConstraintsSetStmt(a, b);
2039 case T_CreateGroupStmt:
2040 retval = _equalCreateGroupStmt(a, b);
2042 case T_AlterGroupStmt:
2043 retval = _equalAlterGroupStmt(a, b);
2045 case T_DropGroupStmt:
2046 retval = _equalDropGroupStmt(a, b);
2049 retval = _equalReindexStmt(a, b);
2051 case T_CheckPointStmt:
2056 retval = _equalAExpr(a, b);
2059 retval = _equalAttr(a, b);
2062 retval = _equalAConst(a, b);
2065 retval = _equalParamNo(a, b);
2068 retval = _equalIdent(a, b);
2071 retval = _equalFuncCall(a, b);
2074 retval = _equalAIndices(a, b);
2077 retval = _equalResTarget(a, b);
2080 retval = _equalTypeCast(a, b);
2083 retval = _equalSortGroupBy(a, b);
2086 retval = _equalRangeVar(a, b);
2088 case T_RangeSubselect:
2089 retval = _equalRangeSubselect(a, b);
2092 retval = _equalTypeName(a, b);
2095 retval = _equalIndexElem(a, b);
2098 retval = _equalColumnDef(a, b);
2101 retval = _equalConstraint(a, b);
2104 retval = _equalDefElem(a, b);
2107 retval = _equalTargetEntry(a, b);
2109 case T_RangeTblEntry:
2110 retval = _equalRangeTblEntry(a, b);
2113 retval = _equalSortClause(a, b);
2116 /* GroupClause is equivalent to SortClause */
2117 retval = _equalSortClause(a, b);
2120 retval = _equalCaseExpr(a, b);
2123 retval = _equalCaseWhen(a, b);
2126 retval = _equalNullTest(a, b);
2129 retval = _equalBooleanTest(a, b);
2131 case T_FkConstraint:
2132 retval = _equalFkConstraint(a, b);
2135 retval = _equalPrivGrantee(a, b);
2137 case T_FuncWithArgs:
2138 retval = _equalFuncWithArgs(a, b);
2142 elog(NOTICE, "equal: don't know whether nodes of type %d are equal",