1 /*-------------------------------------------------------------------------
4 * Routines to support inter-object dependencies.
7 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
11 * $PostgreSQL: pgsql/src/backend/catalog/dependency.c,v 1.88 2009/06/04 18:33:06 tgl Exp $
13 *-------------------------------------------------------------------------
17 #include "access/genam.h"
18 #include "access/heapam.h"
19 #include "access/sysattr.h"
20 #include "access/xact.h"
21 #include "catalog/dependency.h"
22 #include "catalog/heap.h"
23 #include "catalog/index.h"
24 #include "catalog/indexing.h"
25 #include "catalog/namespace.h"
26 #include "catalog/pg_amop.h"
27 #include "catalog/pg_amproc.h"
28 #include "catalog/pg_attrdef.h"
29 #include "catalog/pg_authid.h"
30 #include "catalog/pg_cast.h"
31 #include "catalog/pg_constraint.h"
32 #include "catalog/pg_conversion.h"
33 #include "catalog/pg_conversion_fn.h"
34 #include "catalog/pg_database.h"
35 #include "catalog/pg_depend.h"
36 #include "catalog/pg_foreign_data_wrapper.h"
37 #include "catalog/pg_foreign_server.h"
38 #include "catalog/pg_language.h"
39 #include "catalog/pg_namespace.h"
40 #include "catalog/pg_opclass.h"
41 #include "catalog/pg_operator.h"
42 #include "catalog/pg_opfamily.h"
43 #include "catalog/pg_proc.h"
44 #include "catalog/pg_rewrite.h"
45 #include "catalog/pg_tablespace.h"
46 #include "catalog/pg_trigger.h"
47 #include "catalog/pg_ts_config.h"
48 #include "catalog/pg_ts_dict.h"
49 #include "catalog/pg_ts_parser.h"
50 #include "catalog/pg_ts_template.h"
51 #include "catalog/pg_type.h"
52 #include "catalog/pg_user_mapping.h"
53 #include "commands/comment.h"
54 #include "commands/dbcommands.h"
55 #include "commands/defrem.h"
56 #include "commands/proclang.h"
57 #include "commands/schemacmds.h"
58 #include "commands/tablespace.h"
59 #include "commands/trigger.h"
60 #include "commands/typecmds.h"
61 #include "foreign/foreign.h"
62 #include "miscadmin.h"
63 #include "nodes/nodeFuncs.h"
64 #include "parser/parsetree.h"
65 #include "rewrite/rewriteRemove.h"
66 #include "storage/lmgr.h"
67 #include "utils/builtins.h"
68 #include "utils/fmgroids.h"
69 #include "utils/guc.h"
70 #include "utils/lsyscache.h"
71 #include "utils/syscache.h"
72 #include "utils/tqual.h"
76 * Deletion processing requires additional state for each ObjectAddress that
77 * it's planning to delete. For simplicity and code-sharing we make the
78 * ObjectAddresses code support arrays with or without this extra state.
82 int flags; /* bitmask, see bit definitions below */
83 ObjectAddress dependee; /* object whose deletion forced this one */
86 /* ObjectAddressExtra flag bits */
87 #define DEPFLAG_ORIGINAL 0x0001 /* an original deletion target */
88 #define DEPFLAG_NORMAL 0x0002 /* reached via normal dependency */
89 #define DEPFLAG_AUTO 0x0004 /* reached via auto dependency */
90 #define DEPFLAG_INTERNAL 0x0008 /* reached via internal dependency */
93 /* expansible list of ObjectAddresses */
94 struct ObjectAddresses
96 ObjectAddress *refs; /* => palloc'd array */
97 ObjectAddressExtra *extras; /* => palloc'd array, or NULL if not used */
98 int numrefs; /* current number of references */
99 int maxrefs; /* current size of palloc'd array(s) */
102 /* typedef ObjectAddresses appears in dependency.h */
104 /* threaded list of ObjectAddresses, for recursion detection */
105 typedef struct ObjectAddressStack
107 const ObjectAddress *object; /* object being visited */
108 int flags; /* its current flag bits */
109 struct ObjectAddressStack *next; /* next outer stack level */
110 } ObjectAddressStack;
112 /* for find_expr_references_walker */
115 ObjectAddresses *addrs; /* addresses being accumulated */
116 List *rtables; /* list of rangetables to resolve Vars */
117 } find_expr_references_context;
120 * This constant table maps ObjectClasses to the corresponding catalog OIDs.
121 * See also getObjectClass().
123 static const Oid object_classes[MAX_OCLASS] = {
124 RelationRelationId, /* OCLASS_CLASS */
125 ProcedureRelationId, /* OCLASS_PROC */
126 TypeRelationId, /* OCLASS_TYPE */
127 CastRelationId, /* OCLASS_CAST */
128 ConstraintRelationId, /* OCLASS_CONSTRAINT */
129 ConversionRelationId, /* OCLASS_CONVERSION */
130 AttrDefaultRelationId, /* OCLASS_DEFAULT */
131 LanguageRelationId, /* OCLASS_LANGUAGE */
132 OperatorRelationId, /* OCLASS_OPERATOR */
133 OperatorClassRelationId, /* OCLASS_OPCLASS */
134 OperatorFamilyRelationId, /* OCLASS_OPFAMILY */
135 AccessMethodOperatorRelationId, /* OCLASS_AMOP */
136 AccessMethodProcedureRelationId, /* OCLASS_AMPROC */
137 RewriteRelationId, /* OCLASS_REWRITE */
138 TriggerRelationId, /* OCLASS_TRIGGER */
139 NamespaceRelationId, /* OCLASS_SCHEMA */
140 TSParserRelationId, /* OCLASS_TSPARSER */
141 TSDictionaryRelationId, /* OCLASS_TSDICT */
142 TSTemplateRelationId, /* OCLASS_TSTEMPLATE */
143 TSConfigRelationId, /* OCLASS_TSCONFIG */
144 AuthIdRelationId, /* OCLASS_ROLE */
145 DatabaseRelationId, /* OCLASS_DATABASE */
146 TableSpaceRelationId /* OCLASS_TBLSPACE */
150 static void findDependentObjects(const ObjectAddress *object,
152 ObjectAddressStack *stack,
153 ObjectAddresses *targetObjects,
154 const ObjectAddresses *pendingObjects,
156 static void reportDependentObjects(const ObjectAddresses *targetObjects,
157 DropBehavior behavior,
159 const ObjectAddress *origObject);
160 static void deleteOneObject(const ObjectAddress *object, Relation depRel);
161 static void doDeletion(const ObjectAddress *object);
162 static void AcquireDeletionLock(const ObjectAddress *object);
163 static void ReleaseDeletionLock(const ObjectAddress *object);
164 static bool find_expr_references_walker(Node *node,
165 find_expr_references_context *context);
166 static void eliminate_duplicate_dependencies(ObjectAddresses *addrs);
167 static int object_address_comparator(const void *a, const void *b);
168 static void add_object_address(ObjectClass oclass, Oid objectId, int32 subId,
169 ObjectAddresses *addrs);
170 static void add_exact_object_address_extra(const ObjectAddress *object,
171 const ObjectAddressExtra *extra,
172 ObjectAddresses *addrs);
173 static bool object_address_present_add_flags(const ObjectAddress *object,
175 ObjectAddresses *addrs);
176 static void getRelationDescription(StringInfo buffer, Oid relid);
177 static void getOpFamilyDescription(StringInfo buffer, Oid opfid);
181 * performDeletion: attempt to drop the specified object. If CASCADE
182 * behavior is specified, also drop any dependent objects (recursively).
183 * If RESTRICT behavior is specified, error out if there are any dependent
184 * objects, except for those that should be implicitly dropped anyway
185 * according to the dependency type.
187 * This is the outer control routine for all forms of DROP that drop objects
188 * that can participate in dependencies. Note that the next two routines
189 * are variants on the same theme; if you change anything here you'll likely
190 * need to fix them too.
193 performDeletion(const ObjectAddress *object,
194 DropBehavior behavior)
197 ObjectAddresses *targetObjects;
201 * We save some cycles by opening pg_depend just once and passing the
202 * Relation pointer down to all the recursive deletion steps.
204 depRel = heap_open(DependRelationId, RowExclusiveLock);
207 * Acquire deletion lock on the target object. (Ideally the caller has
208 * done this already, but many places are sloppy about it.)
210 AcquireDeletionLock(object);
213 * Construct a list of objects to delete (ie, the given object plus
214 * everything directly or indirectly dependent on it).
216 targetObjects = new_object_addresses();
218 findDependentObjects(object,
220 NULL, /* empty stack */
222 NULL, /* no pendingObjects */
226 * Check if deletion is allowed, and report about cascaded deletes.
228 reportDependentObjects(targetObjects,
234 * Delete all the objects in the proper order.
236 for (i = 0; i < targetObjects->numrefs; i++)
238 ObjectAddress *thisobj = targetObjects->refs + i;
240 deleteOneObject(thisobj, depRel);
244 free_object_addresses(targetObjects);
246 heap_close(depRel, RowExclusiveLock);
250 * performMultipleDeletions: Similar to performDeletion, but act on multiple
253 * The main difference from issuing multiple performDeletion calls is that the
254 * list of objects that would be implicitly dropped, for each object to be
255 * dropped, is the union of the implicit-object list for all objects. This
256 * makes each check be more relaxed.
259 performMultipleDeletions(const ObjectAddresses *objects,
260 DropBehavior behavior)
263 ObjectAddresses *targetObjects;
266 /* No work if no objects... */
267 if (objects->numrefs <= 0)
271 * We save some cycles by opening pg_depend just once and passing the
272 * Relation pointer down to all the recursive deletion steps.
274 depRel = heap_open(DependRelationId, RowExclusiveLock);
277 * Construct a list of objects to delete (ie, the given objects plus
278 * everything directly or indirectly dependent on them). Note that
279 * because we pass the whole objects list as pendingObjects context,
280 * we won't get a failure from trying to delete an object that is
281 * internally dependent on another one in the list; we'll just skip
282 * that object and delete it when we reach its owner.
284 targetObjects = new_object_addresses();
286 for (i = 0; i < objects->numrefs; i++)
288 const ObjectAddress *thisobj = objects->refs + i;
291 * Acquire deletion lock on each target object. (Ideally the caller
292 * has done this already, but many places are sloppy about it.)
294 AcquireDeletionLock(thisobj);
296 findDependentObjects(thisobj,
298 NULL, /* empty stack */
305 * Check if deletion is allowed, and report about cascaded deletes.
307 * If there's exactly one object being deleted, report it the same
308 * way as in performDeletion(), else we have to be vaguer.
310 reportDependentObjects(targetObjects,
313 (objects->numrefs == 1 ? objects->refs : NULL));
316 * Delete all the objects in the proper order.
318 for (i = 0; i < targetObjects->numrefs; i++)
320 ObjectAddress *thisobj = targetObjects->refs + i;
322 deleteOneObject(thisobj, depRel);
326 free_object_addresses(targetObjects);
328 heap_close(depRel, RowExclusiveLock);
332 * deleteWhatDependsOn: attempt to drop everything that depends on the
333 * specified object, though not the object itself. Behavior is always
336 * This is currently used only to clean out the contents of a schema
337 * (namespace): the passed object is a namespace. We normally want this
338 * to be done silently, so there's an option to suppress NOTICE messages.
341 deleteWhatDependsOn(const ObjectAddress *object,
345 ObjectAddresses *targetObjects;
349 * We save some cycles by opening pg_depend just once and passing the
350 * Relation pointer down to all the recursive deletion steps.
352 depRel = heap_open(DependRelationId, RowExclusiveLock);
355 * Acquire deletion lock on the target object. (Ideally the caller has
356 * done this already, but many places are sloppy about it.)
358 AcquireDeletionLock(object);
361 * Construct a list of objects to delete (ie, the given object plus
362 * everything directly or indirectly dependent on it).
364 targetObjects = new_object_addresses();
366 findDependentObjects(object,
368 NULL, /* empty stack */
370 NULL, /* no pendingObjects */
374 * Check if deletion is allowed, and report about cascaded deletes.
376 reportDependentObjects(targetObjects,
378 showNotices ? NOTICE : DEBUG2,
382 * Delete all the objects in the proper order, except we skip the original
385 for (i = 0; i < targetObjects->numrefs; i++)
387 ObjectAddress *thisobj = targetObjects->refs + i;
388 ObjectAddressExtra *thisextra = targetObjects->extras + i;
390 if (thisextra->flags & DEPFLAG_ORIGINAL)
393 deleteOneObject(thisobj, depRel);
397 free_object_addresses(targetObjects);
399 heap_close(depRel, RowExclusiveLock);
403 * findDependentObjects - find all objects that depend on 'object'
405 * For every object that depends on the starting object, acquire a deletion
406 * lock on the object, add it to targetObjects (if not already there),
407 * and recursively find objects that depend on it. An object's dependencies
408 * will be placed into targetObjects before the object itself; this means
409 * that the finished list's order represents a safe deletion order.
411 * The caller must already have a deletion lock on 'object' itself,
412 * but must not have added it to targetObjects. (Note: there are corner
413 * cases where we won't add the object either, and will also release the
414 * caller-taken lock. This is a bit ugly, but the API is set up this way
415 * to allow easy rechecking of an object's liveness after we lock it. See
416 * notes within the function.)
418 * When dropping a whole object (subId = 0), we find dependencies for
419 * its sub-objects too.
421 * object: the object to add to targetObjects and find dependencies on
422 * flags: flags to be ORed into the object's targetObjects entry
423 * stack: list of objects being visited in current recursion; topmost item
424 * is the object that we recursed from (NULL for external callers)
425 * targetObjects: list of objects that are scheduled to be deleted
426 * pendingObjects: list of other objects slated for destruction, but
427 * not necessarily in targetObjects yet (can be NULL if none)
428 * depRel: already opened pg_depend relation
431 findDependentObjects(const ObjectAddress *object,
433 ObjectAddressStack *stack,
434 ObjectAddresses *targetObjects,
435 const ObjectAddresses *pendingObjects,
442 ObjectAddress otherObject;
443 ObjectAddressStack mystack;
444 ObjectAddressExtra extra;
445 ObjectAddressStack *stackptr;
448 * If the target object is already being visited in an outer recursion
449 * level, just report the current flags back to that level and exit.
450 * This is needed to avoid infinite recursion in the face of circular
453 * The stack check alone would result in dependency loops being broken at
454 * an arbitrary point, ie, the first member object of the loop to be
455 * visited is the last one to be deleted. This is obviously unworkable.
456 * However, the check for internal dependency below guarantees that we
457 * will not break a loop at an internal dependency: if we enter the loop
458 * at an "owned" object we will switch and start at the "owning" object
459 * instead. We could probably hack something up to avoid breaking at an
460 * auto dependency, too, if we had to. However there are no known cases
461 * where that would be necessary.
463 for (stackptr = stack; stackptr; stackptr = stackptr->next)
465 if (object->classId == stackptr->object->classId &&
466 object->objectId == stackptr->object->objectId)
468 if (object->objectSubId == stackptr->object->objectSubId)
470 stackptr->flags |= flags;
474 * Could visit column with whole table already on stack; this is
475 * the same case noted in object_address_present_add_flags().
476 * (It's not clear this can really happen, but we might as well
479 if (stackptr->object->objectSubId == 0)
485 * It's also possible that the target object has already been completely
486 * processed and put into targetObjects. If so, again we just add the
487 * specified flags to its entry and return.
489 * (Note: in these early-exit cases we could release the caller-taken
490 * lock, since the object is presumably now locked multiple times;
491 * but it seems not worth the cycles.)
493 if (object_address_present_add_flags(object, flags, targetObjects))
497 * The target object might be internally dependent on some other object
498 * (its "owner"). If so, and if we aren't recursing from the owning
499 * object, we have to transform this deletion request into a deletion
500 * request of the owning object. (We'll eventually recurse back to this
501 * object, but the owning object has to be visited first so it will be
502 * deleted after.) The way to find out about this is to scan the
503 * pg_depend entries that show what this object depends on.
506 Anum_pg_depend_classid,
507 BTEqualStrategyNumber, F_OIDEQ,
508 ObjectIdGetDatum(object->classId));
510 Anum_pg_depend_objid,
511 BTEqualStrategyNumber, F_OIDEQ,
512 ObjectIdGetDatum(object->objectId));
513 if (object->objectSubId != 0)
516 Anum_pg_depend_objsubid,
517 BTEqualStrategyNumber, F_INT4EQ,
518 Int32GetDatum(object->objectSubId));
524 scan = systable_beginscan(depRel, DependDependerIndexId, true,
525 SnapshotNow, nkeys, key);
527 while (HeapTupleIsValid(tup = systable_getnext(scan)))
529 Form_pg_depend foundDep = (Form_pg_depend) GETSTRUCT(tup);
531 otherObject.classId = foundDep->refclassid;
532 otherObject.objectId = foundDep->refobjid;
533 otherObject.objectSubId = foundDep->refobjsubid;
535 switch (foundDep->deptype)
537 case DEPENDENCY_NORMAL:
538 case DEPENDENCY_AUTO:
541 case DEPENDENCY_INTERNAL:
544 * This object is part of the internal implementation of
545 * another object. We have three cases:
547 * 1. At the outermost recursion level, disallow the DROP. (We
548 * just ereport here, rather than proceeding, since no other
549 * dependencies are likely to be interesting.) However, if
550 * the other object is listed in pendingObjects, just release
551 * the caller's lock and return; we'll eventually complete
552 * the DROP when we reach that entry in the pending list.
558 if (object_address_present(&otherObject, pendingObjects))
560 systable_endscan(scan);
561 /* need to release caller's lock; see notes below */
562 ReleaseDeletionLock(object);
565 otherObjDesc = getObjectDescription(&otherObject);
567 (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
568 errmsg("cannot drop %s because %s requires it",
569 getObjectDescription(object),
571 errhint("You can drop %s instead.",
576 * 2. When recursing from the other end of this dependency,
577 * it's okay to continue with the deletion. This holds when
578 * recursing from a whole object that includes the nominal
579 * other end as a component, too.
581 if (stack->object->classId == otherObject.classId &&
582 stack->object->objectId == otherObject.objectId &&
583 (stack->object->objectSubId == otherObject.objectSubId ||
584 stack->object->objectSubId == 0))
588 * 3. When recursing from anyplace else, transform this
589 * deletion request into a delete of the other object.
591 * First, release caller's lock on this object and get
592 * deletion lock on the other object. (We must release
593 * caller's lock to avoid deadlock against a concurrent
594 * deletion of the other object.)
596 ReleaseDeletionLock(object);
597 AcquireDeletionLock(&otherObject);
600 * The other object might have been deleted while we waited
601 * to lock it; if so, neither it nor the current object are
602 * interesting anymore. We test this by checking the
603 * pg_depend entry (see notes below).
605 if (!systable_recheck_tuple(scan, tup))
607 systable_endscan(scan);
608 ReleaseDeletionLock(&otherObject);
613 * Okay, recurse to the other object instead of proceeding.
614 * We treat this exactly as if the original reference had
615 * linked to that object instead of this one; hence, pass
616 * through the same flags and stack.
618 findDependentObjects(&otherObject,
624 /* And we're done here. */
625 systable_endscan(scan);
630 * Should not happen; PIN dependencies should have zeroes in
631 * the depender fields...
633 elog(ERROR, "incorrect use of PIN dependency with %s",
634 getObjectDescription(object));
637 elog(ERROR, "unrecognized dependency type '%c' for %s",
638 foundDep->deptype, getObjectDescription(object));
643 systable_endscan(scan);
646 * Now recurse to any dependent objects. We must visit them first
647 * since they have to be deleted before the current object.
649 mystack.object = object; /* set up a new stack level */
650 mystack.flags = flags;
651 mystack.next = stack;
654 Anum_pg_depend_refclassid,
655 BTEqualStrategyNumber, F_OIDEQ,
656 ObjectIdGetDatum(object->classId));
658 Anum_pg_depend_refobjid,
659 BTEqualStrategyNumber, F_OIDEQ,
660 ObjectIdGetDatum(object->objectId));
661 if (object->objectSubId != 0)
664 Anum_pg_depend_refobjsubid,
665 BTEqualStrategyNumber, F_INT4EQ,
666 Int32GetDatum(object->objectSubId));
672 scan = systable_beginscan(depRel, DependReferenceIndexId, true,
673 SnapshotNow, nkeys, key);
675 while (HeapTupleIsValid(tup = systable_getnext(scan)))
677 Form_pg_depend foundDep = (Form_pg_depend) GETSTRUCT(tup);
680 otherObject.classId = foundDep->classid;
681 otherObject.objectId = foundDep->objid;
682 otherObject.objectSubId = foundDep->objsubid;
685 * Must lock the dependent object before recursing to it.
687 AcquireDeletionLock(&otherObject);
690 * The dependent object might have been deleted while we waited
691 * to lock it; if so, we don't need to do anything more with it.
692 * We can test this cheaply and independently of the object's type
693 * by seeing if the pg_depend tuple we are looking at is still live.
694 * (If the object got deleted, the tuple would have been deleted too.)
696 if (!systable_recheck_tuple(scan, tup))
698 /* release the now-useless lock */
699 ReleaseDeletionLock(&otherObject);
700 /* and continue scanning for dependencies */
704 /* Recurse, passing flags indicating the dependency type */
705 switch (foundDep->deptype)
707 case DEPENDENCY_NORMAL:
708 subflags = DEPFLAG_NORMAL;
710 case DEPENDENCY_AUTO:
711 subflags = DEPFLAG_AUTO;
713 case DEPENDENCY_INTERNAL:
714 subflags = DEPFLAG_INTERNAL;
719 * For a PIN dependency we just ereport immediately; there
720 * won't be any others to report.
723 (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
724 errmsg("cannot drop %s because it is required by the database system",
725 getObjectDescription(object))));
726 subflags = 0; /* keep compiler quiet */
729 elog(ERROR, "unrecognized dependency type '%c' for %s",
730 foundDep->deptype, getObjectDescription(object));
731 subflags = 0; /* keep compiler quiet */
735 findDependentObjects(&otherObject,
743 systable_endscan(scan);
746 * Finally, we can add the target object to targetObjects. Be careful
747 * to include any flags that were passed back down to us from inner
750 extra.flags = mystack.flags;
752 extra.dependee = *stack->object;
754 memset(&extra.dependee, 0, sizeof(extra.dependee));
755 add_exact_object_address_extra(object, &extra, targetObjects);
759 * reportDependentObjects - report about dependencies, and fail if RESTRICT
761 * Tell the user about dependent objects that we are going to delete
762 * (or would need to delete, but are prevented by RESTRICT mode);
763 * then error out if there are any and it's not CASCADE mode.
765 * targetObjects: list of objects that are scheduled to be deleted
766 * behavior: RESTRICT or CASCADE
767 * msglevel: elog level for non-error report messages
768 * origObject: base object of deletion, or NULL if not available
769 * (the latter case occurs in DROP OWNED)
772 reportDependentObjects(const ObjectAddresses *targetObjects,
773 DropBehavior behavior,
775 const ObjectAddress *origObject)
778 StringInfoData clientdetail;
779 StringInfoData logdetail;
780 int numReportedClient = 0;
781 int numNotReportedClient = 0;
785 * If no error is to be thrown, and the msglevel is too low to be shown
786 * to either client or server log, there's no need to do any of the work.
788 * Note: this code doesn't know all there is to be known about elog
789 * levels, but it works for NOTICE and DEBUG2, which are the only values
790 * msglevel can currently have. We also assume we are running in a normal
791 * operating environment.
793 if (behavior == DROP_CASCADE &&
794 msglevel < client_min_messages &&
795 (msglevel < log_min_messages || log_min_messages == LOG))
799 * We limit the number of dependencies reported to the client to
800 * MAX_REPORTED_DEPS, since client software may not deal well with
801 * enormous error strings. The server log always gets a full report.
803 #define MAX_REPORTED_DEPS 100
805 initStringInfo(&clientdetail);
806 initStringInfo(&logdetail);
809 * We process the list back to front (ie, in dependency order not deletion
810 * order), since this makes for a more understandable display.
812 for (i = targetObjects->numrefs - 1; i >= 0; i--)
814 const ObjectAddress *obj = &targetObjects->refs[i];
815 const ObjectAddressExtra *extra = &targetObjects->extras[i];
818 /* Ignore the original deletion target(s) */
819 if (extra->flags & DEPFLAG_ORIGINAL)
822 objDesc = getObjectDescription(obj);
825 * If, at any stage of the recursive search, we reached the object
826 * via an AUTO or INTERNAL dependency, then it's okay to delete it
827 * even in RESTRICT mode.
829 if (extra->flags & (DEPFLAG_AUTO | DEPFLAG_INTERNAL))
832 * auto-cascades are reported at DEBUG2, not msglevel. We
833 * don't try to combine them with the regular message because
834 * the results are too confusing when client_min_messages and
835 * log_min_messages are different.
838 (errmsg("drop auto-cascades to %s",
841 else if (behavior == DROP_RESTRICT)
843 char *otherDesc = getObjectDescription(&extra->dependee);
845 if (numReportedClient < MAX_REPORTED_DEPS)
847 /* separate entries with a newline */
848 if (clientdetail.len != 0)
849 appendStringInfoChar(&clientdetail, '\n');
850 appendStringInfo(&clientdetail, _("%s depends on %s"),
855 numNotReportedClient++;
856 /* separate entries with a newline */
857 if (logdetail.len != 0)
858 appendStringInfoChar(&logdetail, '\n');
859 appendStringInfo(&logdetail, _("%s depends on %s"),
866 if (numReportedClient < MAX_REPORTED_DEPS)
868 /* separate entries with a newline */
869 if (clientdetail.len != 0)
870 appendStringInfoChar(&clientdetail, '\n');
871 appendStringInfo(&clientdetail, _("drop cascades to %s"),
876 numNotReportedClient++;
877 /* separate entries with a newline */
878 if (logdetail.len != 0)
879 appendStringInfoChar(&logdetail, '\n');
880 appendStringInfo(&logdetail, _("drop cascades to %s"),
887 if (numNotReportedClient > 0)
888 appendStringInfo(&clientdetail, ngettext("\nand %d other object "
889 "(see server log for list)",
890 "\nand %d other objects "
891 "(see server log for list)",
892 numNotReportedClient),
893 numNotReportedClient);
899 (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
900 errmsg("cannot drop %s because other objects depend on it",
901 getObjectDescription(origObject)),
902 errdetail("%s", clientdetail.data),
903 errdetail_log("%s", logdetail.data),
904 errhint("Use DROP ... CASCADE to drop the dependent objects too.")));
907 (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
908 errmsg("cannot drop desired object(s) because other objects depend on them"),
909 errdetail("%s", clientdetail.data),
910 errdetail_log("%s", logdetail.data),
911 errhint("Use DROP ... CASCADE to drop the dependent objects too.")));
913 else if (numReportedClient > 1)
916 /* translator: %d always has a value larger than 1 */
917 (errmsg_plural("drop cascades to %d other object",
918 "drop cascades to %d other objects",
919 numReportedClient + numNotReportedClient,
920 numReportedClient + numNotReportedClient),
921 errdetail("%s", clientdetail.data),
922 errdetail_log("%s", logdetail.data)));
924 else if (numReportedClient == 1)
926 /* we just use the single item as-is */
928 (errmsg_internal("%s", clientdetail.data)));
931 pfree(clientdetail.data);
932 pfree(logdetail.data);
936 * deleteOneObject: delete a single object for performDeletion.
938 * depRel is the already-open pg_depend relation.
941 deleteOneObject(const ObjectAddress *object, Relation depRel)
949 * First remove any pg_depend records that link from this object to
950 * others. (Any records linking to this object should be gone already.)
952 * When dropping a whole object (subId = 0), remove all pg_depend records
953 * for its sub-objects too.
956 Anum_pg_depend_classid,
957 BTEqualStrategyNumber, F_OIDEQ,
958 ObjectIdGetDatum(object->classId));
960 Anum_pg_depend_objid,
961 BTEqualStrategyNumber, F_OIDEQ,
962 ObjectIdGetDatum(object->objectId));
963 if (object->objectSubId != 0)
966 Anum_pg_depend_objsubid,
967 BTEqualStrategyNumber, F_INT4EQ,
968 Int32GetDatum(object->objectSubId));
974 scan = systable_beginscan(depRel, DependDependerIndexId, true,
975 SnapshotNow, nkeys, key);
977 while (HeapTupleIsValid(tup = systable_getnext(scan)))
979 simple_heap_delete(depRel, &tup->t_self);
982 systable_endscan(scan);
985 * Delete shared dependency references related to this object. Again,
986 * if subId = 0, remove records for sub-objects too.
988 deleteSharedDependencyRecordsFor(object->classId, object->objectId,
989 object->objectSubId);
992 * Now delete the object itself, in an object-type-dependent way.
997 * Delete any comments associated with this object. (This is a convenient
998 * place to do it instead of having every object type know to do it.)
1000 DeleteComments(object->objectId, object->classId, object->objectSubId);
1003 * CommandCounterIncrement here to ensure that preceding changes are all
1004 * visible to the next deletion step.
1006 CommandCounterIncrement();
1014 * doDeletion: actually delete a single object
1017 doDeletion(const ObjectAddress *object)
1019 switch (getObjectClass(object))
1023 char relKind = get_rel_relkind(object->objectId);
1025 if (relKind == RELKIND_INDEX)
1027 Assert(object->objectSubId == 0);
1028 index_drop(object->objectId);
1032 if (object->objectSubId != 0)
1033 RemoveAttributeById(object->objectId,
1034 object->objectSubId);
1036 heap_drop_with_catalog(object->objectId);
1042 RemoveFunctionById(object->objectId);
1046 RemoveTypeById(object->objectId);
1050 DropCastById(object->objectId);
1053 case OCLASS_CONSTRAINT:
1054 RemoveConstraintById(object->objectId);
1057 case OCLASS_CONVERSION:
1058 RemoveConversionById(object->objectId);
1061 case OCLASS_DEFAULT:
1062 RemoveAttrDefaultById(object->objectId);
1065 case OCLASS_LANGUAGE:
1066 DropProceduralLanguageById(object->objectId);
1069 case OCLASS_OPERATOR:
1070 RemoveOperatorById(object->objectId);
1073 case OCLASS_OPCLASS:
1074 RemoveOpClassById(object->objectId);
1077 case OCLASS_OPFAMILY:
1078 RemoveOpFamilyById(object->objectId);
1082 RemoveAmOpEntryById(object->objectId);
1086 RemoveAmProcEntryById(object->objectId);
1089 case OCLASS_REWRITE:
1090 RemoveRewriteRuleById(object->objectId);
1093 case OCLASS_TRIGGER:
1094 RemoveTriggerById(object->objectId);
1098 RemoveSchemaById(object->objectId);
1101 case OCLASS_TSPARSER:
1102 RemoveTSParserById(object->objectId);
1106 RemoveTSDictionaryById(object->objectId);
1109 case OCLASS_TSTEMPLATE:
1110 RemoveTSTemplateById(object->objectId);
1113 case OCLASS_TSCONFIG:
1114 RemoveTSConfigurationById(object->objectId);
1117 case OCLASS_USER_MAPPING:
1118 RemoveUserMappingById(object->objectId);
1121 case OCLASS_FOREIGN_SERVER:
1122 RemoveForeignServerById(object->objectId);
1126 RemoveForeignDataWrapperById(object->objectId);
1129 /* OCLASS_ROLE, OCLASS_DATABASE, OCLASS_TBLSPACE not handled */
1132 elog(ERROR, "unrecognized object class: %u",
1138 * AcquireDeletionLock - acquire a suitable lock for deleting an object
1140 * We use LockRelation for relations, LockDatabaseObject for everything
1141 * else. Note that dependency.c is not concerned with deleting any kind of
1142 * shared-across-databases object, so we have no need for LockSharedObject.
1145 AcquireDeletionLock(const ObjectAddress *object)
1147 if (object->classId == RelationRelationId)
1148 LockRelationOid(object->objectId, AccessExclusiveLock);
1150 /* assume we should lock the whole object not a sub-object */
1151 LockDatabaseObject(object->classId, object->objectId, 0,
1152 AccessExclusiveLock);
1156 * ReleaseDeletionLock - release an object deletion lock
1159 ReleaseDeletionLock(const ObjectAddress *object)
1161 if (object->classId == RelationRelationId)
1162 UnlockRelationOid(object->objectId, AccessExclusiveLock);
1164 /* assume we should lock the whole object not a sub-object */
1165 UnlockDatabaseObject(object->classId, object->objectId, 0,
1166 AccessExclusiveLock);
1170 * recordDependencyOnExpr - find expression dependencies
1172 * This is used to find the dependencies of rules, constraint expressions,
1175 * Given an expression or query in node-tree form, find all the objects
1176 * it refers to (tables, columns, operators, functions, etc). Record
1177 * a dependency of the specified type from the given depender object
1178 * to each object mentioned in the expression.
1180 * rtable is the rangetable to be used to interpret Vars with varlevelsup=0.
1181 * It can be NIL if no such variables are expected.
1184 recordDependencyOnExpr(const ObjectAddress *depender,
1185 Node *expr, List *rtable,
1186 DependencyType behavior)
1188 find_expr_references_context context;
1190 context.addrs = new_object_addresses();
1192 /* Set up interpretation for Vars at varlevelsup = 0 */
1193 context.rtables = list_make1(rtable);
1195 /* Scan the expression tree for referenceable objects */
1196 find_expr_references_walker(expr, &context);
1198 /* Remove any duplicates */
1199 eliminate_duplicate_dependencies(context.addrs);
1201 /* And record 'em */
1202 recordMultipleDependencies(depender,
1203 context.addrs->refs, context.addrs->numrefs,
1206 free_object_addresses(context.addrs);
1210 * recordDependencyOnSingleRelExpr - find expression dependencies
1212 * As above, but only one relation is expected to be referenced (with
1213 * varno = 1 and varlevelsup = 0). Pass the relation OID instead of a
1214 * range table. An additional frammish is that dependencies on that
1215 * relation (or its component columns) will be marked with 'self_behavior',
1216 * whereas 'behavior' is used for everything else.
1219 recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
1220 Node *expr, Oid relId,
1221 DependencyType behavior,
1222 DependencyType self_behavior)
1224 find_expr_references_context context;
1227 context.addrs = new_object_addresses();
1229 /* We gin up a rather bogus rangetable list to handle Vars */
1230 MemSet(&rte, 0, sizeof(rte));
1231 rte.type = T_RangeTblEntry;
1232 rte.rtekind = RTE_RELATION;
1235 context.rtables = list_make1(list_make1(&rte));
1237 /* Scan the expression tree for referenceable objects */
1238 find_expr_references_walker(expr, &context);
1240 /* Remove any duplicates */
1241 eliminate_duplicate_dependencies(context.addrs);
1243 /* Separate self-dependencies if necessary */
1244 if (behavior != self_behavior && context.addrs->numrefs > 0)
1246 ObjectAddresses *self_addrs;
1247 ObjectAddress *outobj;
1251 self_addrs = new_object_addresses();
1253 outobj = context.addrs->refs;
1255 for (oldref = 0; oldref < context.addrs->numrefs; oldref++)
1257 ObjectAddress *thisobj = context.addrs->refs + oldref;
1259 if (thisobj->classId == RelationRelationId &&
1260 thisobj->objectId == relId)
1262 /* Move this ref into self_addrs */
1263 add_exact_object_address(thisobj, self_addrs);
1267 /* Keep it in context.addrs */
1273 context.addrs->numrefs = outrefs;
1275 /* Record the self-dependencies */
1276 recordMultipleDependencies(depender,
1277 self_addrs->refs, self_addrs->numrefs,
1280 free_object_addresses(self_addrs);
1283 /* Record the external dependencies */
1284 recordMultipleDependencies(depender,
1285 context.addrs->refs, context.addrs->numrefs,
1288 free_object_addresses(context.addrs);
1292 * Recursively search an expression tree for object references.
1294 * Note: we avoid creating references to columns of tables that participate
1295 * in an SQL JOIN construct, but are not actually used anywhere in the query.
1296 * To do so, we do not scan the joinaliasvars list of a join RTE while
1297 * scanning the query rangetable, but instead scan each individual entry
1298 * of the alias list when we find a reference to it.
1300 * Note: in many cases we do not need to create dependencies on the datatypes
1301 * involved in an expression, because we'll have an indirect dependency via
1302 * some other object. For instance Var nodes depend on a column which depends
1303 * on the datatype, and OpExpr nodes depend on the operator which depends on
1304 * the datatype. However we do need a type dependency if there is no such
1305 * indirect dependency, as for example in Const and CoerceToDomain nodes.
1308 find_expr_references_walker(Node *node,
1309 find_expr_references_context *context)
1315 Var *var = (Var *) node;
1319 /* Find matching rtable entry, or complain if not found */
1320 if (var->varlevelsup >= list_length(context->rtables))
1321 elog(ERROR, "invalid varlevelsup %d", var->varlevelsup);
1322 rtable = (List *) list_nth(context->rtables, var->varlevelsup);
1323 if (var->varno <= 0 || var->varno > list_length(rtable))
1324 elog(ERROR, "invalid varno %d", var->varno);
1325 rte = rt_fetch(var->varno, rtable);
1328 * A whole-row Var references no specific columns, so adds no new
1331 if (var->varattno == InvalidAttrNumber)
1333 if (rte->rtekind == RTE_RELATION)
1335 /* If it's a plain relation, reference this column */
1336 add_object_address(OCLASS_CLASS, rte->relid, var->varattno,
1339 else if (rte->rtekind == RTE_JOIN)
1341 /* Scan join output column to add references to join inputs */
1344 /* We must make the context appropriate for join's level */
1345 save_rtables = context->rtables;
1346 context->rtables = list_copy_tail(context->rtables,
1348 if (var->varattno <= 0 ||
1349 var->varattno > list_length(rte->joinaliasvars))
1350 elog(ERROR, "invalid varattno %d", var->varattno);
1351 find_expr_references_walker((Node *) list_nth(rte->joinaliasvars,
1354 list_free(context->rtables);
1355 context->rtables = save_rtables;
1359 else if (IsA(node, Const))
1361 Const *con = (Const *) node;
1364 /* A constant must depend on the constant's datatype */
1365 add_object_address(OCLASS_TYPE, con->consttype, 0,
1369 * If it's a regclass or similar literal referring to an existing
1370 * object, add a reference to that object. (Currently, only the
1371 * regclass and regconfig cases have any likely use, but we may as
1372 * well handle all the OID-alias datatypes consistently.)
1374 if (!con->constisnull)
1376 switch (con->consttype)
1379 case REGPROCEDUREOID:
1380 objoid = DatumGetObjectId(con->constvalue);
1381 if (SearchSysCacheExists(PROCOID,
1382 ObjectIdGetDatum(objoid),
1384 add_object_address(OCLASS_PROC, objoid, 0,
1388 case REGOPERATOROID:
1389 objoid = DatumGetObjectId(con->constvalue);
1390 if (SearchSysCacheExists(OPEROID,
1391 ObjectIdGetDatum(objoid),
1393 add_object_address(OCLASS_OPERATOR, objoid, 0,
1397 objoid = DatumGetObjectId(con->constvalue);
1398 if (SearchSysCacheExists(RELOID,
1399 ObjectIdGetDatum(objoid),
1401 add_object_address(OCLASS_CLASS, objoid, 0,
1405 objoid = DatumGetObjectId(con->constvalue);
1406 if (SearchSysCacheExists(TYPEOID,
1407 ObjectIdGetDatum(objoid),
1409 add_object_address(OCLASS_TYPE, objoid, 0,
1413 objoid = DatumGetObjectId(con->constvalue);
1414 if (SearchSysCacheExists(TSCONFIGOID,
1415 ObjectIdGetDatum(objoid),
1417 add_object_address(OCLASS_TSCONFIG, objoid, 0,
1420 case REGDICTIONARYOID:
1421 objoid = DatumGetObjectId(con->constvalue);
1422 if (SearchSysCacheExists(TSDICTOID,
1423 ObjectIdGetDatum(objoid),
1425 add_object_address(OCLASS_TSDICT, objoid, 0,
1432 else if (IsA(node, Param))
1434 Param *param = (Param *) node;
1436 /* A parameter must depend on the parameter's datatype */
1437 add_object_address(OCLASS_TYPE, param->paramtype, 0,
1440 else if (IsA(node, FuncExpr))
1442 FuncExpr *funcexpr = (FuncExpr *) node;
1444 add_object_address(OCLASS_PROC, funcexpr->funcid, 0,
1446 /* fall through to examine arguments */
1448 else if (IsA(node, OpExpr))
1450 OpExpr *opexpr = (OpExpr *) node;
1452 add_object_address(OCLASS_OPERATOR, opexpr->opno, 0,
1454 /* fall through to examine arguments */
1456 else if (IsA(node, DistinctExpr))
1458 DistinctExpr *distinctexpr = (DistinctExpr *) node;
1460 add_object_address(OCLASS_OPERATOR, distinctexpr->opno, 0,
1462 /* fall through to examine arguments */
1464 else if (IsA(node, ScalarArrayOpExpr))
1466 ScalarArrayOpExpr *opexpr = (ScalarArrayOpExpr *) node;
1468 add_object_address(OCLASS_OPERATOR, opexpr->opno, 0,
1470 /* fall through to examine arguments */
1472 else if (IsA(node, NullIfExpr))
1474 NullIfExpr *nullifexpr = (NullIfExpr *) node;
1476 add_object_address(OCLASS_OPERATOR, nullifexpr->opno, 0,
1478 /* fall through to examine arguments */
1480 else if (IsA(node, Aggref))
1482 Aggref *aggref = (Aggref *) node;
1484 add_object_address(OCLASS_PROC, aggref->aggfnoid, 0,
1486 /* fall through to examine arguments */
1488 else if (IsA(node, WindowFunc))
1490 WindowFunc *wfunc = (WindowFunc *) node;
1492 add_object_address(OCLASS_PROC, wfunc->winfnoid, 0,
1494 /* fall through to examine arguments */
1496 else if (IsA(node, SubPlan))
1498 /* Extra work needed here if we ever need this case */
1499 elog(ERROR, "already-planned subqueries not supported");
1501 else if (IsA(node, RelabelType))
1503 RelabelType *relab = (RelabelType *) node;
1505 /* since there is no function dependency, need to depend on type */
1506 add_object_address(OCLASS_TYPE, relab->resulttype, 0,
1509 else if (IsA(node, CoerceViaIO))
1511 CoerceViaIO *iocoerce = (CoerceViaIO *) node;
1513 /* since there is no exposed function, need to depend on type */
1514 add_object_address(OCLASS_TYPE, iocoerce->resulttype, 0,
1517 else if (IsA(node, ArrayCoerceExpr))
1519 ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
1521 if (OidIsValid(acoerce->elemfuncid))
1522 add_object_address(OCLASS_PROC, acoerce->elemfuncid, 0,
1524 add_object_address(OCLASS_TYPE, acoerce->resulttype, 0,
1526 /* fall through to examine arguments */
1528 else if (IsA(node, ConvertRowtypeExpr))
1530 ConvertRowtypeExpr *cvt = (ConvertRowtypeExpr *) node;
1532 /* since there is no function dependency, need to depend on type */
1533 add_object_address(OCLASS_TYPE, cvt->resulttype, 0,
1536 else if (IsA(node, RowExpr))
1538 RowExpr *rowexpr = (RowExpr *) node;
1540 add_object_address(OCLASS_TYPE, rowexpr->row_typeid, 0,
1543 else if (IsA(node, RowCompareExpr))
1545 RowCompareExpr *rcexpr = (RowCompareExpr *) node;
1548 foreach(l, rcexpr->opnos)
1550 add_object_address(OCLASS_OPERATOR, lfirst_oid(l), 0,
1553 foreach(l, rcexpr->opfamilies)
1555 add_object_address(OCLASS_OPFAMILY, lfirst_oid(l), 0,
1558 /* fall through to examine arguments */
1560 else if (IsA(node, CoerceToDomain))
1562 CoerceToDomain *cd = (CoerceToDomain *) node;
1564 add_object_address(OCLASS_TYPE, cd->resulttype, 0,
1567 else if (IsA(node, SortGroupClause))
1569 SortGroupClause *sgc = (SortGroupClause *) node;
1571 add_object_address(OCLASS_OPERATOR, sgc->eqop, 0,
1573 if (OidIsValid(sgc->sortop))
1574 add_object_address(OCLASS_OPERATOR, sgc->sortop, 0,
1578 else if (IsA(node, Query))
1580 /* Recurse into RTE subquery or not-yet-planned sublink subquery */
1581 Query *query = (Query *) node;
1586 * Add whole-relation refs for each plain relation mentioned in the
1587 * subquery's rtable, as well as datatype refs for any datatypes used
1588 * as a RECORD function's output. (Note: query_tree_walker takes care
1589 * of recursing into RTE_FUNCTION RTEs, subqueries, etc, so no need to
1590 * do that here. But keep it from looking at join alias lists.)
1592 foreach(rtable, query->rtable)
1594 RangeTblEntry *rte = (RangeTblEntry *) lfirst(rtable);
1597 switch (rte->rtekind)
1600 add_object_address(OCLASS_CLASS, rte->relid, 0,
1604 foreach(ct, rte->funccoltypes)
1606 add_object_address(OCLASS_TYPE, lfirst_oid(ct), 0,
1615 /* query_tree_walker ignores ORDER BY etc, but we need those opers */
1616 find_expr_references_walker((Node *) query->sortClause, context);
1617 find_expr_references_walker((Node *) query->groupClause, context);
1618 find_expr_references_walker((Node *) query->windowClause, context);
1619 find_expr_references_walker((Node *) query->distinctClause, context);
1621 /* Examine substructure of query */
1622 context->rtables = lcons(query->rtable, context->rtables);
1623 result = query_tree_walker(query,
1624 find_expr_references_walker,
1626 QTW_IGNORE_JOINALIASES);
1627 context->rtables = list_delete_first(context->rtables);
1630 else if (IsA(node, SetOperationStmt))
1632 SetOperationStmt *setop = (SetOperationStmt *) node;
1634 /* we need to look at the groupClauses for operator references */
1635 find_expr_references_walker((Node *) setop->groupClauses, context);
1636 /* fall through to examine child nodes */
1639 return expression_tree_walker(node, find_expr_references_walker,
1644 * Given an array of dependency references, eliminate any duplicates.
1647 eliminate_duplicate_dependencies(ObjectAddresses *addrs)
1649 ObjectAddress *priorobj;
1654 * We can't sort if the array has "extra" data, because there's no way
1655 * to keep it in sync. Fortunately that combination of features is
1658 Assert(!addrs->extras);
1660 if (addrs->numrefs <= 1)
1661 return; /* nothing to do */
1663 /* Sort the refs so that duplicates are adjacent */
1664 qsort((void *) addrs->refs, addrs->numrefs, sizeof(ObjectAddress),
1665 object_address_comparator);
1668 priorobj = addrs->refs;
1670 for (oldref = 1; oldref < addrs->numrefs; oldref++)
1672 ObjectAddress *thisobj = addrs->refs + oldref;
1674 if (priorobj->classId == thisobj->classId &&
1675 priorobj->objectId == thisobj->objectId)
1677 if (priorobj->objectSubId == thisobj->objectSubId)
1678 continue; /* identical, so drop thisobj */
1681 * If we have a whole-object reference and a reference to a part
1682 * of the same object, we don't need the whole-object reference
1683 * (for example, we don't need to reference both table foo and
1684 * column foo.bar). The whole-object reference will always appear
1685 * first in the sorted list.
1687 if (priorobj->objectSubId == 0)
1689 /* replace whole ref with partial */
1690 priorobj->objectSubId = thisobj->objectSubId;
1694 /* Not identical, so add thisobj to output set */
1696 *priorobj = *thisobj;
1700 addrs->numrefs = newrefs;
1704 * qsort comparator for ObjectAddress items
1707 object_address_comparator(const void *a, const void *b)
1709 const ObjectAddress *obja = (const ObjectAddress *) a;
1710 const ObjectAddress *objb = (const ObjectAddress *) b;
1712 if (obja->classId < objb->classId)
1714 if (obja->classId > objb->classId)
1716 if (obja->objectId < objb->objectId)
1718 if (obja->objectId > objb->objectId)
1722 * We sort the subId as an unsigned int so that 0 will come first. See
1723 * logic in eliminate_duplicate_dependencies.
1725 if ((unsigned int) obja->objectSubId < (unsigned int) objb->objectSubId)
1727 if ((unsigned int) obja->objectSubId > (unsigned int) objb->objectSubId)
1733 * Routines for handling an expansible array of ObjectAddress items.
1735 * new_object_addresses: create a new ObjectAddresses array.
1738 new_object_addresses(void)
1740 ObjectAddresses *addrs;
1742 addrs = palloc(sizeof(ObjectAddresses));
1745 addrs->maxrefs = 32;
1746 addrs->refs = (ObjectAddress *)
1747 palloc(addrs->maxrefs * sizeof(ObjectAddress));
1748 addrs->extras = NULL; /* until/unless needed */
1754 * Add an entry to an ObjectAddresses array.
1756 * It is convenient to specify the class by ObjectClass rather than directly
1760 add_object_address(ObjectClass oclass, Oid objectId, int32 subId,
1761 ObjectAddresses *addrs)
1763 ObjectAddress *item;
1765 /* enlarge array if needed */
1766 if (addrs->numrefs >= addrs->maxrefs)
1768 addrs->maxrefs *= 2;
1769 addrs->refs = (ObjectAddress *)
1770 repalloc(addrs->refs, addrs->maxrefs * sizeof(ObjectAddress));
1771 Assert(!addrs->extras);
1773 /* record this item */
1774 item = addrs->refs + addrs->numrefs;
1775 item->classId = object_classes[oclass];
1776 item->objectId = objectId;
1777 item->objectSubId = subId;
1782 * Add an entry to an ObjectAddresses array.
1784 * As above, but specify entry exactly.
1787 add_exact_object_address(const ObjectAddress *object,
1788 ObjectAddresses *addrs)
1790 ObjectAddress *item;
1792 /* enlarge array if needed */
1793 if (addrs->numrefs >= addrs->maxrefs)
1795 addrs->maxrefs *= 2;
1796 addrs->refs = (ObjectAddress *)
1797 repalloc(addrs->refs, addrs->maxrefs * sizeof(ObjectAddress));
1798 Assert(!addrs->extras);
1800 /* record this item */
1801 item = addrs->refs + addrs->numrefs;
1807 * Add an entry to an ObjectAddresses array.
1809 * As above, but specify entry exactly and provide some "extra" data too.
1812 add_exact_object_address_extra(const ObjectAddress *object,
1813 const ObjectAddressExtra *extra,
1814 ObjectAddresses *addrs)
1816 ObjectAddress *item;
1817 ObjectAddressExtra *itemextra;
1819 /* allocate extra space if first time */
1821 addrs->extras = (ObjectAddressExtra *)
1822 palloc(addrs->maxrefs * sizeof(ObjectAddressExtra));
1824 /* enlarge array if needed */
1825 if (addrs->numrefs >= addrs->maxrefs)
1827 addrs->maxrefs *= 2;
1828 addrs->refs = (ObjectAddress *)
1829 repalloc(addrs->refs, addrs->maxrefs * sizeof(ObjectAddress));
1830 addrs->extras = (ObjectAddressExtra *)
1831 repalloc(addrs->extras, addrs->maxrefs * sizeof(ObjectAddressExtra));
1833 /* record this item */
1834 item = addrs->refs + addrs->numrefs;
1836 itemextra = addrs->extras + addrs->numrefs;
1837 *itemextra = *extra;
1842 * Test whether an object is present in an ObjectAddresses array.
1844 * We return "true" if object is a subobject of something in the array, too.
1847 object_address_present(const ObjectAddress *object,
1848 const ObjectAddresses *addrs)
1852 for (i = addrs->numrefs - 1; i >= 0; i--)
1854 const ObjectAddress *thisobj = addrs->refs + i;
1856 if (object->classId == thisobj->classId &&
1857 object->objectId == thisobj->objectId)
1859 if (object->objectSubId == thisobj->objectSubId ||
1860 thisobj->objectSubId == 0)
1869 * As above, except that if the object is present then also OR the given
1870 * flags into its associated extra data (which must exist).
1873 object_address_present_add_flags(const ObjectAddress *object,
1875 ObjectAddresses *addrs)
1879 for (i = addrs->numrefs - 1; i >= 0; i--)
1881 ObjectAddress *thisobj = addrs->refs + i;
1883 if (object->classId == thisobj->classId &&
1884 object->objectId == thisobj->objectId)
1886 if (object->objectSubId == thisobj->objectSubId)
1888 ObjectAddressExtra *thisextra = addrs->extras + i;
1890 thisextra->flags |= flags;
1893 if (thisobj->objectSubId == 0)
1896 * We get here if we find a need to delete a column after
1897 * having already decided to drop its whole table. Obviously
1898 * we no longer need to drop the column. But don't plaster
1899 * its flags on the table.
1910 * Record multiple dependencies from an ObjectAddresses array, after first
1911 * removing any duplicates.
1914 record_object_address_dependencies(const ObjectAddress *depender,
1915 ObjectAddresses *referenced,
1916 DependencyType behavior)
1918 eliminate_duplicate_dependencies(referenced);
1919 recordMultipleDependencies(depender,
1920 referenced->refs, referenced->numrefs,
1925 * Clean up when done with an ObjectAddresses array.
1928 free_object_addresses(ObjectAddresses *addrs)
1932 pfree(addrs->extras);
1937 * Determine the class of a given object identified by objectAddress.
1939 * This function is essentially the reverse mapping for the object_classes[]
1940 * table. We implement it as a function because the OIDs aren't consecutive.
1943 getObjectClass(const ObjectAddress *object)
1945 switch (object->classId)
1947 case RelationRelationId:
1948 /* caller must check objectSubId */
1949 return OCLASS_CLASS;
1951 case ProcedureRelationId:
1952 Assert(object->objectSubId == 0);
1955 case TypeRelationId:
1956 Assert(object->objectSubId == 0);
1959 case CastRelationId:
1960 Assert(object->objectSubId == 0);
1963 case ConstraintRelationId:
1964 Assert(object->objectSubId == 0);
1965 return OCLASS_CONSTRAINT;
1967 case ConversionRelationId:
1968 Assert(object->objectSubId == 0);
1969 return OCLASS_CONVERSION;
1971 case AttrDefaultRelationId:
1972 Assert(object->objectSubId == 0);
1973 return OCLASS_DEFAULT;
1975 case LanguageRelationId:
1976 Assert(object->objectSubId == 0);
1977 return OCLASS_LANGUAGE;
1979 case OperatorRelationId:
1980 Assert(object->objectSubId == 0);
1981 return OCLASS_OPERATOR;
1983 case OperatorClassRelationId:
1984 Assert(object->objectSubId == 0);
1985 return OCLASS_OPCLASS;
1987 case OperatorFamilyRelationId:
1988 Assert(object->objectSubId == 0);
1989 return OCLASS_OPFAMILY;
1991 case AccessMethodOperatorRelationId:
1992 Assert(object->objectSubId == 0);
1995 case AccessMethodProcedureRelationId:
1996 Assert(object->objectSubId == 0);
1997 return OCLASS_AMPROC;
1999 case RewriteRelationId:
2000 Assert(object->objectSubId == 0);
2001 return OCLASS_REWRITE;
2003 case TriggerRelationId:
2004 Assert(object->objectSubId == 0);
2005 return OCLASS_TRIGGER;
2007 case NamespaceRelationId:
2008 Assert(object->objectSubId == 0);
2009 return OCLASS_SCHEMA;
2011 case TSParserRelationId:
2012 Assert(object->objectSubId == 0);
2013 return OCLASS_TSPARSER;
2015 case TSDictionaryRelationId:
2016 Assert(object->objectSubId == 0);
2017 return OCLASS_TSDICT;
2019 case TSTemplateRelationId:
2020 Assert(object->objectSubId == 0);
2021 return OCLASS_TSTEMPLATE;
2023 case TSConfigRelationId:
2024 Assert(object->objectSubId == 0);
2025 return OCLASS_TSCONFIG;
2027 case AuthIdRelationId:
2028 Assert(object->objectSubId == 0);
2031 case DatabaseRelationId:
2032 Assert(object->objectSubId == 0);
2033 return OCLASS_DATABASE;
2035 case TableSpaceRelationId:
2036 Assert(object->objectSubId == 0);
2037 return OCLASS_TBLSPACE;
2039 case ForeignDataWrapperRelationId:
2040 Assert(object->objectSubId == 0);
2043 case ForeignServerRelationId:
2044 Assert(object->objectSubId == 0);
2045 return OCLASS_FOREIGN_SERVER;
2047 case UserMappingRelationId:
2048 Assert(object->objectSubId == 0);
2049 return OCLASS_USER_MAPPING;
2052 /* shouldn't get here */
2053 elog(ERROR, "unrecognized object class: %u", object->classId);
2054 return OCLASS_CLASS; /* keep compiler quiet */
2058 * getObjectDescription: build an object description for messages
2060 * The result is a palloc'd string.
2063 getObjectDescription(const ObjectAddress *object)
2065 StringInfoData buffer;
2067 initStringInfo(&buffer);
2069 switch (getObjectClass(object))
2072 getRelationDescription(&buffer, object->objectId);
2073 if (object->objectSubId != 0)
2074 appendStringInfo(&buffer, _(" column %s"),
2075 get_relid_attribute_name(object->objectId,
2076 object->objectSubId));
2080 appendStringInfo(&buffer, _("function %s"),
2081 format_procedure(object->objectId));
2085 appendStringInfo(&buffer, _("type %s"),
2086 format_type_be(object->objectId));
2092 ScanKeyData skey[1];
2095 Form_pg_cast castForm;
2097 castDesc = heap_open(CastRelationId, AccessShareLock);
2099 ScanKeyInit(&skey[0],
2100 ObjectIdAttributeNumber,
2101 BTEqualStrategyNumber, F_OIDEQ,
2102 ObjectIdGetDatum(object->objectId));
2104 rcscan = systable_beginscan(castDesc, CastOidIndexId, true,
2105 SnapshotNow, 1, skey);
2107 tup = systable_getnext(rcscan);
2109 if (!HeapTupleIsValid(tup))
2110 elog(ERROR, "could not find tuple for cast %u",
2113 castForm = (Form_pg_cast) GETSTRUCT(tup);
2115 appendStringInfo(&buffer, _("cast from %s to %s"),
2116 format_type_be(castForm->castsource),
2117 format_type_be(castForm->casttarget));
2119 systable_endscan(rcscan);
2120 heap_close(castDesc, AccessShareLock);
2124 case OCLASS_CONSTRAINT:
2127 Form_pg_constraint con;
2129 conTup = SearchSysCache(CONSTROID,
2130 ObjectIdGetDatum(object->objectId),
2132 if (!HeapTupleIsValid(conTup))
2133 elog(ERROR, "cache lookup failed for constraint %u",
2135 con = (Form_pg_constraint) GETSTRUCT(conTup);
2137 if (OidIsValid(con->conrelid))
2141 initStringInfo(&rel);
2142 getRelationDescription(&rel, con->conrelid);
2143 appendStringInfo(&buffer, _("constraint %s on %s"),
2144 NameStr(con->conname), rel.data);
2149 appendStringInfo(&buffer, _("constraint %s"),
2150 NameStr(con->conname));
2153 ReleaseSysCache(conTup);
2157 case OCLASS_CONVERSION:
2161 conTup = SearchSysCache(CONVOID,
2162 ObjectIdGetDatum(object->objectId),
2164 if (!HeapTupleIsValid(conTup))
2165 elog(ERROR, "cache lookup failed for conversion %u",
2167 appendStringInfo(&buffer, _("conversion %s"),
2168 NameStr(((Form_pg_conversion) GETSTRUCT(conTup))->conname));
2169 ReleaseSysCache(conTup);
2173 case OCLASS_DEFAULT:
2175 Relation attrdefDesc;
2176 ScanKeyData skey[1];
2179 Form_pg_attrdef attrdef;
2180 ObjectAddress colobject;
2182 attrdefDesc = heap_open(AttrDefaultRelationId, AccessShareLock);
2184 ScanKeyInit(&skey[0],
2185 ObjectIdAttributeNumber,
2186 BTEqualStrategyNumber, F_OIDEQ,
2187 ObjectIdGetDatum(object->objectId));
2189 adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
2190 true, SnapshotNow, 1, skey);
2192 tup = systable_getnext(adscan);
2194 if (!HeapTupleIsValid(tup))
2195 elog(ERROR, "could not find tuple for attrdef %u",
2198 attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
2200 colobject.classId = RelationRelationId;
2201 colobject.objectId = attrdef->adrelid;
2202 colobject.objectSubId = attrdef->adnum;
2204 appendStringInfo(&buffer, _("default for %s"),
2205 getObjectDescription(&colobject));
2207 systable_endscan(adscan);
2208 heap_close(attrdefDesc, AccessShareLock);
2212 case OCLASS_LANGUAGE:
2216 langTup = SearchSysCache(LANGOID,
2217 ObjectIdGetDatum(object->objectId),
2219 if (!HeapTupleIsValid(langTup))
2220 elog(ERROR, "cache lookup failed for language %u",
2222 appendStringInfo(&buffer, _("language %s"),
2223 NameStr(((Form_pg_language) GETSTRUCT(langTup))->lanname));
2224 ReleaseSysCache(langTup);
2228 case OCLASS_OPERATOR:
2229 appendStringInfo(&buffer, _("operator %s"),
2230 format_operator(object->objectId));
2233 case OCLASS_OPCLASS:
2236 Form_pg_opclass opcForm;
2241 opcTup = SearchSysCache(CLAOID,
2242 ObjectIdGetDatum(object->objectId),
2244 if (!HeapTupleIsValid(opcTup))
2245 elog(ERROR, "cache lookup failed for opclass %u",
2247 opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
2249 amTup = SearchSysCache(AMOID,
2250 ObjectIdGetDatum(opcForm->opcmethod),
2252 if (!HeapTupleIsValid(amTup))
2253 elog(ERROR, "cache lookup failed for access method %u",
2254 opcForm->opcmethod);
2255 amForm = (Form_pg_am) GETSTRUCT(amTup);
2257 /* Qualify the name if not visible in search path */
2258 if (OpclassIsVisible(object->objectId))
2261 nspname = get_namespace_name(opcForm->opcnamespace);
2263 appendStringInfo(&buffer, _("operator class %s for access method %s"),
2264 quote_qualified_identifier(nspname,
2265 NameStr(opcForm->opcname)),
2266 NameStr(amForm->amname));
2268 ReleaseSysCache(amTup);
2269 ReleaseSysCache(opcTup);
2273 case OCLASS_OPFAMILY:
2274 getOpFamilyDescription(&buffer, object->objectId);
2280 ScanKeyData skey[1];
2283 Form_pg_amop amopForm;
2284 StringInfoData opfam;
2286 amopDesc = heap_open(AccessMethodOperatorRelationId,
2289 ScanKeyInit(&skey[0],
2290 ObjectIdAttributeNumber,
2291 BTEqualStrategyNumber, F_OIDEQ,
2292 ObjectIdGetDatum(object->objectId));
2294 amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
2295 SnapshotNow, 1, skey);
2297 tup = systable_getnext(amscan);
2299 if (!HeapTupleIsValid(tup))
2300 elog(ERROR, "could not find tuple for amop entry %u",
2303 amopForm = (Form_pg_amop) GETSTRUCT(tup);
2305 initStringInfo(&opfam);
2306 getOpFamilyDescription(&opfam, amopForm->amopfamily);
2308 * translator: %d is the operator strategy (a number), the
2309 * first %s is the textual form of the operator, and the second
2310 * %s is the description of the operator family.
2312 appendStringInfo(&buffer, _("operator %d %s of %s"),
2313 amopForm->amopstrategy,
2314 format_operator(amopForm->amopopr),
2318 systable_endscan(amscan);
2319 heap_close(amopDesc, AccessShareLock);
2325 Relation amprocDesc;
2326 ScanKeyData skey[1];
2329 Form_pg_amproc amprocForm;
2330 StringInfoData opfam;
2332 amprocDesc = heap_open(AccessMethodProcedureRelationId,
2335 ScanKeyInit(&skey[0],
2336 ObjectIdAttributeNumber,
2337 BTEqualStrategyNumber, F_OIDEQ,
2338 ObjectIdGetDatum(object->objectId));
2340 amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
2341 SnapshotNow, 1, skey);
2343 tup = systable_getnext(amscan);
2345 if (!HeapTupleIsValid(tup))
2346 elog(ERROR, "could not find tuple for amproc entry %u",
2349 amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
2351 initStringInfo(&opfam);
2352 getOpFamilyDescription(&opfam, amprocForm->amprocfamily);
2354 * translator: %d is the function number, the first %s is the
2355 * textual form of the function with arguments, and the second
2356 * %s is the description of the operator family.
2358 appendStringInfo(&buffer, _("function %d %s of %s"),
2359 amprocForm->amprocnum,
2360 format_procedure(amprocForm->amproc),
2364 systable_endscan(amscan);
2365 heap_close(amprocDesc, AccessShareLock);
2369 case OCLASS_REWRITE:
2372 ScanKeyData skey[1];
2375 Form_pg_rewrite rule;
2377 ruleDesc = heap_open(RewriteRelationId, AccessShareLock);
2379 ScanKeyInit(&skey[0],
2380 ObjectIdAttributeNumber,
2381 BTEqualStrategyNumber, F_OIDEQ,
2382 ObjectIdGetDatum(object->objectId));
2384 rcscan = systable_beginscan(ruleDesc, RewriteOidIndexId, true,
2385 SnapshotNow, 1, skey);
2387 tup = systable_getnext(rcscan);
2389 if (!HeapTupleIsValid(tup))
2390 elog(ERROR, "could not find tuple for rule %u",
2393 rule = (Form_pg_rewrite) GETSTRUCT(tup);
2395 appendStringInfo(&buffer, _("rule %s on "),
2396 NameStr(rule->rulename));
2397 getRelationDescription(&buffer, rule->ev_class);
2399 systable_endscan(rcscan);
2400 heap_close(ruleDesc, AccessShareLock);
2404 case OCLASS_TRIGGER:
2407 ScanKeyData skey[1];
2410 Form_pg_trigger trig;
2412 trigDesc = heap_open(TriggerRelationId, AccessShareLock);
2414 ScanKeyInit(&skey[0],
2415 ObjectIdAttributeNumber,
2416 BTEqualStrategyNumber, F_OIDEQ,
2417 ObjectIdGetDatum(object->objectId));
2419 tgscan = systable_beginscan(trigDesc, TriggerOidIndexId, true,
2420 SnapshotNow, 1, skey);
2422 tup = systable_getnext(tgscan);
2424 if (!HeapTupleIsValid(tup))
2425 elog(ERROR, "could not find tuple for trigger %u",
2428 trig = (Form_pg_trigger) GETSTRUCT(tup);
2430 appendStringInfo(&buffer, _("trigger %s on "),
2431 NameStr(trig->tgname));
2432 getRelationDescription(&buffer, trig->tgrelid);
2434 systable_endscan(tgscan);
2435 heap_close(trigDesc, AccessShareLock);
2443 nspname = get_namespace_name(object->objectId);
2445 elog(ERROR, "cache lookup failed for namespace %u",
2447 appendStringInfo(&buffer, _("schema %s"), nspname);
2451 case OCLASS_TSPARSER:
2455 tup = SearchSysCache(TSPARSEROID,
2456 ObjectIdGetDatum(object->objectId),
2458 if (!HeapTupleIsValid(tup))
2459 elog(ERROR, "cache lookup failed for text search parser %u",
2461 appendStringInfo(&buffer, _("text search parser %s"),
2462 NameStr(((Form_pg_ts_parser) GETSTRUCT(tup))->prsname));
2463 ReleaseSysCache(tup);
2471 tup = SearchSysCache(TSDICTOID,
2472 ObjectIdGetDatum(object->objectId),
2474 if (!HeapTupleIsValid(tup))
2475 elog(ERROR, "cache lookup failed for text search dictionary %u",
2477 appendStringInfo(&buffer, _("text search dictionary %s"),
2478 NameStr(((Form_pg_ts_dict) GETSTRUCT(tup))->dictname));
2479 ReleaseSysCache(tup);
2483 case OCLASS_TSTEMPLATE:
2487 tup = SearchSysCache(TSTEMPLATEOID,
2488 ObjectIdGetDatum(object->objectId),
2490 if (!HeapTupleIsValid(tup))
2491 elog(ERROR, "cache lookup failed for text search template %u",
2493 appendStringInfo(&buffer, _("text search template %s"),
2494 NameStr(((Form_pg_ts_template) GETSTRUCT(tup))->tmplname));
2495 ReleaseSysCache(tup);
2499 case OCLASS_TSCONFIG:
2503 tup = SearchSysCache(TSCONFIGOID,
2504 ObjectIdGetDatum(object->objectId),
2506 if (!HeapTupleIsValid(tup))
2507 elog(ERROR, "cache lookup failed for text search configuration %u",
2509 appendStringInfo(&buffer, _("text search configuration %s"),
2510 NameStr(((Form_pg_ts_config) GETSTRUCT(tup))->cfgname));
2511 ReleaseSysCache(tup);
2517 appendStringInfo(&buffer, _("role %s"),
2518 GetUserNameFromId(object->objectId));
2522 case OCLASS_DATABASE:
2526 datname = get_database_name(object->objectId);
2528 elog(ERROR, "cache lookup failed for database %u",
2530 appendStringInfo(&buffer, _("database %s"), datname);
2534 case OCLASS_TBLSPACE:
2538 tblspace = get_tablespace_name(object->objectId);
2540 elog(ERROR, "cache lookup failed for tablespace %u",
2542 appendStringInfo(&buffer, _("tablespace %s"), tblspace);
2548 ForeignDataWrapper *fdw;
2550 fdw = GetForeignDataWrapper(object->objectId);
2551 appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
2555 case OCLASS_FOREIGN_SERVER:
2559 srv = GetForeignServer(object->objectId);
2560 appendStringInfo(&buffer, _("server %s"), srv->servername);
2564 case OCLASS_USER_MAPPING:
2570 tup = SearchSysCache(USERMAPPINGOID,
2571 ObjectIdGetDatum(object->objectId),
2573 if (!HeapTupleIsValid(tup))
2574 elog(ERROR, "cache lookup failed for user mapping %u",
2577 useid = ((Form_pg_user_mapping) GETSTRUCT(tup))->umuser;
2579 ReleaseSysCache(tup);
2581 if (OidIsValid(useid))
2582 usename = GetUserNameFromId(useid);
2586 appendStringInfo(&buffer, _("user mapping for %s"), usename);
2591 appendStringInfo(&buffer, "unrecognized object %u %u %d",
2594 object->objectSubId);
2602 * subroutine for getObjectDescription: describe a relation
2605 getRelationDescription(StringInfo buffer, Oid relid)
2608 Form_pg_class relForm;
2612 relTup = SearchSysCache(RELOID,
2613 ObjectIdGetDatum(relid),
2615 if (!HeapTupleIsValid(relTup))
2616 elog(ERROR, "cache lookup failed for relation %u", relid);
2617 relForm = (Form_pg_class) GETSTRUCT(relTup);
2619 /* Qualify the name if not visible in search path */
2620 if (RelationIsVisible(relid))
2623 nspname = get_namespace_name(relForm->relnamespace);
2625 relname = quote_qualified_identifier(nspname, NameStr(relForm->relname));
2627 switch (relForm->relkind)
2629 case RELKIND_RELATION:
2630 appendStringInfo(buffer, _("table %s"),
2634 appendStringInfo(buffer, _("index %s"),
2637 case RELKIND_SEQUENCE:
2638 appendStringInfo(buffer, _("sequence %s"),
2641 case RELKIND_UNCATALOGED:
2642 appendStringInfo(buffer, _("uncataloged table %s"),
2645 case RELKIND_TOASTVALUE:
2646 appendStringInfo(buffer, _("toast table %s"),
2650 appendStringInfo(buffer, _("view %s"),
2653 case RELKIND_COMPOSITE_TYPE:
2654 appendStringInfo(buffer, _("composite type %s"),
2658 /* shouldn't get here */
2659 appendStringInfo(buffer, _("relation %s"),
2664 ReleaseSysCache(relTup);
2668 * subroutine for getObjectDescription: describe an operator family
2671 getOpFamilyDescription(StringInfo buffer, Oid opfid)
2674 Form_pg_opfamily opfForm;
2679 opfTup = SearchSysCache(OPFAMILYOID,
2680 ObjectIdGetDatum(opfid),
2682 if (!HeapTupleIsValid(opfTup))
2683 elog(ERROR, "cache lookup failed for opfamily %u", opfid);
2684 opfForm = (Form_pg_opfamily) GETSTRUCT(opfTup);
2686 amTup = SearchSysCache(AMOID,
2687 ObjectIdGetDatum(opfForm->opfmethod),
2689 if (!HeapTupleIsValid(amTup))
2690 elog(ERROR, "cache lookup failed for access method %u",
2691 opfForm->opfmethod);
2692 amForm = (Form_pg_am) GETSTRUCT(amTup);
2694 /* Qualify the name if not visible in search path */
2695 if (OpfamilyIsVisible(opfid))
2698 nspname = get_namespace_name(opfForm->opfnamespace);
2700 appendStringInfo(buffer, _("operator family %s for access method %s"),
2701 quote_qualified_identifier(nspname,
2702 NameStr(opfForm->opfname)),
2703 NameStr(amForm->amname));
2705 ReleaseSysCache(amTup);
2706 ReleaseSysCache(opfTup);