Commit c9e2e2db authored by Robert Haas's avatar Robert Haas

Partially restore comments discussing enum renumbering hazards.

As noted by Tom Lane, commit 813fb031
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.
parent da85fb47
......@@ -462,9 +462,22 @@ restart:
* Renumber existing enum elements to have sort positions 1..n.
*
* We avoid doing this unless absolutely necessary; in most installations
* it will never happen. Before we had MVCC catalog scans, this function
* posed various concurrency hazards. It no longer does, but it's still
* extra work, so we don't do it unless it's needed.
* it will never happen. The reason is that updating existing pg_enum
* entries creates hazards for other backends that are concurrently reading
* pg_enum. Although system catalog scans now use MVCC semantics, the
* syscache machinery might read different pg_enum entries under different
* snapshots, so some other backend might get confused about the proper
* ordering if a concurrent renumbering occurs.
*
* We therefore make the following choices:
*
* 1. Any code that is interested in the enumsortorder values MUST read
* all the relevant pg_enum entries with a single MVCC snapshot, or else
* acquire lock on the enum type to prevent concurrent execution of
* AddEnumLabel().
*
* 2. Code that is not examining enumsortorder can use a syscache
* (for example, enum_in and enum_out do so).
*/
static void
RenumberEnumType(Relation pg_enum, HeapTuple *existing, int nelems)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment