Skip to content

Commit 52f3de8

Browse files
committed
Avoid failure to open dropped detached partition
When a partition is detached and immediately dropped, a prepared statement could try to compute a new partition descriptor that includes it. This leads to this kind of error: ERROR: could not open relation with OID 457639 Avoid this by skipping the partition in expand_partitioned_rtentry if it doesn't exist. Noted by me while investigating bug #18559. Kuntal Gosh helped to identify the exact failure. Backpatch to 14, where DETACH CONCURRENTLY was introduced. Author: Álvaro Herrera <alvherre@alvh.no-ip.org> Reviewed-by: Kuntal Ghosh <kuntalghosh.2007@gmail.com> Reviewed-by: Junwang Zhao <zhjwpku@gmail.com> Discussion: https://postgr.es/m/202408122233.bo4adt3vh5bi@alvherre.pgsql
1 parent 0d06a7e commit 52f3de8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/backend/optimizer/util/inherit.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,17 @@ expand_partitioned_rtentry(PlannerInfo *root, RelOptInfo *relinfo,
386386
Index childRTindex;
387387
RelOptInfo *childrelinfo;
388388

389-
/* Open rel, acquiring required locks */
390-
childrel = table_open(childOID, lockmode);
389+
/*
390+
* Open rel, acquiring required locks. If a partition was recently
391+
* detached and subsequently dropped, then opening it will fail. In
392+
* this case, behave as though the partition had been pruned.
393+
*/
394+
childrel = try_table_open(childOID, lockmode);
395+
if (childrel == NULL)
396+
{
397+
relinfo->live_parts = bms_del_member(relinfo->live_parts, i);
398+
continue;
399+
}
391400

392401
/*
393402
* Temporary partitions belonging to other sessions should have been

0 commit comments

Comments
 (0)