PostgreSQL Source Code git master
dependency.c File Reference
#include "postgres.h"
#include "access/genam.h"
#include "access/htup_details.h"
#include "access/table.h"
#include "access/xact.h"
#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/heap.h"
#include "catalog/index.h"
#include "catalog/namespace.h"
#include "catalog/objectaccess.h"
#include "catalog/pg_am.h"
#include "catalog/pg_amop.h"
#include "catalog/pg_amproc.h"
#include "catalog/pg_attrdef.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_auth_members.h"
#include "catalog/pg_cast.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_conversion.h"
#include "catalog/pg_database.h"
#include "catalog/pg_default_acl.h"
#include "catalog/pg_depend.h"
#include "catalog/pg_event_trigger.h"
#include "catalog/pg_extension.h"
#include "catalog/pg_foreign_data_wrapper.h"
#include "catalog/pg_foreign_server.h"
#include "catalog/pg_init_privs.h"
#include "catalog/pg_language.h"
#include "catalog/pg_largeobject.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_opfamily.h"
#include "catalog/pg_parameter_acl.h"
#include "catalog/pg_policy.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_publication.h"
#include "catalog/pg_publication_namespace.h"
#include "catalog/pg_publication_rel.h"
#include "catalog/pg_rewrite.h"
#include "catalog/pg_statistic_ext.h"
#include "catalog/pg_subscription.h"
#include "catalog/pg_tablespace.h"
#include "catalog/pg_transform.h"
#include "catalog/pg_trigger.h"
#include "catalog/pg_ts_config.h"
#include "catalog/pg_ts_dict.h"
#include "catalog/pg_ts_parser.h"
#include "catalog/pg_ts_template.h"
#include "catalog/pg_type.h"
#include "catalog/pg_user_mapping.h"
#include "commands/comment.h"
#include "commands/defrem.h"
#include "commands/event_trigger.h"
#include "commands/extension.h"
#include "commands/policy.h"
#include "commands/publicationcmds.h"
#include "commands/seclabel.h"
#include "commands/sequence.h"
#include "commands/trigger.h"
#include "commands/typecmds.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "nodes/nodeFuncs.h"
#include "parser/parsetree.h"
#include "rewrite/rewriteRemove.h"
#include "storage/lmgr.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
Include dependency graph for dependency.c:

Go to the source code of this file.

Data Structures

struct  ObjectAddressExtra
 
struct  ObjectAddresses
 
struct  ObjectAddressStack
 
struct  ObjectAddressAndFlags
 
struct  find_expr_references_context
 

Macros

#define DEPFLAG_ORIGINAL   0x0001 /* an original deletion target */
 
#define DEPFLAG_NORMAL   0x0002 /* reached via normal dependency */
 
#define DEPFLAG_AUTO   0x0004 /* reached via auto dependency */
 
#define DEPFLAG_INTERNAL   0x0008 /* reached via internal dependency */
 
#define DEPFLAG_PARTITION   0x0010 /* reached via partition dependency */
 
#define DEPFLAG_EXTENSION   0x0020 /* reached via extension dependency */
 
#define DEPFLAG_REVERSE   0x0040 /* reverse internal/extension link */
 
#define DEPFLAG_IS_PART   0x0080 /* has a partition dependency */
 
#define DEPFLAG_SUBOBJECT   0x0100 /* subobject of another deletable object */
 
#define MAX_REPORTED_DEPS   100
 

Typedefs

typedef struct ObjectAddressStack ObjectAddressStack
 

Functions

static void findDependentObjects (const ObjectAddress *object, int objflags, int flags, ObjectAddressStack *stack, ObjectAddresses *targetObjects, const ObjectAddresses *pendingObjects, Relation *depRel)
 
static void reportDependentObjects (const ObjectAddresses *targetObjects, DropBehavior behavior, int flags, const ObjectAddress *origObject)
 
static void deleteOneObject (const ObjectAddress *object, Relation *depRel, int32 flags)
 
static void doDeletion (const ObjectAddress *object, int flags)
 
static bool find_expr_references_walker (Node *node, find_expr_references_context *context)
 
static void process_function_rte_ref (RangeTblEntry *rte, AttrNumber attnum, find_expr_references_context *context)
 
static void eliminate_duplicate_dependencies (ObjectAddresses *addrs)
 
static int object_address_comparator (const void *a, const void *b)
 
static void add_object_address (Oid classId, Oid objectId, int32 subId, ObjectAddresses *addrs)
 
static void add_exact_object_address_extra (const ObjectAddress *object, const ObjectAddressExtra *extra, ObjectAddresses *addrs)
 
static bool object_address_present_add_flags (const ObjectAddress *object, int flags, ObjectAddresses *addrs)
 
static bool stack_address_present_add_flags (const ObjectAddress *object, int flags, ObjectAddressStack *stack)
 
static void DeleteInitPrivs (const ObjectAddress *object)
 
static void deleteObjectsInList (ObjectAddresses *targetObjects, Relation *depRel, int flags)
 
void performDeletion (const ObjectAddress *object, DropBehavior behavior, int flags)
 
void performMultipleDeletions (const ObjectAddresses *objects, DropBehavior behavior, int flags)
 
static void DropObjectById (const ObjectAddress *object)
 
static void deleteOneObject (const ObjectAddress *object, Relation *depRel, int flags)
 
void AcquireDeletionLock (const ObjectAddress *object, int flags)
 
void ReleaseDeletionLock (const ObjectAddress *object)
 
void recordDependencyOnExpr (const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior)
 
void collectDependenciesOfExpr (ObjectAddresses *addrs, Node *expr, List *rtable)
 
void recordDependencyOnSingleRelExpr (const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool reverse_self)
 
bool find_temp_object (const ObjectAddresses *addrs, bool local_temp_okay, ObjectAddress *foundobj)
 
bool query_uses_temp_object (Query *query, ObjectAddress *temp_object)
 
ObjectAddressesnew_object_addresses (void)
 
void add_exact_object_address (const ObjectAddress *object, ObjectAddresses *addrs)
 
bool object_address_present (const ObjectAddress *object, const ObjectAddresses *addrs)
 
void record_object_address_dependencies (const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
 
void sort_object_addresses (ObjectAddresses *addrs)
 
void free_object_addresses (ObjectAddresses *addrs)
 

Macro Definition Documentation

◆ DEPFLAG_AUTO

#define DEPFLAG_AUTO   0x0004 /* reached via auto dependency */

Definition at line 104 of file dependency.c.

◆ DEPFLAG_EXTENSION

#define DEPFLAG_EXTENSION   0x0020 /* reached via extension dependency */

Definition at line 107 of file dependency.c.

◆ DEPFLAG_INTERNAL

#define DEPFLAG_INTERNAL   0x0008 /* reached via internal dependency */

Definition at line 105 of file dependency.c.

◆ DEPFLAG_IS_PART

#define DEPFLAG_IS_PART   0x0080 /* has a partition dependency */

Definition at line 109 of file dependency.c.

◆ DEPFLAG_NORMAL

#define DEPFLAG_NORMAL   0x0002 /* reached via normal dependency */

Definition at line 103 of file dependency.c.

◆ DEPFLAG_ORIGINAL

#define DEPFLAG_ORIGINAL   0x0001 /* an original deletion target */

Definition at line 102 of file dependency.c.

◆ DEPFLAG_PARTITION

#define DEPFLAG_PARTITION   0x0010 /* reached via partition dependency */

Definition at line 106 of file dependency.c.

◆ DEPFLAG_REVERSE

#define DEPFLAG_REVERSE   0x0040 /* reverse internal/extension link */

Definition at line 108 of file dependency.c.

◆ DEPFLAG_SUBOBJECT

#define DEPFLAG_SUBOBJECT   0x0100 /* subobject of another deletable object */

Definition at line 110 of file dependency.c.

◆ MAX_REPORTED_DEPS

#define MAX_REPORTED_DEPS   100

Typedef Documentation

◆ ObjectAddressStack

Function Documentation

◆ AcquireDeletionLock()

void AcquireDeletionLock ( const ObjectAddress object,
int  flags 
)

Definition at line 1497 of file dependency.c.

1498{
1499 if (object->classId == RelationRelationId)
1500 {
1501 /*
1502 * In DROP INDEX CONCURRENTLY, take only ShareUpdateExclusiveLock on
1503 * the index for the moment. index_drop() will promote the lock once
1504 * it's safe to do so. In all other cases we need full exclusive
1505 * lock.
1506 */
1509 else
1511 }
1512 else if (object->classId == AuthMemRelationId)
1513 LockSharedObject(object->classId, object->objectId, 0,
1515 else
1516 {
1517 /* assume we should lock the whole object not a sub-object */
1518 LockDatabaseObject(object->classId, object->objectId, 0,
1520 }
1521}
#define PERFORM_DELETION_CONCURRENTLY
Definition: dependency.h:93
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1088
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1008
void LockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:107
#define AccessExclusiveLock
Definition: lockdefs.h:43
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39

References AccessExclusiveLock, ObjectAddress::classId, ObjectAddressStack::flags, LockDatabaseObject(), LockRelationOid(), LockSharedObject(), ObjectAddressStack::object, ObjectAddress::objectId, PERFORM_DELETION_CONCURRENTLY, and ShareUpdateExclusiveLock.

Referenced by findDependentObjects(), performDeletion(), performMultipleDeletions(), and shdepDropOwned().

◆ add_exact_object_address()

void add_exact_object_address ( const ObjectAddress object,
ObjectAddresses addrs 
)

Definition at line 2661 of file dependency.c.

2663{
2664 ObjectAddress *item;
2665
2666 /* enlarge array if needed */
2667 if (addrs->numrefs >= addrs->maxrefs)
2668 {
2669 addrs->maxrefs *= 2;
2670 addrs->refs = (ObjectAddress *)
2671 repalloc(addrs->refs, addrs->maxrefs * sizeof(ObjectAddress));
2672 Assert(!addrs->extras);
2673 }
2674 /* record this item */
2675 item = addrs->refs + addrs->numrefs;
2676 *item = *object;
2677 addrs->numrefs++;
2678}
Assert(PointerIsAligned(start, uint64))
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1610
ObjectAddressExtra * extras
Definition: dependency.c:117
ObjectAddress * refs
Definition: dependency.c:116

References Assert(), ObjectAddresses::extras, ObjectAddresses::maxrefs, ObjectAddresses::numrefs, ObjectAddressStack::object, ObjectAddresses::refs, and repalloc().

Referenced by AggregateCreate(), AlterConstraintNamespaces(), AlterIndexNamespaces(), AlterRelationNamespaceInternal(), AlterTypeNamespaceInternal(), ATExecDropColumn(), ATPostAlterTypeCleanup(), CastCreate(), CreateConstraintEntry(), CreateProceduralLanguage(), CreateTransform(), DropClonedTriggersFromPartition(), GenerateTypeDependencies(), heap_create_with_catalog(), index_create(), InsertExtensionTuple(), makeConfigurationDependencies(), makeDictionaryDependencies(), makeOperatorDependencies(), makeParserDependencies(), makeTSTemplateDependencies(), PreCommit_on_commit_actions(), ProcedureCreate(), RangeCreate(), recordDependencyOnSingleRelExpr(), ReindexRelationConcurrently(), RemoveInheritedConstraint(), RemoveObjects(), RemoveRelations(), shdepDropOwned(), and StorePartitionKey().

◆ add_exact_object_address_extra()

static void add_exact_object_address_extra ( const ObjectAddress object,
const ObjectAddressExtra extra,
ObjectAddresses addrs 
)
static

Definition at line 2686 of file dependency.c.

2689{
2690 ObjectAddress *item;
2691 ObjectAddressExtra *itemextra;
2692
2693 /* allocate extra space if first time */
2694 if (!addrs->extras)
2695 addrs->extras = (ObjectAddressExtra *)
2696 palloc(addrs->maxrefs * sizeof(ObjectAddressExtra));
2697
2698 /* enlarge array if needed */
2699 if (addrs->numrefs >= addrs->maxrefs)
2700 {
2701 addrs->maxrefs *= 2;
2702 addrs->refs = (ObjectAddress *)
2703 repalloc(addrs->refs, addrs->maxrefs * sizeof(ObjectAddress));
2704 addrs->extras = (ObjectAddressExtra *)
2705 repalloc(addrs->extras, addrs->maxrefs * sizeof(ObjectAddressExtra));
2706 }
2707 /* record this item */
2708 item = addrs->refs + addrs->numrefs;
2709 *item = *object;
2710 itemextra = addrs->extras + addrs->numrefs;
2711 *itemextra = *extra;
2712 addrs->numrefs++;
2713}
void * palloc(Size size)
Definition: mcxt.c:1365

References ObjectAddresses::extras, ObjectAddresses::maxrefs, ObjectAddresses::numrefs, ObjectAddressStack::object, palloc(), ObjectAddresses::refs, and repalloc().

Referenced by findDependentObjects().

◆ add_object_address()

static void add_object_address ( Oid  classId,
Oid  objectId,
int32  subId,
ObjectAddresses addrs 
)
static

Definition at line 2634 of file dependency.c.

2636{
2637 ObjectAddress *item;
2638
2639 /* enlarge array if needed */
2640 if (addrs->numrefs >= addrs->maxrefs)
2641 {
2642 addrs->maxrefs *= 2;
2643 addrs->refs = (ObjectAddress *)
2644 repalloc(addrs->refs, addrs->maxrefs * sizeof(ObjectAddress));
2645 Assert(!addrs->extras);
2646 }
2647 /* record this item */
2648 item = addrs->refs + addrs->numrefs;
2649 item->classId = classId;
2650 item->objectId = objectId;
2651 item->objectSubId = subId;
2652 addrs->numrefs++;
2653}

References Assert(), ObjectAddress::classId, ObjectAddresses::extras, ObjectAddresses::maxrefs, ObjectAddresses::numrefs, ObjectAddress::objectId, ObjectAddress::objectSubId, ObjectAddresses::refs, and repalloc().

Referenced by find_expr_references_walker(), and process_function_rte_ref().

◆ collectDependenciesOfExpr()

void collectDependenciesOfExpr ( ObjectAddresses addrs,
Node expr,
List rtable 
)

Definition at line 1597 of file dependency.c.

1599{
1601
1602 context.addrs = addrs;
1603
1604 /* Set up interpretation for Vars at varlevelsup = 0 */
1605 context.rtables = list_make1(rtable);
1606
1607 /* Scan the expression tree for referenceable objects */
1608 find_expr_references_walker(expr, &context);
1609}
static bool find_expr_references_walker(Node *node, find_expr_references_context *context)
Definition: dependency.c:1731
#define list_make1(x1)
Definition: pg_list.h:212
ObjectAddresses * addrs
Definition: dependency.c:142

References find_expr_references_context::addrs, find_expr_references_walker(), list_make1, and find_expr_references_context::rtables.

Referenced by ProcedureCreate(), query_uses_temp_object(), and recordDependencyOnExpr().

◆ DeleteInitPrivs()

static void DeleteInitPrivs ( const ObjectAddress object)
static

Definition at line 2913 of file dependency.c.

2914{
2915 Relation relation;
2916 ScanKeyData key[3];
2917 int nkeys;
2918 SysScanDesc scan;
2919 HeapTuple oldtuple;
2920
2921 relation = table_open(InitPrivsRelationId, RowExclusiveLock);
2922
2923 ScanKeyInit(&key[0],
2924 Anum_pg_init_privs_objoid,
2925 BTEqualStrategyNumber, F_OIDEQ,
2926 ObjectIdGetDatum(object->objectId));
2927 ScanKeyInit(&key[1],
2928 Anum_pg_init_privs_classoid,
2929 BTEqualStrategyNumber, F_OIDEQ,
2930 ObjectIdGetDatum(object->classId));
2931 if (object->objectSubId != 0)
2932 {
2933 ScanKeyInit(&key[2],
2934 Anum_pg_init_privs_objsubid,
2935 BTEqualStrategyNumber, F_INT4EQ,
2936 Int32GetDatum(object->objectSubId));
2937 nkeys = 3;
2938 }
2939 else
2940 nkeys = 2;
2941
2942 scan = systable_beginscan(relation, InitPrivsObjIndexId, true,
2943 NULL, nkeys, key);
2944
2945 while (HeapTupleIsValid(oldtuple = systable_getnext(scan)))
2946 CatalogTupleDelete(relation, &oldtuple->t_self);
2947
2948 systable_endscan(scan);
2949
2950 table_close(relation, RowExclusiveLock);
2951}
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:603
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:514
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:388
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
void CatalogTupleDelete(Relation heapRel, const ItemPointerData *tid)
Definition: indexing.c:365
#define RowExclusiveLock
Definition: lockdefs.h:38
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:262
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:222
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31
ItemPointerData t_self
Definition: htup.h:65
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

References BTEqualStrategyNumber, CatalogTupleDelete(), ObjectAddress::classId, HeapTupleIsValid, Int32GetDatum(), sort-test::key, ObjectAddressStack::object, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), and table_open().

Referenced by deleteOneObject().

◆ deleteObjectsInList()

static void deleteObjectsInList ( ObjectAddresses targetObjects,
Relation depRel,
int  flags 
)
static

Definition at line 186 of file dependency.c.

188{
189 int i;
190
191 /*
192 * Keep track of objects for event triggers, if necessary.
193 */
195 {
196 for (i = 0; i < targetObjects->numrefs; i++)
197 {
198 const ObjectAddress *thisobj = &targetObjects->refs[i];
199 const ObjectAddressExtra *extra = &targetObjects->extras[i];
200 bool original = false;
201 bool normal = false;
202
203 if (extra->flags & DEPFLAG_ORIGINAL)
204 original = true;
205 if (extra->flags & DEPFLAG_NORMAL)
206 normal = true;
207 if (extra->flags & DEPFLAG_REVERSE)
208 normal = true;
209
210 if (EventTriggerSupportsObject(thisobj))
211 {
212 EventTriggerSQLDropAddObject(thisobj, original, normal);
213 }
214 }
215 }
216
217 /*
218 * Delete all the objects in the proper order, except that if told to, we
219 * should skip the original object(s).
220 */
221 for (i = 0; i < targetObjects->numrefs; i++)
222 {
223 ObjectAddress *thisobj = targetObjects->refs + i;
224 ObjectAddressExtra *thisextra = targetObjects->extras + i;
225
226 if ((flags & PERFORM_DELETION_SKIP_ORIGINAL) &&
227 (thisextra->flags & DEPFLAG_ORIGINAL))
228 continue;
229
230 deleteOneObject(thisobj, depRel, flags);
231 }
232}
static void deleteOneObject(const ObjectAddress *object, Relation *depRel, int32 flags)
#define DEPFLAG_ORIGINAL
Definition: dependency.c:102
#define DEPFLAG_REVERSE
Definition: dependency.c:108
#define DEPFLAG_NORMAL
Definition: dependency.c:103
#define PERFORM_DELETION_SKIP_ORIGINAL
Definition: dependency.h:95
#define PERFORM_DELETION_INTERNAL
Definition: dependency.h:92
void EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool normal)
bool trackDroppedObjectsNeeded(void)
bool EventTriggerSupportsObject(const ObjectAddress *object)
int i
Definition: isn.c:77

References deleteOneObject(), DEPFLAG_NORMAL, DEPFLAG_ORIGINAL, DEPFLAG_REVERSE, EventTriggerSQLDropAddObject(), EventTriggerSupportsObject(), ObjectAddresses::extras, ObjectAddressExtra::flags, ObjectAddressStack::flags, i, ObjectAddresses::numrefs, PERFORM_DELETION_INTERNAL, PERFORM_DELETION_SKIP_ORIGINAL, ObjectAddresses::refs, and trackDroppedObjectsNeeded().

Referenced by performDeletion(), and performMultipleDeletions().

◆ deleteOneObject() [1/2]

static void deleteOneObject ( const ObjectAddress object,
Relation depRel,
int  flags 
)
static

Definition at line 1247 of file dependency.c.

1248{
1249 ScanKeyData key[3];
1250 int nkeys;
1251 SysScanDesc scan;
1252 HeapTuple tup;
1253
1254 /* DROP hook of the objects being removed */
1255 InvokeObjectDropHookArg(object->classId, object->objectId,
1256 object->objectSubId, flags);
1257
1258 /*
1259 * Close depRel if we are doing a drop concurrently. The object deletion
1260 * subroutine will commit the current transaction, so we can't keep the
1261 * relation open across doDeletion().
1262 */
1264 table_close(*depRel, RowExclusiveLock);
1265
1266 /*
1267 * Delete the object itself, in an object-type-dependent way.
1268 *
1269 * We used to do this after removing the outgoing dependency links, but it
1270 * seems just as reasonable to do it beforehand. In the concurrent case
1271 * we *must* do it in this order, because we can't make any transactional
1272 * updates before calling doDeletion() --- they'd get committed right
1273 * away, which is not cool if the deletion then fails.
1274 */
1275 doDeletion(object, flags);
1276
1277 /*
1278 * Reopen depRel if we closed it above
1279 */
1281 *depRel = table_open(DependRelationId, RowExclusiveLock);
1282
1283 /*
1284 * Now remove any pg_depend records that link from this object to others.
1285 * (Any records linking to this object should be gone already.)
1286 *
1287 * When dropping a whole object (subId = 0), remove all pg_depend records
1288 * for its sub-objects too.
1289 */
1290 ScanKeyInit(&key[0],
1291 Anum_pg_depend_classid,
1292 BTEqualStrategyNumber, F_OIDEQ,
1293 ObjectIdGetDatum(object->classId));
1294 ScanKeyInit(&key[1],
1295 Anum_pg_depend_objid,
1296 BTEqualStrategyNumber, F_OIDEQ,
1297 ObjectIdGetDatum(object->objectId));
1298 if (object->objectSubId != 0)
1299 {
1300 ScanKeyInit(&key[2],
1301 Anum_pg_depend_objsubid,
1302 BTEqualStrategyNumber, F_INT4EQ,
1303 Int32GetDatum(object->objectSubId));
1304 nkeys = 3;
1305 }
1306 else
1307 nkeys = 2;
1308
1309 scan = systable_beginscan(*depRel, DependDependerIndexId, true,
1310 NULL, nkeys, key);
1311
1312 while (HeapTupleIsValid(tup = systable_getnext(scan)))
1313 {
1314 CatalogTupleDelete(*depRel, &tup->t_self);
1315 }
1316
1317 systable_endscan(scan);
1318
1319 /*
1320 * Delete shared dependency references related to this object. Again, if
1321 * subId = 0, remove records for sub-objects too.
1322 */
1324 object->objectSubId);
1325
1326
1327 /*
1328 * Delete any comments, security labels, or initial privileges associated
1329 * with this object. (This is a convenient place to do these things,
1330 * rather than having every object type know to do it.) As above, all
1331 * these functions must remove records for sub-objects too if the subid is
1332 * zero.
1333 */
1334 DeleteComments(object->objectId, object->classId, object->objectSubId);
1335 DeleteSecurityLabel(object);
1336 DeleteInitPrivs(object);
1337
1338 /*
1339 * CommandCounterIncrement here to ensure that preceding changes are all
1340 * visible to the next deletion step.
1341 */
1343
1344 /*
1345 * And we're done!
1346 */
1347}
void DeleteComments(Oid oid, Oid classoid, int32 subid)
Definition: comment.c:326
static void doDeletion(const ObjectAddress *object, int flags)
Definition: dependency.c:1353
static void DeleteInitPrivs(const ObjectAddress *object)
Definition: dependency.c:2913
#define InvokeObjectDropHookArg(classId, objectId, subId, dropflags)
Definition: objectaccess.h:184
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
Definition: pg_shdepend.c:1047
void DeleteSecurityLabel(const ObjectAddress *object)
Definition: seclabel.c:523
void CommandCounterIncrement(void)
Definition: xact.c:1101

