diff options
author | Robert Haas <rhaas@postgresql.org> | 2011-02-14 23:17:35 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2011-02-14 23:40:05 -0500 |
commit | 0d90dc16f87bd991d7eb9f536ca46acef7586d95 (patch) | |
tree | f769863a1ee93935f6d968728ea3374384d6c85b /src/backend/commands/tablecmds.c | |
parent | 8e1124eeeb128ef87045debfeb8f24cd6dbab874 (diff) | |
download | postgresql-0d90dc16f87bd991d7eb9f536ca46acef7586d95.tar.gz postgresql-0d90dc16f87bd991d7eb9f536ca46acef7586d95.zip |
Avoid a few more SET DATA TYPE table rewrites.
When the new type is an unconstrained domain over the old type, we don't
need to rewrite the table.
Noah Misch and Robert Haas
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index f901ecfd27f..5789a39ba3d 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -6632,10 +6632,14 @@ ATPrepAlterColumnType(List **wqueue, } /* - * When the data type of a column is changed, a rewrite might not be require - * if the data type is being changed to its current type, or more interestingly - * to a type to which it is binary coercible. But we must check carefully that - * the USING clause isn't trying to insert some other value. + * When the data type of a column is changed, a rewrite might not be required + * if the new type is sufficiently identical to the old one, and the USING + * clause isn't trying to insert some other value. It's safe to skip the + * rewrite if the old type is binary coercible to the new type, or if the + * new type is an unconstrained domain over the old type. In the case of a + * constrained domain, we could get by with scanning the table and checking + * the constraint rather than actually rewriting it, but we don't currently + * try to do that. */ static bool ATColumnChangeRequiresRewrite(Node *expr, AttrNumber varattno) @@ -6649,6 +6653,14 @@ ATColumnChangeRequiresRewrite(Node *expr, AttrNumber varattno) return false; else if (IsA(expr, RelabelType)) expr = (Node *) ((RelabelType *) expr)->arg; + else if (IsA(expr, CoerceToDomain)) + { + CoerceToDomain *d = (CoerceToDomain *) expr; + + if (GetDomainConstraints(d->resulttype) != NIL) + return true; + expr = (Node *) d->arg; + } else return true; } |