You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use pipeline aggregation when data is implicitly sorted by group-by keys #19655
Is your feature request related to a problem or challenge?
We have a use case where the query groups by columns that are implicitly sorted, and we would like DataFusion to recognize that ordering so it can apply pipeline aggregation.
Consider the following query:
SELECT ...
FROM t
GROUP BY a, b;
In our data, the input is explicitly sorted only by a. However, b is always unique within each (a, b) pair, which means the data is implicitly sorted by (a, b) even though only a appears in the physical sort order.
If DataFusion could infer or be informed that the data is effectively sorted by (a, b), it would be able to use pipeline aggregation, resulting in better performance.
Some hints: I suggest we start by running some benchmarking or performance tests to determine whether this is worth pursuing.
Create two different schemas on the same dataset: one explicitly sorted on (a, b) and another sorted only on a. The first should produce a group‑by pipeline, while the second will fall back to a group‑by hash.
We may also want to run these tests on more realistic query such as (data is explicitly sorted on f_dkey, timestamp but implicitly sorted by f_dkey, date_bin, env)
SELECT env, time_bin, AVG(max_bin_value) AS avg_max_value
FROM
(
SELECT f_dkey,
date_bin(INTERVAL '30 seconds', timestamp) AS time_bin,
env,
MAX(value) AS max_bin_value
FROM
(
SELECTf.f_dkey,
d.env,
d.service,
d.host,
f.timestamp,
f.valueFROM dimension_table d
INNER JOIN fact_table_ordered f ONd.d_dkey=f.f_dkeyWHERE service ='log'
) AS j
GROUP BY f_dkey, time_bin, env
) AS a
GROUP BY env, time_bin
ORDER BY env, time_bin;
Also, these 2 PRs have some related properties and tests:
Activity
xavlee commentedon Jan 5, 2026
take
NGA-TRAN commentedon Jan 12, 2026
Some hints: I suggest we start by running some benchmarking or performance tests to determine whether this is worth pursuing.
(a, b)and another sorted only ona. The first should produce a group‑by pipeline, while the second will fall back to a group‑by hash.f_dkey, timestampbut implicitly sorted byf_dkey, date_bin, env)@xavlee : When you start working on this, let us chat with @gene-bordegaray first.