@@ -283,6 +283,14 @@ struct DropRelationCallbackState
283283#define ATT_COMPOSITE_TYPE 0x0010
284284#define ATT_FOREIGN_TABLE 0x0020
285285
286+ /*
287+ * Partition tables are expected to be dropped when the parent partitioned
288+ * table gets dropped. Hence for partitioning we use AUTO dependency.
289+ * Otherwise, for regular inheritance use NORMAL dependency.
290+ */
291+ #define child_dependency_type (child_is_partition ) \
292+ ((child_is_partition) ? DEPENDENCY_AUTO : DEPENDENCY_NORMAL)
293+
286294static void truncate_check_rel (Relation rel );
287295static List * MergeAttributes (List * schema , List * supers , char relpersistence ,
288296 bool is_partition , List * * supOids , List * * supconstr ,
@@ -439,7 +447,8 @@ static void ATExecEnableDisableRule(Relation rel, char *rulename,
439447static void ATPrepAddInherit (Relation child_rel );
440448static ObjectAddress ATExecAddInherit (Relation child_rel , RangeVar * parent , LOCKMODE lockmode );
441449static ObjectAddress ATExecDropInherit (Relation rel , RangeVar * parent , LOCKMODE lockmode );
442- static void drop_parent_dependency (Oid relid , Oid refclassid , Oid refobjid );
450+ static void drop_parent_dependency (Oid relid , Oid refclassid , Oid refobjid ,
451+ DependencyType deptype );
443452static ObjectAddress ATExecAddOf (Relation rel , const TypeName * ofTypename , LOCKMODE lockmode );
444453static void ATExecDropOf (Relation rel , LOCKMODE lockmode );
445454static void ATExecReplicaIdentity (Relation rel , ReplicaIdentityStmt * stmt , LOCKMODE lockmode );
@@ -2367,14 +2376,8 @@ StoreCatalogInheritance1(Oid relationId, Oid parentOid,
23672376 childobject .objectId = relationId ;
23682377 childobject .objectSubId = 0 ;
23692378
2370- /*
2371- * Partition tables are expected to be dropped when the parent partitioned
2372- * table gets dropped.
2373- */
2374- if (child_is_partition )
2375- recordDependencyOn (& childobject , & parentobject , DEPENDENCY_AUTO );
2376- else
2377- recordDependencyOn (& childobject , & parentobject , DEPENDENCY_NORMAL );
2379+ recordDependencyOn (& childobject , & parentobject ,
2380+ child_dependency_type (child_is_partition ));
23782381
23792382 /*
23802383 * Post creation hook of this inheritance. Since object_access_hook
@@ -11666,7 +11669,8 @@ RemoveInheritance(Relation child_rel, Relation parent_rel)
1166611669
1166711670 drop_parent_dependency (RelationGetRelid (child_rel ),
1166811671 RelationRelationId ,
11669- RelationGetRelid (parent_rel ));
11672+ RelationGetRelid (parent_rel ),
11673+ child_dependency_type (child_is_partition ));
1167011674
1167111675 /*
1167211676 * Post alter hook of this inherits. Since object_access_hook doesn't take
@@ -11686,7 +11690,8 @@ RemoveInheritance(Relation child_rel, Relation parent_rel)
1168611690 * through pg_depend.
1168711691 */
1168811692static void
11689- drop_parent_dependency (Oid relid , Oid refclassid , Oid refobjid )
11693+ drop_parent_dependency (Oid relid , Oid refclassid , Oid refobjid ,
11694+ DependencyType deptype )
1169011695{
1169111696 Relation catalogRelation ;
1169211697 SysScanDesc scan ;
@@ -11718,7 +11723,7 @@ drop_parent_dependency(Oid relid, Oid refclassid, Oid refobjid)
1171811723 if (dep -> refclassid == refclassid &&
1171911724 dep -> refobjid == refobjid &&
1172011725 dep -> refobjsubid == 0 &&
11721- dep -> deptype == DEPENDENCY_NORMAL )
11726+ dep -> deptype == deptype )
1172211727 CatalogTupleDelete (catalogRelation , & depTuple -> t_self );
1172311728 }
1172411729
@@ -11839,7 +11844,8 @@ ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKMODE lockmode)
1183911844
1184011845 /* If the table was already typed, drop the existing dependency. */
1184111846 if (rel -> rd_rel -> reloftype )
11842- drop_parent_dependency (relid , TypeRelationId , rel -> rd_rel -> reloftype );
11847+ drop_parent_dependency (relid , TypeRelationId , rel -> rd_rel -> reloftype ,
11848+ DEPENDENCY_NORMAL );
1184311849
1184411850 /* Record a dependency on the new type. */
1184511851 tableobj .classId = RelationRelationId ;
@@ -11892,7 +11898,8 @@ ATExecDropOf(Relation rel, LOCKMODE lockmode)
1189211898 * table is presumed enough rights. No lock required on the type, either.
1189311899 */
1189411900
11895- drop_parent_dependency (relid , TypeRelationId , rel -> rd_rel -> reloftype );
11901+ drop_parent_dependency (relid , TypeRelationId , rel -> rd_rel -> reloftype ,
11902+ DEPENDENCY_NORMAL );
1189611903
1189711904 /* Clear pg_class.reloftype */
1189811905 relationRelation = heap_open (RelationRelationId , RowExclusiveLock );
0 commit comments