You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "NGA-TRAN (via GitHub)" <gi...@apache.org> on 2026/01/05 19:35:16 UTC

[I] Use pipeline aggregation when data is implicitly sorted by group-by keys [datafusion]

NGA-TRAN opened a new issue, #19655:
URL: https://github.com/apache/datafusion/issues/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:
   
   ```SQL
   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.
   
   This is related to https://github.com/apache/datafusion/issues/16899
   
   ### Describe the solution you'd like
   
   We need to define and propagate the uniqueness-based sort order.
   
   ### Describe alternatives you've considered
   
   _No response_
   
   ### Additional context
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Use pipeline aggregation when data is implicitly sorted by group-by keys [datafusion]

Posted by "NGA-TRAN (via GitHub)" <gi...@apache.org>.
NGA-TRAN commented on issue #19655:
URL: https://github.com/apache/datafusion/issues/19655#issuecomment-3736644707

   **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`)
   
   ```SQL
   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
           (
           SELECT
               f.f_dkey,
               d.env,
               d.service,
               d.host,
               f.timestamp,
               f.value
           FROM dimension_table d
           INNER JOIN fact_table_ordered f ON d.d_dkey = f.f_dkey
           WHERE 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:
      - https://github.com/apache/datafusion/pull/19124
      - https://github.com/apache/datafusion/pull/19304
      
   @xavlee : When you start working on this, let us chat with @gene-bordegaray first. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Use pipeline aggregation when data is implicitly sorted by group-by keys [datafusion]

Posted by "xavlee (via GitHub)" <gi...@apache.org>.
xavlee commented on issue #19655:
URL: https://github.com/apache/datafusion/issues/19655#issuecomment-3712011265

   take


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org