Relax transactional restrictions on ALTER TYPE ... ADD VALUE.

Enterprise / PostgreSQL - Tom Lane [sss.pgh.pa.us] - 5 September 2016 11:59 UTC

To prevent possibly breaking indexes on enum columns, we must keep uncommitted enum values from getting stored in tables, unless we can be sure that any such column is new in the current transaction.

Formerly, we enforced this by disallowing ALTER TYPE ... ADD VALUE from being executed at all in a transaction block, unless the target enum type had been created in the current transaction. This patch removes that restriction, and instead insists that an uncommitted enum
value can't be referenced unless it belongs to an enum type created in the same transaction as the value. Per discussion, this should be a bit less onerous. It does require each function that could possibly return a new enum value to SQL operations to check this restriction, but there aren't so many of those that this seems unmaintainable.

Andrew Dunstan and Tom Lane

Discussion: <4075.1459088427@sss.pgh.pa.us>

15bc038 Relax transactional restrictions on ALTER TYPE ... ADD VALUE.
doc/src/sgml/ref/alter_type.sgml | 6 ++-
src/backend/commands/typecmds.c | 21 +-------
src/backend/tcop/utility.c | 2 +-
src/backend/utils/adt/enum.c | 104 ++++++++++++++++++++++++++++++++++++
src/backend/utils/errcodes.txt | 1 +
src/include/commands/typecmds.h | 2 +-
src/test/regress/expected/enum.out | 65 ++++++++++++++++++----
src/test/regress/sql/enum.sql | 30 ++++++++---
8 files changed, 191 insertions(+), 40 deletions(-)

Upstream: git.postgresql.org


  • Share