Hello!
+static bool
+distinct_redundant_by_groupby(Query *parse)
I think this also should check hasTargetSRFs:
CREATE TABLE t (a int, b int, c int);
INSERT INTO t VALUES (1,1,10),(1,2,20),(2,1,30),(2,2,40),(1,1,50);
SELECT DISTINCT a, unnest(ARRAY[1,1]) AS u FROM t GROUP BY a ORDER BY a, u;
Also, query_is_distinct_for already does something similar (and
already handles hasTargetSRFs) - would it be possible to extract the
common part instead of duplicating the logic?