]> granicus.if.org Git - postgresql/blobdiff - src/backend/nodes/equalfuncs.c
Support UPDATE/DELETE WHERE CURRENT OF cursor_name, per SQL standard.
[postgresql] / src / backend / nodes / equalfuncs.c
index e341b74f3e6369505f59224e6cc750dbe25188aa..04072c7a65422560271d422496ac86230e40f817 100644 (file)
  * either.     This might need to be fixed someday.
  *
  *
- * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.288 2006/12/10 22:13:26 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.309 2007/06/11 01:16:22 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -102,6 +102,18 @@ _equalRangeVar(RangeVar *a, RangeVar *b)
        return true;
 }
 
+static bool
+_equalIntoClause(IntoClause *a, IntoClause *b)
+{
+       COMPARE_NODE_FIELD(rel);
+       COMPARE_NODE_FIELD(colNames);
+       COMPARE_NODE_FIELD(options);
+       COMPARE_SCALAR_FIELD(onCommit);
+       COMPARE_STRING_FIELD(tableSpaceName);
+
+       return true;
+}
+
 /*
  * We don't need an _equalExpr because Expr is an abstract supertype which
  * should never actually get instantiated.     Also, since it has no common
@@ -127,6 +139,7 @@ static bool
 _equalConst(Const *a, Const *b)
 {
        COMPARE_SCALAR_FIELD(consttype);
+       COMPARE_SCALAR_FIELD(consttypmod);
        COMPARE_SCALAR_FIELD(constlen);
        COMPARE_SCALAR_FIELD(constisnull);
        COMPARE_SCALAR_FIELD(constbyval);
@@ -168,9 +181,9 @@ _equalAggref(Aggref *a, Aggref *b)
 static bool
 _equalArrayRef(ArrayRef *a, ArrayRef *b)
 {
-       COMPARE_SCALAR_FIELD(refrestype);
        COMPARE_SCALAR_FIELD(refarraytype);
        COMPARE_SCALAR_FIELD(refelemtype);
+       COMPARE_SCALAR_FIELD(reftypmod);
        COMPARE_NODE_FIELD(refupperindexpr);
        COMPARE_NODE_FIELD(reflowerindexpr);
        COMPARE_NODE_FIELD(refexpr);
@@ -294,9 +307,8 @@ _equalSubPlan(SubPlan *a, SubPlan *b)
        COMPARE_SCALAR_FIELD(subLinkType);
        COMPARE_NODE_FIELD(testexpr);
        COMPARE_NODE_FIELD(paramIds);
-       /* should compare plans, but have to settle for comparing plan IDs */
        COMPARE_SCALAR_FIELD(plan_id);
-       COMPARE_NODE_FIELD(rtable);
+       COMPARE_SCALAR_FIELD(firstColType);
        COMPARE_SCALAR_FIELD(useHashTable);
        COMPARE_SCALAR_FIELD(unknownEqFalse);
        COMPARE_NODE_FIELD(setParam);
@@ -347,6 +359,45 @@ _equalRelabelType(RelabelType *a, RelabelType *b)
        return true;
 }
 
