30 #include "utils/fmgroids.h"
69 bool nulls[Natts_pg_enum];
93 for (elemno = 0; elemno < num_elems; elemno++)
106 }
while (new_oid & 1);
107 oids[elemno] = new_oid;
114 memset(nulls,
false,
sizeof(nulls));
127 (
errcode(ERRCODE_INVALID_NAME),
128 errmsg(
"invalid enum label \"%s\"", lab),
129 errdetail(
"Labels must be %d bytes or less.",
167 Anum_pg_enum_enumtypid,
210 const char *neighbor,
217 bool nulls[Natts_pg_enum];
229 (
errcode(ERRCODE_INVALID_NAME),
230 errmsg(
"invalid enum label \"%s\"", newVal),
231 errdetail(
"Labels must be %d bytes or less.",
259 errmsg(
"enum label \"%s\" already exists, skipping",
266 errmsg(
"enum label \"%s\" already exists",
278 nelems =
list->n_members;
282 for (
i = 0;
i < nelems;
i++)
283 existing[
i] = &(
list->members[
i]->tuple);
287 if (neighbor == NULL)
297 newelemorder = en->enumsortorder + 1;
311 for (nbr_index = 0; nbr_index < nelems; nbr_index++)
315 if (strcmp(
NameStr(en->enumlabel), neighbor) == 0)
318 if (nbr_index >= nelems)
320 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
321 errmsg(
"\"%s\" is not an existing enum label",
336 other_nbr_index = nbr_index + 1;
338 other_nbr_index = nbr_index - 1;
340 if (other_nbr_index < 0)
341 newelemorder = nbr_en->enumsortorder - 1;
342 else if (other_nbr_index >= nelems)
343 newelemorder = nbr_en->enumsortorder + 1;
356 midpoint = (nbr_en->enumsortorder +
357 other_nbr_en->enumsortorder) / 2;
359 if (midpoint == nbr_en->enumsortorder ||
360 midpoint == other_nbr_en->enumsortorder)
369 newelemorder = midpoint;
378 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
379 errmsg(
"pg_enum OID value not set when in binary upgrade mode")));
386 if (neighbor != NULL)
388 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
389 errmsg(
"ALTER TYPE ADD BEFORE/AFTER is incompatible with binary upgrade")));
418 for (
i = 0;
i < nelems;
i++)
422 Oid exists_oid = exists_en->oid;
427 if (exists_en->enumsortorder < newelemorder)
430 if (exists_oid >= newOid)
439 if (exists_oid <= newOid)
450 if ((newOid & 1) == 0)
482 memset(nulls,
false,
sizeof(nulls));
524 (
errcode(ERRCODE_INVALID_NAME),
525 errmsg(
"invalid enum label \"%s\"", newVal),
526 errdetail(
"Labels must be %d bytes or less.",
543 nelems =
list->n_members;
552 for (
i = 0;
i < nelems;
i++)
554 enum_tup = &(
list->members[
i]->tuple);
556 if (strcmp(
NameStr(en->enumlabel), oldVal) == 0)
558 if (strcmp(
NameStr(en->enumlabel), newVal) == 0)
563 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
564 errmsg(
"\"%s\" is not an existing enum label",
569 errmsg(
"enum label \"%s\" already exists",
652 for (
i = nelems - 1;
i >= 0;
i--)
661 newsortorder =
i + 1;
662 if (en->enumsortorder != newsortorder)
664 en->enumsortorder = newsortorder;
686 if (en1->enumsortorder < en2->enumsortorder)
688 else if (en1->enumsortorder > en2->enumsortorder)
705 return sizeof(
Oid) * (entries + 1);
711 Oid *serialized = (
Oid *) space;
727 *serialized++ = *
value;
737 Assert((
char *) (serialized + 1) == ((
char *) space) + size);
743 Oid *serialized = (
Oid *) space;
static Datum values[MAXATTR]
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
void ReleaseCatCacheList(CatCList *list)
static void PGresult const char * p2
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
long hash_get_num_entries(HTAB *hashp)
void * hash_seq_search(HASH_SEQ_STATUS *status)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
HeapTuple heap_copytuple(HeapTuple tuple)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Assert(fmt[strlen(fmt) - 1] !='\n')
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
MemoryContext TopTransactionContext
void pfree(void *pointer)
void namestrcpy(Name name, const char *str)
int oid_cmp(const void *p1, const void *p2)
static HTAB * uncommitted_enums
void RestoreUncommittedEnums(void *space)
void RenameEnumLabel(Oid enumTypeOid, const char *oldVal, const char *newVal)
Size EstimateUncommittedEnumsSpace(void)
static void init_uncommitted_enums(void)
bool EnumUncommitted(Oid enum_id)
void EnumValuesDelete(Oid enumTypeOid)
void AddEnumLabel(Oid enumTypeOid, const char *newVal, const char *neighbor, bool newValIsAfter, bool skipIfExists)
void SerializeUncommittedEnums(void *space, Size size)
Oid binary_upgrade_next_pg_enum_oid
static int sort_order_cmp(const void *p1, const void *p2)
static void RenumberEnumType(Relation pg_enum, HeapTuple *existing, int nelems)
void EnumValuesCreate(Oid enumTypeOid, List *vals)
FormData_pg_enum * Form_pg_enum
static int list_length(const List *l)
static void static void status(const char *fmt,...) pg_attribute_printf(1
#define qsort(a, b, c, d)
static Datum Float4GetDatum(float4 X)
#define CStringGetDatum(X)
#define ObjectIdGetDatum(X)
#define RelationGetDescr(relation)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
#define BTEqualStrategyNumber
#define ERRCODE_DUPLICATE_OBJECT
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
#define SearchSysCacheList1(cacheId, key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
void CommandCounterIncrement(void)