Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c9e2e2d

Browse files
committed
Partially restore comments discussing enum renumbering hazards.
As noted by Tom Lane, commit 813fb03 was overly optimistic about how safe it is to concurrently change enumsortorder values under MVCC catalog scan semantics. Restore some of the previous text, with hopefully-correct adjustments for the new state of play.
1 parent da85fb4 commit c9e2e2d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/backend/catalog/pg_enum.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,22 @@ AddEnumLabel(Oid enumTypeOid,
462462
* Renumber existing enum elements to have sort positions 1..n.
463463
*
464464
* We avoid doing this unless absolutely necessary; in most installations
465-
* it will never happen. Before we had MVCC catalog scans, this function
466-
* posed various concurrency hazards. It no longer does, but it's still
467-
* extra work, so we don't do it unless it's needed.
465+
* it will never happen. The reason is that updating existing pg_enum
466+
* entries creates hazards for other backends that are concurrently reading
467+
* pg_enum. Although system catalog scans now use MVCC semantics, the
468+
* syscache machinery might read different pg_enum entries under different
469+
* snapshots, so some other backend might get confused about the proper
470+
* ordering if a concurrent renumbering occurs.
471+
*
472+
* We therefore make the following choices:
473+
*
474+
* 1. Any code that is interested in the enumsortorder values MUST read
475+
* all the relevant pg_enum entries with a single MVCC snapshot, or else
476+
* acquire lock on the enum type to prevent concurrent execution of
477+
* AddEnumLabel().
478+
*
479+
* 2. Code that is not examining enumsortorder can use a syscache
480+
* (for example, enum_in and enum_out do so).
468481
*/
469482
static void
470483
RenumberEnumType(Relation pg_enum, HeapTuple *existing, int nelems)

0 commit comments

Comments
 (0)