diff --git a/src/backend/optimizer/util/inherit.c b/src/backend/optimizer/util/inherit.c index 7ea758049ed..b7ed598a48a 100644 --- a/src/backend/optimizer/util/inherit.c +++ b/src/backend/optimizer/util/inherit.c @@ -378,8 +378,14 @@ expand_partitioned_rtentry(PlannerInfo *root, RelOptInfo *relinfo, Index childRTindex; RelOptInfo *childrelinfo; - /* Open rel, acquiring required locks */ - childrel = table_open(childOID, lockmode); + /* + * Open rel, acquiring required locks. If a partition was recently + * detached and subsequently dropped, then opening it will fail. In + * this case, behave as though the partition had been pruned. + */ + childrel = try_table_open(childOID, lockmode); + if (childrel == NULL) + continue; /* * Temporary partitions belonging to other sessions should have been