84 #include "utils/fmgroids.h"
101 #define DEPFLAG_ORIGINAL 0x0001
102 #define DEPFLAG_NORMAL 0x0002
103 #define DEPFLAG_AUTO 0x0004
104 #define DEPFLAG_INTERNAL 0x0008
105 #define DEPFLAG_PARTITION 0x0010
106 #define DEPFLAG_EXTENSION 0x0020
107 #define DEPFLAG_REVERSE 0x0040
108 #define DEPFLAG_IS_PART 0x0080
109 #define DEPFLAG_SUBOBJECT 0x0100
199 bool original =
false;
448 int numDependentObjects;
449 int maxDependentObjects;
496 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
497 errmsg(
"cannot drop %s because it is required by the database system",
511 Anum_pg_depend_classid,
515 Anum_pg_depend_objid,
522 Anum_pg_depend_objsubid,
537 memset(&owningObject, 0,
sizeof(owningObject));
538 memset(&partitionObject, 0,
sizeof(partitionObject));
544 otherObject.
classId = foundDep->refclassid;
545 otherObject.
objectId = foundDep->refobjid;
560 switch (foundDep->deptype)
588 otherObject.
classId == ExtensionRelationId &&
616 if (pendingObjects &&
637 owningObject = otherObject;
722 elog(
ERROR,
"deletion of owning object %s failed to delete %s",
743 partitionObject = otherObject;
753 partitionObject = otherObject;
764 elog(
ERROR,
"unrecognized dependency type '%c' for %s",
788 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
789 errmsg(
"cannot drop %s because %s requires it",
791 errhint(
"You can drop %s instead.", otherObjDesc)));
802 maxDependentObjects = 128;
805 numDependentObjects = 0;
808 Anum_pg_depend_refclassid,
812 Anum_pg_depend_refobjid,
818 Anum_pg_depend_refobjsubid,
834 otherObject.
classId = foundDep->classid;
835 otherObject.
objectId = foundDep->objid;
872 switch (foundDep->deptype)
892 elog(
ERROR,
"unrecognized dependency type '%c' for %s",
899 if (numDependentObjects >= maxDependentObjects)
902 maxDependentObjects *= 2;
908 dependentObjects[numDependentObjects].
obj = otherObject;
909 dependentObjects[numDependentObjects].
subflags = subflags;
910 numDependentObjects++;
920 if (numDependentObjects > 1)
921 qsort(dependentObjects, numDependentObjects,
930 mystack.
flags = objflags;
931 mystack.
next = stack;
933 for (
int i = 0;
i < numDependentObjects;
i++)
946 pfree(dependentObjects);
989 int numReportedClient = 0;
990 int numNotReportedClient = 0;
1015 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
1016 errmsg(
"cannot drop %s because %s requires it",
1018 errhint(
"You can drop %s instead.", otherObjDesc)));
1036 #define MAX_REPORTED_DEPS 100
1045 for (
i = targetObjects->
numrefs - 1;
i >= 0;
i--)
1062 if (objDesc == NULL)
1095 if (clientdetail.
len != 0)
1098 objDesc, otherDesc);
1099 numReportedClient++;
1102 numNotReportedClient++;
1104 if (logdetail.
len != 0)
1107 objDesc, otherDesc);
1111 numNotReportedClient++;
1119 if (clientdetail.
len != 0)
1123 numReportedClient++;
1126 numNotReportedClient++;
1128 if (logdetail.
len != 0)
1137 if (numNotReportedClient > 0)
1139 "(see server log for list)",
1140 "\nand %d other objects "
1141 "(see server log for list)",
1142 numNotReportedClient),
1143 numNotReportedClient);
1149 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
1150 errmsg(
"cannot drop %s because other objects depend on it",
1154 errhint(
"Use DROP ... CASCADE to drop the dependent objects too.")));
1157 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
1158 errmsg(
"cannot drop desired object(s) because other objects depend on them"),
1161 errhint(
"Use DROP ... CASCADE to drop the dependent objects too.")));
1163 else if (numReportedClient > 1)
1167 "drop cascades to %d other objects",
1168 numReportedClient + numNotReportedClient,
1169 numReportedClient + numNotReportedClient),
1173 else if (numReportedClient == 1)
1206 elog(
ERROR,
"cache lookup failed for %s %u",
1229 elog(
ERROR,
"could not find tuple for %s %u",
1290 Anum_pg_depend_classid,
1294 Anum_pg_depend_objid,
1300 Anum_pg_depend_objsubid,
1356 case RelationRelationId:
1360 if (relKind == RELKIND_INDEX ||
1361 relKind == RELKIND_PARTITIONED_INDEX)
1382 if (relKind == RELKIND_SEQUENCE)
1387 case ProcedureRelationId:
1391 case TypeRelationId:
1395 case ConstraintRelationId:
1399 case AttrDefaultRelationId:
1403 case LargeObjectRelationId:
1407 case OperatorRelationId:
1411 case RewriteRelationId:
1415 case TriggerRelationId:
1419 case StatisticExtRelationId:
1423 case TSConfigRelationId:
1427 case ExtensionRelationId:
1431 case PolicyRelationId:
1435 case PublicationNamespaceRelationId:
1439 case PublicationRelRelationId:
1443 case PublicationRelationId:
1447 case CastRelationId:
1448 case CollationRelationId:
1449 case ConversionRelationId:
1450 case LanguageRelationId:
1451 case OperatorClassRelationId:
1452 case OperatorFamilyRelationId:
1453 case AccessMethodRelationId:
1454 case AccessMethodOperatorRelationId:
1455 case AccessMethodProcedureRelationId:
1456 case NamespaceRelationId:
1457 case TSParserRelationId:
1458 case TSDictionaryRelationId:
1459 case TSTemplateRelationId:
1460 case ForeignDataWrapperRelationId:
1461 case ForeignServerRelationId:
1462 case UserMappingRelationId:
1463 case DefaultAclRelationId:
1464 case EventTriggerRelationId:
1465 case TransformRelationId:
1466 case AuthMemRelationId:
1473 case AuthIdRelationId:
1474 case DatabaseRelationId:
1475 case TableSpaceRelationId:
1476 case SubscriptionRelationId:
1477 case ParameterAclRelationId:
1478 elog(
ERROR,
"global objects cannot be deleted by doDeletion");
1608 rte.type = T_RangeTblEntry;
1611 rte.relkind = RELKIND_RELATION;
1623 if ((behavior != self_behavior || reverse_self) &&
1635 for (oldref = 0; oldref <
context.addrs->numrefs; oldref++)
1639 if (thisobj->
classId == RelationRelationId &&
1653 context.addrs->numrefs = outrefs;
1665 for (selfref = 0; selfref < self_addrs->
numrefs; selfref++)
1769 con->constcollid != DEFAULT_COLLATION_OID)
1779 if (!con->constisnull)
1784 case REGPROCEDUREOID:
1792 case REGOPERATOROID:
1813 case REGCOLLATIONOID:
1827 case REGDICTIONARYOID:
1835 case REGNAMESPACEOID:
1849 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1850 errmsg(
"constant of the type %s cannot be used here",
1866 param->paramcollid != DEFAULT_COLLATION_OID)
1936 if (sbsref->refrestype != sbsref->refcontainertype &&
1937 sbsref->refrestype != sbsref->refelemtype)
1945 elog(
ERROR,
"already-planned subqueries not supported");
1970 fselect->resultcollid != DEFAULT_COLLATION_OID)
1984 foreach(l, fstore->fieldnums)
2001 relab->resultcollid != DEFAULT_COLLATION_OID)
2014 iocoerce->resultcollid != DEFAULT_COLLATION_OID)
2027 acoerce->resultcollid != DEFAULT_COLLATION_OID)
2059 foreach(l, rcexpr->opnos)
2064 foreach(l, rcexpr->opfamilies)
2116 wc->inRangeColl != DEFAULT_COLLATION_OID)
2159 foreach(lc, query->
rtable)
2185 for (
int i = 0;
i < rte->joinmergedcols;
i++)
2211 if (query->resultRelation <= 0 ||
2213 elog(
ERROR,
"invalid resultRelation %d",
2214 query->resultRelation);
2233 foreach(lc, query->constraintDeps)
2267 foreach(ct, rtfunc->funccoltypes)
2272 foreach(ct, rtfunc->funccolcollations)
2289 foreach(ct, tf->coltypes)
2294 foreach(ct, tf->colcollations)
2337 if (
attnum > atts_done &&
2338 attnum <= atts_done + rtfunc->funccolcount)
2343 if (rtfunc->funccolnames !=
NIL)
2347 if (tupdesc && tupdesc->
tdtypeid != RECORDOID)
2365 atts_done += rtfunc->funccolcount;
2374 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2375 errmsg(
"column %d of relation \"%s\" does not exist",
2376 attnum, rte->eref->aliasname)));
2404 priorobj = addrs->
refs;
2406 for (oldref = 1; oldref < addrs->
numrefs; oldref++)
2432 *priorobj = *thisobj;
2583 *itemextra = *extra;
2623 bool result =
false;
2696 bool result =
false;
2699 for (stackptr = stack; stackptr; stackptr = stackptr->
next)
2796 Anum_pg_init_privs_objoid,
2800 Anum_pg_init_privs_classoid,
2806 Anum_pg_init_privs_objsubid,
#define InvalidAttrNumber
#define ngettext(s, p, n)
#define Assert(condition)
#define OidIsValid(objectId)
bool IsPinnedObject(Oid classId, Oid objectId)
void DeleteSequenceTuple(Oid relid)
static bool object_address_present_add_flags(const ObjectAddress *object, int flags, ObjectAddresses *addrs)
#define DEPFLAG_PARTITION
void performMultipleDeletions(const ObjectAddresses *objects, DropBehavior behavior, int flags)
struct ObjectAddressStack ObjectAddressStack
static void add_exact_object_address_extra(const ObjectAddress *object, const ObjectAddressExtra *extra, ObjectAddresses *addrs)
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
static void DropObjectById(const ObjectAddress *object)
static int object_address_comparator(const void *a, const void *b)
void sort_object_addresses(ObjectAddresses *addrs)
static void doDeletion(const ObjectAddress *object, int flags)
static bool stack_address_present_add_flags(const ObjectAddress *object, int flags, ObjectAddressStack *stack)
static void add_object_address(Oid classId, Oid objectId, int32 subId, ObjectAddresses *addrs)
static bool find_expr_references_walker(Node *node, find_expr_references_context *context)
static void eliminate_duplicate_dependencies(ObjectAddresses *addrs)
void AcquireDeletionLock(const ObjectAddress *object, int flags)
void performDeletion(const ObjectAddress *object, DropBehavior behavior, int flags)
static void deleteOneObject(const ObjectAddress *object, Relation *depRel, int32 flags)
static void DeleteInitPrivs(const ObjectAddress *object)
#define MAX_REPORTED_DEPS
static void process_function_rte_ref(RangeTblEntry *rte, AttrNumber attnum, find_expr_references_context *context)
static void reportDependentObjects(const ObjectAddresses *targetObjects, DropBehavior behavior, int flags, const ObjectAddress *origObject)
void ReleaseDeletionLock(const ObjectAddress *object)
void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool reverse_self)
void recordDependencyOnExpr(const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior)
static void findDependentObjects(const ObjectAddress *object, int objflags, int flags, ObjectAddressStack *stack, ObjectAddresses *targetObjects, const ObjectAddresses *pendingObjects, Relation *depRel)
bool object_address_present(const ObjectAddress *object, const ObjectAddresses *addrs)
ObjectAddresses * new_object_addresses(void)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
#define DEPFLAG_SUBOBJECT
#define DEPFLAG_EXTENSION
static void deleteObjectsInList(ObjectAddresses *targetObjects, Relation *depRel, int flags)
void free_object_addresses(ObjectAddresses *addrs)
#define PERFORM_DELETION_CONCURRENTLY
#define PERFORM_DELETION_SKIP_EXTENSIONS
@ DEPENDENCY_AUTO_EXTENSION
@ DEPENDENCY_PARTITION_PRI
@ DEPENDENCY_PARTITION_SEC
#define PERFORM_DELETION_CONCURRENT_LOCK
#define PERFORM_DELETION_QUIETLY
#define PERFORM_DELETION_SKIP_ORIGINAL
#define PERFORM_DELETION_INTERNAL
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
int errmsg_internal(const char *fmt,...)
int errdetail_internal(const char *fmt,...)
int errhint(const char *fmt,...)
bool message_level_is_interesting(int elevel)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
int errdetail_log(const char *fmt,...)
#define ereport(elevel,...)
void EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool normal)
bool trackDroppedObjectsNeeded(void)
bool EventTriggerSupportsObject(const ObjectAddress *object)
Oid CurrentExtensionObject
void RemoveExtensionById(Oid extId)
TupleDesc get_expr_result_tupdesc(Node *expr, bool noError)
void RemoveFunctionById(Oid funcOid)
void systable_endscan(SysScanDesc sysscan)
bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
void RemoveAttributeById(Oid relid, AttrNumber attnum)
void heap_drop_with_catalog(Oid relid)
#define HeapTupleIsValid(tuple)
void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
List * list_delete_first(List *list)
List * lcons(void *datum, List *list)
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
#define AccessExclusiveLock
#define ShareUpdateExclusiveLock
char get_rel_relkind(Oid relid)
Oid get_typ_typrelid(Oid typid)
Oid getBaseType(Oid typid)
void pfree(void *pointer)
void * repalloc(void *pointer, Size size)
Oid exprType(const Node *expr)
#define query_tree_walker(q, w, c, f)
#define QTW_EXAMINE_SORTGROUP
#define expression_tree_walker(n, w, c)
#define QTW_IGNORE_JOINALIASES
#define IsA(nodeptr, _type_)
#define InvokeObjectDropHookArg(classId, objectId, subId, dropflags)
AttrNumber get_object_attnum_oid(Oid class_id)
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
int get_object_catcache_oid(Oid class_id)
Oid get_object_oid_index(Oid class_id)
const char * get_object_class_descr(Oid class_id)
void RemoveOperatorById(Oid operOid)
#define rt_fetch(rangetable_index, rangetable)
void RemoveAttrDefaultById(Oid attrdefId)
void RemoveConstraintById(Oid conId)
void recordMultipleDependencies(const ObjectAddress *depender, const ObjectAddress *referenced, int nreferenced, DependencyType behavior)
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
FormData_pg_depend * Form_pg_depend
void LargeObjectDrop(Oid loid)
static int list_length(const List *l)
static void * list_nth(const List *list, int n)
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
void RemovePolicyById(Oid policy_id)
#define qsort(a, b, c, d)
void check_stack_depth(void)
static Oid DatumGetObjectId(Datum X)
static Datum ObjectIdGetDatum(Oid X)
static Datum Int32GetDatum(int32 X)
void RemovePublicationSchemaById(Oid psoid)
void RemovePublicationById(Oid pubid)
void RemovePublicationRelById(Oid proid)
void RemoveRewriteRuleById(Oid ruleOid)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
void DeleteSecurityLabel(const ObjectAddress *object)
void RemoveStatisticsById(Oid statsOid)
#define BTEqualStrategyNumber
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
const ObjectAddress * object
struct ObjectAddressStack * next
ObjectAddressExtra * extras
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)
void RemoveTriggerById(Oid trigOid)
void RemoveTSConfigurationById(Oid cfgId)
void RemoveTypeById(Oid typeOid)
void CommandCounterIncrement(void)