myself.objectId = HeapTupleGetOid(tuple);
myself.objectSubId = 0;
- performDeletion(&myself, DROP_RESTRICT);
+ performDeletion(&myself, DROP_RESTRICT, 0);
}
}
else
DropBehavior behavior,
int msglevel,
const ObjectAddress *origObject);
-static void deleteOneObject(const ObjectAddress *object, Relation depRel);
+static void deleteOneObject(const ObjectAddress *object,
+ Relation depRel, int32 flags);
static void doDeletion(const ObjectAddress *object);
static void AcquireDeletionLock(const ObjectAddress *object);
static void ReleaseDeletionLock(const ObjectAddress *object);
* that can participate in dependencies. Note that the next two routines
* are variants on the same theme; if you change anything here you'll likely
* need to fix them too.
+ *
+ * flags should include PERFORM_DELETION_INTERNAL when the drop operation is
+ * not the direct result of a user-initiated action. For example, when a
+ * temporary schema is cleaned out so that a new backend can use it, or when
+ * a column default is dropped as an intermediate step while adding a new one,
+ * that's an internal operation. On the other hand, when the we drop something
+ * because the user issued a DROP statement against it, that's not internal.
*/
void
performDeletion(const ObjectAddress *object,
- DropBehavior behavior)
+ DropBehavior behavior, int flags)
{
Relation depRel;
ObjectAddresses *targetObjects;
{
ObjectAddress *thisobj = targetObjects->refs + i;
- deleteOneObject(thisobj, depRel);
+ deleteOneObject(thisobj, depRel, flags);
}
/* And clean up */
*/
void
performMultipleDeletions(const ObjectAddresses *objects,
- DropBehavior behavior)
+ DropBehavior behavior, int flags)
{
Relation depRel;
ObjectAddresses *targetObjects;
{
ObjectAddress *thisobj = targetObjects->refs + i;
- deleteOneObject(thisobj, depRel);
+ deleteOneObject(thisobj, depRel, flags);
}
/* And clean up */
if (thisextra->flags & DEPFLAG_ORIGINAL)
continue;
- deleteOneObject(thisobj, depRel);
+ /*
+ * Since this function is currently only used to clean out temporary
+ * schemas, we pass PERFORM_DELETION_INTERNAL here, indicating that
+ * the operation is an automatic system operation rather than a user
+ * action. If, in the future, this function is used for other
+ * purposes, we might need to revisit this.
+ */
+ deleteOneObject(thisobj, depRel, PERFORM_DELETION_INTERNAL);
}
/* And clean up */
* depRel is the already-open pg_depend relation.
*/
static void
-deleteOneObject(const ObjectAddress *object, Relation depRel)
+deleteOneObject(const ObjectAddress *object, Relation depRel, int flags)
{
ScanKeyData key[3];
int nkeys;
*/
void
RemoveAttrDefault(Oid relid, AttrNumber attnum,
- DropBehavior behavior, bool complain)
+ DropBehavior behavior, bool complain, bool internal)
{
Relation attrdef_rel;
ScanKeyData scankeys[2];
object.objectId = HeapTupleGetOid(tuple);
object.objectSubId = 0;
- performDeletion(&object, behavior);
+ performDeletion(&object, behavior,
+ internal ? PERFORM_DELETION_INTERNAL : 0);
found = true;
}
}
/* the dependency mechanism does the actual work */
- performMultipleDeletions(deleteobjs, behavior);
+ performMultipleDeletions(deleteobjs, behavior, 0);
heap_close(sdepRel, RowExclusiveLock);
* The new relation is local to our transaction and we know nothing
* depends on it, so DROP_RESTRICT should be OK.
*/
- performDeletion(&object, DROP_RESTRICT);
+ performDeletion(&object, DROP_RESTRICT, PERFORM_DELETION_INTERNAL);
/* performDeletion does CommandCounterIncrement at end */
}
/* Here we really delete them. */
- performMultipleDeletions(objects, stmt->behavior);
+ performMultipleDeletions(objects, stmt->behavior, 0);
free_object_addresses(objects);
}
object.objectId = umId;
object.objectSubId = 0;
- performDeletion(&object, DROP_CASCADE);
+ performDeletion(&object, DROP_CASCADE, 0);
}
object.objectId = amopid;
object.objectSubId = 0;
- performDeletion(&object, DROP_RESTRICT);
+ performDeletion(&object, DROP_RESTRICT, 0);
}
}
object.objectId = amprocid;
object.objectSubId = 0;
- performDeletion(&object, DROP_RESTRICT);
+ performDeletion(&object, DROP_RESTRICT, 0);
}
}
add_exact_object_address(&obj, objects);
}
- performMultipleDeletions(objects, drop->behavior);
+ performMultipleDeletions(objects, drop->behavior, 0);
free_object_addresses(objects);
}
* Remove any old default for the column. We use RESTRICT here for
* safety, but at present we do not expect anything to depend on the
* default.
+ *
+ * We treat removing the existing default as an internal operation when
+ * it is preparatory to adding a new default, but as a user-initiated
+ * operation when the user asked for a drop.
*/
- RemoveAttrDefault(RelationGetRelid(rel), attnum, DROP_RESTRICT, false);
+ RemoveAttrDefault(RelationGetRelid(rel), attnum, DROP_RESTRICT, false,
+ newDefault == NULL ? false : true);
if (newDefault)
{
object.objectId = RelationGetRelid(rel);
object.objectSubId = attnum;
- performDeletion(&object, behavior);
+ performDeletion(&object, behavior, 0);
/*
* If we dropped the OID column, must adjust pg_class.relhasoids and tell
conobj.objectId = HeapTupleGetOid(tuple);
conobj.objectSubId = 0;
- performDeletion(&conobj, behavior);
+ performDeletion(&conobj, behavior, 0);
found = true;
* We use RESTRICT here for safety, but at present we do not expect
* anything to depend on the default.
*/
- RemoveAttrDefault(RelationGetRelid(rel), attnum, DROP_RESTRICT, true);
+ RemoveAttrDefault(RelationGetRelid(rel), attnum, DROP_RESTRICT, true,
+ true);
StoreAttrDefault(rel, attnum, defaultexpr);
}
obj.classId = ConstraintRelationId;
obj.objectId = lfirst_oid(oid_item);
obj.objectSubId = 0;
- performDeletion(&obj, DROP_RESTRICT);
+ performDeletion(&obj, DROP_RESTRICT, PERFORM_DELETION_INTERNAL);
}
foreach(oid_item, tab->changedIndexOids)
obj.classId = RelationRelationId;
obj.objectId = lfirst_oid(oid_item);
obj.objectSubId = 0;
- performDeletion(&obj, DROP_RESTRICT);
+ performDeletion(&obj, DROP_RESTRICT, PERFORM_DELETION_INTERNAL);
}
/*
object.classId = RelationRelationId;
object.objectId = oc->relid;
object.objectSubId = 0;
- performDeletion(&object, DROP_CASCADE);
+
+ /*
+ * Since this is an automatic drop, rather than one
+ * directly initiated by the user, we pass the
+ * PERFORM_DELETION_INTERNAL flag.
+ */
+ performDeletion(&object,
+ DROP_CASCADE, PERFORM_DELETION_INTERNAL);
/*
* Note that table deletion will call
conobj.objectId = HeapTupleGetOid(contup);
conobj.objectSubId = 0;
- performDeletion(&conobj, behavior);
+ performDeletion(&conobj, behavior, 0);
found = true;
}
}
object.classId = RelationRelationId;
object.objectId = relid;
object.objectSubId = 0;
- performDeletion(&object, DROP_CASCADE);
+ performDeletion(&object, DROP_CASCADE, PERFORM_DELETION_INTERNAL);
}
else
{
object.classId = LargeObjectRelationId;
object.objectId = lobjId;
object.objectSubId = 0;
- performDeletion(&object, DROP_CASCADE);
+ performDeletion(&object, DROP_CASCADE, 0);
/*
* Advance command counter so that tuple removal will be seen by later
/* in dependency.c */
+#define PERFORM_DELETION_INTERNAL 0x0001
+
extern void performDeletion(const ObjectAddress *object,
- DropBehavior behavior);
+ DropBehavior behavior, int flags);
extern void performMultipleDeletions(const ObjectAddresses *objects,
- DropBehavior behavior);
+ DropBehavior behavior, int flags);
extern void deleteWhatDependsOn(const ObjectAddress *object,
bool showNotices);
extern void DeleteAttributeTuples(Oid relid);
extern void RemoveAttributeById(Oid relid, AttrNumber attnum);
extern void RemoveAttrDefault(Oid relid, AttrNumber attnum,
- DropBehavior behavior, bool complain);
+ DropBehavior behavior, bool complain, bool internal);
extern void RemoveAttrDefaultById(Oid attrdefId);
extern void RemoveStatistics(Oid relid, AttrNumber attnum);