aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util/inherit.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2024-08-19 16:09:10 -0400
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2024-08-19 16:09:10 -0400
commit52f3de874bbeaf16b3ae2efb505c1117be8355cc (patch)
treeeee572634071ce0419bdd427423128b89e4fa8eb /src/backend/optimizer/util/inherit.c
parent0d06a7eac4b23cc7b8fd4568d8623a6023646f63 (diff)
downloadpostgresql-52f3de874bbeaf16b3ae2efb505c1117be8355cc.tar.gz
postgresql-52f3de874bbeaf16b3ae2efb505c1117be8355cc.zip
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
Diffstat (limited to 'src/backend/optimizer/util/inherit.c')
-rw-r--r--src/backend/optimizer/util/inherit.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/backend/optimizer/util/inherit.c b/src/backend/optimizer/util/inherit.c
index 4797312ae53..c5b906a9d43 100644
--- a/src/backend/optimizer/util/inherit.c
+++ b/src/backend/optimizer/util/inherit.c
@@ -386,8 +386,17 @@ 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)
+ {
+ relinfo->live_parts = bms_del_member(relinfo->live_parts, i);
+ continue;
+ }
/*
* Temporary partitions belonging to other sessions should have been