Yida Wu has uploaded a new patch set (#5). ( https://gerrit.cloudera.org/25386 )
Change subject: IMPALA-13081: Chain nested grouping sets in streaming
preaggregation
......................................................................
IMPALA-13081: Chain nested grouping sets in streaming preaggregation
A streaming preaggregation over grouping sets passes every input row to
the aggregator of every grouping set ('replicate_input'), so a ROLLUP
over N exprs evaluates and hashes the whole input N + 1 times.
Example: GROUP BY ROLLUP(a, b, c) has 4 grouping sets.
Not chained: every Aggregator reads every input row.
+--> Agg 0 (a, b, c) --+
+--> Agg 1 (a, b) --+
child -----+--> Agg 2 (a) --+--> exchange --> merge agg
(N rows) +--> Agg 3 () --+
All N rows are evaluated and hashed 4 times.
Chained: Agg i + 1 merges the output of Agg i.
child --> Agg 0 ---> Agg 1 ---> Agg 2 ---> Agg 3
(N rows) (a, b, c) (a, b) (a) ()
| | | |
+----------+----------+----------+--> exchange
--> merge agg
The N rows are hashed once, by Agg 0. Each later Aggregator reads
only the rows that the one before it outputs.
Chaining applies when each grouping set is a subset of the previous
one, as for ROLLUP:
- AggregationNode detects such grouping sets and sets
TAggregationNode.chain_aggregators. The chained classes group by slot
refs into the intermediate tuple of the previous class and use merge
aggregate functions.
- StreamingAggregationNode::GetNextChained() feeds each output batch of
aggregator i into aggregator i + 1 and returns the batches in order.
The profile shows the ExecOption "Chained Aggregators".
- At EXTENDED level, EXPLAIN shows the input class and the merge
functions of each chained class.
- The new query option CHAIN_GROUPING_SETS_PREAGG (default true) turns
this off.
The merge aggregation is unchanged.
GroupingAggregator::AddBatchStreaming() now allocates the serialized
intermediates of passed-through rows from the output batch, as the
expr results pool can be cleared while the rows are still referenced.
Testing:
- Added grouping-sets-chained-preagg.test to PlannerTest, which checks
which grouping sets chain and the EXTENDED explain of the chained
classes.
- Updated the EXTENDED and VERBOSE plans of the planner tests with
chained ROLLUP preaggregations, e.g. TPC-DS q05, q18, q22, q27, q36,
q67, q70, q77, q80 and q86.
- Added the TPC-H end-to-end tests grouping-sets-chained-preagg.test
and grouping-sets-chained-preagg-profile.test.
- Added TestGroupingSetsChainedPreaggResults, which compares ROLLUP and
GROUPING SETS results with and without chaining to equivalent
GROUP BY queries, also with denied reservations, small batches,
mt_dop and a low preagg_bytes_limit.
Performance was measured with 3 impalads on a release build, as the
median of 5 runs with CHAIN_GROUPING_SETS_PREAGG=true (Chain) and
false (NoChain):
- Q1: TPC-H SF1:
select count(*), sum(c), sum(sp) from (
select year(l_shipdate) y, month(l_shipdate) m,
day(l_shipdate) d, l_shipmode s, count(*) c,
sum(l_extendedprice) sp
from tpch_parquet.lineitem
group by rollup(year(l_shipdate), month(l_shipdate),
day(l_shipdate), l_shipmode)) v;
- Q2: TPC-DS q67 SF10 (mem_limit=1g), a ROLLUP over 8 columns.
- Q3: TPC-H SF1, ROLLUP(l_orderkey, l_linenumber).
Preagg time Query time Agg 1-N rows read
Chain/NoChain Chain/NoChain per instance
Q1 0.9s/2.7s 1.4s/3.4s (-59%) 20K/8.0M
Q2 2.1s/4.4s 21.4s/24.2s (-12%) 2.6M/14.2M
Q3 0.7s/0.7s 4.5s/4.5s (0%) 2.5M/4.0M
In Q1 and Q2, Agg 0 reduces the input a lot, so the later Aggregators
merge far fewer rows than they hash without chaining. In Q3, Agg 0
passes 93% of the rows through, so chaining gains little but does no
harm.
On TPC-DS SF10 (median of 3 runs), the 11 ROLLUP queries (q5, q14a,
q18, q22, q27, q36, q67, q70, q77, q80, q86) take 58.9s in total with
chaining and 66.8s without it, 11.8% faster. The other 92 queries are
unchanged.
Change-Id: I20667d8f97962ddbb10147f498722cc4cf25dd29
Assisted-by: Claude Opus 5.5 (Claude Code)
---
M be/src/exec/aggregation-node-base.cc
M be/src/exec/aggregation-node-base.h
M be/src/exec/aggregation-node.cc
M be/src/exec/aggregator.cc
M be/src/exec/aggregator.h
M be/src/exec/grouping-aggregator.cc
M be/src/exec/streaming-aggregation-node.cc
M be/src/exec/streaming-aggregation-node.h
M be/src/service/query-options.cc
M be/src/service/query-options.h
M common/thrift/ImpalaService.thrift
M common/thrift/PlanNodes.thrift
M common/thrift/Query.thrift
M fe/src/main/java/org/apache/impala/planner/AggregationNode.java
M fe/src/test/java/org/apache/impala/planner/PlannerTest.java
M
testdata/workloads/functional-planner/queries/PlannerTest/agg-node-high-mem-estimate.test
M
testdata/workloads/functional-planner/queries/PlannerTest/agg-node-low-mem-estimate.test
M
testdata/workloads/functional-planner/queries/PlannerTest/agg-node-max-mem-estimate.test
M
testdata/workloads/functional-planner/queries/PlannerTest/calcite_tpcds/tpcds-q05.test
M
testdata/workloads/functional-planner/queries/PlannerTest/calcite_tpcds/tpcds-q14a.test
M
testdata/workloads/functional-planner/queries/PlannerTest/calcite_tpcds/tpcds-q18.test
M
testdata/workloads/functional-planner/queries/PlannerTest/calcite_tpcds/tpcds-q22.test
M
testdata/workloads/functional-planner/queries/PlannerTest/calcite_tpcds/tpcds-q27.test
M
testdata/workloads/functional-planner/queries/PlannerTest/calcite_tpcds/tpcds-q36.test
M
testdata/workloads/functional-planner/queries/PlannerTest/calcite_tpcds/tpcds-q67-mem_limit-10g.test
M
testdata/workloads/functional-planner/queries/PlannerTest/calcite_tpcds/tpcds-q67-mem_limit_executors-20g.test
M
testdata/workloads/functional-planner/queries/PlannerTest/calcite_tpcds/tpcds-q67.test
M
testdata/workloads/functional-planner/queries/PlannerTest/calcite_tpcds/tpcds-q70.test
M
testdata/workloads/functional-planner/queries/PlannerTest/calcite_tpcds/tpcds-q77.test
M
testdata/workloads/functional-planner/queries/PlannerTest/calcite_tpcds/tpcds-q80.test
M
testdata/workloads/functional-planner/queries/PlannerTest/calcite_tpcds/tpcds-q86.test
M
testdata/workloads/functional-planner/queries/PlannerTest/explain-verbose-mt_dop.test
A
testdata/workloads/functional-planner/queries/PlannerTest/grouping-sets-chained-preagg.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds-processing-cost.test
M testdata/workloads/functional-planner/queries/PlannerTest/tpcds/tpcds-q05.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds/tpcds-q14a.test
M testdata/workloads/functional-planner/queries/PlannerTest/tpcds/tpcds-q18.test
M testdata/workloads/functional-planner/queries/PlannerTest/tpcds/tpcds-q22.test
M testdata/workloads/functional-planner/queries/PlannerTest/tpcds/tpcds-q27.test
M testdata/workloads/functional-planner/queries/PlannerTest/tpcds/tpcds-q36.test
M testdata/workloads/functional-planner/queries/PlannerTest/tpcds/tpcds-q67.test
M testdata/workloads/functional-planner/queries/PlannerTest/tpcds/tpcds-q70.test
M testdata/workloads/functional-planner/queries/PlannerTest/tpcds/tpcds-q77.test
M testdata/workloads/functional-planner/queries/PlannerTest/tpcds/tpcds-q80.test
M testdata/workloads/functional-planner/queries/PlannerTest/tpcds/tpcds-q86.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cpu_cost/tpcds-q05.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cpu_cost/tpcds-q14a.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cpu_cost/tpcds-q18.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cpu_cost/tpcds-q22.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cpu_cost/tpcds-q27.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cpu_cost/tpcds-q36.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cpu_cost/tpcds-q67-mem_limit-10g.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cpu_cost/tpcds-q67-mem_limit_executors-20g.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cpu_cost/tpcds-q67.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cpu_cost/tpcds-q70.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cpu_cost/tpcds-q77.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cpu_cost/tpcds-q80.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cpu_cost/tpcds-q86.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cte/tpcds-q05.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cte/tpcds-q14a.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cte/tpcds-q18.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cte/tpcds-q22.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cte/tpcds-q27.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cte/tpcds-q36.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cte/tpcds-q67.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cte/tpcds-q70.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cte/tpcds-q77.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cte/tpcds-q80.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_cte/tpcds-q86.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_tuple_cache/tpcds-q05.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_tuple_cache/tpcds-q14a.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_tuple_cache/tpcds-q18.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_tuple_cache/tpcds-q22.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_tuple_cache/tpcds-q27.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_tuple_cache/tpcds-q36.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_tuple_cache/tpcds-q67.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_tuple_cache/tpcds-q70.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_tuple_cache/tpcds-q77.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_tuple_cache/tpcds-q80.test
M
testdata/workloads/functional-planner/queries/PlannerTest/tpcds_tuple_cache/tpcds-q86.test
A testdata/workloads/tpch/queries/grouping-sets-chained-preagg-profile.test
A testdata/workloads/tpch/queries/grouping-sets-chained-preagg.test
M tests/query_test/test_aggregation.py
83 files changed, 2,687 insertions(+), 500 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/86/25386/5
--
To view, visit https://gerrit.cloudera.org/25386
To unsubscribe, visit https://gerrit.cloudera.org/settings
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I20667d8f97962ddbb10147f498722cc4cf25dd29
Gerrit-Change-Number: 25386
Gerrit-PatchSet: 5
Gerrit-Owner: Yida Wu <[email protected]>
Gerrit-Reviewer: Impala Public Jenkins <[email protected]>
Gerrit-Reviewer: Yida Wu <[email protected]>
Gerrit-Reviewer: Zoltan Borok-Nagy <[email protected]>