@@ -6632,10 +6632,14 @@ ATPrepAlterColumnType(List **wqueue,
6632
6632
}
6633
6633
6634
6634
/*
6635
- * When the data type of a column is changed, a rewrite might not be require
6636
- * if the data type is being changed to its current type, or more interestingly
6637
- * to a type to which it is binary coercible. But we must check carefully that
6638
- * the USING clause isn't trying to insert some other value.
6635
+ * When the data type of a column is changed, a rewrite might not be required
6636
+ * if the new type is sufficiently identical to the old one, and the USING
6637
+ * clause isn't trying to insert some other value. It's safe to skip the
6638
+ * rewrite if the old type is binary coercible to the new type, or if the
6639
+ * new type is an unconstrained domain over the old type. In the case of a
6640
+ * constrained domain, we could get by with scanning the table and checking
6641
+ * the constraint rather than actually rewriting it, but we don't currently
6642
+ * try to do that.
6639
6643
*/
6640
6644
static bool
6641
6645
ATColumnChangeRequiresRewrite (Node * expr , AttrNumber varattno )
@@ -6649,6 +6653,14 @@ ATColumnChangeRequiresRewrite(Node *expr, AttrNumber varattno)
6649
6653
return false;
6650
6654
else if (IsA (expr , RelabelType ))
6651
6655
expr = (Node * ) ((RelabelType * ) expr )-> arg ;
6656
+ else if (IsA (expr , CoerceToDomain ))
6657
+ {
6658
+ CoerceToDomain * d = (CoerceToDomain * ) expr ;
6659
+
6660
+ if (GetDomainConstraints (d -> resulttype ) != NIL )
6661
+ return true;
6662
+ expr = (Node * ) d -> arg ;
6663
+ }
6652
6664
else
6653
6665
return true;
6654
6666
}
0 commit comments