30 #include "utils/fmgroids.h"
93 for (elemno = 0; elemno < num_elems; elemno++)
106 }
while (new_oid & 1);
107 oids[elemno] = new_oid;
117 nslots =
Min(num_elems,
120 for (
int i = 0;
i < nslots;
i++)
136 (
errcode(ERRCODE_INVALID_NAME),
137 errmsg(
"invalid enum label \"%s\"", lab),
138 errdetail(
"Labels must be %d bytes or less.",
143 memset(slot[slotCount]->tts_isnull,
false,
144 slot[slotCount]->tts_tupleDescriptor->natts *
sizeof(
bool));
157 if (slotCount == nslots)
174 for (
int i = 0;
i < nslots;
i++)
196 Anum_pg_enum_enumtypid,
239 const char *neighbor,
246 bool nulls[Natts_pg_enum];
258 (
errcode(ERRCODE_INVALID_NAME),
259 errmsg(
"invalid enum label \"%s\"", newVal),
260 errdetail(
"Labels must be %d bytes or less.",
288 errmsg(
"enum label \"%s\" already exists, skipping",
295 errmsg(
"enum label \"%s\" already exists",
307 nelems =
list->n_members;
311 for (
i = 0;
i < nelems;
i++)
312 existing[
i] = &(
list->members[
i]->tuple);
316 if (neighbor == NULL)
326 newelemorder = en->enumsortorder + 1;
340 for (nbr_index = 0; nbr_index < nelems; nbr_index++)
344 if (strcmp(
NameStr(en->enumlabel), neighbor) == 0)
347 if (nbr_index >= nelems)
349 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
350 errmsg(
"\"%s\" is not an existing enum label",
365 other_nbr_index = nbr_index + 1;
367 other_nbr_index = nbr_index - 1;
369 if (other_nbr_index < 0)
370 newelemorder = nbr_en->enumsortorder - 1;
371 else if (other_nbr_index >= nelems)
372 newelemorder = nbr_en->enumsortorder + 1;
385 midpoint = (nbr_en->enumsortorder +
386 other_nbr_en->enumsortorder) / 2;
388 if (midpoint == nbr_en->enumsortorder ||
389 midpoint == other_nbr_en->enumsortorder)
398 newelemorder = midpoint;
407 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
408 errmsg(
"pg_enum OID value not set when in binary upgrade mode")));
415 if (neighbor != NULL)
417 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
418 errmsg(
"ALTER TYPE ADD BEFORE/AFTER is incompatible with binary upgrade")));
447 for (
i = 0;
i < nelems;
i++)
451 Oid exists_oid = exists_en->oid;
456 if (exists_en->enumsortorder < newelemorder)
459 if (exists_oid >= newOid)
468 if (exists_oid <= newOid)
479 if ((newOid & 1) == 0)
511 memset(nulls,
false,
sizeof(nulls));
553 (
errcode(ERRCODE_INVALID_NAME),
554 errmsg(
"invalid enum label \"%s\"", newVal),
555 errdetail(
"Labels must be %d bytes or less.",
572 nelems =
list->n_members;
581 for (
i = 0;
i < nelems;
i++)
583 enum_tup = &(
list->members[
i]->tuple);
585 if (strcmp(
NameStr(en->enumlabel), oldVal) == 0)
587 if (strcmp(
NameStr(en->enumlabel), newVal) == 0)
592 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
593 errmsg(
"\"%s\" is not an existing enum label",
598 errmsg(
"enum label \"%s\" already exists",
681 for (
i = nelems - 1;
i >= 0;
i--)
690 newsortorder =
i + 1;
691 if (en->enumsortorder != newsortorder)
693 en->enumsortorder = newsortorder;
715 if (en1->enumsortorder < en2->enumsortorder)
717 else if (en1->enumsortorder > en2->enumsortorder)
734 return sizeof(
Oid) * (entries + 1);
740 Oid *serialized = (
Oid *) space;
756 *serialized++ = *
value;
766 Assert((
char *) (serialized + 1) == ((
char *) space) + size);
772 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,...)
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
const TupleTableSlotOps TTSOpsHeapTuple
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
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 CatalogTuplesMultiInsertWithInfo(Relation heapRel, TupleTableSlot **slot, int ntuples, CatalogIndexState indstate)
void CatalogCloseIndexes(CatalogIndexState indstate)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
CatalogIndexState CatalogOpenIndexes(Relation heapRel)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
#define MAX_CATALOG_MULTI_INSERT_BYTES
Assert(fmt[strlen(fmt) - 1] !='\n')
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
MemoryContext TopTransactionContext
void pfree(void *pointer)
void * palloc0(Size size)
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)
#define qsort(a, b, c, d)
static Datum Float4GetDatum(float4 X)
static Datum ObjectIdGetDatum(Oid X)
static Datum NameGetDatum(const NameData *X)
static Datum CStringGetDatum(const char *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)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
void CommandCounterIncrement(void)