+static bool
+_equalCoerceViaIO(CoerceViaIO *a, CoerceViaIO *b)
+{
+       COMPARE_NODE_FIELD(arg);
+       COMPARE_SCALAR_FIELD(resulttype);
+
+       /*
+        * Special-case COERCE_DONTCARE, so that planner can build coercion nodes
+        * that are equal() to both explicit and implicit coercions.
+        */
+       if (a->coerceformat != b->coerceformat &&
+               a->coerceformat != COERCE_DONTCARE &&
+               b->coerceformat != COERCE_DONTCARE)
+               return false;
+
+       return true;
+}
+
+static bool
+_equalArrayCoerceExpr(ArrayCoerceExpr *a, ArrayCoerceExpr *b)
+{
+       COMPARE_NODE_FIELD(arg);
+       COMPARE_SCALAR_FIELD(elemfuncid);
+       COMPARE_SCALAR_FIELD(resulttype);
+       COMPARE_SCALAR_FIELD(resulttypmod);
+       COMPARE_SCALAR_FIELD(isExplicit);
+
+       /*
+        * Special-case COERCE_DONTCARE, so that planner can build coercion nodes
+        * that are equal() to both explicit and implicit coercions.
+        */
+       if (a->coerceformat != b->coerceformat &&
+               a->coerceformat != COERCE_DONTCARE &&
+               b->coerceformat != COERCE_DONTCARE)
+               return false;
+
+       return true;
+}
+
 static bool
 _equalConvertRowtypeExpr(ConvertRowtypeExpr *a, ConvertRowtypeExpr *b)
 {
@@ -428,7 +479,7 @@ _equalRowCompareExpr(RowCompareExpr *a, RowCompareExpr *b)
 {
        COMPARE_SCALAR_FIELD(rctype);
        COMPARE_NODE_FIELD(opnos);
-       COMPARE_NODE_FIELD(opclasses);
+       COMPARE_NODE_FIELD(opfamilies);
        COMPARE_NODE_FIELD(largs);
        COMPARE_NODE_FIELD(rargs);
 
@@ -454,6 +505,21 @@ _equalMinMaxExpr(MinMaxExpr *a, MinMaxExpr *b)
        return true;
 }
 
+static bool
+_equalXmlExpr(XmlExpr *a, XmlExpr *b)
+{
+       COMPARE_SCALAR_FIELD(op);
+       COMPARE_STRING_FIELD(name);
+       COMPARE_NODE_FIELD(named_args);
+       COMPARE_NODE_FIELD(arg_names);
+       COMPARE_NODE_FIELD(args);
+       COMPARE_SCALAR_FIELD(xmloption);
+       COMPARE_SCALAR_FIELD(type);
+       COMPARE_SCALAR_FIELD(typmod);
+
+       return true;
+}
+
 static bool
 _equalNullIfExpr(NullIfExpr *a, NullIfExpr *b)
 {
@@ -532,6 +598,15 @@ _equalSetToDefault(SetToDefault *a, SetToDefault *b)
        return true;
 }
 
+static bool
+_equalCurrentOfExpr(CurrentOfExpr *a, CurrentOfExpr *b)
+{
+       COMPARE_SCALAR_FIELD(cvarno);
+       COMPARE_STRING_FIELD(cursor_name);
+
+       return true;
+}
+
 static bool
 _equalTargetEntry(TargetEntry *a, TargetEntry *b)
 {
@@ -584,10 +659,27 @@ _equalFromExpr(FromExpr *a, FromExpr *b)
  */
 
 static bool
-_equalPathKeyItem(PathKeyItem *a, PathKeyItem *b)
+_equalPathKey(PathKey *a, PathKey *b)
 {
-       COMPARE_NODE_FIELD(key);
-       COMPARE_SCALAR_FIELD(sortop);
+       /*
+        * This is normally used on non-canonicalized PathKeys, so must chase
+        * up to the topmost merged EquivalenceClass and see if those are the
+        * same (by pointer equality).
+        */
+       EquivalenceClass *a_eclass;
+       EquivalenceClass *b_eclass;
+
+       a_eclass = a->pk_eclass;
+       while (a_eclass->ec_merged)
+               a_eclass = a_eclass->ec_merged;
+       b_eclass = b->pk_eclass;
+       while (b_eclass->ec_merged)
+               b_eclass = b_eclass->ec_merged;
+       if (a_eclass != b_eclass)
+               return false;
+       COMPARE_SCALAR_FIELD(pk_opfamily);
+       COMPARE_SCALAR_FIELD(pk_strategy);
+       COMPARE_SCALAR_FIELD(pk_nulls_first);
 
        return true;
 }
@@ -615,6 +707,7 @@ _equalOuterJoinInfo(OuterJoinInfo *a, OuterJoinInfo *b)
        COMPARE_BITMAPSET_FIELD(min_righthand);
        COMPARE_SCALAR_FIELD(is_full_join);
        COMPARE_SCALAR_FIELD(lhs_strict);
+       COMPARE_SCALAR_FIELD(delay_upper_joins);
 
        return true;
 }
@@ -625,6 +718,7 @@ _equalInClauseInfo(InClauseInfo *a, InClauseInfo *b)
        COMPARE_BITMAPSET_FIELD(lefthand);
        COMPARE_BITMAPSET_FIELD(righthand);
        COMPARE_NODE_FIELD(sub_targetlist);
+       COMPARE_NODE_FIELD(in_operators);
 
        return true;
 }
@@ -656,10 +750,7 @@ _equalQuery(Query *a, Query *b)
        COMPARE_SCALAR_FIELD(canSetTag);
        COMPARE_NODE_FIELD(utilityStmt);
        COMPARE_SCALAR_FIELD(resultRelation);
-       COMPARE_NODE_FIELD(into);
-       COMPARE_NODE_FIELD(intoOptions);
-       COMPARE_SCALAR_FIELD(intoOnCommit);
-       COMPARE_STRING_FIELD(intoTableSpaceName);
+       COMPARE_NODE_FIELD(intoClause);
        COMPARE_SCALAR_FIELD(hasAggs);
        COMPARE_SCALAR_FIELD(hasSubLinks);
        COMPARE_NODE_FIELD(rtable);
@@ -674,8 +765,6 @@ _equalQuery(Query *a, Query *b)
        COMPARE_NODE_FIELD(limitCount);
        COMPARE_NODE_FIELD(rowMarks);
        COMPARE_NODE_FIELD(setOperations);
-       COMPARE_NODE_FIELD(resultRelations);
-       COMPARE_NODE_FIELD(returningLists);
 
        return true;
 }
@@ -718,11 +807,7 @@ static bool
 _equalSelectStmt(SelectStmt *a, SelectStmt *b)
 {
        COMPARE_NODE_FIELD(distinctClause);
-       COMPARE_NODE_FIELD(into);
-       COMPARE_NODE_FIELD(intoColNames);
-       COMPARE_NODE_FIELD(intoOptions);
-       COMPARE_SCALAR_FIELD(intoOnCommit);
-       COMPARE_STRING_FIELD(intoTableSpaceName);
+       COMPARE_NODE_FIELD(intoClause);
        COMPARE_NODE_FIELD(targetList);
        COMPARE_NODE_FIELD(fromClause);
        COMPARE_NODE_FIELD(whereClause);
@@ -959,7 +1044,6 @@ _equalIndexStmt(IndexStmt *a, IndexStmt *b)
        COMPARE_NODE_FIELD(indexParams);
        COMPARE_NODE_FIELD(options);
        COMPARE_NODE_FIELD(whereClause);
-       COMPARE_NODE_FIELD(rangetable);
        COMPARE_SCALAR_FIELD(unique);
        COMPARE_SCALAR_FIELD(primary);
        COMPARE_SCALAR_FIELD(isconstraint);
@@ -1023,6 +1107,17 @@ _equalRemoveOpClassStmt(RemoveOpClassStmt *a, RemoveOpClassStmt *b)
        return true;
 }
 
+static bool
+_equalRemoveOpFamilyStmt(RemoveOpFamilyStmt *a, RemoveOpFamilyStmt *b)
+{
+       COMPARE_NODE_FIELD(opfamilyname);
+       COMPARE_STRING_FIELD(amname);
+       COMPARE_SCALAR_FIELD(behavior);
+       COMPARE_SCALAR_FIELD(missing_ok);
+
+       return true;
+}
+
 static bool
 _equalRenameStmt(RenameStmt *a, RenameStmt *b)
 {
@@ -1119,6 +1214,15 @@ _equalCompositeTypeStmt(CompositeTypeStmt *a, CompositeTypeStmt *b)
        return true;
 }
 
