Use a blacklist to distinguish original from add-on enum values.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 26 Sep 2017 17:12:03 +0000 (13:12 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 26 Sep 2017 17:14:47 +0000 (13:14 -0400)
commit175774d2932d969875b0709ec5f400ba19000c99
treedd65fb5488d7f1d7e8b5d9a62b5eeb8a390de454
parent1a499c252049dad9016a04bcbab27b8c616d4d03
Use a blacklist to distinguish original from add-on enum values.

Commit 15bc038f9 allowed ALTER TYPE ADD VALUE to be executed inside
transaction blocks, by disallowing the use of the added value later
in the same transaction, except under limited circumstances.  However,
the test for "limited circumstances" was heuristic and could reject
references to enum values that were created during CREATE TYPE AS ENUM,
not just later.  This breaks the use-case of restoring pg_dump scripts
in a single transaction, as reported in bug #14825 from Balazs Szilfai.

We can improve this by keeping a "blacklist" table of enum value OIDs
created by ALTER TYPE ADD VALUE during the current transaction.  Any
visible-but-uncommitted value whose OID is not in the blacklist must
have been created by CREATE TYPE AS ENUM, and can be used safely
because it could not have a lifespan shorter than its parent enum type.

This change also removes the restriction that a renamed enum value
can't be used before being committed (unless it was on the blacklist).

Andrew Dunstan, with cosmetic improvements by me.
Back-patch to v10.

Discussion: https://postgr.es/m/20170922185904.1448.16585@wrigleys.postgresql.org
doc/src/sgml/ref/alter_type.sgml
src/backend/access/transam/xact.c
src/backend/catalog/pg_enum.c
src/backend/utils/adt/enum.c
src/include/catalog/pg_enum.h
src/test/regress/expected/enum.out
src/test/regress/sql/enum.sql