Skip to content

Simplify aggregate table for ordered cases #23318

Description

@2010YOUY01

Is your feature request related to a problem or challenge?

Part of #22710
Follow up to #23309

Describe the solution you'd like

For ordered aggregation, we can likely simplify the implementation in a similar way to #23309.

The ordered aggregation case can be split into two variants:

  • Fully ordered input: the input is ordered by (a, b), and the query groups by (a, b)
  • Partially ordered input: the input is ordered by a, and the query groups by (a, b)

For the partially ordered variant, we should still use regular hash aggregation, with the early-emit optimization. For the fully ordered variant, there may be a deeper optimization that avoids the hash table entirely.

This refactor is probably easier after we first add the fast path for the fully ordered case. 🤔

Describe alternatives you've considered

No response

Additional context

No response

Activity

  1. self-assigned this
    on Jul 4, 2026
  2. hhhizzz commented on Jul 6, 2026

    @hhhizzz
    Contributor

    I found a TPC-DS SF10 performance regression on current main that appears related to the partially ordered aggregation path.

    Environment:

    • DataFusion current main: 6a0e76ed692afaafd616e0d98d51bef63c1ff02d
    • Dataset: TPC-DS SF10 Parquet
    • Query set: 99 queries
    • Parquet pushdown / filter reorder / pruning: enabled

    Result summary:

    Version DataFusion Arrow Avg full 99-query round
    Previous baseline 4d898e93f0 7b335b7712 31090.78 ms
    Current main 6a0e76ed69 d8d980bdcf 32876.21 ms

    Current main is about +1785 ms/round slower. The main stable contributors are q39 and q78.

    Per-query comparison:

    Query Before Current main Delta
    q39 ~1274 ms ~1962 ms +688 ms
    q78 ~655 ms ~1121 ms +466 ms

    Both q39 and q78 contain AggregateExec ... ordering_mode=PartiallySorted(...).

    The likely cause is that after #23181, these partially sorted aggregate cases are routed through the new ordered partial/final aggregate streams. For these TPC-DS queries, that path appears slower than the previous regular hash aggregation path with early emit. Debug metrics also suggest the extra time is concentrated in the aggregate emitting path.

    This seems consistent with the point in this issue that partially ordered input should likely still use regular hash aggregation with the early-emit optimization, while fully ordered input may need a separate optimized path.

  3. 2010YOUY01 commented on Jul 7, 2026

    @2010YOUY01
    ContributorAuthor

    I suspect the root cause is something similar to #23251

    For now we might want to do some patches without significant structural changes, eventually they should be reworked after #7065

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions