@@ -283,6 +283,14 @@ struct DropRelationCallbackState
283
283
#define ATT_COMPOSITE_TYPE 0x0010
284
284
#define ATT_FOREIGN_TABLE 0x0020
285
285
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
+
286
294
static void truncate_check_rel (Relation rel );
287
295
static List * MergeAttributes (List * schema , List * supers , char relpersistence ,
288
296
bool is_partition , List * * supOids , List * * supconstr ,
@@ -439,7 +447,8 @@ static void ATExecEnableDisableRule(Relation rel, char *rulename,
439
447
static void ATPrepAddInherit (Relation child_rel );
440
448
static ObjectAddress ATExecAddInherit (Relation child_rel , RangeVar * parent , LOCKMODE lockmode );
441
449
static 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 );
443
452
static ObjectAddress ATExecAddOf (Relation rel , const TypeName * ofTypename , LOCKMODE lockmode );
444
453
static void ATExecDropOf (Relation rel , LOCKMODE lockmode );
445
454
static void ATExecReplicaIdentity (Relation rel , ReplicaIdentityStmt * stmt , LOCKMODE lockmode );
@@ -2367,14 +2376,8 @@ StoreCatalogInheritance1(Oid relationId, Oid parentOid,
2367
2376
childobject .objectId = relationId ;
2368
2377
childobject .objectSubId = 0 ;
2369
2378
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 ));
2378
2381
2379
2382
/*
2380
2383
* Post creation hook of this inheritance. Since object_access_hook
@@ -11666,7 +11669,8 @@ RemoveInheritance(Relation child_rel, Relation parent_rel)
11666
11669
11667
11670
drop_parent_dependency (RelationGetRelid (child_rel ),
11668
11671
RelationRelationId ,
11669
- RelationGetRelid (parent_rel ));
11672
+ RelationGetRelid (parent_rel ),
11673
+ child_dependency_type (child_is_partition ));
11670
11674
11671
11675
/*
11672
11676
* Post alter hook of this inherits. Since object_access_hook doesn't take
@@ -11686,7 +11690,8 @@ RemoveInheritance(Relation child_rel, Relation parent_rel)
11686
11690
* through pg_depend.
11687
11691
*/
11688
11692
static void
11689
- drop_parent_dependency (Oid relid , Oid refclassid , Oid refobjid )
11693
+ drop_parent_dependency (Oid relid , Oid refclassid , Oid refobjid ,
11694
+ DependencyType deptype )
11690
11695
{
11691
11696
Relation catalogRelation ;
11692
11697
SysScanDesc scan ;
@@ -11718,7 +11723,7 @@ drop_parent_dependency(Oid relid, Oid refclassid, Oid refobjid)
11718
11723
if (dep -> refclassid == refclassid &&
11719
11724
dep -> refobjid == refobjid &&
11720
11725
dep -> refobjsubid == 0 &&
11721
- dep -> deptype == DEPENDENCY_NORMAL )
11726
+ dep -> deptype == deptype )
11722
11727
CatalogTupleDelete (catalogRelation , & depTuple -> t_self );
11723
11728
}
11724
11729
@@ -11839,7 +11844,8 @@ ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKMODE lockmode)
11839
11844
11840
11845
/* If the table was already typed, drop the existing dependency. */
11841
11846
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 );
11843
11849
11844
11850
/* Record a dependency on the new type. */
11845
11851
tableobj .classId = RelationRelationId ;
@@ -11892,7 +11898,8 @@ ATExecDropOf(Relation rel, LOCKMODE lockmode)
11892
11898
* table is presumed enough rights. No lock required on the type, either.
11893
11899
*/
11894
11900
11895
- drop_parent_dependency (relid , TypeRelationId , rel -> rd_rel -> reloftype );
11901
+ drop_parent_dependency (relid , TypeRelationId , rel -> rd_rel -> reloftype ,
11902
+ DEPENDENCY_NORMAL );
11896
11903
11897
11904
/* Clear pg_class.reloftype */
11898
11905
relationRelation = heap_open (RelationRelationId , RowExclusiveLock );
0 commit comments