Optimization for COUNT(DISTINCT) and uniq variants in subqueries with GROUP BY
Official CH changelog text
An optimization to rewrite COUNT(DISTINCT ...) and various uniq variants to count if it is selected from a subquery with GROUP BY. #52082#52645 (JackyWoo).