References BTEqualStrategyNumber, CatalogTupleDelete(), ObjectAddress::classId, CommandCounterIncrement(), DeleteComments(), DeleteInitPrivs(), DeleteSecurityLabel(), deleteSharedDependencyRecordsFor(), doDeletion(), ObjectAddressStack::flags, HeapTupleIsValid, Int32GetDatum(), InvokeObjectDropHookArg, sort-test::key, ObjectAddressStack::object, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, PERFORM_DELETION_CONCURRENTLY, RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), and table_open().

◆ deleteOneObject() [2/2]

static void deleteOneObject ( const ObjectAddress object,
Relation depRel,
int32  flags 
)
static

Referenced by deleteObjectsInList().

◆ doDeletion()

static void doDeletion ( const ObjectAddress object,
int  flags 
)
static

Definition at line 1353 of file dependency.c.

1354{
1355 switch (object->classId)
1356 {
1357 case RelationRelationId:
1358 {
1359 char relKind = get_rel_relkind(object->objectId);
1360
1361 if (relKind == RELKIND_INDEX ||
1362 relKind == RELKIND_PARTITIONED_INDEX)
1363 {
1364 bool concurrent = ((flags & PERFORM_DELETION_CONCURRENTLY) != 0);
1365 bool concurrent_lock_mode = ((flags & PERFORM_DELETION_CONCURRENT_LOCK) != 0);
1366
1367 Assert(object->objectSubId == 0);
1368 index_drop(object->objectId, concurrent, concurrent_lock_mode);
1369 }
1370 else
1371 {
1372 if (object->objectSubId != 0)
1374 object->objectSubId);
1375 else
1377 }
1378
1379 /*
1380 * for a sequence, in addition to dropping the heap, also
1381 * delete pg_sequence tuple
1382 */
1383 if (relKind == RELKIND_SEQUENCE)
1385 break;
1386 }
1387
1388 case ProcedureRelationId:
1390 break;
1391
1392 case TypeRelationId:
1393 RemoveTypeById(object->objectId);
1394 break;
1395
1396 case ConstraintRelationId:
1398 break;
1399
1400 case AttrDefaultRelationId:
1402 break;
1403
1404 case LargeObjectRelationId:
1405 LargeObjectDrop(object->objectId);
1406 break;
1407
1408 case OperatorRelationId:
1410 break;
1411
1412 case RewriteRelationId:
1414 break;
1415
1416 case TriggerRelationId:
1417 RemoveTriggerById(object->objectId);
1418 break;
1419
1420 case StatisticExtRelationId:
1422 break;
1423
1424 case TSConfigRelationId:
1426 break;
1427
1428 case ExtensionRelationId:
1430 break;
1431
1432 case PolicyRelationId:
1433 RemovePolicyById(object->objectId);
1434 break;
1435
1436 case PublicationNamespaceRelationId:
1438 break;
1439
1440 case PublicationRelRelationId:
1442 break;
1443
1444 case PublicationRelationId:
1446 break;
1447
1448 case CastRelationId:
1449 case CollationRelationId:
1450 case ConversionRelationId:
1451 case LanguageRelationId:
1452 case OperatorClassRelationId:
1453 case OperatorFamilyRelationId:
1454 case AccessMethodRelationId:
1455 case AccessMethodOperatorRelationId:
1456 case AccessMethodProcedureRelationId:
1457 case NamespaceRelationId:
1458 case TSParserRelationId:
1459 case TSDictionaryRelationId:
1460 case TSTemplateRelationId:
1461 case ForeignDataWrapperRelationId:
1462 case ForeignServerRelationId:
1463 case UserMappingRelationId:
1464 case DefaultAclRelationId:
1465 case EventTriggerRelationId:
1466 case TransformRelationId:
1467 case AuthMemRelationId:
1468 DropObjectById(object);
1469 break;
1470
1471 /*
1472 * These global object types are not supported here.
1473 */
1474 case AuthIdRelationId:
1475 case DatabaseRelationId:
1476 case TableSpaceRelationId:
1477 case SubscriptionRelationId:
1478 case ParameterAclRelationId:
1479 elog(ERROR, "global objects cannot be deleted by doDeletion");
1480 break;
1481
1482 default:
1483 elog(ERROR, "unsupported object class: %u", object->classId);
1484 }
1485}
void DeleteSequenceTuple(Oid relid)
Definition: sequence.c:571
static void DropObjectById(const ObjectAddress *object)
Definition: dependency.c:1190
#define PERFORM_DELETION_CONCURRENT_LOCK
Definition: dependency.h:97
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
void RemoveExtensionById(Oid extId)
Definition: extension.c:2151
void RemoveFunctionById(Oid funcOid)
void RemoveAttributeById(Oid relid, AttrNumber attnum)
Definition: heap.c:1683
void heap_drop_with_catalog(Oid relid)
Definition: heap.c:1784
void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)
Definition: index.c:2122
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:2170
void RemoveOperatorById(Oid operOid)
Definition: operatorcmds.c:413
void RemoveAttrDefaultById(Oid attrdefId)
Definition: pg_attrdef.c:208
void RemoveConstraintById(Oid conId)
void LargeObjectDrop(Oid loid)
void RemovePolicyById(Oid policy_id)
Definition: policy.c:332
void RemovePublicationSchemaById(Oid psoid)
void RemovePublicationById(Oid pubid)
void RemovePublicationRelById(Oid proid)
void RemoveRewriteRuleById(Oid ruleOid)
Definition: rewriteRemove.c:33
void RemoveStatisticsById(Oid statsOid)
Definition: statscmds.c:787
void RemoveTriggerById(Oid trigOid)
Definition: trigger.c:1291
void RemoveTSConfigurationById(Oid cfgId)
Definition: tsearchcmds.c:1108
void RemoveTypeById(Oid typeOid)
Definition: typecmds.c:657

References Assert(), ObjectAddress::classId, DeleteSequenceTuple(), DropObjectById(), elog, ERROR, ObjectAddressStack::flags, get_rel_relkind(), heap_drop_with_catalog(), index_drop(), LargeObjectDrop(), ObjectAddressStack::object, ObjectAddress::objectId, ObjectAddress::objectSubId, PERFORM_DELETION_CONCURRENT_LOCK, PERFORM_DELETION_CONCURRENTLY, RemoveAttrDefaultById(), RemoveAttributeById(), RemoveConstraintById(), RemoveExtensionById(), RemoveFunctionById(), RemoveOperatorById(), RemovePolicyById(), RemovePublicationById(), RemovePublicationRelById(), RemovePublicationSchemaById(), RemoveRewriteRuleById(), RemoveStatisticsById(), RemoveTriggerById(), RemoveTSConfigurationById(), and RemoveTypeById().

Referenced by deleteOneObject().

◆ DropObjectById()

static void DropObjectById ( const ObjectAddress object)
static

Definition at line 1190 of file dependency.c.

1191{
1192 int cacheId;
1193 Relation rel;
1194 HeapTuple tup;
1195
1196 cacheId = get_object_catcache_oid(object->classId);
1197
1198 rel = table_open(object->classId, RowExclusiveLock);
1199
1200 /*
1201 * Use the system cache for the oid column, if one exists.
1202 */
1203 if (cacheId >= 0)
1204 {
1205 tup = SearchSysCache1(cacheId, ObjectIdGetDatum(object->objectId));
1206 if (!HeapTupleIsValid(tup))
1207 elog(ERROR, "cache lookup failed for %s %u",
1208 get_object_class_descr(object->classId), object->objectId);
1209
1210 CatalogTupleDelete(rel, &tup->t_self);
1211
1212 ReleaseSysCache(tup);
1213 }
1214 else
1215 {
1216 ScanKeyData skey[1];
1217 SysScanDesc scan;
1218
1219 ScanKeyInit(&skey[0],
1221 BTEqualStrategyNumber, F_OIDEQ,
1222 ObjectIdGetDatum(object->objectId));
1223
1224 scan = systable_beginscan(rel, get_object_oid_index(object->classId), true,
1225 NULL, 1, skey);
1226
1227 /* we expect exactly one match */
1228 tup = systable_getnext(scan);
1229 if (!HeapTupleIsValid(tup))
1230 elog(ERROR, "could not find tuple for %s %u",
1231 get_object_class_descr(object->classId), object->objectId);
1232
1233 CatalogTupleDelete(rel, &tup->t_self);
1234
1235 systable_endscan(scan);
1236 }
1237
1239}
AttrNumber get_object_attnum_oid(Oid class_id)
const char * get_object_class_descr(Oid class_id)
int get_object_catcache_oid(Oid class_id)
Oid get_object_oid_index(Oid class_id)
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:264
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:220

References BTEqualStrategyNumber, CatalogTupleDelete(), ObjectAddress::classId, elog, ERROR, get_object_attnum_oid(), get_object_catcache_oid(), get_object_class_descr(), get_object_oid_index(), HeapTupleIsValid, ObjectAddressStack::object, ObjectAddress::objectId, ObjectIdGetDatum(), ReleaseSysCache(), RowExclusiveLock, ScanKeyInit(), SearchSysCache1(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), and table_open().

Referenced by doDeletion().

◆ eliminate_duplicate_dependencies()

static void eliminate_duplicate_dependencies ( ObjectAddresses addrs)
static

Definition at line 2511 of file dependency.c.

2512{
2513 ObjectAddress *priorobj;
2514 int oldref,
2515 newrefs;
2516
2517 /*
2518 * We can't sort if the array has "extra" data, because there's no way to
2519 * keep it in sync. Fortunately that combination of features is not
2520 * needed.
2521 */
2522 Assert(!addrs->extras);
2523
2524 if (addrs->numrefs <= 1)
2525 return; /* nothing to do */
2526
2527 /* Sort the refs so that duplicates are adjacent */
2528 qsort(addrs->refs, addrs->numrefs, sizeof(ObjectAddress),
2530
2531 /* Remove dups */
2532 priorobj = addrs->refs;
2533 newrefs = 1;
2534 for (oldref = 1; oldref < addrs->numrefs; oldref++)
2535 {
2536 ObjectAddress *thisobj = addrs->refs + oldref;
2537
2538 if (priorobj->classId == thisobj->classId &&
2539 priorobj->objectId == thisobj->objectId)
2540 {
2541 if (priorobj->objectSubId == thisobj->objectSubId)
2542 continue; /* identical, so drop thisobj */
2543
2544 /*
2545 * If we have a whole-object reference and a reference to a part
2546 * of the same object, we don't need the whole-object reference
2547 * (for example, we don't need to reference both table foo and
2548 * column foo.bar). The whole-object reference will always appear
2549 * first in the sorted list.
2550 */
2551 if (priorobj->objectSubId == 0)
2552 {
2553 /* replace whole ref with partial */
2554 priorobj->objectSubId = thisobj->objectSubId;
2555 continue;
2556 }
2557 }
2558 /* Not identical, so add thisobj to output set */
2559 priorobj++;
2560 *priorobj = *thisobj;
2561 newrefs++;
2562 }
2563
2564 addrs->numrefs = newrefs;
2565}
static int object_address_comparator(const void *a, const void *b)
Definition: dependency.c:2571
#define qsort(a, b, c, d)
Definition: port.h:500

References Assert(), ObjectAddress::classId, ObjectAddresses::extras, ObjectAddresses::numrefs, object_address_comparator(), ObjectAddress::objectId, ObjectAddress::objectSubId, qsort, and ObjectAddresses::refs.

Referenced by record_object_address_dependencies(), recordDependencyOnExpr(), and recordDependencyOnSingleRelExpr().

◆ find_expr_references_walker()

static bool find_expr_references_walker ( Node node,
find_expr_references_context context 
)
static

Definition at line 1731 of file dependency.c.

1733{
1734 if (node == NULL)
1735 return false;
1736 if (IsA(node, Var))
1737 {
1738 Var *var = (Var *) node;
1739 List *rtable;
1740 RangeTblEntry *rte;
1741
1742 /* Find matching rtable entry, or complain if not found */
1743 if (var->varlevelsup >= list_length(context->rtables))
1744 elog(ERROR, "invalid varlevelsup %d", var->varlevelsup);
1745 rtable = (List *) list_nth(context->rtables, var->varlevelsup);
1746 if (var->varno <= 0 || var->varno > list_length(rtable))
1747 elog(ERROR, "invalid varno %d", var->varno);
1748 rte = rt_fetch(var->varno, rtable);
1749
1750 /*
1751 * A whole-row Var references no specific columns, so adds no new
1752 * dependency. (We assume that there is a whole-table dependency
1753 * arising from each underlying rangetable entry. While we could
1754 * record such a dependency when finding a whole-row Var that
1755 * references a relation directly, it's quite unclear how to extend
1756 * that to whole-row Vars for JOINs, so it seems better to leave the
1757 * responsibility with the range table. Note that this poses some
1758 * risks for identifying dependencies of stand-alone expressions:
1759 * whole-table references may need to be created separately.)
1760 */
1761 if (var->varattno == InvalidAttrNumber)
1762 return false;
1763 if (rte->rtekind == RTE_RELATION)
1764 {
1765 /* If it's a plain relation, reference this column */
1766 add_object_address(RelationRelationId, rte->relid, var->varattno,
1767 context->addrs);
1768 }
1769 else if (rte->rtekind == RTE_FUNCTION)
1770 {
1771 /* Might need to add a dependency on a composite type's column */
1772 /* (done out of line, because it's a bit bulky) */
1773 process_function_rte_ref(rte, var->varattno, context);
1774 }
1775
1776 /*
1777 * Vars referencing other RTE types require no additional work. In
1778 * particular, a join alias Var can be ignored, because it must
1779 * reference a merged USING column. The relevant join input columns
1780 * will also be referenced in the join qual, and any type coercion
1781 * functions involved in the alias expression will be dealt with when
1782 * we scan the RTE itself.
1783 */
1784 return false;
1785 }
1786 else if (IsA(node, Const))
1787 {
1788 Const *con = (Const *) node;
1789 Oid objoid;
1790
1791 /* A constant must depend on the constant's datatype */
1792 add_object_address(TypeRelationId, con->consttype, 0,
1793 context->addrs);
1794
1795 /*
1796 * We must also depend on the constant's collation: it could be
1797 * different from the datatype's, if a CollateExpr was const-folded to
1798 * a simple constant. However we can save work in the most common
1799 * case where the collation is "default", since we know that's pinned.
1800 */
1801 if (OidIsValid(con->constcollid) &&
1802 con->constcollid != DEFAULT_COLLATION_OID)
1803 add_object_address(CollationRelationId, con->constcollid, 0,
1804 context->addrs);
1805
1806 /*
1807 * If it's a regclass or similar literal referring to an existing
1808 * object, add a reference to that object. (Currently, only the
1809 * regclass and regconfig cases have any likely use, but we may as
1810 * well handle all the OID-alias datatypes consistently.)
1811 */
1812 if (!con->constisnull)
1813 {
1814 switch (con->consttype)
1815 {
1816 case REGPROCOID:
1817 case REGPROCEDUREOID:
1818 objoid = DatumGetObjectId(con->constvalue);
1819 if (SearchSysCacheExists1(PROCOID,
1820 ObjectIdGetDatum(objoid)))
1821 add_object_address(ProcedureRelationId, objoid, 0,
1822 context->addrs);
1823 break;
1824 case REGOPEROID:
1825 case REGOPERATOROID:
1826 objoid = DatumGetObjectId(con->constvalue);
1827 if (SearchSysCacheExists1(OPEROID,
1828 ObjectIdGetDatum(objoid)))
1829 add_object_address(OperatorRelationId, objoid, 0,
1830 context->addrs);
1831 break;
1832 case REGCLASSOID:
1833 objoid = DatumGetObjectId(con->constvalue);
1834 if (SearchSysCacheExists1(RELOID,
1835 ObjectIdGetDatum(objoid)))
1836 add_object_address(RelationRelationId, objoid, 0,
1837 context->addrs);
1838 break;
1839 case REGTYPEOID:
1840 objoid = DatumGetObjectId(con->constvalue);
1841 if (SearchSysCacheExists1(TYPEOID,
1842 ObjectIdGetDatum(objoid)))
1843 add_object_address(TypeRelationId, objoid, 0,
1844 context->addrs);
1845 break;
1846 case REGCOLLATIONOID:
1847 objoid = DatumGetObjectId(con->constvalue);
1848 if (SearchSysCacheExists1(COLLOID,
1849 ObjectIdGetDatum(objoid)))
1850 add_object_address(CollationRelationId, objoid, 0,
1851 context->addrs);
1852 break;
1853 case REGCONFIGOID:
1854 objoid = DatumGetObjectId(con->constvalue);
1855 if (SearchSysCacheExists1(TSCONFIGOID,
1856 ObjectIdGetDatum(objoid)))
1857 add_object_address(TSConfigRelationId, objoid, 0,
1858 context->addrs);
1859 break;
1860 case REGDICTIONARYOID:
1861 objoid = DatumGetObjectId(con->constvalue);
1862 if (SearchSysCacheExists1(TSDICTOID,
1863 ObjectIdGetDatum(objoid)))
1864 add_object_address(TSDictionaryRelationId, objoid, 0,
1865 context->addrs);
1866 break;
1867
1868 case REGNAMESPACEOID:
1869 objoid = DatumGetObjectId(con->constvalue);
1870 if (SearchSysCacheExists1(NAMESPACEOID,
1871 ObjectIdGetDatum(objoid)))
1872 add_object_address(NamespaceRelationId, objoid, 0,
1873 context->addrs);
1874 break;
1875
1876 /*
1877 * Dependencies for regrole should be shared among all
1878 * databases, so explicitly inhibit to have dependencies.
1879 */
1880 case REGROLEOID:
1881 ereport(ERROR,
1882 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1883 errmsg("constant of the type %s cannot be used here",
1884 "regrole")));
1885 break;
1886
1887 /*
1888 * Dependencies for regdatabase should be shared among all
1889 * databases, so explicitly inhibit to have dependencies.
1890 */
1891 case REGDATABASEOID:
1892 ereport(ERROR,
1893 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1894 errmsg("constant of the type %s cannot be used here",
1895 "regdatabase")));
1896 break;
1897 }
1898 }
1899 return false;
1900 }
1901 else if (IsA(node, Param))
1902 {
1903 Param *param = (Param *) node;
1904
1905 /* A parameter must depend on the parameter's datatype */
1906 add_object_address(TypeRelationId, param->paramtype, 0,
1907 context->addrs);
1908 /* and its collation, just as for Consts */
1909 if (OidIsValid(param->paramcollid) &&
1910 param->paramcollid != DEFAULT_COLLATION_OID)
1911 add_object_address(CollationRelationId, param->paramcollid, 0,
1912 context->addrs);
1913 }
1914 else if (IsA(node, FuncExpr))
1915 {
1916 FuncExpr *funcexpr = (FuncExpr *) node;
1917
1918 add_object_address(ProcedureRelationId, funcexpr->funcid, 0,
1919 context->addrs);
1920 /* fall through to examine arguments */
1921 }
1922 else if (IsA(node, OpExpr))
1923 {
1924 OpExpr *opexpr = (OpExpr *) node;
1925
1926 add_object_address(OperatorRelationId, opexpr->opno, 0,
1927 context->addrs);
1928 /* fall through to examine arguments */
1929 }
1930 else if (IsA(node, DistinctExpr))
1931 {
1932 DistinctExpr *distinctexpr = (DistinctExpr *) node;
1933
1934 add_object_address(OperatorRelationId, distinctexpr->opno, 0,
1935 context->addrs);
1936 /* fall through to examine arguments */
1937 }
1938 else if (IsA(node, NullIfExpr))
1939 {
1940 NullIfExpr *nullifexpr = (NullIfExpr *) node;
1941
1942 add_object_address(OperatorRelationId, nullifexpr->opno, 0,
1943 context->addrs);
1944 /* fall through to examine arguments */
1945 }
1946 else if (IsA(node, ScalarArrayOpExpr))
1947 {
1948 ScalarArrayOpExpr *opexpr = (ScalarArrayOpExpr *) node;
1949
1950 add_object_address(OperatorRelationId, opexpr->opno, 0,
1951 context->addrs);
1952 /* fall through to examine arguments */
1953 }
1954 else if (IsA(node, Aggref))
1955 {
1956 Aggref *aggref = (Aggref *) node;
1957
1958 add_object_address(ProcedureRelationId, aggref->aggfnoid, 0,
1959 context->addrs);
1960 /* fall through to examine arguments */
1961 }
1962 else if (IsA(node, WindowFunc))
1963 {
1964 WindowFunc *wfunc = (WindowFunc *) node;
1965
1966 add_object_address(ProcedureRelationId, wfunc->winfnoid, 0,
1967 context->addrs);
1968 /* fall through to examine arguments */
1969 }
1970 else if (IsA(node, SubscriptingRef))
1971 {
1972 SubscriptingRef *sbsref = (SubscriptingRef *) node;
1973
1974 /*
1975 * The refexpr should provide adequate dependency on refcontainertype,
1976 * and that type in turn depends on refelemtype. However, a custom
1977 * subscripting handler might set refrestype to something different
1978 * from either of those, in which case we'd better record it.
1979 */
1980 if (sbsref->refrestype != sbsref->refcontainertype &&
1981 sbsref->refrestype != sbsref->refelemtype)
1982 add_object_address(TypeRelationId, sbsref->refrestype, 0,
1983 context->addrs);
1984 /* fall through to examine arguments */
1985 }
1986 else if (IsA(node, SubPlan))
1987 {
1988 /* Extra work needed here if we ever need this case */
1989 elog(ERROR, "already-planned subqueries not supported");
1990 }
1991 else if (IsA(node, FieldSelect))
1992 {
1993 FieldSelect *fselect = (FieldSelect *) node;
1994 Oid argtype = getBaseType(exprType((Node *) fselect->arg));
1995 Oid reltype = get_typ_typrelid(argtype);
1996
1997 /*
1998 * We need a dependency on the specific column named in FieldSelect,
1999 * assuming we can identify the pg_class OID for it. (Probably we
2000 * always can at the moment, but in future it might be possible for
2001 * argtype to be RECORDOID.) If we can make a column dependency then
2002 * we shouldn't need a dependency on the column's type; but if we
2003 * can't, make a dependency on the type, as it might not appear
2004 * anywhere else in the expression.
2005 */
2006 if (OidIsValid(reltype))
2007 add_object_address(RelationRelationId, reltype, fselect->fieldnum,
2008 context->addrs);
2009 else
2010 add_object_address(TypeRelationId, fselect->resulttype, 0,
2011 context->addrs);
2012 /* the collation might not be referenced anywhere else, either */
2013 if (OidIsValid(fselect->resultcollid) &&
2014 fselect->resultcollid != DEFAULT_COLLATION_OID)
2015 add_object_address(CollationRelationId, fselect->resultcollid, 0,
2016 context->addrs);
2017 }
2018 else if (IsA(node, FieldStore))
2019 {
2020 FieldStore *fstore = (FieldStore *) node;
2021 Oid reltype = get_typ_typrelid(fstore->resulttype);
2022
2023 /* similar considerations to FieldSelect, but multiple column(s) */
2024 if (OidIsValid(reltype))
2025 {
2026 ListCell *l;
2027
2028 foreach(l, fstore->fieldnums)
2029 add_object_address(RelationRelationId, reltype, lfirst_int(l),
2030 context->addrs);
2031 }
2032 else
2033 add_object_address(TypeRelationId, fstore->resulttype, 0,
2034 context->addrs);
2035 }
2036 else if (IsA(node, RelabelType))
2037 {
2038 RelabelType *relab = (RelabelType *) node;
2039
2040 /* since there is no function dependency, need to depend on type */
2041 add_object_address(TypeRelationId, relab->resulttype, 0,
2042 context->addrs);
2043 /* the collation might not be referenced anywhere else, either */
2044 if (OidIsValid(relab->resultcollid) &&
2045 relab->resultcollid != DEFAULT_COLLATION_OID)
2046 add_object_address(CollationRelationId, relab->resultcollid, 0,
2047 context->addrs);
2048 }
2049 else if (IsA(node, CoerceViaIO))
2050 {
2051 CoerceViaIO *iocoerce = (CoerceViaIO *) node;
2052
2053 /* since there is no exposed function, need to depend on type */
2054 add_object_address(TypeRelationId, iocoerce->resulttype, 0,
2055 context->addrs);
2056 /* the collation might not be referenced anywhere else, either */
2057 if (OidIsValid(iocoerce->resultcollid) &&
2058 iocoerce->resultcollid != DEFAULT_COLLATION_OID)
2059 add_object_address(CollationRelationId, iocoerce->resultcollid, 0,
2060 context->addrs);
2061 }
2062 else if (IsA(node, ArrayCoerceExpr))
2063 {
2064 ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
2065
2066 /* as above, depend on type */
2067 add_object_address(TypeRelationId, acoerce->resulttype, 0,
2068 context->addrs);
2069 /* the collation might not be referenced anywhere else, either */
2070 if (OidIsValid(acoerce->resultcollid) &&
2071 acoerce->resultcollid != DEFAULT_COLLATION_OID)
2072 add_object_address(CollationRelationId, acoerce->resultcollid, 0,
2073 context->addrs);
2074 /* fall through to examine arguments */
2075 }
2076 else if (IsA(node, ConvertRowtypeExpr))
2077 {
2078 ConvertRowtypeExpr *cvt = (ConvertRowtypeExpr *) node;
2079
2080 /* since there is no function dependency, need to depend on type */
2081 add_object_address(TypeRelationId, cvt->resulttype, 0,
2082 context->addrs);
2083 }
2084 else if (IsA(node, CollateExpr))
2085 {
2086 CollateExpr *coll = (CollateExpr *) node;
2087
2088 add_object_address(CollationRelationId, coll->collOid, 0,
2089 context->addrs);
2090 }
2091 else if (IsA(node, RowExpr))
2092 {
2093 RowExpr *rowexpr = (RowExpr *) node;
2094
2095 add_object_address(TypeRelationId, rowexpr->row_typeid, 0,
2096 context->addrs);
2097 }
2098 else if (IsA(node, RowCompareExpr))
2099 {
2100 RowCompareExpr *rcexpr = (RowCompareExpr *) node;
2101 ListCell *l;
2102
2103 foreach(l, rcexpr->opnos)
2104 {
2105 add_object_address(OperatorRelationId, lfirst_oid(l), 0,
2106 context->addrs);
2107 }
2108 foreach(l, rcexpr->opfamilies)
2109 {
2110 add_object_address(OperatorFamilyRelationId, lfirst_oid(l), 0,
2111 context->addrs);
2112 }
2113 /* fall through to examine arguments */
2114 }
2115 else if (IsA(node, CoerceToDomain))
2116 {
2117 CoerceToDomain *cd = (CoerceToDomain *) node;
2118
2119 add_object_address(TypeRelationId, cd->resulttype, 0,
2120 context->addrs);
2121 }
2122 else if (IsA(node, NextValueExpr))
2123 {
2124 NextValueExpr *nve = (NextValueExpr *) node;
2125
2126 add_object_address(RelationRelationId, nve->seqid, 0,
2127 context->addrs);
2128 }
2129 else if (IsA(node, OnConflictExpr))
2130 {
2131 OnConflictExpr *onconflict = (OnConflictExpr *) node;
2132
2133 if (OidIsValid(onconflict->constraint))
2134 add_object_address(ConstraintRelationId, onconflict->constraint, 0,
2135 context->addrs);
2136 /* fall through to examine arguments */
2137 }
2138 else if (IsA(node, SortGroupClause))
2139 {
2140 SortGroupClause *sgc = (SortGroupClause *) node;
2141
2142 add_object_address(OperatorRelationId, sgc->eqop, 0,
2143 context->addrs);
2144 if (OidIsValid(sgc->sortop))
2145 add_object_address(OperatorRelationId, sgc->sortop, 0,
2146 context->addrs);
2147 return false;
2148 }
2149 else if (IsA(node, WindowClause))
2150 {
2151 WindowClause *wc = (WindowClause *) node;
2152
2153 if (OidIsValid(wc->startInRangeFunc))
2154 add_object_address(ProcedureRelationId, wc->startInRangeFunc, 0,
2155 context->addrs);
2156 if (OidIsValid(wc->endInRangeFunc))
2157 add_object_address(ProcedureRelationId, wc->endInRangeFunc, 0,
2158 context->addrs);
2159 if (OidIsValid(wc->inRangeColl) &&
2160 wc->inRangeColl != DEFAULT_COLLATION_OID)
2161 add_object_address(CollationRelationId, wc->inRangeColl, 0,
2162 context->addrs);
2163 /* fall through to examine substructure */
2164 }
2165 else if (IsA(node, CTECycleClause))
2166 {
2167 CTECycleClause *cc = (CTECycleClause *) node;
2168
2169 if (OidIsValid(cc->cycle_mark_type))
2170 add_object_address(TypeRelationId, cc->cycle_mark_type, 0,
2171 context->addrs);
2173 add_object_address(CollationRelationId, cc->cycle_mark_collation, 0,
2174 context->addrs);
2175 if (OidIsValid(cc->cycle_mark_neop))
2176 add_object_address(OperatorRelationId, cc->cycle_mark_neop, 0,
2177 context->addrs);
2178 /* fall through to examine substructure */
2179 }
2180 else if (IsA(node, Query))
2181 {
2182 /* Recurse into RTE subquery or not-yet-planned sublink subquery */
2183 Query *query = (Query *) node;
2184 ListCell *lc;
2185 bool result;
2186
2187 /*
2188 * Add whole-relation refs for each plain relation mentioned in the
2189 * subquery's rtable, and ensure we add refs for any type-coercion
2190 * functions used in join alias lists.
2191 *
2192 * Note: query_tree_walker takes care of recursing into RTE_FUNCTION
2193 * RTEs, subqueries, etc, so no need to do that here. But we must
2194 * tell it not to visit join alias lists, or we'll add refs for join
2195 * input columns whether or not they are actually used in our query.
2196 *
2197 * Note: we don't need to worry about collations mentioned in
2198 * RTE_VALUES or RTE_CTE RTEs, because those must just duplicate
2199 * collations referenced in other parts of the Query. We do have to
2200 * worry about collations mentioned in RTE_FUNCTION, but we take care
2201 * of those when we recurse to the RangeTblFunction node(s).
2202 */
2203 foreach(lc, query->rtable)
2204 {
2205 RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc);
2206
2207 switch (rte->rtekind)
2208 {
2209 case RTE_RELATION:
2210 add_object_address(RelationRelationId, rte->relid, 0,
2211 context->addrs);
2212 break;
2213 case RTE_JOIN:
2214
2215 /*
2216 * Examine joinaliasvars entries only for merged JOIN
2217 * USING columns. Only those entries could contain
2218 * type-coercion functions. Also, their join input
2219 * columns must be referenced in the join quals, so this
2220 * won't accidentally add refs to otherwise-unused join
2221 * input columns. (We want to ref the type coercion
2222 * functions even if the merged column isn't explicitly
2223 * used anywhere, to protect possible expansion of the
2224 * join RTE as a whole-row var, and because it seems like
2225 * a bad idea to allow dropping a function that's present
2226 * in our query tree, whether or not it could get called.)
2227 */
2228 context->rtables = lcons(query->rtable, context->rtables);
2229 for (int i = 0; i < rte->joinmergedcols; i++)
2230 {
2231 Node *aliasvar = list_nth(rte->joinaliasvars, i);
2232
2233 if (!IsA(aliasvar, Var))
2234 find_expr_references_walker(aliasvar, context);
2235 }
2236 context->rtables = list_delete_first(context->rtables);
2237 break;
2239
2240 /*
2241 * Cataloged objects cannot depend on tuplestores, because
2242 * those have no cataloged representation. For now we can
2243 * call the tuplestore a "transition table" because that's
2244 * the only kind exposed to SQL, but someday we might have
2245 * to work harder.
2246 */
2247 ereport(ERROR,
2248 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2249 errmsg("transition table \"%s\" cannot be referenced in a persistent object",
2250 rte->eref->aliasname)));
2251 break;
2252 default:
2253 /* Other RTE types can be ignored here */
2254 break;
2255 }
2256 }
2257
2258 /*
2259 * If the query is an INSERT or UPDATE, we should create a dependency
2260 * on each target column, to prevent the specific target column from
2261 * being dropped. Although we will visit the TargetEntry nodes again
2262 * during query_tree_walker, we won't have enough context to do this
2263 * conveniently, so do it here.
2264 */
2265 if (query->commandType == CMD_INSERT ||
2266 query->commandType == CMD_UPDATE)
2267 {
2268 RangeTblEntry *rte;
2269
2270 if (query->resultRelation <= 0 ||
2271 query->resultRelation > list_length(query->rtable))
2272 elog(ERROR, "invalid resultRelation %d",
2273 query->resultRelation);
2274 rte = rt_fetch(query->resultRelation, query->rtable);
2275 if (rte->rtekind == RTE_RELATION)
2276 {
2277 foreach(lc, query->targetList)
2278 {
2279 TargetEntry *tle = (TargetEntry *) lfirst(lc);
2280
2281 if (tle->resjunk)
2282 continue; /* ignore junk tlist items */
2283 add_object_address(RelationRelationId, rte->relid, tle->resno,
2284 context->addrs);
2285 }
2286 }
2287 }
2288
2289 /*
2290 * Add dependencies on constraints listed in query's constraintDeps
2291 */
2292 foreach(lc, query->constraintDeps)
2293 {
2294 add_object_address(ConstraintRelationId, lfirst_oid(lc), 0,
2295 context->addrs);
2296 }
2297
2298 /* Examine substructure of query */
2299 context->rtables = lcons(query->rtable, context->rtables);
2300 result = query_tree_walker(query,
2302 context,
2305 context->rtables = list_delete_first(context->rtables);
2306 return result;
2307 }
2308 else if (IsA(node, SetOperationStmt))
2309 {
2310 SetOperationStmt *setop = (SetOperationStmt *) node;
2311
2312 /* we need to look at the groupClauses for operator references */
2313 find_expr_references_walker((Node *) setop->groupClauses, context);
2314 /* fall through to examine child nodes */
2315 }
2316 else if (IsA(node, RangeTblFunction))
2317 {
2318 RangeTblFunction *rtfunc = (RangeTblFunction *) node;
2319 ListCell *ct;
2320
2321 /*
2322 * Add refs for any datatypes and collations used in a column
2323 * definition list for a RECORD function. (For other cases, it should
2324 * be enough to depend on the function itself.)
2325 */
2326 foreach(ct, rtfunc->funccoltypes)
2327 {
2328 add_object_address(TypeRelationId, lfirst_oid(ct), 0,
2329 context->addrs);
2330 }
2331 foreach(ct, rtfunc->funccolcollations)
2332 {
2333 Oid collid = lfirst_oid(ct);
2334
2335 if (OidIsValid(collid) && collid != DEFAULT_COLLATION_OID)
2336 add_object_address(CollationRelationId, collid, 0,
2337 context->addrs);
2338 }
2339 }
2340 else if (IsA(node, TableFunc))
2341 {
2342 TableFunc *tf = (TableFunc *) node;
2343 ListCell *ct;
2344
2345 /*
2346 * Add refs for the datatypes and collations used in the TableFunc.
2347 */
2348 foreach(ct, tf->coltypes)
2349 {
2350 add_object_address(TypeRelationId, lfirst_oid(ct), 0,
2351 context->addrs);
2352 }
2353 foreach(ct, tf->colcollations)
2354 {
2355 Oid collid = lfirst_oid(ct);
2356
2357 if (OidIsValid(collid) && collid != DEFAULT_COLLATION_OID)
2358 add_object_address(CollationRelationId, collid, 0,
2359 context->addrs);
2360 }
2361 }
2362 else if (IsA(node, TableSampleClause))
2363 {
2364 TableSampleClause *tsc = (TableSampleClause *) node;
2365
2366 add_object_address(ProcedureRelationId, tsc->tsmhandler, 0,
2367 context->addrs);
2368 /* fall through to examine arguments */
2369 }
2370
2372 context);
2373}
#define InvalidAttrNumber
Definition: attnum.h:23
#define OidIsValid(objectId)
Definition: c.h:777
Oid collid
static void add_object_address(Oid classId, Oid objectId, int32 subId, ObjectAddresses *addrs)
Definition: dependency.c:2634
static void process_function_rte_ref(RangeTblEntry *rte, AttrNumber attnum, find_expr_references_context *context)
Definition: dependency.c:2380
int errcode(int sqlerrcode)
Definition: elog.c:863
int errmsg(const char *fmt,...)
Definition: elog.c:1080
#define ereport(elevel,...)
Definition: elog.h:150
List * list_delete_first(List *list)
Definition: list.c:943
List * lcons(void *datum, List *list)
Definition: list.c:495
Oid get_typ_typrelid(Oid typid)
Definition: lsyscache.c:2898
Oid getBaseType(Oid typid)
Definition: lsyscache.c:2688
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
#define query_tree_walker(q, w, c, f)
Definition: nodeFuncs.h:158
#define QTW_EXAMINE_SORTGROUP
Definition: nodeFuncs.h:30
#define expression_tree_walker(n, w, c)
Definition: nodeFuncs.h:153
#define QTW_IGNORE_JOINALIASES
Definition: nodeFuncs.h:25
#define IsA(nodeptr, _type_)
Definition: nodes.h:164
@ CMD_INSERT
Definition: nodes.h:277
@ CMD_UPDATE
Definition: nodes.h:276
@ RTE_JOIN
Definition: parsenodes.h:1045
@ RTE_NAMEDTUPLESTORE
Definition: parsenodes.h:1050
@ RTE_FUNCTION
Definition: parsenodes.h:1046
@ RTE_RELATION
Definition: parsenodes.h:1043
#define rt_fetch(rangetable_index, rangetable)
Definition: parsetree.h:31
#define lfirst(lc)
Definition: pg_list.h:172
static int list_length(const List *l)
Definition: pg_list.h:152
#define lfirst_int(lc)
Definition: pg_list.h:173
static void * list_nth(const List *list, int n)
Definition: pg_list.h:299
#define lfirst_oid(lc)
Definition: pg_list.h:174
static Oid DatumGetObjectId(Datum X)
Definition: postgres.h:252
unsigned int Oid
Definition: postgres_ext.h:32
Oid aggfnoid
Definition: primnodes.h:463
Oid cycle_mark_collation
Definition: parsenodes.h:1695
Oid resulttype
Definition: primnodes.h:1241
Oid consttype
Definition: primnodes.h:329
AttrNumber fieldnum
Definition: primnodes.h:1162
Expr * arg
Definition: primnodes.h:1161
Oid funcid
Definition: primnodes.h:782
Definition: pg_list.h:54
Definition: nodes.h:135
Oid opno
Definition: primnodes.h:850
Oid paramtype
Definition: primnodes.h:397
Oid paramcollid
Definition: primnodes.h:401
List * rtable
Definition: parsenodes.h:175
CmdType commandType
Definition: parsenodes.h:121
List * targetList
Definition: parsenodes.h:198
RTEKind rtekind
Definition: parsenodes.h:1078
Oid resulttype
Definition: primnodes.h:1218
AttrNumber resno
Definition: primnodes.h:2241
Definition: primnodes.h:262
AttrNumber varattno
Definition: primnodes.h:274
int varno
Definition: primnodes.h:269
Index varlevelsup
Definition: primnodes.h:294
Oid winfnoid
Definition: primnodes.h:597
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:100

References add_object_address(), find_expr_references_context::addrs, Aggref::aggfnoid, FieldSelect::arg, CMD_INSERT, CMD_UPDATE, collid, CollateExpr::collOid, Query::commandType, OnConflictExpr::constraint, Const::consttype, CTECycleClause::cycle_mark_collation, CTECycleClause::cycle_mark_neop, CTECycleClause::cycle_mark_type, DatumGetObjectId(), elog, SortGroupClause::eqop, ereport, errcode(), errmsg(), ERROR, expression_tree_walker, exprType(), FieldSelect::fieldnum, find_expr_references_walker(), FuncExpr::funcid, get_typ_typrelid(), getBaseType(), i, InvalidAttrNumber, IsA, lcons(), lfirst, lfirst_int, lfirst_oid, list_delete_first(), list_length(), list_nth(), ObjectIdGetDatum(), OidIsValid, OpExpr::opno, ScalarArrayOpExpr::opno, Param::paramcollid, Param::paramtype, process_function_rte_ref(), QTW_EXAMINE_SORTGROUP, QTW_IGNORE_JOINALIASES, query_tree_walker, TargetEntry::resno, RelabelType::resulttype, CoerceViaIO::resulttype, ArrayCoerceExpr::resulttype, ConvertRowtypeExpr::resulttype, CoerceToDomain::resulttype, rt_fetch, Query::rtable, find_expr_references_context::rtables, RTE_FUNCTION, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RangeTblEntry::rtekind, SearchSysCacheExists1, NextValueExpr::seqid, SortGroupClause::sortop, Query::targetList, TableSampleClause::tsmhandler, Var::varattno, Var::varlevelsup, Var::varno, and WindowFunc::winfnoid.

Referenced by collectDependenciesOfExpr(), find_expr_references_walker(), and recordDependencyOnSingleRelExpr().

◆ find_temp_object()

bool find_temp_object ( const ObjectAddresses addrs,
bool  local_temp_okay,
ObjectAddress foundobj 
)

Definition at line 2454 of file dependency.c.

2456{
2457 for (int i = 0; i < addrs->numrefs; i++)
2458 {
2459 const ObjectAddress *thisobj = addrs->refs + i;
2460 Oid objnamespace;
2461
2462 /*
2463 * Use get_object_namespace() to see if this object belongs to a
2464 * schema. If not, we can skip it.
2465 */
2466 objnamespace = get_object_namespace(thisobj);
2467
2468 /*
2469 * If the object is in a temporary namespace, complain, except if
2470 * local_temp_okay and it's our own temp namespace.
2471 */
2472 if (OidIsValid(objnamespace) && isAnyTempNamespace(objnamespace) &&
2473 !(local_temp_okay && isTempNamespace(objnamespace)))
2474 {
2475 *foundobj = *thisobj;
2476 return true;
2477 }
2478 }
2479 return false;
2480}
bool isTempNamespace(Oid namespaceId)
Definition: namespace.c:3719
bool isAnyTempNamespace(Oid namespaceId)
Definition: namespace.c:3757
Oid get_object_namespace(const ObjectAddress *address)

References get_object_namespace(), i, isAnyTempNamespace(), isTempNamespace(), ObjectAddresses::numrefs, OidIsValid, and ObjectAddresses::refs.

Referenced by ProcedureCreate(), and query_uses_temp_object().

◆ findDependentObjects()

static void findDependentObjects ( const ObjectAddress object,
int  objflags,
int  flags,
ObjectAddressStack stack,
ObjectAddresses targetObjects,
const ObjectAddresses pendingObjects,
Relation depRel 
)
static

Definition at line 433 of file dependency.c.

440{
441 ScanKeyData key[3];
442 int nkeys;
443 SysScanDesc scan;
444 HeapTuple tup;
445 ObjectAddress otherObject;
446 ObjectAddress owningObject;
447 ObjectAddress partitionObject;
448 ObjectAddressAndFlags *dependentObjects;
449 int numDependentObjects;
450 int maxDependentObjects;
451 ObjectAddressStack mystack;
452 ObjectAddressExtra extra;
453
454 /*
455 * If the target object is already being visited in an outer recursion
456 * level, just report the current objflags back to that level and exit.
457 * This is needed to avoid infinite recursion in the face of circular
458 * dependencies.
459 *
460 * The stack check alone would result in dependency loops being broken at
461 * an arbitrary point, ie, the first member object of the loop to be
462 * visited is the last one to be deleted. This is obviously unworkable.
463 * However, the check for internal dependency below guarantees that we
464 * will not break a loop at an internal dependency: if we enter the loop
465 * at an "owned" object we will switch and start at the "owning" object
466 * instead. We could probably hack something up to avoid breaking at an
467 * auto dependency, too, if we had to. However there are no known cases
468 * where that would be necessary.
469 */
470 if (stack_address_present_add_flags(object, objflags, stack))
471 return;
472
473 /*
474 * since this function recurses, it could be driven to stack overflow,
475 * because of the deep dependency tree, not only due to dependency loops.
476 */
478
479 /*
480 * It's also possible that the target object has already been completely
481 * processed and put into targetObjects. If so, again we just add the
482 * specified objflags to its entry and return.
483 *
484 * (Note: in these early-exit cases we could release the caller-taken
485 * lock, since the object is presumably now locked multiple times; but it
486 * seems not worth the cycles.)
487 */
488 if (object_address_present_add_flags(object, objflags, targetObjects))
489 return;
490
491 /*
492 * If the target object is pinned, we can just error out immediately; it
493 * won't have any objects recorded as depending on it.
494 */
495 if (IsPinnedObject(object->classId, object->objectId))
497 (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
498 errmsg("cannot drop %s because it is required by the database system",
499 getObjectDescription(object, false))));
500
501 /*
502 * The target object might be internally dependent on some other object
503 * (its "owner"), and/or be a member of an extension (also considered its
504 * owner). If so, and if we aren't recursing from the owning object, we
505 * have to transform this deletion request into a deletion request of the
506 * owning object. (We'll eventually recurse back to this object, but the
507 * owning object has to be visited first so it will be deleted after.) The
508 * way to find out about this is to scan the pg_depend entries that show
509 * what this object depends on.
510 */
511 ScanKeyInit(&key[0],
512 Anum_pg_depend_classid,
513 BTEqualStrategyNumber, F_OIDEQ,
514 ObjectIdGetDatum(object->classId));
515 ScanKeyInit(&key[1],
516 Anum_pg_depend_objid,
517 BTEqualStrategyNumber, F_OIDEQ,
518 ObjectIdGetDatum(object->objectId));
519 if (object->objectSubId != 0)
520 {
521 /* Consider only dependencies of this sub-object */
522 ScanKeyInit(&key[2],
523 Anum_pg_depend_objsubid,
524 BTEqualStrategyNumber, F_INT4EQ,
525 Int32GetDatum(object->objectSubId));
526 nkeys = 3;
527 }
528 else
529 {
530 /* Consider dependencies of this object and any sub-objects it has */
531 nkeys = 2;
532 }
533
534 scan = systable_beginscan(*depRel, DependDependerIndexId, true,
535 NULL, nkeys, key);
536
537 /* initialize variables that loop may fill */
538 memset(&owningObject, 0, sizeof(owningObject));
539 memset(&partitionObject, 0, sizeof(partitionObject));
540
541 while (HeapTupleIsValid(tup = systable_getnext(scan)))
542 {
543 Form_pg_depend foundDep = (Form_pg_depend) GETSTRUCT(tup);
544
545 otherObject.classId = foundDep->refclassid;
546 otherObject.objectId = foundDep->refobjid;
547 otherObject.objectSubId = foundDep->refobjsubid;
548
549 /*
550 * When scanning dependencies of a whole object, we may find rows
551 * linking sub-objects of the object to the object itself. (Normally,
552 * such a dependency is implicit, but we must make explicit ones in
553 * some cases involving partitioning.) We must ignore such rows to
554 * avoid infinite recursion.
555 */
556 if (otherObject.classId == object->classId &&
557 otherObject.objectId == object->objectId &&
558 object->objectSubId == 0)
559 continue;
560
561 switch (foundDep->deptype)
562 {
564 case DEPENDENCY_AUTO:
566 /* no problem */
567 break;
568
570
571 /*
572 * If told to, ignore EXTENSION dependencies altogether. This
573 * flag is normally used to prevent dropping extensions during
574 * temporary-object cleanup, even if a temp object was created
575 * during an extension script.
576 */
578 break;
579
580 /*
581 * If the other object is the extension currently being
582 * created/altered, ignore this dependency and continue with
583 * the deletion. This allows dropping of an extension's
584 * objects within the extension's scripts, as well as corner
585 * cases such as dropping a transient object created within
586 * such a script.
587 */
588 if (creating_extension &&
589 otherObject.classId == ExtensionRelationId &&
590 otherObject.objectId == CurrentExtensionObject)
591 break;
592
593 /* Otherwise, treat this like an internal dependency */
594 /* FALL THRU */
595
597
598 /*
599 * This object is part of the internal implementation of
600 * another object, or is part of the extension that is the
601 * other object. We have three cases:
602 *
603 * 1. At the outermost recursion level, we must disallow the
604 * DROP. However, if the owning object is listed in
605 * pendingObjects, just release the caller's lock and return;
606 * we'll eventually complete the DROP when we reach that entry
607 * in the pending list.
608 *
609 * Note: the above statement is true only if this pg_depend
610 * entry still exists by then; in principle, therefore, we
611 * could miss deleting an item the user told us to delete.
612 * However, no inconsistency can result: since we're at outer
613 * level, there is no object depending on this one.
614 */
615 if (stack == NULL)
616 {
617 if (pendingObjects &&
618 object_address_present(&otherObject, pendingObjects))
619 {
620 systable_endscan(scan);
621 /* need to release caller's lock; see notes below */
622 ReleaseDeletionLock(object);
623 return;
624 }
625
626 /*
627 * We postpone actually issuing the error message until
628 * after this loop, so that we can make the behavior
629 * independent of the ordering of pg_depend entries, at
630 * least if there's not more than one INTERNAL and one
631 * EXTENSION dependency. (If there's more, we'll complain
632 * about a random one of them.) Prefer to complain about
633 * EXTENSION, since that's generally a more important
634 * dependency.
635 */
636 if (!OidIsValid(owningObject.classId) ||
637 foundDep->deptype == DEPENDENCY_EXTENSION)
638 owningObject = otherObject;
639 break;
640 }
641
642 /*
643 * 2. When recursing from the other end of this dependency,
644 * it's okay to continue with the deletion. This holds when
645 * recursing from a whole object that includes the nominal
646 * other end as a component, too. Since there can be more
647 * than one "owning" object, we have to allow matches that are
648 * more than one level down in the stack.
649 */
650 if (stack_address_present_add_flags(&otherObject, 0, stack))
651 break;
652
653 /*
654 * 3. Not all the owning objects have been visited, so
655 * transform this deletion request into a delete of this
656 * owning object.
657 *
658 * First, release caller's lock on this object and get
659 * deletion lock on the owning object. (We must release
660 * caller's lock to avoid deadlock against a concurrent
661 * deletion of the owning object.)
662 */
663 ReleaseDeletionLock(object);
664 AcquireDeletionLock(&otherObject, 0);
665
666 /*
667 * The owning object might have been deleted while we waited
668 * to lock it; if so, neither it nor the current object are
669 * interesting anymore. We test this by checking the
670 * pg_depend entry (see notes below).
671 */
672 if (!systable_recheck_tuple(scan, tup))
673 {
674 systable_endscan(scan);
675 ReleaseDeletionLock(&otherObject);
676 return;
677 }
678
679 /*
680 * One way or the other, we're done with the scan; might as
681 * well close it down before recursing, to reduce peak
682 * resource consumption.
683 */
684 systable_endscan(scan);
685
686 /*
687 * Okay, recurse to the owning object instead of proceeding.
688 *
689 * We do not need to stack the current object; we want the
690 * traversal order to be as if the original reference had
691 * linked to the owning object instead of this one.
692 *
693 * The dependency type is a "reverse" dependency: we need to
694 * delete the owning object if this one is to be deleted, but
695 * this linkage is never a reason for an automatic deletion.
696 */
697 findDependentObjects(&otherObject,
699 flags,
700 stack,
701 targetObjects,
702 pendingObjects,
703 depRel);
704
705 /*
706 * The current target object should have been added to
707 * targetObjects while processing the owning object; but it
708 * probably got only the flag bits associated with the
709 * dependency we're looking at. We need to add the objflags
710 * that were passed to this recursion level, too, else we may
711 * get a bogus failure in reportDependentObjects (if, for
712 * example, we were called due to a partition dependency).
713 *
714 * If somehow the current object didn't get scheduled for
715 * deletion, bleat. (That would imply that somebody deleted
716 * this dependency record before the recursion got to it.)
717 * Another idea would be to reacquire lock on the current
718 * object and resume trying to delete it, but it seems not
719 * worth dealing with the race conditions inherent in that.
720 */
721 if (!object_address_present_add_flags(object, objflags,
722 targetObjects))
723 elog(ERROR, "deletion of owning object %s failed to delete %s",
724 getObjectDescription(&otherObject, false),
725 getObjectDescription(object, false));
726
727 /* And we're done here. */
728 return;
729
731
732 /*
733 * Remember that this object has a partition-type dependency.
734 * After the dependency scan, we'll complain if we didn't find
735 * a reason to delete one of its partition dependencies.
736 */
737 objflags |= DEPFLAG_IS_PART;
738
739 /*
740 * Also remember the primary partition owner, for error
741 * messages. If there are multiple primary owners (which
742 * there should not be), we'll report a random one of them.
743 */
744 partitionObject = otherObject;
745 break;
746
748
749 /*
750 * Only use secondary partition owners in error messages if we
751 * find no primary owner (which probably shouldn't happen).
752 */
753 if (!(objflags & DEPFLAG_IS_PART))
754 partitionObject = otherObject;
755
756 /*
757 * Remember that this object has a partition-type dependency.
758 * After the dependency scan, we'll complain if we didn't find
759 * a reason to delete one of its partition dependencies.
760 */
761 objflags |= DEPFLAG_IS_PART;
762 break;
763
764 default:
765 elog(ERROR, "unrecognized dependency type '%c' for %s",
766 foundDep->deptype, getObjectDescription(object, false));
767 break;
768 }
769 }
770
771 systable_endscan(scan);
772
773 /*
774 * If we found an INTERNAL or EXTENSION dependency when we're at outer
775 * level, complain about it now. If we also found a PARTITION dependency,
776 * we prefer to report the PARTITION dependency. This is arbitrary but
777 * seems to be more useful in practice.
778 */
779 if (OidIsValid(owningObject.classId))
780 {
781 char *otherObjDesc;
782
783 if (OidIsValid(partitionObject.classId))
784 otherObjDesc = getObjectDescription(&partitionObject, false);
785 else
786 otherObjDesc = getObjectDescription(&owningObject, false);
787
789 (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
790 errmsg("cannot drop %s because %s requires it",
791 getObjectDescription(object, false), otherObjDesc),
792 errhint("You can drop %s instead.", otherObjDesc)));
793 }
794
795 /*
796 * Next, identify all objects that directly depend on the current object.
797 * To ensure predictable deletion order, we collect them up in
798 * dependentObjects and sort the list before actually recursing. (The
799 * deletion order would be valid in any case, but doing this ensures
800 * consistent output from DROP CASCADE commands, which is helpful for
801 * regression testing.)
802 */
803 maxDependentObjects = 128; /* arbitrary initial allocation */
804 dependentObjects = (ObjectAddressAndFlags *)
805 palloc(maxDependentObjects * sizeof(ObjectAddressAndFlags));
806 numDependentObjects = 0;
807
808 ScanKeyInit(&key[0],
809 Anum_pg_depend_refclassid,
810 BTEqualStrategyNumber, F_OIDEQ,
811 ObjectIdGetDatum(object->classId));
812 ScanKeyInit(&key[1],
813 Anum_pg_depend_refobjid,
814 BTEqualStrategyNumber, F_OIDEQ,
815 ObjectIdGetDatum(object->objectId));
816 if (object->objectSubId != 0)
817 {
818 ScanKeyInit(&key[2],
819 Anum_pg_depend_refobjsubid,
820 BTEqualStrategyNumber, F_INT4EQ,
821 Int32GetDatum(object->objectSubId));
822 nkeys = 3;
823 }
824 else
825 nkeys = 2;
826
827 scan = systable_beginscan(*depRel, DependReferenceIndexId, true,
828 NULL, nkeys, key);
829
830 while (HeapTupleIsValid(tup = systable_getnext(scan)))
831 {
832 Form_pg_depend foundDep = (Form_pg_depend) GETSTRUCT(tup);
833 int subflags;
834
835 otherObject.classId = foundDep->classid;
836 otherObject.objectId = foundDep->objid;
837 otherObject.objectSubId = foundDep->objsubid;
838
839 /*
840 * If what we found is a sub-object of the current object, just ignore
841 * it. (Normally, such a dependency is implicit, but we must make
842 * explicit ones in some cases involving partitioning.)
843 */
844 if (otherObject.classId == object->classId &&
845 otherObject.objectId == object->objectId &&
846 object->objectSubId == 0)
847 continue;
848
849 /*
850 * Must lock the dependent object before recursing to it.
851 */
852 AcquireDeletionLock(&otherObject, 0);
853
854 /*
855 * The dependent object might have been deleted while we waited to
856 * lock it; if so, we don't need to do anything more with it. We can
857 * test this cheaply and independently of the object's type by seeing
858 * if the pg_depend tuple we are looking at is still live. (If the
859 * object got deleted, the tuple would have been deleted too.)
860 */
861 if (!systable_recheck_tuple(scan, tup))
862 {
863 /* release the now-useless lock */
864 ReleaseDeletionLock(&otherObject);
865 /* and continue scanning for dependencies */
866 continue;
867 }
868
869 /*
870 * We do need to delete it, so identify objflags to be passed down,
871 * which depend on the dependency type.
872 */
873 switch (foundDep->deptype)
874 {
876 subflags = DEPFLAG_NORMAL;
877 break;
878 case DEPENDENCY_AUTO:
880 subflags = DEPFLAG_AUTO;
881 break;
883 subflags = DEPFLAG_INTERNAL;
884 break;
887 subflags = DEPFLAG_PARTITION;
888 break;
890 subflags = DEPFLAG_EXTENSION;
891 break;
892 default:
893 elog(ERROR, "unrecognized dependency type '%c' for %s",
894 foundDep->deptype, getObjectDescription(object, false));
895 subflags = 0; /* keep compiler quiet */
896 break;
897 }
898
899 /* And add it to the pending-objects list */
900 if (numDependentObjects >= maxDependentObjects)
901 {
902 /* enlarge array if needed */
903 maxDependentObjects *= 2;
904 dependentObjects = (ObjectAddressAndFlags *)
905 repalloc(dependentObjects,
906 maxDependentObjects * sizeof(ObjectAddressAndFlags));
907 }
908
909 dependentObjects[numDependentObjects].obj = otherObject;
910 dependentObjects[numDependentObjects].subflags = subflags;
911 numDependentObjects++;
912 }
913
914 systable_endscan(scan);
915
916 /*
917 * Now we can sort the dependent objects into a stable visitation order.
918 * It's safe to use object_address_comparator here since the obj field is
919 * first within ObjectAddressAndFlags.
920 */
921 if (numDependentObjects > 1)
922 qsort(dependentObjects, numDependentObjects,
923 sizeof(ObjectAddressAndFlags),
925
926 /*
927 * Now recurse to the dependent objects. We must visit them first since
928 * they have to be deleted before the current object.
929 */
930 mystack.object = object; /* set up a new stack level */
931 mystack.flags = objflags;
932 mystack.next = stack;
933
934 for (int i = 0; i < numDependentObjects; i++)
935 {
936 ObjectAddressAndFlags *depObj = dependentObjects + i;
937
938 findDependentObjects(&depObj->obj,
939 depObj->subflags,
940 flags,
941 &mystack,
942 targetObjects,
943 pendingObjects,
944 depRel);
945 }
946
947 pfree(dependentObjects);
948
949 /*
950 * Finally, we can add the target object to targetObjects. Be careful to
951 * include any flags that were passed back down to us from inner recursion
952 * levels. Record the "dependee" as being either the most important
953 * partition owner if there is one, else the object we recursed from, if
954 * any. (The logic in reportDependentObjects() is such that it can only
955 * need one of those objects.)
956 */
957 extra.flags = mystack.flags;
958 if (extra.flags & DEPFLAG_IS_PART)
959 extra.dependee = partitionObject;
960 else if (stack)
961 extra.dependee = *stack->object;
962 else
963 memset(&extra.dependee, 0, sizeof(extra.dependee));
964 add_exact_object_address_extra(object, &extra, targetObjects);
965}
bool IsPinnedObject(Oid classId, Oid objectId)
Definition: catalog.c:370
static bool object_address_present_add_flags(const ObjectAddress *object, int flags, ObjectAddresses *addrs)
Definition: dependency.c:2747
#define DEPFLAG_PARTITION
Definition: dependency.c:106
static void add_exact_object_address_extra(const ObjectAddress *object, const ObjectAddressExtra *extra, ObjectAddresses *addrs)
Definition: dependency.c:2686
static bool stack_address_present_add_flags(const ObjectAddress *object, int flags, ObjectAddressStack *stack)
Definition: dependency.c:2820
#define DEPFLAG_IS_PART
Definition: dependency.c:109
void AcquireDeletionLock(const ObjectAddress *object, int flags)
Definition: dependency.c:1497
void ReleaseDeletionLock(const ObjectAddress *object)
Definition: dependency.c:1529
#define DEPFLAG_AUTO
Definition: dependency.c:104
static void findDependentObjects(const ObjectAddress *object, int objflags, int flags, ObjectAddressStack *stack, ObjectAddresses *targetObjects, const ObjectAddresses *pendingObjects, Relation *depRel)
Definition: dependency.c:433
bool object_address_present(const ObjectAddress *object, const ObjectAddresses *addrs)
Definition: dependency.c:2721
#define DEPFLAG_EXTENSION
Definition: dependency.c:107
#define DEPFLAG_INTERNAL
Definition: dependency.c:105
#define PERFORM_DELETION_SKIP_EXTENSIONS
Definition: dependency.h:96
@ DEPENDENCY_AUTO
Definition: dependency.h:34
@ DEPENDENCY_AUTO_EXTENSION
Definition: dependency.h:39
@ DEPENDENCY_INTERNAL
Definition: dependency.h:35
@ DEPENDENCY_PARTITION_PRI
Definition: dependency.h:36
@ DEPENDENCY_PARTITION_SEC
Definition: dependency.h:37
@ DEPENDENCY_EXTENSION
Definition: dependency.h:38
@ DEPENDENCY_NORMAL
Definition: dependency.h:33
int errhint(const char *fmt,...)
Definition: elog.c:1330
bool creating_extension
Definition: extension.c:77
Oid CurrentExtensionObject
Definition: extension.c:78
bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup)
Definition: genam.c:573
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
void pfree(void *pointer)
Definition: mcxt.c:1594
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
FormData_pg_depend * Form_pg_depend
Definition: pg_depend.h:72
void check_stack_depth(void)
Definition: stack_depth.c:95
ObjectAddress obj
Definition: dependency.c:135
ObjectAddress dependee
Definition: dependency.c:98
const ObjectAddress * object
Definition: dependency.c:127
struct ObjectAddressStack * next
Definition: dependency.c:129

References AcquireDeletionLock(), add_exact_object_address_extra(), BTEqualStrategyNumber, check_stack_depth(), ObjectAddress::classId, creating_extension, CurrentExtensionObject, ObjectAddressExtra::dependee, DEPENDENCY_AUTO, DEPENDENCY_AUTO_EXTENSION, DEPENDENCY_EXTENSION, DEPENDENCY_INTERNAL, DEPENDENCY_NORMAL, DEPENDENCY_PARTITION_PRI, DEPENDENCY_PARTITION_SEC, DEPFLAG_AUTO, DEPFLAG_EXTENSION, DEPFLAG_INTERNAL, DEPFLAG_IS_PART, DEPFLAG_NORMAL, DEPFLAG_PARTITION, DEPFLAG_REVERSE, elog, ereport, errcode(), errhint(), errmsg(), ERROR, findDependentObjects(), ObjectAddressExtra::flags, ObjectAddressStack::flags, getObjectDescription(), GETSTRUCT(), HeapTupleIsValid, i, Int32GetDatum(), IsPinnedObject(), sort-test::key, ObjectAddressStack::next, ObjectAddressAndFlags::obj, ObjectAddressStack::object, object_address_comparator(), object_address_present(), object_address_present_add_flags(), ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, OidIsValid, palloc(), PERFORM_DELETION_SKIP_EXTENSIONS, pfree(), qsort, ReleaseDeletionLock(), repalloc(), ScanKeyInit(), stack_address_present_add_flags(), ObjectAddressAndFlags::subflags, systable_beginscan(), systable_endscan(), systable_getnext(), and systable_recheck_tuple().

Referenced by findDependentObjects(), performDeletion(), and performMultipleDeletions().

◆ free_object_addresses()

◆ new_object_addresses()

◆ object_address_comparator()

static int object_address_comparator ( const void *  a,
const void *  b 
)
static

Definition at line 2571 of file dependency.c.

2572{
2573 const ObjectAddress *obja = (const ObjectAddress *) a;
2574 const ObjectAddress *objb = (const ObjectAddress *) b;
2575
2576 /*
2577 * Primary sort key is OID descending. Most of the time, this will result
2578 * in putting newer objects before older ones, which is likely to be the
2579 * right order to delete in.
2580 */
2581 if (obja->objectId > objb->objectId)
2582 return -1;
2583 if (obja->objectId < objb->objectId)
2584 return 1;
2585
2586 /*
2587 * Next sort on catalog ID, in case identical OIDs appear in different
2588 * catalogs. Sort direction is pretty arbitrary here.
2589 */
2590 if (obja->classId < objb->classId)
2591 return -1;
2592 if (obja->classId > objb->classId)
2593 return 1;
2594
2595 /*
2596 * Last, sort on object subId.
2597 *
2598 * We sort the subId as an unsigned int so that 0 (the whole object) will
2599 * come first. This is essential for eliminate_duplicate_dependencies,
2600 * and is also the best order for findDependentObjects.
2601 */
2602 if ((unsigned int) obja->objectSubId < (unsigned int) objb->objectSubId)
2603 return -1;
2604 if ((unsigned int) obja->objectSubId > (unsigned int) objb->objectSubId)
2605 return 1;
2606 return 0;
2607}
int b
Definition: isn.c:74
int a
Definition: isn.c:73

References a, b, ObjectAddress::classId, ObjectAddress::objectId, and ObjectAddress::objectSubId.

Referenced by eliminate_duplicate_dependencies(), findDependentObjects(), and sort_object_addresses().

◆ object_address_present()

bool object_address_present ( const ObjectAddress object,
const ObjectAddresses addrs 
)

Definition at line 2721 of file dependency.c.

2723{
2724 int i;
2725
2726 for (i = addrs->numrefs - 1; i >= 0; i--)
2727 {
2728 const ObjectAddress *thisobj = addrs->refs + i;
2729
2730 if (object->classId == thisobj->classId &&
2731 object->objectId == thisobj->objectId)
2732 {
2733 if (object->objectSubId == thisobj->objectSubId ||
2734 thisobj->objectSubId == 0)
2735 return true;
2736 }
2737 }
2738
2739 return false;
2740}

References ObjectAddress::classId, i, ObjectAddresses::numrefs, ObjectAddressStack::object, ObjectAddress::objectId, ObjectAddress::objectSubId, and ObjectAddresses::refs.

Referenced by AlterConstraintNamespaces(), AlterIndexNamespaces(), AlterRelationNamespaceInternal(), AlterTypeNamespaceInternal(), findDependentObjects(), and PreCommit_on_commit_actions().

◆ object_address_present_add_flags()

static bool object_address_present_add_flags ( const ObjectAddress object,
int  flags,
ObjectAddresses addrs 
)
static

Definition at line 2747 of file dependency.c.

2750{
2751 bool result = false;
2752 int i;
2753
2754 for (i = addrs->numrefs - 1; i >= 0; i--)
2755 {
2756 ObjectAddress *thisobj = addrs->refs + i;
2757
2758 if (object->classId == thisobj->classId &&
2759 object->objectId == thisobj->objectId)
2760 {
2761 if (object->objectSubId == thisobj->objectSubId)
2762 {
2763 ObjectAddressExtra *thisextra = addrs->extras + i;
2764
2765 thisextra->flags |= flags;
2766 result = true;
2767 }
2768 else if (thisobj->objectSubId == 0)
2769 {
2770 /*
2771 * We get here if we find a need to delete a column after
2772 * having already decided to drop its whole table. Obviously
2773 * we no longer need to drop the subobject, so report that we
2774 * found the subobject in the array. But don't plaster its
2775 * flags on the whole object.
2776 */
2777 result = true;
2778 }
2779 else if (object->objectSubId == 0)
2780 {
2781 /*
2782 * We get here if we find a need to delete a whole table after
2783 * having already decided to drop one of its columns. We
2784 * can't report that the whole object is in the array, but we
2785 * should mark the subobject with the whole object's flags.
2786 *
2787 * It might seem attractive to physically delete the column's
2788 * array entry, or at least mark it as no longer needing
2789 * separate deletion. But that could lead to, e.g., dropping
2790 * the column's datatype before we drop the table, which does
2791 * not seem like a good idea. This is a very rare situation
2792 * in practice, so we just take the hit of doing a separate
2793 * DROP COLUMN action even though we know we're gonna delete
2794 * the table later.
2795 *
2796 * What we can do, though, is mark this as a subobject so that
2797 * we don't report it separately, which is confusing because
2798 * it's unpredictable whether it happens or not. But do so
2799 * only if flags != 0 (flags == 0 is a read-only probe).
2800 *
2801 * Because there could be other subobjects of this object in
2802 * the array, this case means we always have to loop through
2803 * the whole array; we cannot exit early on a match.
2804 */
2805 ObjectAddressExtra *thisextra = addrs->extras + i;
2806
2807 if (flags)
2808 thisextra->flags |= (flags | DEPFLAG_SUBOBJECT);
2809 }
2810 }
2811 }
2812
2813 return result;
2814}
#define DEPFLAG_SUBOBJECT
Definition: dependency.c:110

References ObjectAddress::classId, DEPFLAG_SUBOBJECT, ObjectAddresses::extras, ObjectAddressExtra::flags, ObjectAddressStack::flags, i, ObjectAddresses::numrefs, ObjectAddressStack::object, ObjectAddress::objectId, ObjectAddress::objectSubId, and ObjectAddresses::refs.

Referenced by findDependentObjects().

◆ performDeletion()

void performDeletion ( const ObjectAddress object,
DropBehavior  behavior,
int  flags 
)

Definition at line 274 of file dependency.c.

276{
277 Relation depRel;
278 ObjectAddresses *targetObjects;
279
280 /*
281 * We save some cycles by opening pg_depend just once and passing the
282 * Relation pointer down to all the recursive deletion steps.
283 */
284 depRel = table_open(DependRelationId, RowExclusiveLock);
285
286 /*
287 * Acquire deletion lock on the target object. (Ideally the caller has
288 * done this already, but many places are sloppy about it.)
289 */
290 AcquireDeletionLock(object, 0);
291
292 /*
293 * Construct a list of objects to delete (ie, the given object plus
294 * everything directly or indirectly dependent on it).
295 */
296 targetObjects = new_object_addresses();
297
300 flags,
301 NULL, /* empty stack */
302 targetObjects,
303 NULL, /* no pendingObjects */
304 &depRel);
305
306 /*
307 * Check if deletion is allowed, and report about cascaded deletes.
308 */
309 reportDependentObjects(targetObjects,
310 behavior,
311 flags,
312 object);
313
314 /* do the deed */
315 deleteObjectsInList(targetObjects, &depRel, flags);
316
317 /* And clean up */
318 free_object_addresses(targetObjects);
319
321}
static void reportDependentObjects(const ObjectAddresses *targetObjects, DropBehavior behavior, int flags, const ObjectAddress *origObject)
Definition: dependency.c:981
ObjectAddresses * new_object_addresses(void)
Definition: dependency.c:2615
static void deleteObjectsInList(ObjectAddresses *targetObjects, Relation *depRel, int flags)
Definition: dependency.c:186
void free_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2901

References AcquireDeletionLock(), deleteObjectsInList(), DEPFLAG_ORIGINAL, findDependentObjects(), ObjectAddressStack::flags, free_object_addresses(), new_object_addresses(), reportDependentObjects(), RowExclusiveLock, table_close(), and table_open().

Referenced by AlterDomainDropConstraint(), AlterDomainNotNull(), ATExecDropIdentity(), DetachPartitionFinalize(), do_autovacuum(), dropconstraint_internal(), DropForeignKeyConstraintTriggers(), dropOperators(), dropProcedures(), finish_heap_swap(), inv_drop(), PublicationDropSchemas(), PublicationDropTables(), RemoveAttrDefault(), RemoveTempRelations(), RemoveUserMapping(), and SetDefaultACL().

◆ performMultipleDeletions()

void performMultipleDeletions ( const ObjectAddresses objects,
DropBehavior  behavior,
int  flags 
)

Definition at line 333 of file dependency.c.

335{
336 Relation depRel;
337 ObjectAddresses *targetObjects;
338 int i;
339
340 /* No work if no objects... */
341 if (objects->numrefs <= 0)
342 return;
343
344 /*
345 * We save some cycles by opening pg_depend just once and passing the
346 * Relation pointer down to all the recursive deletion steps.
347 */
348 depRel = table_open(DependRelationId, RowExclusiveLock);
349
350 /*
351 * Construct a list of objects to delete (ie, the given objects plus
352 * everything directly or indirectly dependent on them). Note that
353 * because we pass the whole objects list as pendingObjects context, we
354 * won't get a failure from trying to delete an object that is internally
355 * dependent on another one in the list; we'll just skip that object and
356 * delete it when we reach its owner.
357 */
358 targetObjects = new_object_addresses();
359
360 for (i = 0; i < objects->numrefs; i++)
361 {
362 const ObjectAddress *thisobj = objects->refs + i;
363
364 /*
365 * Acquire deletion lock on each target object. (Ideally the caller
366 * has done this already, but many places are sloppy about it.)
367 */
368 AcquireDeletionLock(thisobj, flags);
369
370 findDependentObjects(thisobj,
372 flags,
373 NULL, /* empty stack */
374 targetObjects,
375 objects,
376 &depRel);
377 }
378
379 /*
380 * Check if deletion is allowed, and report about cascaded deletes.
381 *
382 * If there's exactly one object being deleted, report it the same way as
383 * in performDeletion(), else we have to be vaguer.
384 */
385 reportDependentObjects(targetObjects,
386 behavior,
387 flags,
388 (objects->numrefs == 1 ? objects->refs : NULL));
389
390 /* do the deed */
391 deleteObjectsInList(targetObjects, &depRel, flags);
392
393 /* And clean up */
394 free_object_addresses(targetObjects);
395
397}

References AcquireDeletionLock(), deleteObjectsInList(), DEPFLAG_ORIGINAL, findDependentObjects(), ObjectAddressStack::flags, free_object_addresses(), i, new_object_addresses(), ObjectAddresses::numrefs, ObjectAddresses::refs, reportDependentObjects(), RowExclusiveLock, table_close(), and table_open().

Referenced by ATExecDropColumn(), DropClonedTriggersFromPartition(), PreCommit_on_commit_actions(), ReindexRelationConcurrently(), RemoveInheritedConstraint(), RemoveObjects(), RemoveRelations(), and shdepDropOwned().

◆ process_function_rte_ref()

static void process_function_rte_ref ( RangeTblEntry rte,
AttrNumber  attnum,
find_expr_references_context context 
)
static

Definition at line 2380 of file dependency.c.

2382{
2383 int atts_done = 0;
2384 ListCell *lc;
2385
2386 /*
2387 * Identify which RangeTblFunction produces this attnum, and see if it
2388 * returns a composite type. If so, we'd better make a dependency on the
2389 * referenced column of the composite type (or actually, of its associated
2390 * relation).
2391 */
2392 foreach(lc, rte->functions)
2393 {
2394 RangeTblFunction *rtfunc = (RangeTblFunction *) lfirst(lc);
2395
2396 if (attnum > atts_done &&
2397 attnum <= atts_done + rtfunc->funccolcount)
2398 {
2399 TupleDesc tupdesc;
2400
2401 /* If it has a coldeflist, it certainly returns RECORD */
2402 if (rtfunc->funccolnames != NIL)
2403 tupdesc = NULL; /* no need to work hard */
2404 else
2405 tupdesc = get_expr_result_tupdesc(rtfunc->funcexpr, true);
2406 if (tupdesc && tupdesc->tdtypeid != RECORDOID)
2407 {
2408 /*
2409 * Named composite type, so individual columns could get
2410 * dropped. Make a dependency on this specific column.
2411 */
2412 Oid reltype = get_typ_typrelid(tupdesc->tdtypeid);
2413
2414 Assert(attnum - atts_done <= tupdesc->natts);
2415 if (OidIsValid(reltype)) /* can this fail? */
2416 add_object_address(RelationRelationId, reltype,
2417 attnum - atts_done,
2418 context->addrs);
2419 return;
2420 }
2421 /* Nothing to do; function's result type is handled elsewhere */
2422 return;
2423 }
2424 atts_done += rtfunc->funccolcount;
2425 }
2426
2427 /* If we get here, must be looking for the ordinality column */
2428 if (rte->funcordinality && attnum == atts_done + 1)
2429 return;
2430
2431 /* this probably can't happen ... */
2432 ereport(ERROR,
2433 (errcode(ERRCODE_UNDEFINED_COLUMN),
2434 errmsg("column %d of relation \"%s\" does not exist",
2435 attnum, rte->eref->aliasname)));
2436}
TupleDesc get_expr_result_tupdesc(Node *expr, bool noError)
Definition: funcapi.c:551
int16 attnum
Definition: pg_attribute.h:74
#define NIL
Definition: pg_list.h:68
bool funcordinality
Definition: parsenodes.h:1210
List * functions
Definition: parsenodes.h:1208
Oid tdtypeid
Definition: tupdesc.h:138

References add_object_address(), find_expr_references_context::addrs, Assert(), attnum, ereport, errcode(), errmsg(), ERROR, RangeTblFunction::funcexpr, RangeTblEntry::funcordinality, RangeTblEntry::functions, get_expr_result_tupdesc(), get_typ_typrelid(), lfirst, NIL, OidIsValid, and TupleDescData::tdtypeid.

Referenced by find_expr_references_walker().

◆ query_uses_temp_object()

bool query_uses_temp_object ( Query query,
ObjectAddress temp_object 
)

Definition at line 2489 of file dependency.c.

2490{
2491 bool result;
2492 ObjectAddresses *addrs;
2493
2494 addrs = new_object_addresses();
2495
2496 /* Collect all dependencies from the Query */
2497 collectDependenciesOfExpr(addrs, (Node *) query, NIL);
2498
2499 /* Look for one that is temp */
2500 result = find_temp_object(addrs, false, temp_object);
2501
2502 free_object_addresses(addrs);
2503
2504 return result;
2505}
void collectDependenciesOfExpr(ObjectAddresses *addrs, Node *expr, List *rtable)
Definition: dependency.c:1597
bool find_temp_object(const ObjectAddresses *addrs, bool local_temp_okay, ObjectAddress *foundobj)
Definition: dependency.c:2454

References collectDependenciesOfExpr(), find_temp_object(), free_object_addresses(), new_object_addresses(), and NIL.

Referenced by DefineView(), and transformCreateTableAsStmt().

◆ record_object_address_dependencies()

void record_object_address_dependencies ( const ObjectAddress depender,
ObjectAddresses referenced,
DependencyType  behavior 
)

◆ recordDependencyOnExpr()

void recordDependencyOnExpr ( const ObjectAddress depender,
Node expr,
List rtable,
DependencyType  behavior 
)

Definition at line 1554 of file dependency.c.

1557{
1558 ObjectAddresses *addrs;
1559
1560 addrs = new_object_addresses();
1561
1562 /* Collect all dependencies from the expression */
1563 collectDependenciesOfExpr(addrs, expr, rtable);
1564
1565 /* Remove duplicates */
1567
1568 /* And record 'em */
1570 addrs->refs, addrs->numrefs,
1571 behavior);
1572
1573 free_object_addresses(addrs);
1574}

References collectDependenciesOfExpr(), eliminate_duplicate_dependencies(), free_object_addresses(), new_object_addresses(), ObjectAddresses::numrefs, recordMultipleDependencies(), and ObjectAddresses::refs.

Referenced by AlterPolicy(), CreatePolicy(), CreateTriggerFiringOn(), GenerateTypeDependencies(), and InsertRule().

◆ recordDependencyOnSingleRelExpr()

void recordDependencyOnSingleRelExpr ( const ObjectAddress depender,
Node expr,
Oid  relId,
DependencyType  behavior,
DependencyType  self_behavior,
bool  reverse_self 
)

Definition at line 1629 of file dependency.c.

1634{
1636 RangeTblEntry rte = {0};
1637
1638 context.addrs = new_object_addresses();
1639
1640 /* We gin up a rather bogus rangetable list to handle Vars */
1641 rte.type = T_RangeTblEntry;
1642 rte.rtekind = RTE_RELATION;
1643 rte.relid = relId;
1644 rte.relkind = RELKIND_RELATION; /* no need for exactness here */
1645 rte.rellockmode = AccessShareLock;
1646
1647 context.rtables = list_make1(list_make1(&rte));
1648
1649 /* Scan the expression tree for referenceable objects */
1650 find_expr_references_walker(expr, &context);
1651
1652 /* Remove any duplicates */
1654
1655 /* Separate self-dependencies if necessary */
1656 if ((behavior != self_behavior || reverse_self) &&
1657 context.addrs->numrefs > 0)
1658 {
1659 ObjectAddresses *self_addrs;
1660 ObjectAddress *outobj;
1661 int oldref,
1662 outrefs;
1663
1664 self_addrs = new_object_addresses();
1665
1666 outobj = context.addrs->refs;
1667 outrefs = 0;
1668 for (oldref = 0; oldref < context.addrs->numrefs; oldref++)
1669 {
1670 ObjectAddress *thisobj = context.addrs->refs + oldref;
1671
1672 if (thisobj->classId == RelationRelationId &&
1673 thisobj->objectId == relId)
1674 {
1675 /* Move this ref into self_addrs */
1676 add_exact_object_address(thisobj, self_addrs);
1677 }
1678 else
1679 {
1680 /* Keep it in context.addrs */
1681 *outobj = *thisobj;
1682 outobj++;
1683 outrefs++;
1684 }
1685 }
1686 context.addrs->numrefs = outrefs;
1687
1688 /* Record the self-dependencies with the appropriate direction */
1689 if (!reverse_self)
1691 self_addrs->refs, self_addrs->numrefs,
1692 self_behavior);
1693 else
1694 {
1695 /* Can't use recordMultipleDependencies, so do it the hard way */
1696 int selfref;
1697
1698 for (selfref = 0; selfref < self_addrs->numrefs; selfref++)
1699 {
1700 ObjectAddress *thisobj = self_addrs->refs + selfref;
1701
1702 recordDependencyOn(thisobj, depender, self_behavior);
1703 }
1704 }
1705
1706 free_object_addresses(self_addrs);
1707 }
1708
1709 /* Record the external dependencies */
1711 context.addrs->refs, context.addrs->numrefs,
1712 behavior);
1713
1715}
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
Definition: dependency.c:2661
#define AccessShareLock
Definition: lockdefs.h:36
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:45

References AccessShareLock, add_exact_object_address(), find_expr_references_context::addrs, ObjectAddress::classId, eliminate_duplicate_dependencies(), find_expr_references_walker(), free_object_addresses(), list_make1, new_object_addresses(), ObjectAddresses::numrefs, ObjectAddress::objectId, recordDependencyOn(), recordMultipleDependencies(), ObjectAddresses::refs, find_expr_references_context::rtables, RTE_RELATION, and RangeTblEntry::rtekind.

Referenced by CreateConstraintEntry(), CreateStatistics(), index_create(), publication_add_relation(), StoreAttrDefault(), and StorePartitionKey().

◆ ReleaseDeletionLock()

void ReleaseDeletionLock ( const ObjectAddress object)

Definition at line 1529 of file dependency.c.

1530{
1531 if (object->classId == RelationRelationId)
1533 else
1534 /* assume we should lock the whole object not a sub-object */
1535 UnlockDatabaseObject(object->classId, object->objectId, 0,
1537}
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:229
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1068

References AccessExclusiveLock, ObjectAddress::classId, ObjectAddressStack::object, ObjectAddress::objectId, UnlockDatabaseObject(), and UnlockRelationOid().

Referenced by findDependentObjects(), and shdepDropOwned().

◆ reportDependentObjects()

static void reportDependentObjects ( const ObjectAddresses targetObjects,
DropBehavior  behavior,
int  flags,
const ObjectAddress origObject 
)
static

Definition at line 981 of file dependency.c.

985{
986 int msglevel = (flags & PERFORM_DELETION_QUIETLY) ? DEBUG2 : NOTICE;
987 bool ok = true;
988 StringInfoData clientdetail;
989 StringInfoData logdetail;
990 int numReportedClient = 0;
991 int numNotReportedClient = 0;
992 int i;
993
994 /*
995 * If we need to delete any partition-dependent objects, make sure that
996 * we're deleting at least one of their partition dependencies, too. That
997 * can be detected by checking that we reached them by a PARTITION
998 * dependency at some point.
999 *
1000 * We just report the first such object, as in most cases the only way to
1001 * trigger this complaint is to explicitly try to delete one partition of
1002 * a partitioned object.
1003 */
1004 for (i = 0; i < targetObjects->numrefs; i++)
1005 {
1006 const ObjectAddressExtra *extra = &targetObjects->extras[i];
1007
1008 if ((extra->flags & DEPFLAG_IS_PART) &&
1009 !(extra->flags & DEPFLAG_PARTITION))
1010 {
1011 const ObjectAddress *object = &targetObjects->refs[i];
1012 char *otherObjDesc = getObjectDescription(&extra->dependee,
1013 false);
1014
1015 ereport(ERROR,
1016 (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
1017 errmsg("cannot drop %s because %s requires it",
1018 getObjectDescription(object, false), otherObjDesc),
1019 errhint("You can drop %s instead.", otherObjDesc)));
1020 }
1021 }
1022
1023 /*
1024 * If no error is to be thrown, and the msglevel is too low to be shown to
1025 * either client or server log, there's no need to do any of the rest of
1026 * the work.
1027 */
1028 if (behavior == DROP_CASCADE &&
1030 return;
1031
1032 /*
1033 * We limit the number of dependencies reported to the client to
1034 * MAX_REPORTED_DEPS, since client software may not deal well with
1035 * enormous error strings. The server log always gets a full report.
1036 */
1037#define MAX_REPORTED_DEPS 100
1038
1039 initStringInfo(&clientdetail);
1040 initStringInfo(&logdetail);
1041
1042 /*
1043 * We process the list back to front (ie, in dependency order not deletion
1044 * order), since this makes for a more understandable display.
1045 */
1046 for (i = targetObjects->numrefs - 1; i >= 0; i--)
1047 {
1048 const ObjectAddress *obj = &targetObjects->refs[i];
1049 const ObjectAddressExtra *extra = &targetObjects->extras[i];
1050 char *objDesc;
1051
1052 /* Ignore the original deletion target(s) */
1053 if (extra->flags & DEPFLAG_ORIGINAL)
1054 continue;
1055
1056 /* Also ignore sub-objects; we'll report the whole object elsewhere */
1057 if (extra->flags & DEPFLAG_SUBOBJECT)
1058 continue;
1059
1060 objDesc = getObjectDescription(obj, false);
1061
1062 /* An object being dropped concurrently doesn't need to be reported */
1063 if (objDesc == NULL)
1064 continue;
1065
1066 /*
1067 * If, at any stage of the recursive search, we reached the object via
1068 * an AUTO, INTERNAL, PARTITION, or EXTENSION dependency, then it's
1069 * okay to delete it even in RESTRICT mode.
1070 */
1071 if (extra->flags & (DEPFLAG_AUTO |
1075 {
1076 /*
1077 * auto-cascades are reported at DEBUG2, not msglevel. We don't
1078 * try to combine them with the regular message because the
1079 * results are too confusing when client_min_messages and
1080 * log_min_messages are different.
1081 */
1083 (errmsg_internal("drop auto-cascades to %s",
1084 objDesc)));
1085 }
1086 else if (behavior == DROP_RESTRICT)
1087 {
1088 char *otherDesc = getObjectDescription(&extra->dependee,
1089 false);
1090
1091 if (otherDesc)
1092 {
1093 if (numReportedClient < MAX_REPORTED_DEPS)
1094 {
1095 /* separate entries with a newline */
1096 if (clientdetail.len != 0)
1097 appendStringInfoChar(&clientdetail, '\n');
1098 appendStringInfo(&clientdetail, _("%s depends on %s"),
1099 objDesc, otherDesc);
1100 numReportedClient++;
1101 }
1102 else
1103 numNotReportedClient++;
1104 /* separate entries with a newline */
1105 if (logdetail.len != 0)
1106 appendStringInfoChar(&logdetail, '\n');
1107 appendStringInfo(&logdetail, _("%s depends on %s"),
1108 objDesc, otherDesc);
1109 pfree(otherDesc);
1110 }
1111 else
1112 numNotReportedClient++;
1113 ok = false;
1114 }
1115 else
1116 {
1117 if (numReportedClient < MAX_REPORTED_DEPS)
1118 {
1119 /* separate entries with a newline */
1120 if (clientdetail.len != 0)
1121 appendStringInfoChar(&clientdetail, '\n');
1122 appendStringInfo(&clientdetail, _("drop cascades to %s"),
1123 objDesc);
1124 numReportedClient++;
1125 }
1126 else
1127 numNotReportedClient++;
1128 /* separate entries with a newline */
1129 if (logdetail.len != 0)
1130 appendStringInfoChar(&logdetail, '\n');
1131 appendStringInfo(&logdetail, _("drop cascades to %s"),
1132 objDesc);
1133 }
1134
1135 pfree(objDesc);
1136 }
1137
1138 if (numNotReportedClient > 0)
1139 appendStringInfo(&clientdetail, ngettext("\nand %d other object "
1140 "(see server log for list)",
1141 "\nand %d other objects "
1142 "(see server log for list)",
1143 numNotReportedClient),
1144 numNotReportedClient);
1145
1146 if (!ok)
1147 {
1148 if (origObject)
1149 ereport(ERROR,
1150 (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
1151 errmsg("cannot drop %s because other objects depend on it",
1152 getObjectDescription(origObject, false)),
1153 errdetail_internal("%s", clientdetail.data),
1154 errdetail_log("%s", logdetail.data),
1155 errhint("Use DROP ... CASCADE to drop the dependent objects too.")));
1156 else
1157 ereport(ERROR,
1158 (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
1159 errmsg("cannot drop desired object(s) because other objects depend on them"),
1160 errdetail_internal("%s", clientdetail.data),
1161 errdetail_log("%s", logdetail.data),
1162 errhint("Use DROP ... CASCADE to drop the dependent objects too.")));
1163 }
1164 else if (numReportedClient > 1)
1165 {
1166 ereport(msglevel,
1167 (errmsg_plural("drop cascades to %d other object",
1168 "drop cascades to %d other objects",
1169 numReportedClient + numNotReportedClient,
1170 numReportedClient + numNotReportedClient),
1171 errdetail_internal("%s", clientdetail.data),
1172 errdetail_log("%s", logdetail.data)));
1173 }
1174 else if (numReportedClient == 1)
1175 {
1176 /* we just use the single item as-is */
1177 ereport(msglevel,
1178 (errmsg_internal("%s", clientdetail.data)));
1179 }
1180
1181 pfree(clientdetail.data);
1182 pfree(logdetail.data);
1183}
#define ngettext(s, p, n)
Definition: c.h:1169
#define MAX_REPORTED_DEPS
#define PERFORM_DELETION_QUIETLY
Definition: dependency.h:94
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1193
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1170
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1243
bool message_level_is_interesting(int elevel)
Definition: elog.c:273
int errdetail_log(const char *fmt,...)
Definition: elog.c:1264
#define _(x)
Definition: elog.c:91
#define DEBUG2
Definition: elog.h:29
#define NOTICE
Definition: elog.h:35
@ DROP_CASCADE
Definition: parsenodes.h:2399
@ DROP_RESTRICT
Definition: parsenodes.h:2398
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:242
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97

References _, appendStringInfo(), appendStringInfoChar(), StringInfoData::data, DEBUG2, ObjectAddressExtra::dependee, DEPFLAG_AUTO, DEPFLAG_EXTENSION, DEPFLAG_INTERNAL, DEPFLAG_IS_PART, DEPFLAG_ORIGINAL, DEPFLAG_PARTITION, DEPFLAG_SUBOBJECT, DROP_CASCADE, DROP_RESTRICT, ereport, errcode(), errdetail_internal(), errdetail_log(), errhint(), errmsg(), errmsg_internal(), errmsg_plural(), ERROR, ObjectAddresses::extras, ObjectAddressExtra::flags, ObjectAddressStack::flags, getObjectDescription(), i, initStringInfo(), StringInfoData::len, MAX_REPORTED_DEPS, message_level_is_interesting(), ngettext, NOTICE, ObjectAddresses::numrefs, PERFORM_DELETION_QUIETLY, pfree(), and ObjectAddresses::refs.

Referenced by performDeletion(), and performMultipleDeletions().

◆ sort_object_addresses()

void sort_object_addresses ( ObjectAddresses addrs)

Definition at line 2889 of file dependency.c.

2890{
2891 if (addrs->numrefs > 1)
2892 qsort(addrs->refs, addrs->numrefs,
2893 sizeof(ObjectAddress),
2895}

References ObjectAddresses::numrefs, object_address_comparator(), qsort, and ObjectAddresses::refs.

Referenced by shdepDropOwned().

◆ stack_address_present_add_flags()

static bool stack_address_present_add_flags ( const ObjectAddress object,
int  flags,
ObjectAddressStack stack 
)
static

Definition at line 2820 of file dependency.c.

2823{
2824 bool result = false;
2825 ObjectAddressStack *stackptr;
2826
2827 for (stackptr = stack; stackptr; stackptr = stackptr->next)
2828 {
2829 const ObjectAddress *thisobj = stackptr->object;
2830
2831 if (object->classId == thisobj->classId &&
2832 object->objectId == thisobj->objectId)
2833 {
2834 if (object->objectSubId == thisobj->objectSubId)
2835 {
2836 stackptr->flags |= flags;
2837 result = true;
2838 }
2839 else if (thisobj->objectSubId == 0)
2840 {
2841 /*
2842 * We're visiting a column with whole table already on stack.
2843 * As in object_address_present_add_flags(), we can skip
2844 * further processing of the subobject, but we don't want to
2845 * propagate flags for the subobject to the whole object.
2846 */
2847 result = true;
2848 }
2849 else if (object->objectSubId == 0)
2850 {
2851 /*
2852 * We're visiting a table with column already on stack. As in
2853 * object_address_present_add_flags(), we should propagate
2854 * flags for the whole object to each of its subobjects.
2855 */
2856 if (flags)
2857 stackptr->flags |= (flags | DEPFLAG_SUBOBJECT);
2858 }
2859 }
2860 }
2861
2862 return result;
2863}

References ObjectAddress::classId, DEPFLAG_SUBOBJECT, ObjectAddressStack::flags, ObjectAddressStack::next, ObjectAddressStack::object, ObjectAddress::objectId, and ObjectAddress::objectSubId.

Referenced by findDependentObjects().