Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit28e0727

Browse files
committed
Revert to 9.6 treatment of ALTER TYPE enumtype ADD VALUE.
This reverts commit15bc038, along with the followon commits1635e80and984c920 that tried to clean up the problems exposed by bug #14825.The result was incomplete because it failed to address parallel-queryrequirements. With 10.0 release so close upon us, now does not seem likethe time to be adding more code to fix that. I hope we can un-revert thiscode and add the missing parallel query support during the v11 cycle.Back-patch to v10.Discussion:https://postgr.es/m/20170922185904.1448.16585@wrigleys.postgresql.org
1 parent65c8656 commit28e0727

File tree

11 files changed

+49
-270
lines changed

11 files changed

+49
-270
lines changed

‎doc/src/sgml/ref/alter_type.sgml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,8 @@ ALTER TYPE <replaceable class="PARAMETER">name</replaceable> RENAME VALUE <repla
290290
<title>Notes</title>
291291

292292
<para>
293-
If <command>ALTER TYPE ... ADD VALUE</> (the form that adds a new value to
294-
an enum type) is executed inside a transaction block, the new value cannot
295-
be used until after the transaction has been committed.
293+
<command>ALTER TYPE ... ADD VALUE</> (the form that adds a new value to an
294+
enum type) cannot be executed inside a transaction block.
296295
</para>
297296

298297
<para>

‎src/backend/access/transam/xact.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include"access/xlogutils.h"
3333
#include"catalog/catalog.h"
3434
#include"catalog/namespace.h"
35-
#include"catalog/pg_enum.h"
3635
#include"catalog/storage.h"
3736
#include"commands/async.h"
3837
#include"commands/tablecmds.h"
@@ -2129,7 +2128,6 @@ CommitTransaction(void)
21292128
AtCommit_Notify();
21302129
AtEOXact_GUC(true,1);
21312130
AtEOXact_SPI(true);
2132-
AtEOXact_Enum();
21332131
AtEOXact_on_commit_actions(true);
21342132
AtEOXact_Namespace(true,is_parallel_worker);
21352133
AtEOXact_SMgr();
@@ -2408,7 +2406,6 @@ PrepareTransaction(void)
24082406
/* PREPARE acts the same as COMMIT as far as GUC is concerned */
24092407
AtEOXact_GUC(true,1);
24102408
AtEOXact_SPI(true);
2411-
AtEOXact_Enum();
24122409
AtEOXact_on_commit_actions(true);
24132410
AtEOXact_Namespace(true, false);
24142411
AtEOXact_SMgr();
@@ -2611,7 +2608,6 @@ AbortTransaction(void)
26112608

26122609
AtEOXact_GUC(false,1);
26132610
AtEOXact_SPI(false);
2614-
AtEOXact_Enum();
26152611
AtEOXact_on_commit_actions(false);
26162612
AtEOXact_Namespace(false,is_parallel_worker);
26172613
AtEOXact_SMgr();

‎src/backend/catalog/pg_enum.c

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,13 @@
2828
#include"utils/builtins.h"
2929
#include"utils/catcache.h"
3030
#include"utils/fmgroids.h"
31-
#include"utils/hsearch.h"
32-
#include"utils/memutils.h"
3331
#include"utils/syscache.h"
3432
#include"utils/tqual.h"
3533

3634

3735
/* Potentially set by pg_upgrade_support functions */
3836
Oidbinary_upgrade_next_pg_enum_oid=InvalidOid;
3937

40-
/*
41-
* Hash table of enum value OIDs created during the current transaction by
42-
* AddEnumLabel. We disallow using these values until the transaction is
43-
* committed; otherwise, they might get into indexes where we can't clean
44-
* them up, and then if the transaction rolls back we have a broken index.
45-
* (See comments for check_safe_enum_use() in enum.c.) Values created by
46-
* EnumValuesCreate are *not* blacklisted; we assume those are created during
47-
* CREATE TYPE, so they can't go away unless the enum type itself does.
48-
*/
49-
staticHTAB*enum_blacklist=NULL;
50-
5138
staticvoidRenumberEnumType(Relationpg_enum,HeapTuple*existing,intnelems);
5239
staticintsort_order_cmp(constvoid*p1,constvoid*p2);
5340

