30 #include "utils/fmgroids.h"
131 for (elemno = 0; elemno < num_elems; elemno++)
144 }
while (new_oid & 1);
145 oids[elemno] = new_oid;
155 nslots =
Min(num_elems,
158 for (
int i = 0;
i < nslots;
i++)
174 (
errcode(ERRCODE_INVALID_NAME),
175 errmsg(
"invalid enum label \"%s\"", lab),
176 errdetail(
"Labels must be %d bytes or less.",
181 memset(slot[slotCount]->tts_isnull,
false,
182 slot[slotCount]->tts_tupleDescriptor->natts *
sizeof(
bool));
195 if (slotCount == nslots)
212 for (
int i = 0;
i < nslots;
i++)
234 Anum_pg_enum_enumtypid,
294 const char *neighbor,
301 bool nulls[Natts_pg_enum];
313 (
errcode(ERRCODE_INVALID_NAME),
314 errmsg(
"invalid enum label \"%s\"", newVal),
315 errdetail(
"Labels must be %d bytes or less.",
343 errmsg(
"enum label \"%s\" already exists, skipping",
350 errmsg(
"enum label \"%s\" already exists",
362 nelems =
list->n_members;
366 for (
i = 0;
i < nelems;
i++)
367 existing[
i] = &(
list->members[
i]->tuple);
371 if (neighbor == NULL)
381 newelemorder = en->enumsortorder + 1;
395 for (nbr_index = 0; nbr_index < nelems; nbr_index++)
399 if (strcmp(
NameStr(en->enumlabel), neighbor) == 0)
402 if (nbr_index >= nelems)
404 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
405 errmsg(
"\"%s\" is not an existing enum label",
420 other_nbr_index = nbr_index + 1;
422 other_nbr_index = nbr_index - 1;
424 if (other_nbr_index < 0)
425 newelemorder = nbr_en->enumsortorder - 1;
426 else if (other_nbr_index >= nelems)
427 newelemorder = nbr_en->enumsortorder + 1;
440 midpoint = (nbr_en->enumsortorder +
441 other_nbr_en->enumsortorder) / 2;
443 if (midpoint == nbr_en->enumsortorder ||
444 midpoint == other_nbr_en->enumsortorder)
453 newelemorder = midpoint;
462 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
463 errmsg(
"pg_enum OID value not set when in binary upgrade mode")));
470 if (neighbor != NULL)
472 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
473 errmsg(
"ALTER TYPE ADD BEFORE/AFTER is incompatible with binary upgrade")));
502 for (
i = 0;
i < nelems;
i++)
506 Oid exists_oid = exists_en->oid;
511 if (exists_en->enumsortorder < newelemorder)
514 if (exists_oid >= newOid)
523 if (exists_oid <= newOid)
534 if ((newOid & 1) == 0)
566 memset(nulls,
false,
sizeof(nulls));
623 (
errcode(ERRCODE_INVALID_NAME),
624 errmsg(
"invalid enum label \"%s\"", newVal),
625 errdetail(
"Labels must be %d bytes or less.",
642 nelems =
list->n_members;
651 for (
i = 0;
i < nelems;
i++)
653 enum_tup = &(
list->members[
i]->tuple);
655 if (strcmp(
NameStr(en->enumlabel), oldVal) == 0)
657 if (strcmp(
NameStr(en->enumlabel), newVal) == 0)
662 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
663 errmsg(
"\"%s\" is not an existing enum label",
668 errmsg(
"enum label \"%s\" already exists",
770 for (
i = nelems - 1;
i >= 0;
i--)
779 newsortorder =
i + 1;
780 if (en->enumsortorder != newsortorder)
782 en->enumsortorder = newsortorder;
804 if (en1->enumsortorder < en2->enumsortorder)
806 else if (en1->enumsortorder > en2->enumsortorder)
823 return sizeof(
Oid) * (entries + 2);
829 Oid *serialized = (
Oid *) space;
845 *serialized++ = *
value;
859 *serialized++ = *
value;
869 Assert((
char *) serialized == ((
char *) space) +
size);
875 Oid *serialized = (
Oid *) space;
static Datum values[MAXATTR]
#define Assert(condition)
#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_copytuple(HeapTuple tuple)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
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
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)
void RestoreUncommittedEnums(void *space)
static HTAB * uncommitted_enum_values
void RenameEnumLabel(Oid enumTypeOid, const char *oldVal, const char *newVal)
Size EstimateUncommittedEnumsSpace(void)
static void init_uncommitted_enum_types(void)
bool EnumUncommitted(Oid enum_id)
static void init_uncommitted_enum_values(void)
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 HTAB * uncommitted_enum_types
static int sort_order_cmp(const void *p1, const void *p2)
static bool EnumTypeUncommitted(Oid typ_id)
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)
static pg_noinline void Size size
#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)
int GetCurrentTransactionNestLevel(void)
void CommandCounterIncrement(void)