Teach ALTER TABLE .. SET DATA TYPE to avoid some table rewrites.
authorRobert Haas <rhaas@postgresql.org>
Sat, 12 Feb 2011 13:27:55 +0000 (08:27 -0500)
committerRobert Haas <rhaas@postgresql.org>
Sat, 12 Feb 2011 13:27:55 +0000 (08:27 -0500)
commitd31e2a495b6f2127afc31b4da2e5f4e89aa2cdfe
treeedd773239c8c89cc7b9f352fcb69d441f100a5d6
parent24d1280c4d75038f130495a25844c60d6810faab
Teach ALTER TABLE .. SET DATA TYPE to avoid some table rewrites.

When the old type is binary coercible to the new type and the using
clause does not change the column contents, we can avoid a full table
rewrite, though any indexes on the affected columns will still need
to be rebuilt.  This applies, for example, when changing a varchar
column to be of type text.

The prior coding assumed that the set of operations that force a
rewrite is identical to the set of operations that must be propagated
to tables making use of the affected table's rowtype.  This is
no longer true: even though the tuples in those tables wouldn't
need to be modified, the data type change invalidate indexes built
using those composite type columns.  Indexes on the table we're
actually modifying can be invalidated too, of course, but the
existing machinery is sufficient to handle that case.

Along the way, add some debugging messages that make it possible
to understand what operations ALTER TABLE is actually performing
in these cases.

Noah Misch and Robert Haas
doc/src/sgml/ref/alter_table.sgml
src/backend/catalog/index.c
src/backend/commands/tablecmds.c