30 #include "utils/fmgroids.h"
84 LOCKMODE lockmode,
bool *detached_exist,
115 Anum_pg_inherits_inhparent,
142 *detached_exist =
true;
167 elog(
WARNING,
"more than one partition pending detach found for table with OID %u",
170 *detached_xmin = xmin;
173 *detached_xmin = xmin;
183 if (numoids >= maxoids)
188 oidarr[numoids++] = inhrelid;
207 for (
i = 0;
i < numoids;
i++)
209 inhrelid = oidarr[
i];
269 seen_rels =
hash_create(
"find_all_inheritors temporary table",
286 foreach(l, rels_list)
289 List *currentchildren;
302 foreach(lc, currentchildren)
329 *numparents = rel_numparents;
363 elog(
ERROR,
"cache lookup failed for relation %u", relationId);
443 foreach(queue_item, queue)
467 Anum_pg_inherits_inhrelid,
477 Oid inhparent = inh->inhparent;
480 if (inhparent == superclassRelid)
512 bool nulls[Natts_pg_inherits];
526 memset(nulls, 0,
sizeof(nulls));
554 const char *childname)
567 Anum_pg_inherits_inhrelid,
571 true, NULL, 1, &
key);
579 if (!
OidIsValid(inhparent) || parent == inhparent)
590 if (detach_pending && !expect_detach_pending)
592 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
593 errmsg(
"cannot detach partition \"%s\"",
594 childname ? childname :
"unknown relation"),
595 errdetail(
"The partition is being detached concurrently or has an unfinished detach."),
596 errhint(
"Use ALTER TABLE ... DETACH PARTITION ... FINALIZE to complete the pending detach operation.")));
597 if (!detach_pending && expect_detach_pending)
599 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
600 errmsg(
"cannot complete detaching partition \"%s\"",
601 childname ? childname :
"unknown relation"),
602 errdetail(
"There's no pending concurrent detach.")));
635 Anum_pg_inherits_inhrelid,
639 true, NULL, 1, &
key);
655 elog(
ERROR,
"relation %u is not a partition", partoid);
static Datum values[MAXATTR]
#define OidIsValid(objectId)
elog(ERROR, "%s: %s", p2, msg)
void hash_destroy(HTAB *hashp)
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)
int errdetail(const char *fmt,...)
int errhint(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, const Datum *values, const bool *isnull)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
#define HeapTupleHeaderGetXmin(tup)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
List * lappend_int(List *list, int datum)
List * lappend_oid(List *list, Oid datum)
void list_free(List *list)
bool list_member_oid(const List *list, Oid datum)
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
void pfree(void *pointer)
MemoryContext CurrentMemoryContext
void * repalloc(void *pointer, Size size)
int oid_cmp(const void *p1, const void *p2)
Oid typeOrDomainTypeRelid(Oid type_id)
Oid typeidTypeRelid(Oid type_id)
FormData_pg_class * Form_pg_class
List * find_inheritance_children_extended(Oid parentrelId, bool omit_detached, LOCKMODE lockmode, bool *detached_exist, TransactionId *detached_xmin)
bool has_subclass(Oid relationId)
bool DeleteInheritsTuple(Oid inhrelid, Oid inhparent, bool expect_detach_pending, const char *childname)
struct SeenRelsEntry SeenRelsEntry
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
void StoreSingleInheritance(Oid relationId, Oid parentOid, int32 seqNumber)
List * find_inheritance_children(Oid parentrelId, LOCKMODE lockmode)
bool has_superclass(Oid relationId)
bool typeInheritsFrom(Oid subclassTypeId, Oid superclassTypeId)
bool PartitionHasPendingDetach(Oid partoid)
FormData_pg_inherits * Form_pg_inherits
static int list_length(const List *l)
#define list_make1_oid(x1)
static ListCell * list_nth_cell(const List *list, int n)
#define list_make1_int(x1)
#define qsort(a, b, c, d)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum Int32GetDatum(int32 X)
#define RelationGetDescr(relation)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
bool ActiveSnapshotSet(void)
Snapshot GetActiveSnapshot(void)
#define BTEqualStrategyNumber
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define SearchSysCacheExists1(cacheId, key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
bool TransactionIdFollows(TransactionId id1, TransactionId id2)
#define InvalidTransactionId