@@ -289,9 +289,11 @@ static List *MergeAttributes(List *schema, List *supers, char relpersistence,
289
289
static bool MergeCheckConstraint (List * constraints , char * name , Node * expr );
290
290
static void MergeAttributesIntoExisting (Relation child_rel , Relation parent_rel );
291
291
static void MergeConstraintsIntoExisting (Relation child_rel , Relation parent_rel );
292
- static void StoreCatalogInheritance (Oid relationId , List * supers );
292
+ static void StoreCatalogInheritance (Oid relationId , List * supers ,
293
+ bool child_is_partition );
293
294
static void StoreCatalogInheritance1 (Oid relationId , Oid parentOid ,
294
- int16 seqNumber , Relation inhRelation );
295
+ int16 seqNumber , Relation inhRelation ,
296
+ bool child_is_partition );
295
297
static int findAttrByName (const char * attributeName , List * schema );
296
298
static void AlterIndexNamespaces (Relation classRel , Relation rel ,
297
299
Oid oldNspOid , Oid newNspOid , ObjectAddresses * objsMoved );
@@ -725,7 +727,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
725
727
typaddress );
726
728
727
729
/* Store inheritance information for new rel. */
728
- StoreCatalogInheritance (relationId , inheritOids );
730
+ StoreCatalogInheritance (relationId , inheritOids , stmt -> partbound != NULL );
729
731
730
732
/*
731
733
* We must bump the command counter to make the newly-created relation
@@ -2248,7 +2250,8 @@ MergeCheckConstraint(List *constraints, char *name, Node *expr)
2248
2250
* supers is a list of the OIDs of the new relation's direct ancestors.
2249
2251
*/
2250
2252
static void
2251
- StoreCatalogInheritance (Oid relationId , List * supers )
2253
+ StoreCatalogInheritance (Oid relationId , List * supers ,
2254
+ bool child_is_partition )
2252
2255
{
2253
2256
Relation relation ;
2254
2257
int16 seqNumber ;
@@ -2278,7 +2281,8 @@ StoreCatalogInheritance(Oid relationId, List *supers)
2278
2281
{
2279
2282
Oid parentOid = lfirst_oid (entry );
2280
2283
2281
- StoreCatalogInheritance1 (relationId , parentOid , seqNumber , relation );
2284
+ StoreCatalogInheritance1 (relationId , parentOid , seqNumber , relation ,
2285
+ child_is_partition );
2282
2286
seqNumber ++ ;
2283
2287
}
2284
2288
@@ -2291,7 +2295,8 @@ StoreCatalogInheritance(Oid relationId, List *supers)
2291
2295
*/
2292
2296
static void
2293
2297
StoreCatalogInheritance1 (Oid relationId , Oid parentOid ,
2294
- int16 seqNumber , Relation inhRelation )
2298
+ int16 seqNumber , Relation inhRelation ,
2299
+ bool child_is_partition )
2295
2300
{
2296
2301
TupleDesc desc = RelationGetDescr (inhRelation );
2297
2302
Datum values [Natts_pg_inherits ];
@@ -2325,7 +2330,14 @@ StoreCatalogInheritance1(Oid relationId, Oid parentOid,
2325
2330
childobject .objectId = relationId ;
2326
2331
childobject .objectSubId = 0 ;
2327
2332
2328
- recordDependencyOn (& childobject , & parentobject , DEPENDENCY_NORMAL );
2333
+ /*
2334
+ * Partition tables are expected to be dropped when the parent partitioned
2335
+ * table gets dropped.
2336
+ */
2337
+ if (child_is_partition )
2338
+ recordDependencyOn (& childobject , & parentobject , DEPENDENCY_AUTO );
2339
+ else
2340
+ recordDependencyOn (& childobject , & parentobject , DEPENDENCY_NORMAL );
2329
2341
2330
2342
/*
2331
2343
* Post creation hook of this inheritance. Since object_access_hook
@@ -10753,7 +10765,9 @@ CreateInheritance(Relation child_rel, Relation parent_rel)
10753
10765
StoreCatalogInheritance1 (RelationGetRelid (child_rel ),
10754
10766
RelationGetRelid (parent_rel ),
10755
10767
inhseqno + 1 ,
10756
- catalogRelation );
10768
+ catalogRelation ,
10769
+ parent_rel -> rd_rel -> relkind ==
10770
+ RELKIND_PARTITIONED_TABLE );
10757
10771
10758
10772
/* Now we're done with pg_inherits */
10759
10773
heap_close (catalogRelation , RowExclusiveLock );
0 commit comments