From d736ba2f654f91f954e4fb0da1257bebbd668e3f Mon Sep 17 00:00:00 2001 From: naisila Date: Thu, 18 Sep 2025 16:43:29 +0300 Subject: [PATCH] Add check to identify views converted to RTE_SUBQUERY in 15.13, 14.18 Previously, when views were converted to RTE_SUBQUERY the relid would be cleared in PG15. In this patch of PG15, relid is retained. Therefore, we add a check with the "relkind and rtekind" to identify the converted views in 15.13 Part of https://github.com/citusdata/citus/commit/c98341e4ed3967219dd5ae0e264dc41a7f442f1c --- .../distributed/planner/multi_router_planner.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/backend/distributed/planner/multi_router_planner.c b/src/backend/distributed/planner/multi_router_planner.c index 1f2ad4751..522677202 100644 --- a/src/backend/distributed/planner/multi_router_planner.c +++ b/src/backend/distributed/planner/multi_router_planner.c @@ -2246,6 +2246,18 @@ SelectsFromDistributedTable(List *rangeTableList, Query *query) continue; } +#if PG_VERSION_NUM >= 140018 && PG_VERSION_NUM < PG_VERSION_16 + if (rangeTableEntry->rtekind == RTE_SUBQUERY && rangeTableEntry->relkind == 0) + { + /* + * In PG14.18&15.13 commit https://github.com/postgres/postgres/commit/317aba70e + * relid is retained when converting views to subqueries, + * so we need an extra check identifying those views + */ + continue; + } +#endif + if (rangeTableEntry->relkind == RELKIND_VIEW || rangeTableEntry->relkind == RELKIND_MATVIEW) {