1919#include "catalog/indexing.h"
2020#include "catalog/pg_enum.h"
2121#include "libpq/pqformat.h"
22- #include "storage/procarray.h"
2322#include "utils/array.h"
2423#include "utils/builtins.h"
2524#include "utils/fmgroids.h"
@@ -32,79 +31,6 @@ static Oid enum_endpoint(Oid enumtypoid, ScanDirection direction);
3231static ArrayType * enum_range_internal (Oid enumtypoid , Oid lower , Oid upper );
3332
3433
35- /*
36- * Disallow use of an uncommitted pg_enum tuple.
37- *
38- * We need to make sure that uncommitted enum values don't get into indexes.
39- * If they did, and if we then rolled back the pg_enum addition, we'd have
40- * broken the index because value comparisons will not work reliably without
41- * an underlying pg_enum entry. (Note that removal of the heap entry
42- * containing an enum value is not sufficient to ensure that it doesn't appear
43- * in upper levels of indexes.) To do this we prevent an uncommitted row from
44- * being used for any SQL-level purpose. This is stronger than necessary,
45- * since the value might not be getting inserted into a table or there might
46- * be no index on its column, but it's easy to enforce centrally.
47- *
48- * However, it's okay to allow use of uncommitted values belonging to enum
49- * types that were themselves created in the same transaction, because then
50- * any such index would also be new and would go away altogether on rollback.
51- * We don't implement that fully right now, but we do allow free use of enum
52- * values created during CREATE TYPE AS ENUM, which are surely of the same
53- * lifespan as the enum type. (This case is required by "pg_restore -1".)
54- * Values added by ALTER TYPE ADD VALUE are currently restricted, but could
55- * be allowed if the enum type could be proven to have been created earlier
56- * in the same transaction. (Note that comparing tuple xmins would not work
57- * for that, because the type tuple might have been updated in the current
58- * transaction. Subtransactions also create hazards to be accounted for.)
59- *
60- * This function needs to be called (directly or indirectly) in any of the
61- * functions below that could return an enum value to SQL operations.
62- */
63- static void
64- check_safe_enum_use (HeapTuple enumval_tup )
65- {
66- TransactionId xmin ;
67- Form_pg_enum en ;
68-
69- /*
70- * If the row is hinted as committed, it's surely safe. This provides a
71- * fast path for all normal use-cases.
72- */
73- if (HeapTupleHeaderXminCommitted (enumval_tup -> t_data ))
74- return ;
75-
76- /*
77- * Usually, a row would get hinted as committed when it's read or loaded
78- * into syscache; but just in case not, let's check the xmin directly.
79- */
80- xmin = HeapTupleHeaderGetXmin (enumval_tup -> t_data );
81- if (!TransactionIdIsInProgress (xmin ) &&
82- TransactionIdDidCommit (xmin ))
83- return ;
84-
85- /*
86- * Check if the enum value is blacklisted. If not, it's safe, because it
87- * was made during CREATE TYPE AS ENUM and can't be shorter-lived than its
88- * owning type. (This'd also be false for values made by other
89- * transactions; but the previous tests should have handled all of those.)
90- */
91- if (!EnumBlacklisted (HeapTupleGetOid (enumval_tup )))
92- return ;
93-
94- /*
95- * There might well be other tests we could do here to narrow down the
96- * unsafe conditions, but for now just raise an exception.
97- */
98- en = (Form_pg_enum ) GETSTRUCT (enumval_tup );
99- ereport (ERROR ,
100- (errcode (ERRCODE_UNSAFE_NEW_ENUM_VALUE_USAGE ),
101- errmsg ("unsafe use of new value \"%s\" of enum type %s" ,
102- NameStr (en -> enumlabel ),
103- format_type_be (en -> enumtypid )),
104- errhint ("New enum values must be committed before they can be used." )));
105- }
106-
107-
10834/* Basic I/O support */
10935
11036Datum
@@ -133,9 +59,6 @@ enum_in(PG_FUNCTION_ARGS)
13359 format_type_be (enumtypoid ),
13460 name )));
13561
136- /* check it's safe to use in SQL */
137- check_safe_enum_use (tup );
138-
13962 /*
14063 * This comes from pg_enum.oid and stores system oids in user tables. This
14164 * oid must be preserved by binary upgrades.
@@ -201,9 +124,6 @@ enum_recv(PG_FUNCTION_ARGS)
201124 format_type_be (enumtypoid ),
202125 name )));
203126
204- /* check it's safe to use in SQL */
205- check_safe_enum_use (tup );
206-
207127 enumoid = HeapTupleGetOid (tup );
208128
209129 ReleaseSysCache (tup );
@@ -411,16 +331,9 @@ enum_endpoint(Oid enumtypoid, ScanDirection direction)
411331
412332 enum_tuple = systable_getnext_ordered (enum_scan , direction );
413333 if (HeapTupleIsValid (enum_tuple ))
414- {
415- /* check it's safe to use in SQL */
416- check_safe_enum_use (enum_tuple );
417334 minmax = HeapTupleGetOid (enum_tuple );
418- }
419335 else
420- {
421- /* should only happen with an empty enum */
422336 minmax = InvalidOid ;
423- }
424337
425338 systable_endscan_ordered (enum_scan );
426339 index_close (enum_idx , AccessShareLock );
@@ -581,9 +494,6 @@ enum_range_internal(Oid enumtypoid, Oid lower, Oid upper)
581494
582495 if (left_found )
583496 {
584- /* check it's safe to use in SQL */
585- check_safe_enum_use (enum_tuple );
586-
587497 if (cnt >= max )
588498 {
589499 max *= 2 ;
0 commit comments