@@ -3581,3 +3581,123 @@ drop table agg_hash_1;
35813581drop table agg_hash_2;
35823582drop table agg_hash_3;
35833583drop table agg_hash_4;
3584+ -- create table to check enable_groupagg
3585+ CREATE TABLE test_groupagg(
3586+ id serial primary key,
3587+ c1 text,
3588+ c2 text,
3589+ c3 numeric);
3590+ INSERT INTO test_groupagg (c1, c2, c3) VALUES
3591+ ('a', 'GGG', 100),
3592+ ('a', 'GGG', 150),
3593+ ('a', 'rrr', 200),
3594+ ('b', 'ooo', 300),
3595+ ('b', 'ooo', 250),
3596+ ('b', 'uuu', 100),
3597+ ('c', 'ppp', 500),
3598+ ('c', 'ppp', 600),
3599+ ('c', 'aaa', 550);
3600+ ANALYZE;
3601+ -- default: GroupAgg and HashAgg are mixed and selected
3602+ SET max_parallel_workers to 0;
3603+ SET max_parallel_workers_per_gather to 0;
3604+ SET enable_hashagg to default;
3605+ SET enable_groupagg to default;
3606+ EXPLAIN(costs off, settings)
3607+ SELECT c1, AVG(total)
3608+ FROM (
3609+ SELECT c1, c2, SUM(c3) AS total
3610+ FROM test_groupagg
3611+ GROUP BY c1, c2
3612+ ) AS sub
3613+ GROUP BY c1
3614+ ORDER BY c1;
3615+ QUERY PLAN
3616+ -----------------------------------------------------------------------------
3617+ GroupAggregate
3618+ Group Key: sub.c1
3619+ -> Sort
3620+ Sort Key: sub.c1
3621+ -> Subquery Scan on sub
3622+ -> HashAggregate
3623+ Group Key: test_groupagg.c1, test_groupagg.c2
3624+ -> Seq Scan on test_groupagg
3625+ Settings: max_parallel_workers = '0', max_parallel_workers_per_gather = '0'
3626+ (9 rows)
3627+
3628+ -- Only GroupAgg is selected
3629+ set enable_hashagg to off;
3630+ EXPLAIN(costs off, settings)
3631+ SELECT c1, AVG(total)
3632+ FROM (
3633+ SELECT c1, c2, SUM(c3) AS total
3634+ FROM test_groupagg
3635+ GROUP BY c1, c2
3636+ ) AS sub
3637+ GROUP BY c1
3638+ ORDER BY c1;
3639+ QUERY PLAN
3640+ -----------------------------------------------------------------------------------------------------
3641+ GroupAggregate
3642+ Group Key: test_groupagg.c1
3643+ -> GroupAggregate
3644+ Group Key: test_groupagg.c1, test_groupagg.c2
3645+ -> Sort
3646+ Sort Key: test_groupagg.c1, test_groupagg.c2
3647+ -> Seq Scan on test_groupagg
3648+ Settings: max_parallel_workers = '0', max_parallel_workers_per_gather = '0', enable_hashagg = 'off'
3649+ (8 rows)
3650+
3651+ -- Only HashAgg is selected
3652+ SET enable_hashagg to on;
3653+ SET enable_groupagg to off;
3654+ EXPLAIN(costs off, settings)
3655+ SELECT c1, AVG(total)
3656+ FROM (
3657+ SELECT c1, c2, SUM(c3) AS total
3658+ FROM test_groupagg
3659+ GROUP BY c1, c2
3660+ ) AS sub
3661+ GROUP BY c1
3662+ ORDER BY c1;
3663+ QUERY PLAN
3664+ ------------------------------------------------------------------------------------------------------
3665+ Sort
3666+ Sort Key: test_groupagg.c1
3667+ -> HashAggregate
3668+ Group Key: test_groupagg.c1
3669+ -> HashAggregate
3670+ Group Key: test_groupagg.c1, test_groupagg.c2
3671+ -> Seq Scan on test_groupagg
3672+ Settings: max_parallel_workers = '0', max_parallel_workers_per_gather = '0', enable_groupagg = 'off'
3673+ (8 rows)
3674+
3675+ -- Only GroupAgg is selected as a fallback
3676+ SET enable_hashagg to off;
3677+ SET enable_groupagg to off;
3678+ EXPLAIN(costs off, settings)
3679+ SELECT c1, AVG(total)
3680+ FROM (
3681+ SELECT c1, c2, SUM(c3) AS total
3682+ FROM test_groupagg
3683+ GROUP BY c1, c2
3684+ ) AS sub
3685+ GROUP BY c1
3686+ ORDER BY c1;
3687+ QUERY PLAN
3688+ ------------------------------------------------------------------------------------------------------------------------------
3689+ GroupAggregate
3690+ Group Key: test_groupagg.c1
3691+ -> GroupAggregate
3692+ Group Key: test_groupagg.c1, test_groupagg.c2
3693+ -> Sort
3694+ Sort Key: test_groupagg.c1, test_groupagg.c2
3695+ -> Seq Scan on test_groupagg
3696+ Settings: max_parallel_workers = '0', max_parallel_workers_per_gather = '0', enable_hashagg = 'off', enable_groupagg = 'off'
3697+ (8 rows)
3698+
3699+ RESET enable_hashagg;
3700+ RESET enable_groupagg;
3701+ RESET max_parallel_workers;
3702+ RESET max_parallel_workers_per_gather;
3703+ DROP TABLE test_groupagg;
0 commit comments