drop table if exists test_hash_agg;

create table test_hash_agg as
    select
        i AS a,
        mod(i,1000000) AS b,
        mod(i,100000) AS c,
        mod(i,10000) AS d,
        mod(i,1000) AS e,
        mod(i,100) AS f
  from generate_series(1,10000000) s(i);

vacuum (full, analyze) test_hash_agg;

\timing on

select count(x) from (select a, count(1) x from test_hash_agg group by a) foo;
select count(x) from (select b, count(1) x from test_hash_agg group by b) foo;
select count(x) from (select c, count(1) x from test_hash_agg group by c) foo;
select count(x) from (select d, count(1) x from test_hash_agg group by d) foo;
select count(x) from (select e, count(1) x from test_hash_agg group by e) foo;
select count(x) from (select f, count(1) x from test_hash_agg group by f) foo;

select count(x) from (select a, array_agg(1) x from test_hash_agg group by a) foo;
select count(x) from (select b, array_agg(1) x from test_hash_agg group by b) foo;
select count(x) from (select c, array_agg(1) x from test_hash_agg group by c) foo;
select count(x) from (select d, array_agg(1) x from test_hash_agg group by d) foo;
select count(x) from (select e, array_agg(1) x from test_hash_agg group by e) foo;
select count(x) from (select f, array_agg(1) x from test_hash_agg group by f) foo;
