diff --git a/src/backend/optimizer/plan/planagg.c b/src/backend/optimizer/plan/planagg.c index 805aae7ee7a..4216fc4a6ea 100644 --- a/src/backend/optimizer/plan/planagg.c +++ b/src/backend/optimizer/plan/planagg.c @@ -103,6 +103,14 @@ preprocess_minmax_aggregates(PlannerInfo *root, List *tlist) parse->hasWindowFuncs) return; + /* + * Reject if query contains any CTEs; there's no way to build an indexscan + * on one so we couldn't succeed here. (If the CTEs are unreferenced, + * that's not true, but it doesn't seem worth expending cycles to check.) + */ + if (parse->cteList) + return; + /* * We also restrict the query to reference exactly one table, since join * conditions can't be handled reasonably. (We could perhaps handle a @@ -360,7 +368,6 @@ build_minmax_path(PlannerInfo *root, MinMaxAggInfo *mminfo, subroot->plan_params = NIL; subroot->outer_params = NULL; subroot->init_plans = NIL; - subroot->cte_plan_ids = NIL; subroot->parse = parse = (Query *) copyObject(root->parse); IncrementVarSublevelsUp((Node *) parse, 1, 1);