Reduce test time for disk-based Hash Aggregation.

Discussion: https://postgr.es/m/23196.1584943506@sss.pgh.pa.us
This commit is contained in:
Jeff Davis 2020-03-23 18:55:12 -07:00
parent 67e0adfb3f
commit 76df765e88
4 changed files with 53 additions and 142 deletions

View File

@ -2453,22 +2453,22 @@ set work_mem='64kB';
set enable_hashagg = false;
set jit_above_cost = 0;
explain (costs off)
select g%100000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 199999) g
group by g%100000;
select g%10000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 19999) g
group by g%10000;
QUERY PLAN
------------------------------------------------
GroupAggregate
Group Key: ((g % 100000))
Group Key: ((g % 10000))
-> Sort
Sort Key: ((g % 100000))
Sort Key: ((g % 10000))
-> Function Scan on generate_series g
(5 rows)
create table agg_group_1 as
select g%100000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 199999) g
group by g%100000;
select g%10000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 19999) g
group by g%10000;
create table agg_group_2 as
select * from
(values (100), (300), (500)) as r(a),
@ -2493,20 +2493,20 @@ set enable_hashagg = true;
set enable_sort = false;
set jit_above_cost = 0;
explain (costs off)
select g%100000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 199999) g
group by g%100000;
select g%10000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 19999) g
group by g%10000;
QUERY PLAN
------------------------------------------
HashAggregate
Group Key: (g % 100000)
Group Key: (g % 10000)
-> Function Scan on generate_series g
(3 rows)
create table agg_hash_1 as
select g%100000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 199999) g
group by g%100000;
select g%10000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 19999) g
group by g%10000;
create table agg_hash_2 as
select * from
(values (100), (300), (500)) as r(a),

View File

@ -1644,10 +1644,10 @@ SET work_mem='64kB';
set enable_hashagg = false;
set jit_above_cost = 0;
explain (costs off)
select g1000, g100, g10, sum(g::numeric), count(*), max(g::text) from
select g100, g10, sum(g::numeric), count(*), max(g::text) from
(select g%1000 as g1000, g%100 as g100, g%10 as g10, g
from generate_series(0,199999) g) s
group by cube (g1000,g100,g10);
from generate_series(0,1999) g) s
group by cube (g1000, g100,g10);
QUERY PLAN
---------------------------------------------------------------
GroupAggregate
@ -1667,31 +1667,18 @@ group by cube (g1000,g100,g10);
(14 rows)
create table gs_group_1 as
select g1000, g100, g10, sum(g::numeric), count(*), max(g::text) from
select g100, g10, sum(g::numeric), count(*), max(g::text) from
(select g%1000 as g1000, g%100 as g100, g%10 as g10, g
from generate_series(0,199999) g) s
group by cube (g1000,g100,g10);
set jit_above_cost to default;
create table gs_group_2 as
select g1000, g100, g10, sum(g::numeric), count(*), max(g::text) from
(select g/20 as g1000, g/200 as g100, g/2000 as g10, g
from generate_series(0,19999) g) s
group by cube (g1000,g100,g10);
create table gs_group_3 as
select g100, g10, array_agg(g) as a, count(*) as c, max(g::text) as m from
(select g/200 as g100, g/2000 as g10, g
from generate_series(0,19999) g) s
group by grouping sets (g100,g10);
from generate_series(0,1999) g) s
group by cube (g1000, g100,g10);
-- Produce results with hash aggregation.
set enable_hashagg = true;
set enable_sort = false;
set work_mem='64kB';
set jit_above_cost = 0;
explain (costs off)
select g1000, g100, g10, sum(g::numeric), count(*), max(g::text) from
select g100, g10, sum(g::numeric), count(*), max(g::text) from
(select g%1000 as g1000, g%100 as g100, g%10 as g10, g
from generate_series(0,199999) g) s
group by cube (g1000,g100,g10);
from generate_series(0,1999) g) s
group by cube (g1000, g100,g10);
QUERY PLAN
---------------------------------------------------
MixedAggregate
@ -1707,52 +1694,21 @@ group by cube (g1000,g100,g10);
(10 rows)
create table gs_hash_1 as
select g1000, g100, g10, sum(g::numeric), count(*), max(g::text) from
select g100, g10, sum(g::numeric), count(*), max(g::text) from
(select g%1000 as g1000, g%100 as g100, g%10 as g10, g
from generate_series(0,199999) g) s
group by cube (g1000,g100,g10);
set jit_above_cost to default;
create table gs_hash_2 as
select g1000, g100, g10, sum(g::numeric), count(*), max(g::text) from
(select g/20 as g1000, g/200 as g100, g/2000 as g10, g
from generate_series(0,19999) g) s
group by cube (g1000,g100,g10);
create table gs_hash_3 as
select g100, g10, array_agg(g) as a, count(*) as c, max(g::text) as m from
(select g/200 as g100, g/2000 as g10, g
from generate_series(0,19999) g) s
group by grouping sets (g100,g10);
from generate_series(0,1999) g) s
group by cube (g1000, g100,g10);
set enable_sort = true;
set work_mem to default;
-- Compare results
(select * from gs_hash_1 except select * from gs_group_1)
union all
(select * from gs_group_1 except select * from gs_hash_1);
g1000 | g100 | g10 | sum | count | max
-------+------+-----+-----+-------+-----
(0 rows)
(select * from gs_hash_2 except select * from gs_group_2)
union all
(select * from gs_group_2 except select * from gs_hash_2);
g1000 | g100 | g10 | sum | count | max
-------+------+-----+-----+-------+-----
(0 rows)
(select g100,g10,unnest(a),c,m from gs_hash_3 except
select g100,g10,unnest(a),c,m from gs_group_3)
union all
(select g100,g10,unnest(a),c,m from gs_group_3 except
select g100,g10,unnest(a),c,m from gs_hash_3);
g100 | g10 | unnest | c | m
------+-----+--------+---+---
g100 | g10 | sum | count | max
------+-----+-----+-------+-----
(0 rows)
drop table gs_group_1;
drop table gs_group_2;
drop table gs_group_3;
drop table gs_hash_1;
drop table gs_hash_2;
drop table gs_hash_3;
SET enable_groupingsets_hash_disk TO DEFAULT;
-- end

View File

@ -1066,14 +1066,14 @@ set enable_hashagg = false;
set jit_above_cost = 0;
explain (costs off)
select g%100000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 199999) g
group by g%100000;
select g%10000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 19999) g
group by g%10000;
create table agg_group_1 as
select g%100000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 199999) g
group by g%100000;
select g%10000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 19999) g
group by g%10000;
create table agg_group_2 as
select * from
@ -1106,14 +1106,14 @@ set enable_sort = false;
set jit_above_cost = 0;
explain (costs off)
select g%100000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 199999) g
group by g%100000;
select g%10000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 19999) g
group by g%10000;
create table agg_hash_1 as
select g%100000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 199999) g
group by g%100000;
select g%10000 as c1, sum(g::numeric) as c2, count(*) as c3
from generate_series(0, 19999) g
group by g%10000;
create table agg_hash_2 as
select * from

View File

@ -453,68 +453,37 @@ SET work_mem='64kB';
-- Produce results with sorting.
set enable_hashagg = false;
set jit_above_cost = 0;
explain (costs off)
select g1000, g100, g10, sum(g::numeric), count(*), max(g::text) from
select g100, g10, sum(g::numeric), count(*), max(g::text) from
(select g%1000 as g1000, g%100 as g100, g%10 as g10, g
from generate_series(0,199999) g) s
group by cube (g1000,g100,g10);
from generate_series(0,1999) g) s
group by cube (g1000, g100,g10);
create table gs_group_1 as
select g1000, g100, g10, sum(g::numeric), count(*), max(g::text) from
select g100, g10, sum(g::numeric), count(*), max(g::text) from
(select g%1000 as g1000, g%100 as g100, g%10 as g10, g
from generate_series(0,199999) g) s
group by cube (g1000,g100,g10);
set jit_above_cost to default;
create table gs_group_2 as
select g1000, g100, g10, sum(g::numeric), count(*), max(g::text) from
(select g/20 as g1000, g/200 as g100, g/2000 as g10, g
from generate_series(0,19999) g) s
group by cube (g1000,g100,g10);
create table gs_group_3 as
select g100, g10, array_agg(g) as a, count(*) as c, max(g::text) as m from
(select g/200 as g100, g/2000 as g10, g
from generate_series(0,19999) g) s
group by grouping sets (g100,g10);
from generate_series(0,1999) g) s
group by cube (g1000, g100,g10);
-- Produce results with hash aggregation.
set enable_hashagg = true;
set enable_sort = false;
set work_mem='64kB';
set jit_above_cost = 0;
explain (costs off)
select g1000, g100, g10, sum(g::numeric), count(*), max(g::text) from
select g100, g10, sum(g::numeric), count(*), max(g::text) from
(select g%1000 as g1000, g%100 as g100, g%10 as g10, g
from generate_series(0,199999) g) s
group by cube (g1000,g100,g10);
from generate_series(0,1999) g) s
group by cube (g1000, g100,g10);
create table gs_hash_1 as
select g1000, g100, g10, sum(g::numeric), count(*), max(g::text) from
select g100, g10, sum(g::numeric), count(*), max(g::text) from
(select g%1000 as g1000, g%100 as g100, g%10 as g10, g
from generate_series(0,199999) g) s
group by cube (g1000,g100,g10);
from generate_series(0,1999) g) s
group by cube (g1000, g100,g10);
set jit_above_cost to default;
create table gs_hash_2 as
select g1000, g100, g10, sum(g::numeric), count(*), max(g::text) from
(select g/20 as g1000, g/200 as g100, g/2000 as g10, g
from generate_series(0,19999) g) s
group by cube (g1000,g100,g10);
create table gs_hash_3 as
select g100, g10, array_agg(g) as a, count(*) as c, max(g::text) as m from
(select g/200 as g100, g/2000 as g10, g
from generate_series(0,19999) g) s
group by grouping sets (g100,g10);
set enable_sort = true;
set work_mem to default;
@ -525,22 +494,8 @@ set work_mem to default;
union all
(select * from gs_group_1 except select * from gs_hash_1);
(select * from gs_hash_2 except select * from gs_group_2)
union all
(select * from gs_group_2 except select * from gs_hash_2);
(select g100,g10,unnest(a),c,m from gs_hash_3 except
select g100,g10,unnest(a),c,m from gs_group_3)
union all
(select g100,g10,unnest(a),c,m from gs_group_3 except
select g100,g10,unnest(a),c,m from gs_hash_3);
drop table gs_group_1;
drop table gs_group_2;
drop table gs_group_3;
drop table gs_hash_1;
drop table gs_hash_2;
drop table gs_hash_3;
SET enable_groupingsets_hash_disk TO DEFAULT;