Skip to content

[FEATURE] Calcite Engine Framework: pushdown sort with non-reference expression #3912

Closed

Description

@qianheng-aws

Is your feature request related to a problem?
Support push down sort on a non-reference expression, for example:

...| sort (a + 1)

...| sort length(a)

What solution would you like?
A clear and concise description of what you want to happen.

What alternatives have you considered?
A clear and concise description of any alternative solutions or features you've considered.

Do you have any additional context?
Add any other context or screenshots about the feature request here.

Activity

  1. songkant-aws commented on Jul 23, 2025

    @songkant-aws
    Collaborator

    Looking this issue

  2. added
    pushdown
    and removed on Jul 24, 2025
  3. added
    calcite
    on Jul 24, 2025
  4. songkant-aws commented on Aug 6, 2025

    @songkant-aws
    Collaborator

    Sort script pushdown needs to match the plan pattern like: Sort-Project-Scan, where non-trivial sort expression is put to a projected column in Project operator and Sort just needs to reference projected expression.

    Calcite Planner doesn't propagate monotonicity of RexCalls very well. It also has limitation of dropping NullDirection if the RexCall can inherit monotonicity based on input reference. There are a bunch of rules recalculating non-trivial expression's monotonicity based on input. So it's hard to maintain monotonicity on non-trivial expression level. It requires more workarounds to achieve it.

    Workarounds needed:

    • Wrap sorted expression with additional monotonic aware UDF to cheat optimizer
    • Extend RelMdCollation to support RexCall level collation propagation (to avoid dropping NullDirection)
    • Maintain virtual metadata column in Scan to avoid some rules failing to map to column

    Instead of pushing down pure sort script to scan, a proper solution is to optimize it as pushing down project expression script to scan. Then the problem would be similar to pushing down sort for reference expression. It may have duplicated script execution for both projected column and sort script but it depends on whether upper project wants to pruning column.

  5. moved this from Not Started to Done in PPL Trackeron Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

calciteenhancementpushdown

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions