30#include "utils/fmgroids.h"
125 for (elemno = 0; elemno < num_elems; elemno++)
138 }
while (new_oid & 1);
139 oids[elemno] = new_oid;
149 nslots =
Min(num_elems,
152 for (
int i = 0;
i < nslots;
i++)
169 (
errcode(ERRCODE_INVALID_NAME),
170 errmsg(
"invalid enum label \"%s\"", lab),
171 errdetail(
"Labels must be %d bytes or less.",
187 errmsg(
"enum label \"%s\" used more than once",
194 memset(slot[slotCount]->tts_isnull,
false,
195 slot[slotCount]->tts_tupleDescriptor->natts *
sizeof(
bool));
208 if (slotCount == nslots)
225 for (
int i = 0;
i < nslots;
i++)
247 Anum_pg_enum_enumtypid,
307 const char *neighbor,
314 bool nulls[Natts_pg_enum];
326 (
errcode(ERRCODE_INVALID_NAME),
327 errmsg(
"invalid enum label \"%s\"", newVal),
328 errdetail(
"Labels must be %d bytes or less.",
356 errmsg(
"enum label \"%s\" already exists, skipping",
363 errmsg(
"enum label \"%s\" already exists",
375 nelems =
list->n_members;
379 for (
i = 0;
i < nelems;
i++)
380 existing[
i] = &(
list->members[
i]->tuple);
384 if (neighbor == NULL)
394 newelemorder = en->enumsortorder + 1;
408 for (nbr_index = 0; nbr_index < nelems; nbr_index++)
412 if (strcmp(
NameStr(en->enumlabel), neighbor) == 0)
415 if (nbr_index >= nelems)
417 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
418 errmsg(
"\"%s\" is not an existing enum label",
433 other_nbr_index = nbr_index + 1;
435 other_nbr_index = nbr_index - 1;
437 if (other_nbr_index < 0)
438 newelemorder = nbr_en->enumsortorder - 1;
439 else if (other_nbr_index >= nelems)
440 newelemorder = nbr_en->enumsortorder + 1;
453 midpoint = (nbr_en->enumsortorder +
454 other_nbr_en->enumsortorder) / 2;
456 if (midpoint == nbr_en->enumsortorder ||
457 midpoint == other_nbr_en->enumsortorder)
466 newelemorder = midpoint;
475 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
476 errmsg(
"pg_enum OID value not set when in binary upgrade mode")));
483 if (neighbor != NULL)
485 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
486 errmsg(
"ALTER TYPE ADD BEFORE/AFTER is incompatible with binary upgrade")));
515 for (
i = 0;
i < nelems;
i++)
519 Oid exists_oid = exists_en->oid;
524 if (exists_en->enumsortorder < newelemorder)
527 if (exists_oid >= newOid)
536 if (exists_oid <= newOid)
547 if ((newOid & 1) == 0)
579 memset(nulls,
false,
sizeof(nulls));
636 (
errcode(ERRCODE_INVALID_NAME),
637 errmsg(
"invalid enum label \"%s\"", newVal),
638 errdetail(
"Labels must be %d bytes or less.",
655 nelems =
list->n_members;
664 for (
i = 0;
i < nelems;
i++)
666 enum_tup = &(
list->members[
i]->tuple);
668 if (strcmp(
NameStr(en->enumlabel), oldVal) == 0)
670 if (strcmp(
NameStr(en->enumlabel), newVal) == 0)
675 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
676 errmsg(
"\"%s\" is not an existing enum label",
681 errmsg(
"enum label \"%s\" already exists",
783 for (
i = nelems - 1;
i >= 0;
i--)
792 newsortorder =
i + 1;
793 if (en->enumsortorder != newsortorder)
795 en->enumsortorder = newsortorder;
817 if (en1->enumsortorder < en2->enumsortorder)
819 else if (en1->enumsortorder > en2->enumsortorder)
836 return sizeof(
Oid) * (entries + 2);
842 Oid *serialized = (
Oid *) space;
858 *serialized++ = *
value;
872 *serialized++ = *
value;
882 Assert((
char *) serialized == ((
char *) space) + size);
888 Oid *serialized = (
Oid *) space;
static Datum values[MAXATTR]
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
void ReleaseCatCacheList(CatCList *list)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
void * hash_seq_search(HASH_SEQ_STATUS *status)
int64 hash_get_num_entries(HTAB *hashp)
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 * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
const TupleTableSlotOps TTSOpsHeapTuple
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)
Assert(PointerIsAligned(start, uint64))
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)
static void * GETSTRUCT(const HeapTupleData *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)
#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)