Skip to content

[Data] Limit operator push down #54457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

goutamvenkat-anyscale
Copy link
Contributor

Why are these changes needed?

Previously, the limit operator push down optimization was disabled because there was no guarantee that Map, MapBatches etc. were not modifying the number of rows. In this change, we pushdown the limit operator for Project, MapRows, MapBatches and for Union each union has its own limit operator pushed down on it.

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: Goutam V <goutam@anyscale.com>
@goutamvenkat-anyscale goutamvenkat-anyscale requested a review from a team as a code owner July 9, 2025 00:49
Signed-off-by: Goutam V <goutam@anyscale.com>
Signed-off-by: Goutam V <goutam@anyscale.com>
@goutamvenkat-anyscale goutamvenkat-anyscale added the data Ray Data-related issues label Jul 9, 2025
Comment on lines +107 to +110
for limit_output_op in limit_op.output_dependencies:
limit_output_op._input_dependencies = [ops_between_new_input_and_limit[0]]
last_op = ops_between_new_input_and_limit[0]
last_op._output_dependencies = limit_op.output_dependencies
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct me if i'm wrong but don't u still need to

  1. link limit_output_op.output_dependencies.input_dependencies to last_op.output_dependencies
  2. ops_between_new_input_and_limit[-1] (most upstream op) input dependencies need to link with limit_output_op.output_dependencies

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me draw it out and double check this

- Union operations (pushed to all inputs)

We stop at:
- Any operator that can modify the number of output rows (Sort, Shuffle, Aggregate, Read etc.)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can pushdown limit into these Ops but not past it. For instance, limit pushdown into Sorts involve sorting on keys for the entire Dataset, but only yield limit rows on the Sorted Dataset.

Same for Joins, Groupbys.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. https://docs.rs/datafusion-optimizer/48.0.1/src/datafusion_optimizer/push_down_limit.rs.html#38 Datafusion does this for sort whereby limit is embedded into the sort operator.

Signed-off-by: Goutam V <goutam@anyscale.com>
Signed-off-by: Goutam V <goutam@anyscale.com>
Signed-off-by: Goutam V <goutam@anyscale.com>
@goutamvenkat-anyscale goutamvenkat-anyscale added the go add ONLY when ready to merge, run all tests label Jul 10, 2025
Signed-off-by: Goutam V <goutam@anyscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data Ray Data-related issues go add ONLY when ready to merge, run all tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants