diff options
author | Thomas Munro <tmunro@postgresql.org> | 2018-10-09 12:51:01 +1300 |
---|---|---|
committer | Thomas Munro <tmunro@postgresql.org> | 2018-10-09 12:51:01 +1300 |
commit | 212fab9926b2f0f04b0187568e7124b70e8deee5 (patch) | |
tree | 4ba239ec3e6f37b86474b915876407549de96eb1 /src/backend/commands/typecmds.c | |
parent | 7767aadd94cd252a12fa00f6122ad4dd10455791 (diff) | |
download | postgresql-212fab9926b2f0f04b0187568e7124b70e8deee5.tar.gz postgresql-212fab9926b2f0f04b0187568e7124b70e8deee5.zip |
Relax transactional restrictions on ALTER TYPE ... ADD VALUE (redux).
Originally committed as 15bc038f (plus some follow-ups), this was
reverted in 28e07270 due to a problem discovered in parallel
workers. This new version corrects that problem by sending the
list of uncommitted enum values to parallel workers.
Here follows the original commit message describing the change:
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.
Author: Andrew Dunstan and Tom Lane, with parallel query fix by Thomas Munro
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/CAEepm%3D0Ei7g6PaNTbcmAh9tCRahQrk%3Dr5ZWLD-jr7hXweYX3yg%40mail.gmail.com
Discussion: https://postgr.es/m/4075.1459088427%40sss.pgh.pa.us
Diffstat (limited to 'src/backend/commands/typecmds.c')
-rw-r--r-- | src/backend/commands/typecmds.c | 29 |
1 files changed, 4 insertions, 25 deletions
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index b018585aef8..3271962a7a7 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -1270,10 +1270,10 @@ DefineEnum(CreateEnumStmt *stmt) /* * AlterEnum - * ALTER TYPE on an enum. + * Adds a new label to an existing enum. */ ObjectAddress -AlterEnum(AlterEnumStmt *stmt, bool isTopLevel) +AlterEnum(AlterEnumStmt *stmt) { Oid enum_type_oid; TypeName *typename; @@ -1291,6 +1291,8 @@ AlterEnum(AlterEnumStmt *stmt, bool isTopLevel) /* Check it's an enum and check user has permission to ALTER the enum */ checkEnumOwner(tup); + ReleaseSysCache(tup); + if (stmt->oldVal) { /* Rename an existing label */ @@ -1299,27 +1301,6 @@ AlterEnum(AlterEnumStmt *stmt, bool isTopLevel) else { /* Add a new label */ - - /* - * Ordinarily we disallow adding values within transaction blocks, - * because we can't cope with enum OID values getting into indexes and - * then having their defining pg_enum entries go away. However, it's - * okay if the enum type was created in the current transaction, since - * then there can be no such indexes that wouldn't themselves go away - * on rollback. (We support this case because pg_dump - * --binary-upgrade needs it.) We test this by seeing if the pg_type - * row has xmin == current XID and is not HEAP_UPDATED. If it is - * HEAP_UPDATED, we can't be sure whether the type was created or only - * modified in this xact. So we are disallowing some cases that could - * theoretically be safe; but fortunately pg_dump only needs the - * simplest case. - */ - if (HeapTupleHeaderGetXmin(tup->t_data) == GetCurrentTransactionId() && - !(tup->t_data->t_infomask & HEAP_UPDATED)) - /* safe to do inside transaction block */ ; - else - PreventInTransactionBlock(isTopLevel, "ALTER TYPE ... ADD"); - AddEnumLabel(enum_type_oid, stmt->newVal, stmt->newValNeighbor, stmt->newValIsAfter, stmt->skipIfNewValExists); @@ -1329,8 +1310,6 @@ AlterEnum(AlterEnumStmt *stmt, bool isTopLevel) ObjectAddressSet(address, TypeRelationId, enum_type_oid); - ReleaseSysCache(tup); - return address; } |