By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
create table data (key int, a int, b int, c int[]);
insert into data values
(1, 0, 1, '{1,2}')
,(1, 1, 2, '{3}')
,(1,-1, 3, '{2}')
,(1, 2, 4, '{}');
CREATE TABLE
INSERT 0 4
SELECT *
FROM (
SELECT key, min(a) AS min_a, sum(b) AS sum_b
FROM data
GROUP BY 1
) x
JOIN (
SELECT key, array_agg(DISTINCT e) AS dist_c
FROM data, unnest(c) e
GROUP BY 1
) y USING (key);
key | min_a | sum_b | dist_c |
---|---|---|---|
1 | -1 | 10 | {1,2,3} |
SELECT 1