+static bool
+_equalCreateEnumStmt(CreateEnumStmt *a, CreateEnumStmt *b)
+{
+       COMPARE_NODE_FIELD(typename);
+       COMPARE_NODE_FIELD(vals);
+
+       return true;
+}
+
 static bool
 _equalViewStmt(ViewStmt *a, ViewStmt *b)
 {
@@ -1152,6 +1256,7 @@ static bool
 _equalCreateOpClassStmt(CreateOpClassStmt *a, CreateOpClassStmt *b)
 {
        COMPARE_NODE_FIELD(opclassname);
+       COMPARE_NODE_FIELD(opfamilyname);
        COMPARE_STRING_FIELD(amname);
        COMPARE_NODE_FIELD(datatype);
        COMPARE_NODE_FIELD(items);
@@ -1168,11 +1273,32 @@ _equalCreateOpClassItem(CreateOpClassItem *a, CreateOpClassItem *b)
        COMPARE_NODE_FIELD(args);
        COMPARE_SCALAR_FIELD(number);
        COMPARE_SCALAR_FIELD(recheck);
+       COMPARE_NODE_FIELD(class_args);
        COMPARE_NODE_FIELD(storedtype);
 
        return true;
 }
 
+static bool
+_equalCreateOpFamilyStmt(CreateOpFamilyStmt *a, CreateOpFamilyStmt *b)
+{
+       COMPARE_NODE_FIELD(opfamilyname);
+       COMPARE_STRING_FIELD(amname);
+
+       return true;
+}
+
+static bool
+_equalAlterOpFamilyStmt(AlterOpFamilyStmt *a, AlterOpFamilyStmt *b)
+{
+       COMPARE_NODE_FIELD(opfamilyname);
+       COMPARE_STRING_FIELD(amname);
+       COMPARE_SCALAR_FIELD(isDrop);
+       COMPARE_NODE_FIELD(items);
+
+       return true;
+}
+
 static bool
 _equalCreatedbStmt(CreatedbStmt *a, CreatedbStmt *b)
 {
@@ -1278,6 +1404,14 @@ _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
        return true;
 }
 
+static bool
+_equalDiscardStmt(DiscardStmt *a, DiscardStmt *b)
+{
+       COMPARE_SCALAR_FIELD(target);
+
+       return true;
+}
+
 static bool
 _equalCreateTableSpaceStmt(CreateTableSpaceStmt *a, CreateTableSpaceStmt *b)
 {
@@ -1468,7 +1602,6 @@ _equalPrepareStmt(PrepareStmt *a, PrepareStmt *b)
 {
        COMPARE_STRING_FIELD(name);
        COMPARE_NODE_FIELD(argtypes);
-       COMPARE_NODE_FIELD(argtype_oids);
        COMPARE_NODE_FIELD(query);
 
        return true;
@@ -1479,9 +1612,6 @@ _equalExecuteStmt(ExecuteStmt *a, ExecuteStmt *b)
 {
        COMPARE_STRING_FIELD(name);
        COMPARE_NODE_FIELD(into);
-       COMPARE_NODE_FIELD(intoOptions);
-       COMPARE_SCALAR_FIELD(into_on_commit);
-       COMPARE_STRING_FIELD(into_tbl_space);
        COMPARE_NODE_FIELD(params);
 
        return true;
@@ -1601,7 +1731,8 @@ _equalTypeName(TypeName *a, TypeName *b)
        COMPARE_SCALAR_FIELD(timezone);
        COMPARE_SCALAR_FIELD(setof);
        COMPARE_SCALAR_FIELD(pct_type);
-       COMPARE_SCALAR_FIELD(typmod);
+       COMPARE_NODE_FIELD(typmods);
+       COMPARE_SCALAR_FIELD(typemod);
        COMPARE_NODE_FIELD(arrayBounds);
        COMPARE_SCALAR_FIELD(location);
 
@@ -1620,7 +1751,8 @@ _equalTypeCast(TypeCast *a, TypeCast *b)
 static bool
 _equalSortBy(SortBy *a, SortBy *b)
 {
-       COMPARE_SCALAR_FIELD(sortby_kind);
+       COMPARE_SCALAR_FIELD(sortby_dir);
+       COMPARE_SCALAR_FIELD(sortby_nulls);
        COMPARE_NODE_FIELD(useOp);
        COMPARE_NODE_FIELD(node);
 
@@ -1652,6 +1784,8 @@ _equalIndexElem(IndexElem *a, IndexElem *b)
        COMPARE_STRING_FIELD(name);
        COMPARE_NODE_FIELD(expr);
        COMPARE_NODE_FIELD(opclass);
+       COMPARE_SCALAR_FIELD(ordering);
+       COMPARE_SCALAR_FIELD(nulls_ordering);
 
        return true;
 }
@@ -1731,6 +1865,7 @@ _equalSortClause(SortClause *a, SortClause *b)
 {
        COMPARE_SCALAR_FIELD(tleSortGroupRef);
        COMPARE_SCALAR_FIELD(sortop);
+       COMPARE_SCALAR_FIELD(nulls_first);
 
        return true;
 }
@@ -1762,6 +1897,15 @@ _equalFkConstraint(FkConstraint *a, FkConstraint *b)
        return true;
 }
 
+static bool
+_equalXmlSerialize(XmlSerialize *a, XmlSerialize *b)
+{
+       COMPARE_SCALAR_FIELD(xmloption);
+       COMPARE_NODE_FIELD(expr);
+       COMPARE_NODE_FIELD(typename);
+
+       return true;
+}
 
 /*
  * Stuff from pg_list.h
@@ -1887,6 +2031,9 @@ equal(void *a, void *b)
                case T_RangeVar:
                        retval = _equalRangeVar(a, b);
                        break;
+               case T_IntoClause:
+                       retval = _equalIntoClause(a, b);
+                       break;
                case T_Var:
                        retval = _equalVar(a, b);
                        break;
@@ -1932,6 +2079,12 @@ equal(void *a, void *b)
                case T_RelabelType:
                        retval = _equalRelabelType(a, b);
                        break;
+               case T_CoerceViaIO:
+                       retval = _equalCoerceViaIO(a, b);
+                       break;
+               case T_ArrayCoerceExpr:
+                       retval = _equalArrayCoerceExpr(a, b);
+                       break;
                case T_ConvertRowtypeExpr:
                        retval = _equalConvertRowtypeExpr(a, b);
                        break;
@@ -1959,6 +2112,9 @@ equal(void *a, void *b)
                case T_MinMaxExpr:
                        retval = _equalMinMaxExpr(a, b);
                        break;
+               case T_XmlExpr:
+                       retval = _equalXmlExpr(a, b);
+                       break;
                case T_NullIfExpr:
                        retval = _equalNullIfExpr(a, b);
                        break;
@@ -1977,6 +2133,9 @@ equal(void *a, void *b)
                case T_SetToDefault:
                        retval = _equalSetToDefault(a, b);
                        break;
+               case T_CurrentOfExpr:
+                       retval = _equalCurrentOfExpr(a, b);
+                       break;
                case T_TargetEntry:
                        retval = _equalTargetEntry(a, b);
                        break;
@@ -1993,8 +2152,8 @@ equal(void *a, void *b)
                        /*
                         * RELATION NODES
                         */
-               case T_PathKeyItem:
-                       retval = _equalPathKeyItem(a, b);
+               case T_PathKey:
+                       retval = _equalPathKey(a, b);
                        break;
                case T_RestrictInfo:
                        retval = _equalRestrictInfo(a, b);
@@ -2109,6 +2268,9 @@ equal(void *a, void *b)
                case T_RemoveOpClassStmt:
                        retval = _equalRemoveOpClassStmt(a, b);
                        break;
+               case T_RemoveOpFamilyStmt:
+                       retval = _equalRemoveOpFamilyStmt(a, b);
+                       break;
                case T_RenameStmt:
                        retval = _equalRenameStmt(a, b);
                        break;
@@ -2136,6 +2298,9 @@ equal(void *a, void *b)
                case T_CompositeTypeStmt:
                        retval = _equalCompositeTypeStmt(a, b);
                        break;
+               case T_CreateEnumStmt:
+                       retval = _equalCreateEnumStmt(a, b);
+                       break;
                case T_ViewStmt:
                        retval = _equalViewStmt(a, b);
                        break;
@@ -2151,6 +2316,12 @@ equal(void *a, void *b)
                case T_CreateOpClassItem:
                        retval = _equalCreateOpClassItem(a, b);
                        break;
+               case T_CreateOpFamilyStmt:
+                       retval = _equalCreateOpFamilyStmt(a, b);
+                       break;
+               case T_AlterOpFamilyStmt:
+                       retval = _equalAlterOpFamilyStmt(a, b);
+                       break;
                case T_CreatedbStmt:
                        retval = _equalCreatedbStmt(a, b);
                        break;
@@ -2184,6 +2355,9 @@ equal(void *a, void *b)
                case T_VariableResetStmt:
                        retval = _equalVariableResetStmt(a, b);
                        break;
+               case T_DiscardStmt:
+                       retval = _equalDiscardStmt(a, b);
+                       break;
                case T_CreateTableSpaceStmt:
                        retval = _equalCreateTableSpaceStmt(a, b);
                        break;
@@ -2331,6 +2505,9 @@ equal(void *a, void *b)
                case T_FuncWithArgs:
                        retval = _equalFuncWithArgs(a, b);
                        break;
+               case T_XmlSerialize:
+                       retval = _equalXmlSerialize(a, b);
+                       break;
 
                default:
                        elog(ERROR, "unrecognized node type: %d",