Repository navigation
[Data] Preserve limit().filter() semantics by stopping predicate pushdown at Limit - #66143
Merged
goutamvenkat-anyscale merged 1 commit intoSep 17, 2026
Conversation
Signed-off-by: Rui <[email protected]>
ai-yang
marked this pull request as ready for review
September 13, 2026 05:39
Contributor
There was a problem hiding this comment.
Code Review
This pull request modifies the query optimizer logic to prevent predicates from pushing through the Limit operator, as filtering before limiting changes the final row selection. The Limit operator no longer inherits from LogicalOperatorSupportsPredicatePassThrough, and its documentation and related tests have been updated to enforce and verify this new behavior. As there are no review comments, no further feedback is provided.
goutamvenkat-anyscale
approved these changes
Sep 17, 2026
goutamvenkat-anyscale
enabled auto-merge (squash)
September 17, 2026 21:36
nadongjun
pushed a commit
to nadongjun/ray
that referenced
this pull request
Oct 6, 2026
…down at Limit (ray-project#66143) ## Description The default optimizer currently rewrites `Filter(Limit(input))` as `Limit(Filter(input))`. For example, `range(10).limit(3).filter(id >= 3)` returns IDs 3, 4, and 5 instead of an empty result. This silently changes which rows the query selects. Remove `Limit`'s predicate pass-through trait so filters cannot cross that boundary. Safe projection rebinding still works, and filters originally placed before the limit remain eligible for reader pushdown. Update the existing tests that assumed these operations commute, and add eight regression cases covering Range/Parquet, one/three input blocks, and partial/empty filtered results after a rename. The complex-pipeline test now compares against an explicit materialization boundary after the limit and verifies that the post-limit filter stays outside the reader. ## Related issues Fixes ray-project#66142. ## Duplicate-work check Rechecked issues and PRs on 2026-09-13 using `limit filter`, `filter limit`, `predicate limit`, and `Filter(Limit`, including current open PRs. No matching in-flight fix was found. ray-project#51966 concerns avoiding unnecessary reads; merged ray-project#64651 changes pushdown rule ordering for efficiency. The tested baseline already includes ray-project#64651 and still returns the incorrect rows described above. ## Validation Revalidated on 2026-09-13. Linux x86_64, Python 3.11.15, Ray `3.0.0.dev0`. The official nightly wheel and source checkout both use commit `be4889928d3a396d7a1476d1bac3288dac72f9ab`; Python sources are linked using `setup-dev.py`. - Two minimal reproduction cases, repeated three times each: all six fail on the baseline and all six return the expected rows after this change. - The complete predicate-pushdown and limit-pushdown test modules: **88 passed**. - Ruff, import sorting, Black, pydoclint, docstyle, and the other pre-commit hooks applicable to the changed files pass, as does `git diff --check`. ```bash RAY_USAGE_STATS_ENABLED=0 python -c 'import ray,pytest; raise SystemExit(pytest.main(["python/ray/data/tests/test_predicate_pushdown.py", "python/ray/data/tests/test_execution_optimizer_limit_pushdown.py", "-q", "--tb=short"]))' ``` The command imports the installed Ray package before pytest to use the matching wheel's compiled components with the linked local Python modules. This does not constitute a full C++ build or full-repository test run. ## Compatibility Queries that filter after a limit will preserve the requested operation order. They may push fewer predicates into readers, because moving those predicates across the limit changes results. No API or configuration changes are introduced. Signed-off-by: Rui <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The default optimizer currently rewrites
Filter(Limit(input))asLimit(Filter(input)). For example,range(10).limit(3).filter(id >= 3)returns IDs 3, 4, and 5 instead of an empty result. This silently changes which rows the query selects.Remove
Limit's predicate pass-through trait so filters cannot cross that boundary. Safe projection rebinding still works, and filters originally placed before the limit remain eligible for reader pushdown. Update the existing tests that assumed these operations commute, and add eight regression cases covering Range/Parquet, one/three input blocks, and partial/empty filtered results after a rename.The complex-pipeline test now compares against an explicit materialization boundary after the limit and verifies that the post-limit filter stays outside the reader.
Related issues
Fixes #66142.
Duplicate-work check
Rechecked issues and PRs on 2026-09-13 using
limit filter,filter limit,predicate limit, andFilter(Limit, including current open PRs. No matching in-flight fix was found. #51966 concerns avoiding unnecessary reads; merged #64651 changes pushdown rule ordering for efficiency. The tested baseline already includes #64651 and still returns the incorrect rows described above.Validation
Revalidated on 2026-09-13. Linux x86_64, Python 3.11.15, Ray
3.0.0.dev0. The official nightly wheel and source checkout both use commitbe4889928d3a396d7a1476d1bac3288dac72f9ab; Python sources are linked usingsetup-dev.py.git diff --check.RAY_USAGE_STATS_ENABLED=0 python -c 'import ray,pytest; raise SystemExit(pytest.main(["python/ray/data/tests/test_predicate_pushdown.py", "python/ray/data/tests/test_execution_optimizer_limit_pushdown.py", "-q", "--tb=short"]))'The command imports the installed Ray package before pytest to use the matching wheel's compiled components with the linked local Python modules. This does not constitute a full C++ build or full-repository test run.
Compatibility
Queries that filter after a limit will preserve the requested operation order. They may push fewer predicates into readers, because moving those predicates across the limit changes results. No API or configuration changes are introduced.