>>>>> "Andrew" == Andrew Gierth <and...@tao11.riddles.org.uk> writes:
Andrew> The other is that in subquery_planner, the optimization of Andrew> converting HAVING clauses to WHERE clauses is suppressed if Andrew> parse->groupingSets isn't empty. (It is empty if there's either Andrew> no group by clause at all, or if there's exactly one grouping Andrew> set, which must not be empty, however derived.) This is costing Andrew> us some optimizations, especially in the case of an explicit Andrew> GROUP BY () clause; I'll look into this. I'm inclined to go with the simplest approach here, which copies the quals if there are grouping sets. The only way we could safely move a qual without copying is if we can show that none of the grouping sets is empty, that is (), and at this point the grouping set list has not been expanded so it's not trivial to determine that. Patch attached. -- Andrew (irc:RhodiumToad)
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index a6ce96e..2866176 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -574,13 +574,12 @@ subquery_planner(PlannerGlobal *glob, Query *parse, if (contain_agg_clause(havingclause) || contain_volatile_functions(havingclause) || - contain_subplans(havingclause) || - parse->groupingSets) + contain_subplans(havingclause)) { /* keep it in HAVING */ newHaving = lappend(newHaving, havingclause); } - else if (parse->groupClause) + else if (parse->groupClause && !parse->groupingSets) { /* move it to WHERE */ parse->jointree->quals = (Node *)
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers