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) {