Yida Wu has uploaded this change for review. ( 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".
- 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 GroupingSetsChainedPreaggTest for the planner.
- Added grouping-sets-chained-preagg.test and its -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, using two queries:
- Q1: on TPC-H SF1. Its first grouping set reduces the input a lot,
which is where chaining helps most:
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 on SF10 with mem_limit=1g. It is a ROLLUP over 8
item, date and store columns (9 grouping sets).
Median times of 5 runs on a release build, with chaining
(CHAIN_GROUPING_SETS_PREAGG=true) and without it (false). Preagg is
the time of the streaming preaggregation node in the exec summary,
Query the time of the whole query:
Preagg time Query time
Chained Not chained Chained Not chained
Q1 0.9s 2.7s 1.4s 3.4s
Q2 2.1s 4.4s 21.4s 24.2s
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
A fe/src/test/java/org/apache/impala/planner/GroupingSetsChainedPreaggTest.java
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
18 files changed, 1,185 insertions(+), 7 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/86/25386/1
--
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: newchange
Gerrit-Change-Id: I20667d8f97962ddbb10147f498722cc4cf25dd29
Gerrit-Change-Number: 25386
Gerrit-PatchSet: 1
Gerrit-Owner: Yida Wu <[email protected]>