Allow ALTER TYPE to change some properties of a base type.
authorTom Lane <[email protected]>
Fri, 6 Mar 2020 17:19:29 +0000 (12:19 -0500)
committerTom Lane <[email protected]>
Fri, 6 Mar 2020 17:19:29 +0000 (12:19 -0500)
commitfe30e7ebfa3846416f1adeb7cf611006513a4ee0
tree9595f013d6fee593182b0f098fbf55dd7562341e
parentaddd034ae1795d0a99305b294e4dce44c6b1dfd8
Allow ALTER TYPE to change some properties of a base type.

Specifically, this  allows ALTER TYPE to:
* Change the default TOAST strategy for a toastable base type;
* Promote a non-toastable type to toastable;
* Add/remove binary I/O functions for a type;
* Add/remove typmod I/O functions for a type;
* Add/remove a custom ANALYZE statistics functions for a type.

The first of these can be done by the type's owner; all the others
require superuser privilege since misuse could cause problems.

The main motivation for this  is to allow extensions to
upgrade the feature sets of their data types, so the set of
alterable properties is biased towards that use-case.  However
it's also true that changing some other properties would be
a lot harder, as they get baked into physical storage and/or
stored expressions that depend on the type.

Along the way, refactor GenerateTypeDependencies() to make it easier
to call, refactor DefineType's volatility checks so they can be shared
by AlterType, and teach typcache.c that it might have to reload data
from the type's pg_type row, a scenario it never handled before.
Also rearrange alter_type.sgml a bit for clarity (put the
composite-type operations together).

Tomas Vondra and Tom Lane

Discussion: https://postgr.es/m/20200228004440.b23ein4qvmxnlpht@development
17 files changed:
doc/src/sgml/catalogs.sgml
doc/src/sgml/ref/alter_type.sgml
src/backend/catalog/pg_type.c
src/backend/commands/typecmds.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/parser/gram.y
src/backend/tcop/utility.c
src/backend/utils/cache/typcache.c
src/bin/psql/tab-complete.c
src/include/catalog/pg_type.h
src/include/commands/typecmds.h
src/include/nodes/nodes.h
src/include/nodes/parsenodes.h
src/include/utils/typcache.h
src/test/regress/expected/create_type.out
src/test/regress/sql/create_type.sql