@@ -473,24 +460,6 @@ AddEnumLabel(Oid enumTypeOid,
473460
heap_freetuple(enum_tup);
474461

475462
heap_close(pg_enum,RowExclusiveLock);
476-
477-
/* Set up the blacklist hash if not already done in this transaction */
478-
if (enum_blacklist==NULL)
479-
{
480-
HASHCTLhash_ctl;
481-
482-
memset(&hash_ctl,0,sizeof(hash_ctl));
483-
hash_ctl.keysize=sizeof(Oid);
484-
hash_ctl.entrysize=sizeof(Oid);
485-
hash_ctl.hcxt=TopTransactionContext;
486-
enum_blacklist=hash_create("Enum value blacklist",
487-
32,
488-
&hash_ctl,
489-
HASH_ELEM |HASH_BLOBS |HASH_CONTEXT);
490-
}
491-
492-
/* Add the new value to the blacklist */
493-
(void)hash_search(enum_blacklist,&newOid,HASH_ENTER,NULL);
494463
}
495464

496465

@@ -578,39 +547,6 @@ RenameEnumLabel(Oid enumTypeOid,
578547
}
579548

580549

581-
/*
582-
* Test if the given enum value is on the blacklist
583-
*/
584-
bool
585-
EnumBlacklisted(Oidenum_id)
586-
{
587-
boolfound;
588-
589-
/* If we've made no blacklist table, all values are safe */
590-
if (enum_blacklist==NULL)
591-
return false;
592-
593-
/* Else, is it in the table? */
594-
(void)hash_search(enum_blacklist,&enum_id,HASH_FIND,&found);
595-
returnfound;
596-
}
597-
598-
599-
/*
600-
* Clean up enum stuff after end of top-level transaction.
601-
*/
602-
void
603-
AtEOXact_Enum(void)
604-
{
605-
/*
606-
* Reset the blacklist table, as all our enum values are now committed.
607-
* The memory will go away automatically when TopTransactionContext is
608-
* freed; it's sufficient to clear our pointer.
609-
*/
610-
enum_blacklist=NULL;
611-
}
612-
613-
614550
/*
615551
* RenumberEnumType
616552
*Renumber existing enum elements to have sort positions 1..n.

‎src/backend/commands/typecmds.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,10 +1222,10 @@ DefineEnum(CreateEnumStmt *stmt)
12221222

12231223
/*
12241224
* AlterEnum
1225-
*Adds a new label to an existing enum.
1225+
*ALTER TYPE on an enum.
12261226
*/
12271227
ObjectAddress
1228-
AlterEnum(AlterEnumStmt*stmt)
1228+
AlterEnum(AlterEnumStmt*stmt,boolisTopLevel)
12291229
{
12301230
Oidenum_type_oid;
12311231
TypeName*typename;
@@ -1243,8 +1243,6 @@ AlterEnum(AlterEnumStmt *stmt)
12431243
/* Check it's an enum and check user has permission to ALTER the enum */
12441244
checkEnumOwner(tup);
12451245

1246-
ReleaseSysCache(tup);
1247-
12481246
if (stmt->oldVal)
12491247
{
12501248
/* Rename an existing label */
@@ -1253,6 +1251,27 @@ AlterEnum(AlterEnumStmt *stmt)
12531251
else
12541252
{
12551253
/* Add a new label */
1254+
1255+
/*
1256+
* Ordinarily we disallow adding values within transaction blocks,
1257+
* because we can't cope with enum OID values getting into indexes and
1258+
* then having their defining pg_enum entries go away. However, it's
1259+
* okay if the enum type was created in the current transaction, since
1260+
* then there can be no such indexes that wouldn't themselves go away
1261+
* on rollback. (We support this case because pg_dump
1262+
* --binary-upgrade needs it.) We test this by seeing if the pg_type
1263+
* row has xmin == current XID and is not HEAP_UPDATED. If it is
1264+
* HEAP_UPDATED, we can't be sure whether the type was created or only
1265+
* modified in this xact. So we are disallowing some cases that could
1266+
* theoretically be safe; but fortunately pg_dump only needs the
1267+
* simplest case.
1268+
*/
1269+
if (HeapTupleHeaderGetXmin(tup->t_data)==GetCurrentTransactionId()&&
1270+
!(tup->t_data->t_infomask&HEAP_UPDATED))
1271+
/* safe to do inside transaction block */ ;
1272+
else
1273+
PreventTransactionChain(isTopLevel,"ALTER TYPE ... ADD");
1274+
12561275
AddEnumLabel(enum_type_oid,stmt->newVal,
12571276
stmt->newValNeighbor,stmt->newValIsAfter,
12581277
stmt->skipIfNewValExists);
@@ -1262,6 +1281,8 @@ AlterEnum(AlterEnumStmt *stmt)
12621281

12631282
ObjectAddressSet(address,TypeRelationId,enum_type_oid);
12641283

1284+
ReleaseSysCache(tup);
1285+
12651286
returnaddress;
12661287
}
12671288

‎src/backend/tcop/utility.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ ProcessUtilitySlow(ParseState *pstate,
14121412
break;
14131413

14141414
caseT_AlterEnumStmt:/* ALTER TYPE (enum) */
1415-
address=AlterEnum((AlterEnumStmt*)parsetree);
1415+
address=AlterEnum((AlterEnumStmt*)parsetree,isTopLevel);
14161416
break;
14171417

14181418
caseT_ViewStmt:/* CREATE VIEW */

‎src/backend/utils/adt/enum.c

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
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 Oidenum_endpoint(Oid enumtypoid, ScanDirection direction);
3231
staticArrayType*enum_range_internal(Oidenumtypoid,Oidlower,Oidupper);
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-
staticvoid
64-
check_safe_enum_use(HeapTupleenumval_tup)
65-
{
66-
TransactionIdxmin;
67-
Form_pg_enumen;
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

11036
Datum
@@ -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;

‎src/backend/utils/errcodes.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ Section: Class 55 - Object Not In Prerequisite State
400400
55006 E ERRCODE_OBJECT_IN_USE object_in_use
401401
55P02 E ERRCODE_CANT_CHANGE_RUNTIME_PARAM cant_change_runtime_param
402402
55P03 E ERRCODE_LOCK_NOT_AVAILABLE lock_not_available
403-
55P04 E ERRCODE_UNSAFE_NEW_ENUM_VALUE_USAGE unsafe_new_enum_value_usage
404403

405404
Section: Class 57 - Operator Intervention
406405

‎src/include/catalog/pg_enum.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,5 @@ extern void AddEnumLabel(Oid enumTypeOid, const char *newVal,
6969
boolskipIfExists);
7070
externvoidRenameEnumLabel(OidenumTypeOid,
7171
constchar*oldVal,constchar*newVal);
72-
externboolEnumBlacklisted(Oidenum_id);
73-
externvoidAtEOXact_Enum(void);
7472

7573
#endif/* PG_ENUM_H */

‎src/include/commands/typecmds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern void RemoveTypeById(Oid typeOid);
2626
externObjectAddressDefineDomain(CreateDomainStmt*stmt);
2727
externObjectAddressDefineEnum(CreateEnumStmt*stmt);
2828
externObjectAddressDefineRange(CreateRangeStmt*stmt);
29-
externObjectAddressAlterEnum(AlterEnumStmt*stmt);
29+
externObjectAddressAlterEnum(AlterEnumStmt*stmt,boolisTopLevel);
3030
externObjectAddressDefineCompositeType(RangeVar*typevar,List*coldeflist);
3131
externOidAssignTypeArrayOid(void);
3232

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp