PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
dependency.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * dependency.c
4  * Routines to support inter-object dependencies.
5  *
6  *
7  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * IDENTIFICATION
11  * src/backend/catalog/dependency.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include "access/htup_details.h"
18 #include "access/xact.h"
19 #include "catalog/dependency.h"
20 #include "catalog/heap.h"
21 #include "catalog/index.h"
22 #include "catalog/objectaccess.h"
23 #include "catalog/pg_am.h"
24 #include "catalog/pg_amop.h"
25 #include "catalog/pg_amproc.h"
26 #include "catalog/pg_attrdef.h"
27 #include "catalog/pg_authid.h"
28 #include "catalog/pg_cast.h"
29 #include "catalog/pg_collation.h"
31 #include "catalog/pg_constraint.h"
33 #include "catalog/pg_conversion.h"
35 #include "catalog/pg_database.h"
36 #include "catalog/pg_default_acl.h"
37 #include "catalog/pg_depend.h"
39 #include "catalog/pg_extension.h"
42 #include "catalog/pg_init_privs.h"
43 #include "catalog/pg_language.h"
44 #include "catalog/pg_largeobject.h"
45 #include "catalog/pg_namespace.h"
46 #include "catalog/pg_opclass.h"
47 #include "catalog/pg_operator.h"
48 #include "catalog/pg_opfamily.h"
49 #include "catalog/pg_policy.h"
50 #include "catalog/pg_proc.h"
51 #include "catalog/pg_publication.h"
53 #include "catalog/pg_rewrite.h"
55 #include "catalog/pg_tablespace.h"
56 #include "catalog/pg_transform.h"
57 #include "catalog/pg_trigger.h"
58 #include "catalog/pg_ts_config.h"
59 #include "catalog/pg_ts_dict.h"
60 #include "catalog/pg_ts_parser.h"
61 #include "catalog/pg_ts_template.h"
62 #include "catalog/pg_type.h"
64 #include "commands/comment.h"
65 #include "commands/defrem.h"
66 #include "commands/event_trigger.h"
67 #include "commands/extension.h"
68 #include "commands/policy.h"
69 #include "commands/proclang.h"
71 #include "commands/schemacmds.h"
72 #include "commands/seclabel.h"
73 #include "commands/sequence.h"
74 #include "commands/trigger.h"
75 #include "commands/typecmds.h"
76 #include "nodes/nodeFuncs.h"
77 #include "parser/parsetree.h"
78 #include "rewrite/rewriteRemove.h"
79 #include "storage/lmgr.h"
80 #include "utils/fmgroids.h"
81 #include "utils/guc.h"
82 #include "utils/lsyscache.h"
83 #include "utils/syscache.h"
84 #include "utils/tqual.h"
85 
86 
87 /*
88  * Deletion processing requires additional state for each ObjectAddress that
89  * it's planning to delete. For simplicity and code-sharing we make the
90  * ObjectAddresses code support arrays with or without this extra state.
91  */
92 typedef struct
93 {
94  int flags; /* bitmask, see bit definitions below */
95  ObjectAddress dependee; /* object whose deletion forced this one */
97 
98 /* ObjectAddressExtra flag bits */
99 #define DEPFLAG_ORIGINAL 0x0001 /* an original deletion target */
100 #define DEPFLAG_NORMAL 0x0002 /* reached via normal dependency */
101 #define DEPFLAG_AUTO 0x0004 /* reached via auto dependency */
102 #define DEPFLAG_INTERNAL 0x0008 /* reached via internal dependency */
103 #define DEPFLAG_EXTENSION 0x0010 /* reached via extension dependency */
104 #define DEPFLAG_REVERSE 0x0020 /* reverse internal/extension link */
105 
106 
107 /* expansible list of ObjectAddresses */
109 {
110  ObjectAddress *refs; /* => palloc'd array */
111  ObjectAddressExtra *extras; /* => palloc'd array, or NULL if not used */
112  int numrefs; /* current number of references */
113  int maxrefs; /* current size of palloc'd array(s) */
114 };
115 
116 /* typedef ObjectAddresses appears in dependency.h */
117 
118 /* threaded list of ObjectAddresses, for recursion detection */
119 typedef struct ObjectAddressStack
120 {
121  const ObjectAddress *object; /* object being visited */
122  int flags; /* its current flag bits */
123  struct ObjectAddressStack *next; /* next outer stack level */
125 
126 /* for find_expr_references_walker */
127 typedef struct
128 {
129  ObjectAddresses *addrs; /* addresses being accumulated */
130  List *rtables; /* list of rangetables to resolve Vars */
132 
133 /*
134  * This constant table maps ObjectClasses to the corresponding catalog OIDs.
135  * See also getObjectClass().
136  */
137 static const Oid object_classes[] = {
138  RelationRelationId, /* OCLASS_CLASS */
139  ProcedureRelationId, /* OCLASS_PROC */
140  TypeRelationId, /* OCLASS_TYPE */
141  CastRelationId, /* OCLASS_CAST */
142  CollationRelationId, /* OCLASS_COLLATION */
143  ConstraintRelationId, /* OCLASS_CONSTRAINT */
144  ConversionRelationId, /* OCLASS_CONVERSION */
145  AttrDefaultRelationId, /* OCLASS_DEFAULT */
146  LanguageRelationId, /* OCLASS_LANGUAGE */
147  LargeObjectRelationId, /* OCLASS_LARGEOBJECT */
148  OperatorRelationId, /* OCLASS_OPERATOR */
149  OperatorClassRelationId, /* OCLASS_OPCLASS */
150  OperatorFamilyRelationId, /* OCLASS_OPFAMILY */
151  AccessMethodRelationId, /* OCLASS_AM */
152  AccessMethodOperatorRelationId, /* OCLASS_AMOP */
153  AccessMethodProcedureRelationId, /* OCLASS_AMPROC */
154  RewriteRelationId, /* OCLASS_REWRITE */
155  TriggerRelationId, /* OCLASS_TRIGGER */
156  NamespaceRelationId, /* OCLASS_SCHEMA */
157  TSParserRelationId, /* OCLASS_TSPARSER */
158  TSDictionaryRelationId, /* OCLASS_TSDICT */
159  TSTemplateRelationId, /* OCLASS_TSTEMPLATE */
160  TSConfigRelationId, /* OCLASS_TSCONFIG */
161  AuthIdRelationId, /* OCLASS_ROLE */
162  DatabaseRelationId, /* OCLASS_DATABASE */
163  TableSpaceRelationId, /* OCLASS_TBLSPACE */
164  ForeignDataWrapperRelationId, /* OCLASS_FDW */
165  ForeignServerRelationId, /* OCLASS_FOREIGN_SERVER */
166  UserMappingRelationId, /* OCLASS_USER_MAPPING */
167  DefaultAclRelationId, /* OCLASS_DEFACL */
168  ExtensionRelationId, /* OCLASS_EXTENSION */
169  EventTriggerRelationId, /* OCLASS_EVENT_TRIGGER */
170  PolicyRelationId, /* OCLASS_POLICY */
171  PublicationRelationId, /* OCLASS_PUBLICATION */
172  PublicationRelRelationId, /* OCLASS_PUBLICATION_REL */
173  SubscriptionRelationId, /* OCLASS_SUBSCRIPTION */
174  TransformRelationId /* OCLASS_TRANSFORM */
175 };
176 
177 
178 static void findDependentObjects(const ObjectAddress *object,
179  int objflags,
180  int flags,
181  ObjectAddressStack *stack,
182  ObjectAddresses *targetObjects,
183  const ObjectAddresses *pendingObjects,
184  Relation *depRel);
185 static void reportDependentObjects(const ObjectAddresses *targetObjects,
186  DropBehavior behavior,
187  int flags,
188  const ObjectAddress *origObject);
189 static void deleteOneObject(const ObjectAddress *object,
190  Relation *depRel, int32 flags);
191 static void doDeletion(const ObjectAddress *object, int flags);
192 static void AcquireDeletionLock(const ObjectAddress *object, int flags);
193 static void ReleaseDeletionLock(const ObjectAddress *object);
194 static bool find_expr_references_walker(Node *node,
197 static int object_address_comparator(const void *a, const void *b);
198 static void add_object_address(ObjectClass oclass, Oid objectId, int32 subId,
199  ObjectAddresses *addrs);
200 static void add_exact_object_address_extra(const ObjectAddress *object,
201  const ObjectAddressExtra *extra,
202  ObjectAddresses *addrs);
203 static bool object_address_present_add_flags(const ObjectAddress *object,
204  int flags,
205  ObjectAddresses *addrs);
206 static bool stack_address_present_add_flags(const ObjectAddress *object,
207  int flags,
208  ObjectAddressStack *stack);
209 static void DeleteInitPrivs(const ObjectAddress *object);
210 
211 
212 /*
213  * Go through the objects given running the final actions on them, and execute
214  * the actual deletion.
215  */
216 static void
218  int flags)
219 {
220  int i;
221 
222  /*
223  * Keep track of objects for event triggers, if necessary.
224  */
226  {
227  for (i = 0; i < targetObjects->numrefs; i++)
228  {
229  const ObjectAddress *thisobj = &targetObjects->refs[i];
230  const ObjectAddressExtra *extra = &targetObjects->extras[i];
231  bool original = false;
232  bool normal = false;
233 
234  if (extra->flags & DEPFLAG_ORIGINAL)
235  original = true;
236  if (extra->flags & DEPFLAG_NORMAL)
237  normal = true;
238  if (extra->flags & DEPFLAG_REVERSE)
239  normal = true;
240 
242  {
243  EventTriggerSQLDropAddObject(thisobj, original, normal);
244  }
245  }
246  }
247 
248  /*
249  * Delete all the objects in the proper order, except that if told to, we
250  * should skip the original object(s).
251  */
252  for (i = 0; i < targetObjects->numrefs; i++)
253  {
254  ObjectAddress *thisobj = targetObjects->refs + i;
255  ObjectAddressExtra *thisextra = targetObjects->extras + i;
256 
257  if ((flags & PERFORM_DELETION_SKIP_ORIGINAL) &&
258  (thisextra->flags & DEPFLAG_ORIGINAL))
259  continue;
260 
261  deleteOneObject(thisobj, depRel, flags);
262  }
263 }
264 
265 /*
266  * performDeletion: attempt to drop the specified object. If CASCADE
267  * behavior is specified, also drop any dependent objects (recursively).
268  * If RESTRICT behavior is specified, error out if there are any dependent
269  * objects, except for those that should be implicitly dropped anyway
270  * according to the dependency type.
271  *
272  * This is the outer control routine for all forms of DROP that drop objects
273  * that can participate in dependencies. Note that performMultipleDeletions
274  * is a variant on the same theme; if you change anything here you'll likely
275  * need to fix that too.
276  *
277  * Bits in the flags argument can include:
278  *
279  * PERFORM_DELETION_INTERNAL: indicates that the drop operation is not the
280  * direct result of a user-initiated action. For example, when a temporary
281  * schema is cleaned out so that a new backend can use it, or when a column
282  * default is dropped as an intermediate step while adding a new one, that's
283  * an internal operation. On the other hand, when we drop something because
284  * the user issued a DROP statement against it, that's not internal. Currently
285  * this suppresses calling event triggers and making some permissions checks.
286  *
287  * PERFORM_DELETION_CONCURRENTLY: perform the drop concurrently. This does
288  * not currently work for anything except dropping indexes; don't set it for
289  * other object types or you may get strange results.
290  *
291  * PERFORM_DELETION_QUIETLY: reduce message level from NOTICE to DEBUG2.
292  *
293  * PERFORM_DELETION_SKIP_ORIGINAL: do not delete the specified object(s),
294  * but only what depends on it/them.
295  *
296  * PERFORM_DELETION_SKIP_EXTENSIONS: do not delete extensions, even when
297  * deleting objects that are part of an extension. This should generally
298  * be used only when dropping temporary objects.
299  */
300 void
302  DropBehavior behavior, int flags)
303 {
304  Relation depRel;
305  ObjectAddresses *targetObjects;
306 
307  /*
308  * We save some cycles by opening pg_depend just once and passing the
309  * Relation pointer down to all the recursive deletion steps.
310  */
312 
313  /*
314  * Acquire deletion lock on the target object. (Ideally the caller has
315  * done this already, but many places are sloppy about it.)
316  */
317  AcquireDeletionLock(object, 0);
318 
319  /*
320  * Construct a list of objects to delete (ie, the given object plus
321  * everything directly or indirectly dependent on it).
322  */
323  targetObjects = new_object_addresses();
324 
325  findDependentObjects(object,
327  flags,
328  NULL, /* empty stack */
329  targetObjects,
330  NULL, /* no pendingObjects */
331  &depRel);
332 
333  /*
334  * Check if deletion is allowed, and report about cascaded deletes.
335  */
336  reportDependentObjects(targetObjects,
337  behavior,
338  flags,
339  object);
340 
341  /* do the deed */
342  deleteObjectsInList(targetObjects, &depRel, flags);
343 
344  /* And clean up */
345  free_object_addresses(targetObjects);
346 
347  heap_close(depRel, RowExclusiveLock);
348 }
349 
350 /*
351  * performMultipleDeletions: Similar to performDeletion, but act on multiple
352  * objects at once.
353  *
354  * The main difference from issuing multiple performDeletion calls is that the
355  * list of objects that would be implicitly dropped, for each object to be
356  * dropped, is the union of the implicit-object list for all objects. This
357  * makes each check be more relaxed.
358  */
359 void
361  DropBehavior behavior, int flags)
362 {
363  Relation depRel;
364  ObjectAddresses *targetObjects;
365  int i;
366 
367  /* No work if no objects... */
368  if (objects->numrefs <= 0)
369  return;
370 
371  /*
372  * We save some cycles by opening pg_depend just once and passing the
373  * Relation pointer down to all the recursive deletion steps.
374  */
376 
377  /*
378  * Construct a list of objects to delete (ie, the given objects plus
379  * everything directly or indirectly dependent on them). Note that
380  * because we pass the whole objects list as pendingObjects context, we
381  * won't get a failure from trying to delete an object that is internally
382  * dependent on another one in the list; we'll just skip that object and
383  * delete it when we reach its owner.
384  */
385  targetObjects = new_object_addresses();
386 
387  for (i = 0; i < objects->numrefs; i++)
388  {
389  const ObjectAddress *thisobj = objects->refs + i;
390 
391  /*
392  * Acquire deletion lock on each target object. (Ideally the caller
393  * has done this already, but many places are sloppy about it.)
394  */
395  AcquireDeletionLock(thisobj, flags);
396 
397  findDependentObjects(thisobj,
399  flags,
400  NULL, /* empty stack */
401  targetObjects,
402  objects,
403  &depRel);
404  }
405 
406  /*
407  * Check if deletion is allowed, and report about cascaded deletes.
408  *
409  * If there's exactly one object being deleted, report it the same way as
410  * in performDeletion(), else we have to be vaguer.
411  */
412  reportDependentObjects(targetObjects,
413  behavior,
414  flags,
415  (objects->numrefs == 1 ? objects->refs : NULL));
416 
417  /* do the deed */
418  deleteObjectsInList(targetObjects, &depRel, flags);
419 
420  /* And clean up */
421  free_object_addresses(targetObjects);
422 
423  heap_close(depRel, RowExclusiveLock);
424 }
425 
426 /*
427  * findDependentObjects - find all objects that depend on 'object'
428  *
429  * For every object that depends on the starting object, acquire a deletion
430  * lock on the object, add it to targetObjects (if not already there),
431  * and recursively find objects that depend on it. An object's dependencies
432  * will be placed into targetObjects before the object itself; this means
433  * that the finished list's order represents a safe deletion order.
434  *
435  * The caller must already have a deletion lock on 'object' itself,
436  * but must not have added it to targetObjects. (Note: there are corner
437  * cases where we won't add the object either, and will also release the
438  * caller-taken lock. This is a bit ugly, but the API is set up this way
439  * to allow easy rechecking of an object's liveness after we lock it. See
440  * notes within the function.)
441  *
442  * When dropping a whole object (subId = 0), we find dependencies for
443  * its sub-objects too.
444  *
445  * object: the object to add to targetObjects and find dependencies on
446  * objflags: flags to be ORed into the object's targetObjects entry
447  * flags: PERFORM_DELETION_xxx flags for the deletion operation as a whole
448  * stack: list of objects being visited in current recursion; topmost item
449  * is the object that we recursed from (NULL for external callers)
450  * targetObjects: list of objects that are scheduled to be deleted
451  * pendingObjects: list of other objects slated for destruction, but
452  * not necessarily in targetObjects yet (can be NULL if none)
453  * *depRel: already opened pg_depend relation
454  *
455  * Note: objflags describes the reason for visiting this particular object
456  * at this time, and is not passed down when recursing. The flags argument
457  * is passed down, since it describes what we're doing overall.
458  */
459 static void
461  int objflags,
462  int flags,
463  ObjectAddressStack *stack,
464  ObjectAddresses *targetObjects,
465  const ObjectAddresses *pendingObjects,
466  Relation *depRel)
467 {
468  ScanKeyData key[3];
469  int nkeys;
470  SysScanDesc scan;
471  HeapTuple tup;
472  ObjectAddress otherObject;
473  ObjectAddressStack mystack;
474  ObjectAddressExtra extra;
475 
476  /*
477  * If the target object is already being visited in an outer recursion
478  * level, just report the current objflags back to that level and exit.
479  * This is needed to avoid infinite recursion in the face of circular
480  * dependencies.
481  *
482  * The stack check alone would result in dependency loops being broken at
483  * an arbitrary point, ie, the first member object of the loop to be
484  * visited is the last one to be deleted. This is obviously unworkable.
485  * However, the check for internal dependency below guarantees that we
486  * will not break a loop at an internal dependency: if we enter the loop
487  * at an "owned" object we will switch and start at the "owning" object
488  * instead. We could probably hack something up to avoid breaking at an
489  * auto dependency, too, if we had to. However there are no known cases
490  * where that would be necessary.
491  */
492  if (stack_address_present_add_flags(object, objflags, stack))
493  return;
494 
495  /*
496  * It's also possible that the target object has already been completely
497  * processed and put into targetObjects. If so, again we just add the
498  * specified objflags to its entry and return.
499  *
500  * (Note: in these early-exit cases we could release the caller-taken
501  * lock, since the object is presumably now locked multiple times; but it
502  * seems not worth the cycles.)
503  */
504  if (object_address_present_add_flags(object, objflags, targetObjects))
505  return;
506 
507  /*
508  * The target object might be internally dependent on some other object
509  * (its "owner"), and/or be a member of an extension (also considered its
510  * owner). If so, and if we aren't recursing from the owning object, we
511  * have to transform this deletion request into a deletion request of the
512  * owning object. (We'll eventually recurse back to this object, but the
513  * owning object has to be visited first so it will be deleted after.) The
514  * way to find out about this is to scan the pg_depend entries that show
515  * what this object depends on.
516  */
517  ScanKeyInit(&key[0],
519  BTEqualStrategyNumber, F_OIDEQ,
520  ObjectIdGetDatum(object->classId));
521  ScanKeyInit(&key[1],
523  BTEqualStrategyNumber, F_OIDEQ,
524  ObjectIdGetDatum(object->objectId));
525  if (object->objectSubId != 0)
526  {
527  ScanKeyInit(&key[2],
529  BTEqualStrategyNumber, F_INT4EQ,
530  Int32GetDatum(object->objectSubId));
531  nkeys = 3;
532  }
533  else
534  nkeys = 2;
535 
536  scan = systable_beginscan(*depRel, DependDependerIndexId, true,
537  NULL, nkeys, key);
538 
539  while (HeapTupleIsValid(tup = systable_getnext(scan)))
540  {
541  Form_pg_depend foundDep = (Form_pg_depend) GETSTRUCT(tup);
542 
543  otherObject.classId = foundDep->refclassid;
544  otherObject.objectId = foundDep->refobjid;
545  otherObject.objectSubId = foundDep->refobjsubid;
546 
547  switch (foundDep->deptype)
548  {
549  case DEPENDENCY_NORMAL:
550  case DEPENDENCY_AUTO:
552  /* no problem */
553  break;
554 
556 
557  /*
558  * If told to, ignore EXTENSION dependencies altogether. This
559  * flag is normally used to prevent dropping extensions during
560  * temporary-object cleanup, even if a temp object was created
561  * during an extension script.
562  */
564  break;
565 
566  /*
567  * If the other object is the extension currently being
568  * created/altered, ignore this dependency and continue with
569  * the deletion. This allows dropping of an extension's
570  * objects within the extension's scripts, as well as corner
571  * cases such as dropping a transient object created within
572  * such a script.
573  */
574  if (creating_extension &&
575  otherObject.classId == ExtensionRelationId &&
576  otherObject.objectId == CurrentExtensionObject)
577  break;
578 
579  /* Otherwise, treat this like an internal dependency */
580  /* FALL THRU */
581 
582  case DEPENDENCY_INTERNAL:
583 
584  /*
585  * This object is part of the internal implementation of
586  * another object, or is part of the extension that is the
587  * other object. We have three cases:
588  *
589  * 1. At the outermost recursion level, disallow the DROP. (We
590  * just ereport here, rather than proceeding, since no other
591  * dependencies are likely to be interesting.) However, if
592  * the owning object is listed in pendingObjects, just release
593  * the caller's lock and return; we'll eventually complete the
594  * DROP when we reach that entry in the pending list.
595  */
596  if (stack == NULL)
597  {
598  char *otherObjDesc;
599 
600  if (pendingObjects &&
601  object_address_present(&otherObject, pendingObjects))
602  {
603  systable_endscan(scan);
604  /* need to release caller's lock; see notes below */
605  ReleaseDeletionLock(object);
606  return;
607  }
608  otherObjDesc = getObjectDescription(&otherObject);
609  ereport(ERROR,
610  (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
611  errmsg("cannot drop %s because %s requires it",
612  getObjectDescription(object),
613  otherObjDesc),
614  errhint("You can drop %s instead.",
615  otherObjDesc)));
616  }
617 
618  /*
619  * 2. When recursing from the other end of this dependency,
620  * it's okay to continue with the deletion. This holds when
621  * recursing from a whole object that includes the nominal
622  * other end as a component, too. Since there can be more
623  * than one "owning" object, we have to allow matches that are
624  * more than one level down in the stack.
625  */
626  if (stack_address_present_add_flags(&otherObject, 0, stack))
627  break;
628 
629  /*
630  * 3. Not all the owning objects have been visited, so
631  * transform this deletion request into a delete of this
632  * owning object.
633  *
634  * First, release caller's lock on this object and get
635  * deletion lock on the owning object. (We must release
636  * caller's lock to avoid deadlock against a concurrent
637  * deletion of the owning object.)
638  */
639  ReleaseDeletionLock(object);
640  AcquireDeletionLock(&otherObject, 0);
641 
642  /*
643  * The owning object might have been deleted while we waited
644  * to lock it; if so, neither it nor the current object are
645  * interesting anymore. We test this by checking the
646  * pg_depend entry (see notes below).
647  */
648  if (!systable_recheck_tuple(scan, tup))
649  {
650  systable_endscan(scan);
651  ReleaseDeletionLock(&otherObject);
652  return;
653  }
654 
655  /*
656  * Okay, recurse to the owning object instead of proceeding.
657  *
658  * We do not need to stack the current object; we want the
659  * traversal order to be as if the original reference had
660  * linked to the owning object instead of this one.
661  *
662  * The dependency type is a "reverse" dependency: we need to
663  * delete the owning object if this one is to be deleted, but
664  * this linkage is never a reason for an automatic deletion.
665  */
666  findDependentObjects(&otherObject,
668  flags,
669  stack,
670  targetObjects,
671  pendingObjects,
672  depRel);
673  /* And we're done here. */
674  systable_endscan(scan);
675  return;
676  case DEPENDENCY_PIN:
677 
678  /*
679  * Should not happen; PIN dependencies should have zeroes in
680  * the depender fields...
681  */
682  elog(ERROR, "incorrect use of PIN dependency with %s",
683  getObjectDescription(object));
684  break;
685  default:
686  elog(ERROR, "unrecognized dependency type '%c' for %s",
687  foundDep->deptype, getObjectDescription(object));
688  break;
689  }
690  }
691 
692  systable_endscan(scan);
693 
694  /*
695  * Now recurse to any dependent objects. We must visit them first since
696  * they have to be deleted before the current object.
697  */
698  mystack.object = object; /* set up a new stack level */
699  mystack.flags = objflags;
700  mystack.next = stack;
701 
702  ScanKeyInit(&key[0],
704  BTEqualStrategyNumber, F_OIDEQ,
705  ObjectIdGetDatum(object->classId));
706  ScanKeyInit(&key[1],
708  BTEqualStrategyNumber, F_OIDEQ,
709  ObjectIdGetDatum(object->objectId));
710  if (object->objectSubId != 0)
711  {
712  ScanKeyInit(&key[2],
714  BTEqualStrategyNumber, F_INT4EQ,
715  Int32GetDatum(object->objectSubId));
716  nkeys = 3;
717  }
718  else
719  nkeys = 2;
720 
721  scan = systable_beginscan(*depRel, DependReferenceIndexId, true,
722  NULL, nkeys, key);
723 
724  while (HeapTupleIsValid(tup = systable_getnext(scan)))
725  {
726  Form_pg_depend foundDep = (Form_pg_depend) GETSTRUCT(tup);
727  int subflags;
728 
729  otherObject.classId = foundDep->classid;
730  otherObject.objectId = foundDep->objid;
731  otherObject.objectSubId = foundDep->objsubid;
732 
733  /*
734  * Must lock the dependent object before recursing to it.
735  */
736  AcquireDeletionLock(&otherObject, 0);
737 
738  /*
739  * The dependent object might have been deleted while we waited to
740  * lock it; if so, we don't need to do anything more with it. We can
741  * test this cheaply and independently of the object's type by seeing
742  * if the pg_depend tuple we are looking at is still live. (If the
743  * object got deleted, the tuple would have been deleted too.)
744  */
745  if (!systable_recheck_tuple(scan, tup))
746  {
747  /* release the now-useless lock */
748  ReleaseDeletionLock(&otherObject);
749  /* and continue scanning for dependencies */
750  continue;
751  }
752 
753  /* Recurse, passing objflags indicating the dependency type */
754  switch (foundDep->deptype)
755  {
756  case DEPENDENCY_NORMAL:
757  subflags = DEPFLAG_NORMAL;
758  break;
759  case DEPENDENCY_AUTO:
761  subflags = DEPFLAG_AUTO;
762  break;
763  case DEPENDENCY_INTERNAL:
764  subflags = DEPFLAG_INTERNAL;
765  break;
767  subflags = DEPFLAG_EXTENSION;
768  break;
769  case DEPENDENCY_PIN:
770 
771  /*
772  * For a PIN dependency we just ereport immediately; there
773  * won't be any others to report.
774  */
775  ereport(ERROR,
776  (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
777  errmsg("cannot drop %s because it is required by the database system",
778  getObjectDescription(object))));
779  subflags = 0; /* keep compiler quiet */
780  break;
781  default:
782  elog(ERROR, "unrecognized dependency type '%c' for %s",
783  foundDep->deptype, getObjectDescription(object));
784  subflags = 0; /* keep compiler quiet */
785  break;
786  }
787 
788  findDependentObjects(&otherObject,
789  subflags,
790  flags,
791  &mystack,
792  targetObjects,
793  pendingObjects,
794  depRel);
795  }
796 
797  systable_endscan(scan);
798 
799  /*
800  * Finally, we can add the target object to targetObjects. Be careful to
801  * include any flags that were passed back down to us from inner recursion
802  * levels.
803  */
804  extra.flags = mystack.flags;
805  if (stack)
806  extra.dependee = *stack->object;
807  else
808  memset(&extra.dependee, 0, sizeof(extra.dependee));
809  add_exact_object_address_extra(object, &extra, targetObjects);
810 }
811 
812 /*
813  * reportDependentObjects - report about dependencies, and fail if RESTRICT
814  *
815  * Tell the user about dependent objects that we are going to delete
816  * (or would need to delete, but are prevented by RESTRICT mode);
817  * then error out if there are any and it's not CASCADE mode.
818  *
819  * targetObjects: list of objects that are scheduled to be deleted
820  * behavior: RESTRICT or CASCADE
821  * flags: other flags for the deletion operation
822  * origObject: base object of deletion, or NULL if not available
823  * (the latter case occurs in DROP OWNED)
824  */
825 static void
827  DropBehavior behavior,
828  int flags,
829  const ObjectAddress *origObject)
830 {
831  int msglevel = (flags & PERFORM_DELETION_QUIETLY) ? DEBUG2 : NOTICE;
832  bool ok = true;
833  StringInfoData clientdetail;
834  StringInfoData logdetail;
835  int numReportedClient = 0;
836  int numNotReportedClient = 0;
837  int i;
838 
839  /*
840  * If no error is to be thrown, and the msglevel is too low to be shown to
841  * either client or server log, there's no need to do any of the work.
842  *
843  * Note: this code doesn't know all there is to be known about elog
844  * levels, but it works for NOTICE and DEBUG2, which are the only values
845  * msglevel can currently have. We also assume we are running in a normal
846  * operating environment.
847  */
848  if (behavior == DROP_CASCADE &&
849  msglevel < client_min_messages &&
850  (msglevel < log_min_messages || log_min_messages == LOG))
851  return;
852 
853  /*
854  * We limit the number of dependencies reported to the client to
855  * MAX_REPORTED_DEPS, since client software may not deal well with
856  * enormous error strings. The server log always gets a full report.
857  */
858 #define MAX_REPORTED_DEPS 100
859 
860  initStringInfo(&clientdetail);
861  initStringInfo(&logdetail);
862 
863  /*
864  * We process the list back to front (ie, in dependency order not deletion
865  * order), since this makes for a more understandable display.
866  */
867  for (i = targetObjects->numrefs - 1; i >= 0; i--)
868  {
869  const ObjectAddress *obj = &targetObjects->refs[i];
870  const ObjectAddressExtra *extra = &targetObjects->extras[i];
871  char *objDesc;
872 
873  /* Ignore the original deletion target(s) */
874  if (extra->flags & DEPFLAG_ORIGINAL)
875  continue;
876 
877  objDesc = getObjectDescription(obj);
878 
879  /*
880  * If, at any stage of the recursive search, we reached the object via
881  * an AUTO, INTERNAL, or EXTENSION dependency, then it's okay to
882  * delete it even in RESTRICT mode.
883  */
884  if (extra->flags & (DEPFLAG_AUTO |
887  {
888  /*
889  * auto-cascades are reported at DEBUG2, not msglevel. We don't
890  * try to combine them with the regular message because the
891  * results are too confusing when client_min_messages and
892  * log_min_messages are different.
893  */
894  ereport(DEBUG2,
895  (errmsg("drop auto-cascades to %s",
896  objDesc)));
897  }
898  else if (behavior == DROP_RESTRICT)
899  {
900  char *otherDesc = getObjectDescription(&extra->dependee);
901 
902  if (numReportedClient < MAX_REPORTED_DEPS)
903  {
904  /* separate entries with a newline */
905  if (clientdetail.len != 0)
906  appendStringInfoChar(&clientdetail, '\n');
907  appendStringInfo(&clientdetail, _("%s depends on %s"),
908  objDesc, otherDesc);
909  numReportedClient++;
910  }
911  else
912  numNotReportedClient++;
913  /* separate entries with a newline */
914  if (logdetail.len != 0)
915  appendStringInfoChar(&logdetail, '\n');
916  appendStringInfo(&logdetail, _("%s depends on %s"),
917  objDesc, otherDesc);
918  pfree(otherDesc);
919  ok = false;
920  }
921  else
922  {
923  if (numReportedClient < MAX_REPORTED_DEPS)
924  {
925  /* separate entries with a newline */
926  if (clientdetail.len != 0)
927  appendStringInfoChar(&clientdetail, '\n');
928  appendStringInfo(&clientdetail, _("drop cascades to %s"),
929  objDesc);
930  numReportedClient++;
931  }
932  else
933  numNotReportedClient++;
934  /* separate entries with a newline */
935  if (logdetail.len != 0)
936  appendStringInfoChar(&logdetail, '\n');
937  appendStringInfo(&logdetail, _("drop cascades to %s"),
938  objDesc);
939  }
940 
941  pfree(objDesc);
942  }
943 
944  if (numNotReportedClient > 0)
945  appendStringInfo(&clientdetail, ngettext("\nand %d other object "
946  "(see server log for list)",
947  "\nand %d other objects "
948  "(see server log for list)",
949  numNotReportedClient),
950  numNotReportedClient);
951 
952  if (!ok)
953  {
954  if (origObject)
955  ereport(ERROR,
956  (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
957  errmsg("cannot drop %s because other objects depend on it",
958  getObjectDescription(origObject)),
959  errdetail("%s", clientdetail.data),
960  errdetail_log("%s", logdetail.data),
961  errhint("Use DROP ... CASCADE to drop the dependent objects too.")));
962  else
963  ereport(ERROR,
964  (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
965  errmsg("cannot drop desired object(s) because other objects depend on them"),
966  errdetail("%s", clientdetail.data),
967  errdetail_log("%s", logdetail.data),
968  errhint("Use DROP ... CASCADE to drop the dependent objects too.")));
969  }
970  else if (numReportedClient > 1)
971  {
972  ereport(msglevel,
973  /* translator: %d always has a value larger than 1 */
974  (errmsg_plural("drop cascades to %d other object",
975  "drop cascades to %d other objects",
976  numReportedClient + numNotReportedClient,
977  numReportedClient + numNotReportedClient),
978  errdetail("%s", clientdetail.data),
979  errdetail_log("%s", logdetail.data)));
980  }
981  else if (numReportedClient == 1)
982  {
983  /* we just use the single item as-is */
984  ereport(msglevel,
985  (errmsg_internal("%s", clientdetail.data)));
986  }
987 
988  pfree(clientdetail.data);
989  pfree(logdetail.data);
990 }
991 
992 /*
993  * deleteOneObject: delete a single object for performDeletion.
994  *
995  * *depRel is the already-open pg_depend relation.
996  */
997 static void
998 deleteOneObject(const ObjectAddress *object, Relation *depRel, int flags)
999 {
1000  ScanKeyData key[3];
1001  int nkeys;
1002  SysScanDesc scan;
1003  HeapTuple tup;
1004 
1005  /* DROP hook of the objects being removed */
1006  InvokeObjectDropHookArg(object->classId, object->objectId,
1007  object->objectSubId, flags);
1008 
1009  /*
1010  * Close depRel if we are doing a drop concurrently. The object deletion
1011  * subroutine will commit the current transaction, so we can't keep the
1012  * relation open across doDeletion().
1013  */
1014  if (flags & PERFORM_DELETION_CONCURRENTLY)
1015  heap_close(*depRel, RowExclusiveLock);
1016 
1017  /*
1018  * Delete the object itself, in an object-type-dependent way.
1019  *
1020  * We used to do this after removing the outgoing dependency links, but it
1021  * seems just as reasonable to do it beforehand. In the concurrent case
1022  * we *must* do it in this order, because we can't make any transactional
1023  * updates before calling doDeletion() --- they'd get committed right
1024  * away, which is not cool if the deletion then fails.
1025  */
1026  doDeletion(object, flags);
1027 
1028  /*
1029  * Reopen depRel if we closed it above
1030  */
1031  if (flags & PERFORM_DELETION_CONCURRENTLY)
1033 
1034  /*
1035  * Now remove any pg_depend records that link from this object to others.
1036  * (Any records linking to this object should be gone already.)
1037  *
1038  * When dropping a whole object (subId = 0), remove all pg_depend records
1039  * for its sub-objects too.
1040  */
1041  ScanKeyInit(&key[0],
1043  BTEqualStrategyNumber, F_OIDEQ,
1044  ObjectIdGetDatum(object->classId));
1045  ScanKeyInit(&key[1],
1047  BTEqualStrategyNumber, F_OIDEQ,
1048  ObjectIdGetDatum(object->objectId));
1049  if (object->objectSubId != 0)
1050  {
1051  ScanKeyInit(&key[2],
1053  BTEqualStrategyNumber, F_INT4EQ,
1054  Int32GetDatum(object->objectSubId));
1055  nkeys = 3;
1056  }
1057  else
1058  nkeys = 2;
1059 
1060  scan = systable_beginscan(*depRel, DependDependerIndexId, true,
1061  NULL, nkeys, key);
1062 
1063  while (HeapTupleIsValid(tup = systable_getnext(scan)))
1064  {
1065  CatalogTupleDelete(*depRel, &tup->t_self);
1066  }
1067 
1068  systable_endscan(scan);
1069 
1070  /*
1071  * Delete shared dependency references related to this object. Again, if
1072  * subId = 0, remove records for sub-objects too.
1073  */
1075  object->objectSubId);
1076 
1077 
1078  /*
1079  * Delete any comments, security labels, or initial privileges associated
1080  * with this object. (This is a convenient place to do these things,
1081  * rather than having every object type know to do it.)
1082  */
1083  DeleteComments(object->objectId, object->classId, object->objectSubId);
1084  DeleteSecurityLabel(object);
1085  DeleteInitPrivs(object);
1086 
1087  /*
1088  * CommandCounterIncrement here to ensure that preceding changes are all
1089  * visible to the next deletion step.
1090  */
1092 
1093  /*
1094  * And we're done!
1095  */
1096 }
1097 
1098 /*
1099  * doDeletion: actually delete a single object
1100  */
1101 static void
1102 doDeletion(const ObjectAddress *object, int flags)
1103 {
1104  switch (getObjectClass(object))
1105  {
1106  case OCLASS_CLASS:
1107  {
1108  char relKind = get_rel_relkind(object->objectId);
1109 
1110  if (relKind == RELKIND_INDEX)
1111  {
1112  bool concurrent = ((flags & PERFORM_DELETION_CONCURRENTLY) != 0);
1113 
1114  Assert(object->objectSubId == 0);
1115  index_drop(object->objectId, concurrent);
1116  }
1117  else
1118  {
1119  if (object->objectSubId != 0)
1120  RemoveAttributeById(object->objectId,
1121  object->objectSubId);
1122  else
1124  }
1125 
1126  /* for a sequence, in addition to dropping the heap, also
1127  * delete pg_sequence tuple */
1128  if (relKind == RELKIND_SEQUENCE)
1129  DeleteSequenceTuple(object->objectId);
1130  break;
1131  }
1132 
1133  case OCLASS_PROC:
1134  RemoveFunctionById(object->objectId);
1135  break;
1136 
1137  case OCLASS_TYPE:
1138  RemoveTypeById(object->objectId);
1139  break;
1140 
1141  case OCLASS_CAST:
1142  DropCastById(object->objectId);
1143  break;
1144 
1145  case OCLASS_COLLATION:
1146  RemoveCollationById(object->objectId);
1147  break;
1148 
1149  case OCLASS_CONSTRAINT:
1150  RemoveConstraintById(object->objectId);
1151  break;
1152 
1153  case OCLASS_CONVERSION:
1154  RemoveConversionById(object->objectId);
1155  break;
1156 
1157  case OCLASS_DEFAULT:
1159  break;
1160 
1161  case OCLASS_LANGUAGE:
1163  break;
1164 
1165  case OCLASS_LARGEOBJECT:
1166  LargeObjectDrop(object->objectId);
1167  break;
1168 
1169  case OCLASS_OPERATOR:
1170  RemoveOperatorById(object->objectId);
1171  break;
1172 
1173  case OCLASS_OPCLASS:
1174  RemoveOpClassById(object->objectId);
1175  break;
1176 
1177  case OCLASS_OPFAMILY:
1178  RemoveOpFamilyById(object->objectId);
1179  break;
1180 
1181  case OCLASS_AM:
1183  break;
1184 
1185  case OCLASS_AMOP:
1186  RemoveAmOpEntryById(object->objectId);
1187  break;
1188 
1189  case OCLASS_AMPROC:
1191  break;
1192 
1193  case OCLASS_REWRITE:
1195  break;
1196 
1197  case OCLASS_TRIGGER:
1198  RemoveTriggerById(object->objectId);
1199  break;
1200 
1201  case OCLASS_SCHEMA:
1202  RemoveSchemaById(object->objectId);
1203  break;
1204 
1205  case OCLASS_TSPARSER:
1206  RemoveTSParserById(object->objectId);
1207  break;
1208 
1209  case OCLASS_TSDICT:
1211  break;
1212 
1213  case OCLASS_TSTEMPLATE:
1214  RemoveTSTemplateById(object->objectId);
1215  break;
1216 
1217  case OCLASS_TSCONFIG:
1219  break;
1220 
1221  /*
1222  * OCLASS_ROLE, OCLASS_DATABASE, OCLASS_TBLSPACE intentionally not
1223  * handled here
1224  */
1225 
1226  case OCLASS_FDW:
1228  break;
1229 
1230  case OCLASS_FOREIGN_SERVER:
1232  break;
1233 
1234  case OCLASS_USER_MAPPING:
1236  break;
1237 
1238  case OCLASS_DEFACL:
1239  RemoveDefaultACLById(object->objectId);
1240  break;
1241 
1242  case OCLASS_EXTENSION:
1243  RemoveExtensionById(object->objectId);
1244  break;
1245 
1246  case OCLASS_EVENT_TRIGGER:
1248  break;
1249 
1250  case OCLASS_POLICY:
1251  RemovePolicyById(object->objectId);
1252  break;
1253 
1254  case OCLASS_PUBLICATION:
1256  break;
1257 
1260  break;
1261 
1262  case OCLASS_TRANSFORM:
1263  DropTransformById(object->objectId);
1264  break;
1265 
1266  default:
1267  elog(ERROR, "unrecognized object class: %u",
1268  object->classId);
1269  }
1270 }
1271 
1272 /*
1273  * AcquireDeletionLock - acquire a suitable lock for deleting an object
1274  *
1275  * We use LockRelation for relations, LockDatabaseObject for everything
1276  * else. Note that dependency.c is not concerned with deleting any kind of
1277  * shared-across-databases object, so we have no need for LockSharedObject.
1278  */
1279 static void
1281 {
1282  if (object->classId == RelationRelationId)
1283  {
1284  /*
1285  * In DROP INDEX CONCURRENTLY, take only ShareUpdateExclusiveLock on
1286  * the index for the moment. index_drop() will promote the lock once
1287  * it's safe to do so. In all other cases we need full exclusive
1288  * lock.
1289  */
1290  if (flags & PERFORM_DELETION_CONCURRENTLY)
1292  else
1294  }
1295  else
1296  {
1297  /* assume we should lock the whole object not a sub-object */
1298  LockDatabaseObject(object->classId, object->objectId, 0,
1300  }
1301 }
1302 
1303 /*
1304  * ReleaseDeletionLock - release an object deletion lock
1305  */
1306 static void
1308 {
1309  if (object->classId == RelationRelationId)
1311  else
1312  /* assume we should lock the whole object not a sub-object */
1313  UnlockDatabaseObject(object->classId, object->objectId, 0,
1315 }
1316 
1317 /*
1318  * recordDependencyOnExpr - find expression dependencies
1319  *
1320  * This is used to find the dependencies of rules, constraint expressions,
1321  * etc.
1322  *
1323  * Given an expression or query in node-tree form, find all the objects
1324  * it refers to (tables, columns, operators, functions, etc). Record
1325  * a dependency of the specified type from the given depender object
1326  * to each object mentioned in the expression.
1327  *
1328  * rtable is the rangetable to be used to interpret Vars with varlevelsup=0.
1329  * It can be NIL if no such variables are expected.
1330  */
1331 void
1333  Node *expr, List *rtable,
1334  DependencyType behavior)
1335 {
1337 
1338  context.addrs = new_object_addresses();
1339 
1340  /* Set up interpretation for Vars at varlevelsup = 0 */
1341  context.rtables = list_make1(rtable);
1342 
1343  /* Scan the expression tree for referenceable objects */
1344  find_expr_references_walker(expr, &context);
1345 
1346  /* Remove any duplicates */
1348 
1349  /* And record 'em */
1350  recordMultipleDependencies(depender,
1351  context.addrs->refs, context.addrs->numrefs,
1352  behavior);
1353 
1354  free_object_addresses(context.addrs);
1355 }
1356 
1357 /*
1358  * recordDependencyOnSingleRelExpr - find expression dependencies
1359  *
1360  * As above, but only one relation is expected to be referenced (with
1361  * varno = 1 and varlevelsup = 0). Pass the relation OID instead of a
1362  * range table. An additional frammish is that dependencies on that
1363  * relation (or its component columns) will be marked with 'self_behavior',
1364  * whereas 'behavior' is used for everything else.
1365  *
1366  * NOTE: the caller should ensure that a whole-table dependency on the
1367  * specified relation is created separately, if one is needed. In particular,
1368  * a whole-row Var "relation.*" will not cause this routine to emit any
1369  * dependency item. This is appropriate behavior for subexpressions of an
1370  * ordinary query, so other cases need to cope as necessary.
1371  */
1372 void
1374  Node *expr, Oid relId,
1375  DependencyType behavior,
1376  DependencyType self_behavior,
1377  bool ignore_self)
1378 {
1380  RangeTblEntry rte;
1381 
1382  context.addrs = new_object_addresses();
1383 
1384  /* We gin up a rather bogus rangetable list to handle Vars */
1385  MemSet(&rte, 0, sizeof(rte));
1386  rte.type = T_RangeTblEntry;
1387  rte.rtekind = RTE_RELATION;
1388  rte.relid = relId;
1389  rte.relkind = RELKIND_RELATION; /* no need for exactness here */
1390 
1391  context.rtables = list_make1(list_make1(&rte));
1392 
1393  /* Scan the expression tree for referenceable objects */
1394  find_expr_references_walker(expr, &context);
1395 
1396  /* Remove any duplicates */
1398 
1399  /* Separate self-dependencies if necessary */
1400  if (behavior != self_behavior && context.addrs->numrefs > 0)
1401  {
1402  ObjectAddresses *self_addrs;
1403  ObjectAddress *outobj;
1404  int oldref,
1405  outrefs;
1406 
1407  self_addrs = new_object_addresses();
1408 
1409  outobj = context.addrs->refs;
1410  outrefs = 0;
1411  for (oldref = 0; oldref < context.addrs->numrefs; oldref++)
1412  {
1413  ObjectAddress *thisobj = context.addrs->refs + oldref;
1414 
1415  if (thisobj->classId == RelationRelationId &&
1416  thisobj->objectId == relId)
1417  {
1418  /* Move this ref into self_addrs */
1419  add_exact_object_address(thisobj, self_addrs);
1420  }
1421  else
1422  {
1423  /* Keep it in context.addrs */
1424  *outobj = *thisobj;
1425  outobj++;
1426  outrefs++;
1427  }
1428  }
1429  context.addrs->numrefs = outrefs;
1430 
1431  /* Record the self-dependencies */
1432  if (!ignore_self)
1433  recordMultipleDependencies(depender,
1434  self_addrs->refs, self_addrs->numrefs,
1435  self_behavior);
1436 
1437  free_object_addresses(self_addrs);
1438  }
1439 
1440  /* Record the external dependencies */
1441  recordMultipleDependencies(depender,
1442  context.addrs->refs, context.addrs->numrefs,
1443  behavior);
1444 
1445  free_object_addresses(context.addrs);
1446 }
1447 
1448 /*
1449  * Recursively search an expression tree for object references.
1450  *
1451  * Note: we avoid creating references to columns of tables that participate
1452  * in an SQL JOIN construct, but are not actually used anywhere in the query.
1453  * To do so, we do not scan the joinaliasvars list of a join RTE while
1454  * scanning the query rangetable, but instead scan each individual entry
1455  * of the alias list when we find a reference to it.
1456  *
1457  * Note: in many cases we do not need to create dependencies on the datatypes
1458  * involved in an expression, because we'll have an indirect dependency via
1459  * some other object. For instance Var nodes depend on a column which depends
1460  * on the datatype, and OpExpr nodes depend on the operator which depends on
1461  * the datatype. However we do need a type dependency if there is no such
1462  * indirect dependency, as for example in Const and CoerceToDomain nodes.
1463  *
1464  * Similarly, we don't need to create dependencies on collations except where
1465  * the collation is being freshly introduced to the expression.
1466  */
1467 static bool
1470 {
1471  if (node == NULL)
1472  return false;
1473  if (IsA(node, Var))
1474  {
1475  Var *var = (Var *) node;
1476  List *rtable;
1477  RangeTblEntry *rte;
1478 
1479  /* Find matching rtable entry, or complain if not found */
1480  if (var->varlevelsup >= list_length(context->rtables))
1481  elog(ERROR, "invalid varlevelsup %d", var->varlevelsup);
1482  rtable = (List *) list_nth(context->rtables, var->varlevelsup);
1483  if (var->varno <= 0 || var->varno > list_length(rtable))
1484  elog(ERROR, "invalid varno %d", var->varno);
1485  rte = rt_fetch(var->varno, rtable);
1486 
1487  /*
1488  * A whole-row Var references no specific columns, so adds no new
1489  * dependency. (We assume that there is a whole-table dependency
1490  * arising from each underlying rangetable entry. While we could
1491  * record such a dependency when finding a whole-row Var that
1492  * references a relation directly, it's quite unclear how to extend
1493  * that to whole-row Vars for JOINs, so it seems better to leave the
1494  * responsibility with the range table. Note that this poses some
1495  * risks for identifying dependencies of stand-alone expressions:
1496  * whole-table references may need to be created separately.)
1497  */
1498  if (var->varattno == InvalidAttrNumber)
1499  return false;
1500  if (rte->rtekind == RTE_RELATION)
1501  {
1502  /* If it's a plain relation, reference this column */
1504  context->addrs);
1505  }
1506  else if (rte->rtekind == RTE_JOIN)
1507  {
1508  /* Scan join output column to add references to join inputs */
1509  List *save_rtables;
1510 
1511  /* We must make the context appropriate for join's level */
1512  save_rtables = context->rtables;
1513  context->rtables = list_copy_tail(context->rtables,
1514  var->varlevelsup);
1515  if (var->varattno <= 0 ||
1516  var->varattno > list_length(rte->joinaliasvars))
1517  elog(ERROR, "invalid varattno %d", var->varattno);
1519  var->varattno - 1),
1520  context);
1521  list_free(context->rtables);
1522  context->rtables = save_rtables;
1523  }
1524  return false;
1525  }
1526  else if (IsA(node, Const))
1527  {
1528  Const *con = (Const *) node;
1529  Oid objoid;
1530 
1531  /* A constant must depend on the constant's datatype */
1533  context->addrs);
1534 
1535  /*
1536  * We must also depend on the constant's collation: it could be
1537  * different from the datatype's, if a CollateExpr was const-folded to
1538  * a simple constant. However we can save work in the most common
1539  * case where the collation is "default", since we know that's pinned.
1540  */
1541  if (OidIsValid(con->constcollid) &&
1544  context->addrs);
1545 
1546  /*
1547  * If it's a regclass or similar literal referring to an existing
1548  * object, add a reference to that object. (Currently, only the
1549  * regclass and regconfig cases have any likely use, but we may as
1550  * well handle all the OID-alias datatypes consistently.)
1551  */
1552  if (!con->constisnull)
1553  {
1554  switch (con->consttype)
1555  {
1556  case REGPROCOID:
1557  case REGPROCEDUREOID:
1558  objoid = DatumGetObjectId(con->constvalue);
1560  ObjectIdGetDatum(objoid)))
1561  add_object_address(OCLASS_PROC, objoid, 0,
1562  context->addrs);
1563  break;
1564  case REGOPEROID:
1565  case REGOPERATOROID:
1566  objoid = DatumGetObjectId(con->constvalue);
1568  ObjectIdGetDatum(objoid)))
1570  context->addrs);
1571  break;
1572  case REGCLASSOID:
1573  objoid = DatumGetObjectId(con->constvalue);
1575  ObjectIdGetDatum(objoid)))
1576  add_object_address(OCLASS_CLASS, objoid, 0,
1577  context->addrs);
1578  break;
1579  case REGTYPEOID:
1580  objoid = DatumGetObjectId(con->constvalue);
1582  ObjectIdGetDatum(objoid)))
1583  add_object_address(OCLASS_TYPE, objoid, 0,
1584  context->addrs);
1585  break;
1586  case REGCONFIGOID:
1587  objoid = DatumGetObjectId(con->constvalue);
1589  ObjectIdGetDatum(objoid)))
1591  context->addrs);
1592  break;
1593  case REGDICTIONARYOID:
1594  objoid = DatumGetObjectId(con->constvalue);
1596  ObjectIdGetDatum(objoid)))
1597  add_object_address(OCLASS_TSDICT, objoid, 0,
1598  context->addrs);
1599  break;
1600 
1601  case REGNAMESPACEOID:
1602  objoid = DatumGetObjectId(con->constvalue);
1604  ObjectIdGetDatum(objoid)))
1605  add_object_address(OCLASS_SCHEMA, objoid, 0,
1606  context->addrs);
1607  break;
1608 
1609  /*
1610  * Dependencies for regrole should be shared among all
1611  * databases, so explicitly inhibit to have dependencies.
1612  */
1613  case REGROLEOID:
1614  ereport(ERROR,
1615  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1616  errmsg("constant of the type %s cannot be used here",
1617  "regrole")));
1618  break;
1619  }
1620  }
1621  return false;
1622  }
1623  else if (IsA(node, Param))
1624  {
1625  Param *param = (Param *) node;
1626 
1627  /* A parameter must depend on the parameter's datatype */
1629  context->addrs);
1630  /* and its collation, just as for Consts */
1631  if (OidIsValid(param->paramcollid) &&
1634  context->addrs);
1635  }
1636  else if (IsA(node, FuncExpr))
1637  {
1638  FuncExpr *funcexpr = (FuncExpr *) node;
1639 
1640  add_object_address(OCLASS_PROC, funcexpr->funcid, 0,
1641  context->addrs);
1642  /* fall through to examine arguments */
1643  }
1644  else if (IsA(node, OpExpr))
1645  {
1646  OpExpr *opexpr = (OpExpr *) node;
1647 
1649  context->addrs);
1650  /* fall through to examine arguments */
1651  }
1652  else if (IsA(node, DistinctExpr))
1653  {
1654  DistinctExpr *distinctexpr = (DistinctExpr *) node;
1655 
1656  add_object_address(OCLASS_OPERATOR, distinctexpr->opno, 0,
1657  context->addrs);
1658  /* fall through to examine arguments */
1659  }
1660  else if (IsA(node, NullIfExpr))
1661  {
1662  NullIfExpr *nullifexpr = (NullIfExpr *) node;
1663 
1664  add_object_address(OCLASS_OPERATOR, nullifexpr->opno, 0,
1665  context->addrs);
1666  /* fall through to examine arguments */
1667  }
1668  else if (IsA(node, ScalarArrayOpExpr))
1669  {
1670  ScalarArrayOpExpr *opexpr = (ScalarArrayOpExpr *) node;
1671 
1673  context->addrs);
1674  /* fall through to examine arguments */
1675  }
1676  else if (IsA(node, Aggref))
1677  {
1678  Aggref *aggref = (Aggref *) node;
1679 
1681  context->addrs);
1682  /* fall through to examine arguments */
1683  }
1684  else if (IsA(node, WindowFunc))
1685  {
1686  WindowFunc *wfunc = (WindowFunc *) node;
1687 
1689  context->addrs);
1690  /* fall through to examine arguments */
1691  }
1692  else if (IsA(node, SubPlan))
1693  {
1694  /* Extra work needed here if we ever need this case */
1695  elog(ERROR, "already-planned subqueries not supported");
1696  }
1697  else if (IsA(node, RelabelType))
1698  {
1699  RelabelType *relab = (RelabelType *) node;
1700 
1701  /* since there is no function dependency, need to depend on type */
1703  context->addrs);
1704  /* the collation might not be referenced anywhere else, either */
1705  if (OidIsValid(relab->resultcollid) &&
1708  context->addrs);
1709  }
1710  else if (IsA(node, CoerceViaIO))
1711  {
1712  CoerceViaIO *iocoerce = (CoerceViaIO *) node;
1713 
1714  /* since there is no exposed function, need to depend on type */
1716  context->addrs);
1717  }
1718  else if (IsA(node, ArrayCoerceExpr))
1719  {
1720  ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
1721 
1722  if (OidIsValid(acoerce->elemfuncid))
1724  context->addrs);
1726  context->addrs);
1727  /* fall through to examine arguments */
1728  }
1729  else if (IsA(node, ConvertRowtypeExpr))
1730  {
1731  ConvertRowtypeExpr *cvt = (ConvertRowtypeExpr *) node;
1732 
1733  /* since there is no function dependency, need to depend on type */
1735  context->addrs);
1736  }
1737  else if (IsA(node, CollateExpr))
1738  {
1739  CollateExpr *coll = (CollateExpr *) node;
1740 
1742  context->addrs);
1743  }
1744  else if (IsA(node, RowExpr))
1745  {
1746  RowExpr *rowexpr = (RowExpr *) node;
1747 
1749  context->addrs);
1750  }
1751  else if (IsA(node, RowCompareExpr))
1752  {
1753  RowCompareExpr *rcexpr = (RowCompareExpr *) node;
1754  ListCell *l;
1755 
1756  foreach(l, rcexpr->opnos)
1757  {
1759  context->addrs);
1760  }
1761  foreach(l, rcexpr->opfamilies)
1762  {
1764  context->addrs);
1765  }
1766  /* fall through to examine arguments */
1767  }
1768  else if (IsA(node, CoerceToDomain))
1769  {
1770  CoerceToDomain *cd = (CoerceToDomain *) node;
1771 
1773  context->addrs);
1774  }
1775  else if (IsA(node, OnConflictExpr))
1776  {
1777  OnConflictExpr *onconflict = (OnConflictExpr *) node;
1778 
1779  if (OidIsValid(onconflict->constraint))
1781  context->addrs);
1782  /* fall through to examine arguments */
1783  }
1784  else if (IsA(node, SortGroupClause))
1785  {
1786  SortGroupClause *sgc = (SortGroupClause *) node;
1787 
1789  context->addrs);
1790  if (OidIsValid(sgc->sortop))
1792  context->addrs);
1793  return false;
1794  }
1795  else if (IsA(node, Query))
1796  {
1797  /* Recurse into RTE subquery or not-yet-planned sublink subquery */
1798  Query *query = (Query *) node;
1799  ListCell *lc;
1800  bool result;
1801 
1802  /*
1803  * Add whole-relation refs for each plain relation mentioned in the
1804  * subquery's rtable.
1805  *
1806  * Note: query_tree_walker takes care of recursing into RTE_FUNCTION
1807  * RTEs, subqueries, etc, so no need to do that here. But keep it
1808  * from looking at join alias lists.
1809  *
1810  * Note: we don't need to worry about collations mentioned in
1811  * RTE_VALUES or RTE_CTE RTEs, because those must just duplicate
1812  * collations referenced in other parts of the Query. We do have to
1813  * worry about collations mentioned in RTE_FUNCTION, but we take care
1814  * of those when we recurse to the RangeTblFunction node(s).
1815  */
1816  foreach(lc, query->rtable)
1817  {
1818  RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc);
1819 
1820  switch (rte->rtekind)
1821  {
1822  case RTE_RELATION:
1824  context->addrs);
1825  break;
1826  default:
1827  break;
1828  }
1829  }
1830 
1831  /*
1832  * If the query is an INSERT or UPDATE, we should create a dependency
1833  * on each target column, to prevent the specific target column from
1834  * being dropped. Although we will visit the TargetEntry nodes again
1835  * during query_tree_walker, we won't have enough context to do this
1836  * conveniently, so do it here.
1837  */
1838  if (query->commandType == CMD_INSERT ||
1839  query->commandType == CMD_UPDATE)
1840  {
1841  RangeTblEntry *rte;
1842 
1843  if (query->resultRelation <= 0 ||
1844  query->resultRelation > list_length(query->rtable))
1845  elog(ERROR, "invalid resultRelation %d",
1846  query->resultRelation);
1847  rte = rt_fetch(query->resultRelation, query->rtable);
1848  if (rte->rtekind == RTE_RELATION)
1849  {
1850  foreach(lc, query->targetList)
1851  {
1852  TargetEntry *tle = (TargetEntry *) lfirst(lc);
1853 
1854  if (tle->resjunk)
1855  continue; /* ignore junk tlist items */
1857  context->addrs);
1858  }
1859  }
1860  }
1861 
1862  /*
1863  * Add dependencies on constraints listed in query's constraintDeps
1864  */
1865  foreach(lc, query->constraintDeps)
1866  {
1868  context->addrs);
1869  }
1870 
1871  /* query_tree_walker ignores ORDER BY etc, but we need those opers */
1872  find_expr_references_walker((Node *) query->sortClause, context);
1873  find_expr_references_walker((Node *) query->groupClause, context);
1874  find_expr_references_walker((Node *) query->windowClause, context);
1875  find_expr_references_walker((Node *) query->distinctClause, context);
1876 
1877  /* Examine substructure of query */
1878  context->rtables = lcons(query->rtable, context->rtables);
1879  result = query_tree_walker(query,
1881  (void *) context,
1883  context->rtables = list_delete_first(context->rtables);
1884  return result;
1885  }
1886  else if (IsA(node, SetOperationStmt))
1887  {
1888  SetOperationStmt *setop = (SetOperationStmt *) node;
1889 
1890  /* we need to look at the groupClauses for operator references */
1891  find_expr_references_walker((Node *) setop->groupClauses, context);
1892  /* fall through to examine child nodes */
1893  }
1894  else if (IsA(node, RangeTblFunction))
1895  {
1896  RangeTblFunction *rtfunc = (RangeTblFunction *) node;
1897  ListCell *ct;
1898 
1899  /*
1900  * Add refs for any datatypes and collations used in a column
1901  * definition list for a RECORD function. (For other cases, it should
1902  * be enough to depend on the function itself.)
1903  */
1904  foreach(ct, rtfunc->funccoltypes)
1905  {
1907  context->addrs);
1908  }
1909  foreach(ct, rtfunc->funccolcollations)
1910  {
1911  Oid collid = lfirst_oid(ct);
1912 
1913  if (OidIsValid(collid) && collid != DEFAULT_COLLATION_OID)
1915  context->addrs);
1916  }
1917  }
1918  else if (IsA(node, TableSampleClause))
1919  {
1920  TableSampleClause *tsc = (TableSampleClause *) node;
1921 
1923  context->addrs);
1924  /* fall through to examine arguments */
1925  }
1926 
1928  (void *) context);
1929 }
1930 
1931 /*
1932  * Given an array of dependency references, eliminate any duplicates.
1933  */
1934 static void
1936 {
1937  ObjectAddress *priorobj;
1938  int oldref,
1939  newrefs;
1940 
1941  /*
1942  * We can't sort if the array has "extra" data, because there's no way to
1943  * keep it in sync. Fortunately that combination of features is not
1944  * needed.
1945  */
1946  Assert(!addrs->extras);
1947 
1948  if (addrs->numrefs <= 1)
1949  return; /* nothing to do */
1950 
1951  /* Sort the refs so that duplicates are adjacent */
1952  qsort((void *) addrs->refs, addrs->numrefs, sizeof(ObjectAddress),
1954 
1955  /* Remove dups */
1956  priorobj = addrs->refs;
1957  newrefs = 1;
1958  for (oldref = 1; oldref < addrs->numrefs; oldref++)
1959  {
1960  ObjectAddress *thisobj = addrs->refs + oldref;
1961 
1962  if (priorobj->classId == thisobj->classId &&
1963  priorobj->objectId == thisobj->objectId)
1964  {
1965  if (priorobj->objectSubId == thisobj->objectSubId)
1966  continue; /* identical, so drop thisobj */
1967 
1968  /*
1969  * If we have a whole-object reference and a reference to a part
1970  * of the same object, we don't need the whole-object reference
1971  * (for example, we don't need to reference both table foo and
1972  * column foo.bar). The whole-object reference will always appear
1973  * first in the sorted list.
1974  */
1975  if (priorobj->objectSubId == 0)
1976  {
1977  /* replace whole ref with partial */
1978  priorobj->objectSubId = thisobj->objectSubId;
1979  continue;
1980  }
1981  }
1982  /* Not identical, so add thisobj to output set */
1983  priorobj++;
1984  *priorobj = *thisobj;
1985  newrefs++;
1986  }
1987 
1988  addrs->numrefs = newrefs;
1989 }
1990 
1991 /*
1992  * qsort comparator for ObjectAddress items
1993  */
1994 static int
1995 object_address_comparator(const void *a, const void *b)
1996 {
1997  const ObjectAddress *obja = (const ObjectAddress *) a;
1998  const ObjectAddress *objb = (const ObjectAddress *) b;
1999 
2000  if (obja->classId < objb->classId)
2001  return -1;
2002  if (obja->classId > objb->classId)
2003  return 1;
2004  if (obja->objectId < objb->objectId)
2005  return -1;
2006  if (obja->objectId > objb->objectId)
2007  return 1;
2008 
2009  /*
2010  * We sort the subId as an unsigned int so that 0 will come first. See
2011  * logic in eliminate_duplicate_dependencies.
2012  */
2013  if ((unsigned int) obja->objectSubId < (unsigned int) objb->objectSubId)
2014  return -1;
2015  if ((unsigned int) obja->objectSubId > (unsigned int) objb->objectSubId)
2016  return 1;
2017  return 0;
2018 }
2019 
2020 /*
2021  * Routines for handling an expansible array of ObjectAddress items.
2022  *
2023  * new_object_addresses: create a new ObjectAddresses array.
2024  */
2027 {
2028  ObjectAddresses *addrs;
2029 
2030  addrs = palloc(sizeof(ObjectAddresses));
2031 
2032  addrs->numrefs = 0;
2033  addrs->maxrefs = 32;
2034  addrs->refs = (ObjectAddress *)
2035  palloc(addrs->maxrefs * sizeof(ObjectAddress));
2036  addrs->extras = NULL; /* until/unless needed */
2037 
2038  return addrs;
2039 }
2040 
2041 /*
2042  * Add an entry to an ObjectAddresses array.
2043  *
2044  * It is convenient to specify the class by ObjectClass rather than directly
2045  * by catalog OID.
2046  */
2047 static void
2048 add_object_address(ObjectClass oclass, Oid objectId, int32 subId,
2049  ObjectAddresses *addrs)
2050 {
2051  ObjectAddress *item;
2052 
2053  /*
2054  * Make sure object_classes is kept up to date with the ObjectClass enum.
2055  */
2057  "object_classes[] must cover all ObjectClasses");
2058 
2059  /* enlarge array if needed */
2060  if (addrs->numrefs >= addrs->maxrefs)
2061  {
2062  addrs->maxrefs *= 2;
2063  addrs->refs = (ObjectAddress *)
2064  repalloc(addrs->refs, addrs->maxrefs * sizeof(ObjectAddress));
2065  Assert(!addrs->extras);
2066  }
2067  /* record this item */
2068  item = addrs->refs + addrs->numrefs;
2069  item->classId = object_classes[oclass];
2070  item->objectId = objectId;
2071  item->objectSubId = subId;
2072  addrs->numrefs++;
2073 }
2074 
2075 /*
2076  * Add an entry to an ObjectAddresses array.
2077  *
2078  * As above, but specify entry exactly.
2079  */
2080 void
2082  ObjectAddresses *addrs)
2083 {
2084  ObjectAddress *item;
2085 
2086  /* enlarge array if needed */
2087  if (addrs->numrefs >= addrs->maxrefs)
2088  {
2089  addrs->maxrefs *= 2;
2090  addrs->refs = (ObjectAddress *)
2091  repalloc(addrs->refs, addrs->maxrefs * sizeof(ObjectAddress));
2092  Assert(!addrs->extras);
2093  }
2094  /* record this item */
2095  item = addrs->refs + addrs->numrefs;
2096  *item = *object;
2097  addrs->numrefs++;
2098 }
2099 
2100 /*
2101  * Add an entry to an ObjectAddresses array.
2102  *
2103  * As above, but specify entry exactly and provide some "extra" data too.
2104  */
2105 static void
2107  const ObjectAddressExtra *extra,
2108  ObjectAddresses *addrs)
2109 {
2110  ObjectAddress *item;
2111  ObjectAddressExtra *itemextra;
2112 
2113  /* allocate extra space if first time */
2114  if (!addrs->extras)
2115  addrs->extras = (ObjectAddressExtra *)
2116  palloc(addrs->maxrefs * sizeof(ObjectAddressExtra));
2117 
2118  /* enlarge array if needed */
2119  if (addrs->numrefs >= addrs->maxrefs)
2120  {
2121  addrs->maxrefs *= 2;
2122  addrs->refs = (ObjectAddress *)
2123  repalloc(addrs->refs, addrs->maxrefs * sizeof(ObjectAddress));
2124  addrs->extras = (ObjectAddressExtra *)
2125  repalloc(addrs->extras, addrs->maxrefs * sizeof(ObjectAddressExtra));
2126  }
2127  /* record this item */
2128  item = addrs->refs + addrs->numrefs;
2129  *item = *object;
2130  itemextra = addrs->extras + addrs->numrefs;
2131  *itemextra = *extra;
2132  addrs->numrefs++;
2133 }
2134 
2135 /*
2136  * Test whether an object is present in an ObjectAddresses array.
2137  *
2138  * We return "true" if object is a subobject of something in the array, too.
2139  */
2140 bool
2142  const ObjectAddresses *addrs)
2143 {
2144  int i;
2145 
2146  for (i = addrs->numrefs - 1; i >= 0; i--)
2147  {
2148  const ObjectAddress *thisobj = addrs->refs + i;
2149 
2150  if (object->classId == thisobj->classId &&
2151  object->objectId == thisobj->objectId)
2152  {
2153  if (object->objectSubId == thisobj->objectSubId ||
2154  thisobj->objectSubId == 0)
2155  return true;
2156  }
2157  }
2158 
2159  return false;
2160 }
2161 
2162 /*
2163  * As above, except that if the object is present then also OR the given
2164  * flags into its associated extra data (which must exist).
2165  */
2166 static bool
2168  int flags,
2169  ObjectAddresses *addrs)
2170 {
2171  bool result = false;
2172  int i;
2173 
2174  for (i = addrs->numrefs - 1; i >= 0; i--)
2175  {
2176  ObjectAddress *thisobj = addrs->refs + i;
2177 
2178  if (object->classId == thisobj->classId &&
2179  object->objectId == thisobj->objectId)
2180  {
2181  if (object->objectSubId == thisobj->objectSubId)
2182  {
2183  ObjectAddressExtra *thisextra = addrs->extras + i;
2184 
2185  thisextra->flags |= flags;
2186  result = true;
2187  }
2188  else if (thisobj->objectSubId == 0)
2189  {
2190  /*
2191  * We get here if we find a need to delete a column after
2192  * having already decided to drop its whole table. Obviously
2193  * we no longer need to drop the subobject, so report that we
2194  * found the subobject in the array. But don't plaster its
2195  * flags on the whole object.
2196  */
2197  result = true;
2198  }
2199  else if (object->objectSubId == 0)
2200  {
2201  /*
2202  * We get here if we find a need to delete a whole table after
2203  * having already decided to drop one of its columns. We
2204  * can't report that the whole object is in the array, but we
2205  * should mark the subobject with the whole object's flags.
2206  *
2207  * It might seem attractive to physically delete the column's
2208  * array entry, or at least mark it as no longer needing
2209  * separate deletion. But that could lead to, e.g., dropping
2210  * the column's datatype before we drop the table, which does
2211  * not seem like a good idea. This is a very rare situation
2212  * in practice, so we just take the hit of doing a separate
2213  * DROP COLUMN action even though we know we're gonna delete
2214  * the table later.
2215  *
2216  * Because there could be other subobjects of this object in
2217  * the array, this case means we always have to loop through
2218  * the whole array; we cannot exit early on a match.
2219  */
2220  ObjectAddressExtra *thisextra = addrs->extras + i;
2221 
2222  thisextra->flags |= flags;
2223  }
2224  }
2225  }
2226 
2227  return result;
2228 }
2229 
2230 /*
2231  * Similar to above, except we search an ObjectAddressStack.
2232  */
2233 static bool
2235  int flags,
2236  ObjectAddressStack *stack)
2237 {
2238  bool result = false;
2239  ObjectAddressStack *stackptr;
2240 
2241  for (stackptr = stack; stackptr; stackptr = stackptr->next)
2242  {
2243  const ObjectAddress *thisobj = stackptr->object;
2244 
2245  if (object->classId == thisobj->classId &&
2246  object->objectId == thisobj->objectId)
2247  {
2248  if (object->objectSubId == thisobj->objectSubId)
2249  {
2250  stackptr->flags |= flags;
2251  result = true;
2252  }
2253  else if (thisobj->objectSubId == 0)
2254  {
2255  /*
2256  * We're visiting a column with whole table already on stack.
2257  * As in object_address_present_add_flags(), we can skip
2258  * further processing of the subobject, but we don't want to
2259  * propagate flags for the subobject to the whole object.
2260  */
2261  result = true;
2262  }
2263  else if (object->objectSubId == 0)
2264  {
2265  /*
2266  * We're visiting a table with column already on stack. As in
2267  * object_address_present_add_flags(), we should propagate
2268  * flags for the whole object to each of its subobjects.
2269  */
2270  stackptr->flags |= flags;
2271  }
2272  }
2273  }
2274 
2275  return result;
2276 }
2277 
2278 /*
2279  * Record multiple dependencies from an ObjectAddresses array, after first
2280  * removing any duplicates.
2281  */
2282 void
2284  ObjectAddresses *referenced,
2285  DependencyType behavior)
2286 {
2288  recordMultipleDependencies(depender,
2289  referenced->refs, referenced->numrefs,
2290  behavior);
2291 }
2292 
2293 /*
2294  * Clean up when done with an ObjectAddresses array.
2295  */
2296 void
2298 {
2299  pfree(addrs->refs);
2300  if (addrs->extras)
2301  pfree(addrs->extras);
2302  pfree(addrs);
2303 }
2304 
2305 /*
2306  * Determine the class of a given object identified by objectAddress.
2307  *
2308  * This function is essentially the reverse mapping for the object_classes[]
2309  * table. We implement it as a function because the OIDs aren't consecutive.
2310  */
2313 {
2314  /* only pg_class entries can have nonzero objectSubId */
2315  if (object->classId != RelationRelationId &&
2316  object->objectSubId != 0)
2317  elog(ERROR, "invalid non-zero objectSubId for object class %u",
2318  object->classId);
2319 
2320  switch (object->classId)
2321  {
2322  case RelationRelationId:
2323  /* caller must check objectSubId */
2324  return OCLASS_CLASS;
2325 
2326  case ProcedureRelationId:
2327  return OCLASS_PROC;
2328 
2329  case TypeRelationId:
2330  return OCLASS_TYPE;
2331 
2332  case CastRelationId:
2333  return OCLASS_CAST;
2334 
2335  case CollationRelationId:
2336  return OCLASS_COLLATION;
2337 
2338  case ConstraintRelationId:
2339  return OCLASS_CONSTRAINT;
2340 
2341  case ConversionRelationId:
2342  return OCLASS_CONVERSION;
2343 
2344  case AttrDefaultRelationId:
2345  return OCLASS_DEFAULT;
2346 
2347  case LanguageRelationId:
2348  return OCLASS_LANGUAGE;
2349 
2350  case LargeObjectRelationId:
2351  return OCLASS_LARGEOBJECT;
2352 
2353  case OperatorRelationId:
2354  return OCLASS_OPERATOR;
2355 
2357  return OCLASS_OPCLASS;
2358 
2360  return OCLASS_OPFAMILY;
2361 
2363  return OCLASS_AM;
2364 
2366  return OCLASS_AMOP;
2367 
2369  return OCLASS_AMPROC;
2370 
2371  case RewriteRelationId:
2372  return OCLASS_REWRITE;
2373 
2374  case TriggerRelationId:
2375  return OCLASS_TRIGGER;
2376 
2377  case NamespaceRelationId:
2378  return OCLASS_SCHEMA;
2379 
2380  case TSParserRelationId:
2381  return OCLASS_TSPARSER;
2382 
2384  return OCLASS_TSDICT;
2385 
2386  case TSTemplateRelationId:
2387  return OCLASS_TSTEMPLATE;
2388 
2389  case TSConfigRelationId:
2390  return OCLASS_TSCONFIG;
2391 
2392  case AuthIdRelationId:
2393  return OCLASS_ROLE;
2394 
2395  case DatabaseRelationId:
2396  return OCLASS_DATABASE;
2397 
2398  case TableSpaceRelationId:
2399  return OCLASS_TBLSPACE;
2400 
2402  return OCLASS_FDW;
2403 
2405  return OCLASS_FOREIGN_SERVER;
2406 
2407  case UserMappingRelationId:
2408  return OCLASS_USER_MAPPING;
2409 
2410  case DefaultAclRelationId:
2411  return OCLASS_DEFACL;
2412 
2413  case ExtensionRelationId:
2414  return OCLASS_EXTENSION;
2415 
2417  return OCLASS_EVENT_TRIGGER;
2418 
2419  case PolicyRelationId:
2420  return OCLASS_POLICY;
2421 
2422  case PublicationRelationId:
2423  return OCLASS_PUBLICATION;
2424 
2426  return OCLASS_PUBLICATION_REL;
2427 
2429  return OCLASS_SUBSCRIPTION;
2430 
2431  case TransformRelationId:
2432  return OCLASS_TRANSFORM;
2433  }
2434 
2435  /* shouldn't get here */
2436  elog(ERROR, "unrecognized object class: %u", object->classId);
2437  return OCLASS_CLASS; /* keep compiler quiet */
2438 }
2439 
2440 /*
2441  * delete initial ACL for extension objects
2442  */
2443 static void
2445 {
2446  Relation relation;
2447  ScanKeyData key[3];
2448  SysScanDesc scan;
2449  HeapTuple oldtuple;
2450 
2452 
2453  ScanKeyInit(&key[0],
2455  BTEqualStrategyNumber, F_OIDEQ,
2456  ObjectIdGetDatum(object->objectId));
2457  ScanKeyInit(&key[1],
2459  BTEqualStrategyNumber, F_OIDEQ,
2460  ObjectIdGetDatum(object->classId));
2461  ScanKeyInit(&key[2],
2463  BTEqualStrategyNumber, F_INT4EQ,
2464  Int32GetDatum(object->objectSubId));
2465 
2466  scan = systable_beginscan(relation, InitPrivsObjIndexId, true,
2467  NULL, 3, key);
2468 
2469  while (HeapTupleIsValid(oldtuple = systable_getnext(scan)))
2470  CatalogTupleDelete(relation, &oldtuple->t_self);
2471 
2472  systable_endscan(scan);
2473 
2474  heap_close(relation, RowExclusiveLock);
2475 }
Datum constvalue
Definition: primnodes.h:174
static void findDependentObjects(const ObjectAddress *object, int objflags, int flags, ObjectAddressStack *stack, ObjectAddresses *targetObjects, const ObjectAddresses *pendingObjects, Relation *depRel)
Definition: dependency.c:460
void RemoveTriggerById(Oid trigOid)
Definition: trigger.c:1190
Oid CurrentExtensionObject
Definition: extension.c:68
static void ReleaseDeletionLock(const ObjectAddress *object)
Definition: dependency.c:1307
DependencyType
Definition: dependency.h:73
bool query_tree_walker(Query *query, bool(*walker)(), void *context, int flags)
Definition: nodeFuncs.c:2244
#define REGCLASSOID
Definition: pg_type.h:565
#define Anum_pg_depend_refobjid
Definition: pg_depend.h:72
#define NamespaceRelationId
Definition: pg_namespace.h:34
static int object_address_comparator(const void *a, const void *b)
Definition: dependency.c:1995
#define IsA(nodeptr, _type_)
Definition: nodes.h:559
#define Anum_pg_depend_refobjsubid
Definition: pg_depend.h:73
#define OperatorRelationId
Definition: pg_operator.h:32
List * joinaliasvars
Definition: parsenodes.h:921
Index varlevelsup
Definition: primnodes.h:151
int errhint(const char *fmt,...)
Definition: elog.c:987
#define Anum_pg_depend_refclassid
Definition: pg_depend.h:71
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
List * sortClause
Definition: parsenodes.h:147
static void add_exact_object_address_extra(const ObjectAddress *object, const ObjectAddressExtra *extra, ObjectAddresses *addrs)
Definition: dependency.c:2106
static bool find_expr_references_walker(Node *node, find_expr_references_context *context)
Definition: dependency.c:1468
static void deleteOneObject(const ObjectAddress *object, Relation *depRel, int32 flags)
#define TransformRelationId
Definition: pg_transform.h:25
#define REGROLEOID
Definition: pg_type.h:573
void RemoveOpClassById(Oid opclassOid)
Definition: opclasscmds.c:1582
void DropTransformById(Oid transformOid)
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:850
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:182
bool trackDroppedObjectsNeeded(void)
void RemoveExtensionById(Oid extId)
Definition: extension.c:1820
#define ProcedureRelationId
Definition: pg_proc.h:33
ObjectAddresses * addrs
Definition: dependency.c:129
List * constraintDeps
Definition: parsenodes.h:157
void DropProceduralLanguageById(Oid langOid)
Definition: proclang.c:528
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1769
void RemoveForeignDataWrapperById(Oid fdwId)
Definition: foreigncmds.c:837
#define DatumGetObjectId(X)
Definition: postgres.h:508
#define DatabaseRelationId
Definition: pg_database.h:29
#define RelationRelationId
Definition: pg_class.h:29
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
Definition: dependency.c:2283
bool object_address_present(const ObjectAddress *object, const ObjectAddresses *addrs)
Definition: dependency.c:2141
#define DependReferenceIndexId
Definition: indexing.h:147
Oid resulttype
Definition: primnodes.h:788
#define Anum_pg_init_privs_classoid
Definition: pg_init_privs.h:70
List * opfamilies
Definition: primnodes.h:1009
#define DependDependerIndexId
Definition: indexing.h:145
#define PERFORM_DELETION_SKIP_ORIGINAL
Definition: dependency.h:176
#define DependRelationId
Definition: pg_depend.h:29
int resultRelation
Definition: parsenodes.h:113
void DeleteSecurityLabel(const ObjectAddress *object)
Definition: seclabel.c:446
#define LAST_OCLASS
Definition: dependency.h:170
#define OperatorClassRelationId
Definition: pg_opclass.h:49
void RemoveSchemaById(Oid schemaOid)
Definition: schemacmds.c:217
Definition: nodes.h:508
#define OperatorFamilyRelationId
Definition: pg_opfamily.h:29
void index_drop(Oid indexId, bool concurrent)
Definition: index.c:1344
int errcode(int sqlerrcode)
Definition: elog.c:575
#define MemSet(start, val, len)
Definition: c.h:852
AttrNumber varattno
Definition: primnodes.h:146
#define PublicationRelationId
void RemovePublicationById(Oid pubid)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:255
void RemovePublicationRelById(Oid proid)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
Definition: dependency.c:2081
#define heap_close(r, l)
Definition: heapam.h:97
#define lengthof(array)
Definition: c.h:557
#define DEPFLAG_REVERSE
Definition: dependency.c:104
ObjectAddresses * new_object_addresses(void)
Definition: dependency.c:2026
List * list_copy_tail(const List *oldlist, int nskip)
Definition: list.c:1203
void RemoveAmProcEntryById(Oid entryOid)
Definition: opclasscmds.c:1630
#define LOG
Definition: elog.h:26
void free_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2297
unsigned int Oid
Definition: postgres_ext.h:31
#define REGTYPEOID
Definition: pg_type.h:569
Definition: primnodes.h:141
#define InitPrivsObjIndexId
Definition: indexing.h:172
#define TypeRelationId
Definition: pg_type.h:34
void RemoveTypeById(Oid typeOid)
Definition: typecmds.c:689
#define REGOPEROID
Definition: pg_type.h:557
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2312
#define OidIsValid(objectId)
Definition: c.h:533
void RemoveCollationById(Oid collationOid)
Definition: pg_collation.c:174
void RemoveUserMappingById(Oid umId)
Definition: foreigncmds.c:1394
struct ObjectAddressStack * next
Definition: dependency.c:123
static void eliminate_duplicate_dependencies(ObjectAddresses *addrs)
Definition: dependency.c:1935
void RemoveConversionById(Oid conversionOid)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
void RemoveAccessMethodById(Oid amOid)
Definition: amcmds.c:115
#define DefaultAclRelationId
#define Anum_pg_depend_objsubid
Definition: pg_depend.h:70
char * getObjectDescription(const ObjectAddress *object)
#define AccessMethodOperatorRelationId
Definition: pg_amop.h:54
signed int int32
Definition: c.h:253
List * windowClause
Definition: parsenodes.h:143
List * targetList
Definition: parsenodes.h:131
bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup)
Definition: genam.c:448
void RemoveOperatorById(Oid operOid)
Definition: operatorcmds.c:340
#define PublicationRelRelationId
#define AuthIdRelationId
Definition: pg_authid.h:42
#define PERFORM_DELETION_CONCURRENTLY
Definition: dependency.h:174
#define list_make1(x1)
Definition: pg_list.h:133
Oid consttype
Definition: primnodes.h:170
#define TSConfigRelationId
Definition: pg_ts_config.h:31
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:752
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:167
void pfree(void *pointer)
Definition: mcxt.c:992
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:110
bool resjunk
Definition: primnodes.h:1337
void RemoveDefaultACLById(Oid defaclOid)
Definition: aclchk.c:1451
List * rtable
Definition: parsenodes.h:128
List * distinctClause
Definition: parsenodes.h:145
Oid funcid
Definition: primnodes.h:426
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
#define DEPFLAG_ORIGINAL
Definition: dependency.c:99
static const Oid object_classes[]
Definition: dependency.c:137
Oid paramcollid
Definition: primnodes.h:226
#define DEPFLAG_AUTO
Definition: dependency.c:101
#define TSDictionaryRelationId
Definition: pg_ts_dict.h:31
void RemoveTSConfigurationById(Oid cfgId)
Definition: tsearchcmds.c:1125
ItemPointerData t_self
Definition: htup.h:65
const ObjectAddress * object
Definition: dependency.c:121
#define DEPFLAG_INTERNAL
Definition: dependency.c:102
Oid constcollid
Definition: primnodes.h:172
#define DEBUG2
Definition: elog.h:24
void RemoveOpFamilyById(Oid opfamilyOid)
Definition: opclasscmds.c:1563
void RemovePolicyById(Oid policy_id)
Definition: policy.c:350
#define SubscriptionRelationId
#define InitPrivsRelationId
Definition: pg_init_privs.h:42
void * list_nth(const List *list, int n)
Definition: list.c:410
#define Anum_pg_init_privs_objoid
Definition: pg_init_privs.h:69
static bool object_address_present_add_flags(const ObjectAddress *object, int flags, ObjectAddresses *addrs)
Definition: dependency.c:2167
#define AccessMethodRelationId
Definition: pg_am.h:32
struct ObjectAddressStack ObjectAddressStack
#define DEFAULT_COLLATION_OID
Definition: pg_collation.h:68
ObjectAddress * refs
Definition: dependency.c:110
ObjectClass
Definition: dependency.h:129
#define RowExclusiveLock
Definition: lockdefs.h:38
void RemoveTSParserById(Oid prsId)
Definition: tsearchcmds.c:292
int errdetail(const char *fmt,...)
Definition: elog.c:873
AttrNumber resno
Definition: primnodes.h:1331
void recordDependencyOnExpr(const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior)
Definition: dependency.c:1332
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:830
void RemoveAttributeById(Oid relid, AttrNumber attnum)
Definition: heap.c:1535
#define REGDICTIONARYOID
Definition: pg_type.h:615
void performDeletion(const ObjectAddress *object, DropBehavior behavior, int flags)
Definition: dependency.c:301
void RemoveTSTemplateById(Oid tmplId)
Definition: tsearchcmds.c:821
static void reportDependentObjects(const ObjectAddresses *targetObjects, DropBehavior behavior, int flags, const ObjectAddress *origObject)
Definition: dependency.c:826
int errdetail_log(const char *fmt,...)
Definition: elog.c:921
Oid winfnoid
Definition: primnodes.h:333
FormData_pg_depend * Form_pg_depend
Definition: pg_depend.h:61
void DeleteSequenceTuple(Oid relid)
Definition: sequence.c:516
void RemoveEventTriggerById(Oid trigOid)
void RemoveAttrDefaultById(Oid attrdefId)
Definition: heap.c:1677
#define ereport(elevel, rest)
Definition: elog.h:122
#define rt_fetch(rangetable_index, rangetable)
Definition: parsetree.h:31
void LargeObjectDrop(Oid loid)
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
Definition: pg_shdepend.c:822
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:851
bool EventTriggerSupportsObjectClass(ObjectClass objclass)
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:201
void initStringInfo(StringInfo str)
Definition: stringinfo.c:65
Index varno
Definition: primnodes.h:144
#define ngettext(s, p, n)
Definition: c.h:127
void RemoveAmOpEntryById(Oid entryOid)
Definition: opclasscmds.c:1601
DropBehavior
Definition: parsenodes.h:1588
static void AcquireDeletionLock(const ObjectAddress *object, int flags)
Definition: dependency.c:1280
void CommandCounterIncrement(void)
Definition: xact.c:921
void DeleteComments(Oid oid, Oid classoid, int32 subid)
Definition: comment.c:325
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define TSParserRelationId
Definition: pg_ts_parser.h:31
Oid resulttype
Definition: primnodes.h:768
#define CollationRelationId
Definition: pg_collation.h:30
int log_min_messages
Definition: guc.c:453
Oid resultcollid
Definition: primnodes.h:770
void RemoveForeignServerById(Oid srvId)
Definition: foreigncmds.c:1071
bool creating_extension
Definition: extension.c:67
Oid aggfnoid
Definition: primnodes.h:272
#define PolicyRelationId
Definition: pg_policy.h:19
#define RewriteRelationId
Definition: pg_rewrite.h:32
#define DEPFLAG_EXTENSION
Definition: dependency.c:103
#define NOTICE
Definition: elog.h:37
CmdType commandType
Definition: parsenodes.h:103
List * lcons(void *datum, List *list)
Definition: list.c:259
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827
#define Anum_pg_init_privs_objsubid
Definition: pg_init_privs.h:71
#define ForeignServerRelationId
List * funccolcollations
Definition: parsenodes.h:999
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
void recordMultipleDependencies(const ObjectAddress *depender, const ObjectAddress *referenced, int nreferenced, DependencyType behavior)
Definition: pg_depend.c:56
#define PERFORM_DELETION_QUIETLY
Definition: dependency.h:175
#define EventTriggerRelationId
#define TriggerRelationId
Definition: pg_trigger.h:34
bool expression_tree_walker(Node *node, bool(*walker)(), void *context)
Definition: nodeFuncs.c:1857
Oid row_typeid
Definition: primnodes.h:963
static int list_length(const List *l)
Definition: pg_list.h:89
#define CastRelationId
Definition: pg_cast.h:31
void EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool normal)
#define ForeignDataWrapperRelationId
static void doDeletion(const ObjectAddress *object, int flags)
Definition: dependency.c:1102
void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool ignore_self)
Definition: dependency.c:1373
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1021
#define InvalidAttrNumber
Definition: attnum.h:23
void RemoveFunctionById(Oid funcOid)
#define TableSpaceRelationId
Definition: pg_tablespace.h:29
#define REGCONFIGOID
Definition: pg_type.h:612
RTEKind rtekind
Definition: parsenodes.h:882
ObjectAddressExtra * extras
Definition: dependency.c:111
#define AccessExclusiveLock
Definition: lockdefs.h:46
#define Int32GetDatum(X)
Definition: postgres.h:487
List * groupClause
Definition: parsenodes.h:137
void * palloc(Size size)
Definition: mcxt.c:891
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define DEPFLAG_NORMAL
Definition: dependency.c:100
NodeTag type
Definition: parsenodes.h:880
#define UserMappingRelationId
void list_free(List *list)
Definition: list.c:1133
void RemoveRewriteRuleById(Oid ruleOid)
Definition: rewriteRemove.c:38
int i
static void DeleteInitPrivs(const ObjectAddress *object)
Definition: dependency.c:2444
List * funccoltypes
Definition: parsenodes.h:997
#define RELKIND_INDEX
Definition: pg_class.h:161
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
int client_min_messages
Definition: guc.c:454
#define LanguageRelationId
Definition: pg_language.h:29
#define ConstraintRelationId
Definition: pg_constraint.h:29
static void deleteObjectsInList(ObjectAddresses *targetObjects, Relation *depRel, int flags)
Definition: dependency.c:217
Oid opno
Definition: primnodes.h:473
void DropCastById(Oid castOid)
#define Anum_pg_depend_classid
Definition: pg_depend.h:68
void performMultipleDeletions(const ObjectAddresses *objects, DropBehavior behavior, int flags)
Definition: dependency.c:360
#define elog
Definition: elog.h:219
#define MAX_REPORTED_DEPS
#define ExtensionRelationId
Definition: pg_extension.h:29
#define qsort(a, b, c, d)
Definition: port.h:440
void LockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:105
#define REGPROCEDUREOID
Definition: pg_type.h:553
static bool stack_address_present_add_flags(const ObjectAddress *object, int flags, ObjectAddressStack *stack)
Definition: dependency.c:2234
#define AttrDefaultRelationId
Definition: pg_attrdef.h:29
#define PERFORM_DELETION_SKIP_EXTENSIONS
Definition: dependency.h:177
#define RELKIND_RELATION
Definition: pg_class.h:160
void heap_drop_with_catalog(Oid relid)
Definition: heap.c:1750
#define LargeObjectRelationId
#define AccessMethodProcedureRelationId
Definition: pg_amproc.h:43
#define RELKIND_SEQUENCE
Definition: pg_class.h:162
Definition: pg_list.h:45
#define ConversionRelationId
Definition: pg_conversion.h:38
#define REGNAMESPACEOID
Definition: pg_type.h:577
static void add_object_address(ObjectClass oclass, Oid objectId, int32 subId, ObjectAddresses *addrs)
Definition: dependency.c:2048
ObjectAddress dependee
Definition: dependency.c:95
void RemoveConstraintById(Oid conId)
#define _(x)
Definition: elog.c:84
#define Anum_pg_depend_objid
Definition: pg_depend.h:69
Oid paramtype
Definition: primnodes.h:224
#define InvokeObjectDropHookArg(classId, objectId, subId, dropflags)
Definition: objectaccess.h:156
bool constisnull
Definition: primnodes.h:175
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define lfirst_oid(lc)
Definition: pg_list.h:108
#define REGOPERATOROID
Definition: pg_type.h:561
List * list_delete_first(List *list)
Definition: list.c:666
#define REGPROCOID
Definition: pg_type.h:320
#define TSTemplateRelationId
#define PERFORM_DELETION_INTERNAL
Definition: dependency.h:173
#define QTW_IGNORE_JOINALIASES
Definition: nodeFuncs.h:23
void RemoveTSDictionaryById(Oid dictId)
Definition: tsearchcmds.c:501