Skip to content

[Data] Preserve limit().filter() semantics by stopping predicate pushdown at Limit - #66143

Merged
goutamvenkat-anyscale merged 1 commit into
ray-project:masterfrom
ai-yang:fix/data-limit-filter-order
Sep 17, 2026
Merged

goutamvenkat-anyscale merged 1 commit into
ray-project:masterfrom
ai-yang:fix/data-limit-filter-order

Conversation

@ai-yang

@ai-yang ai-yang commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

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 #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. #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 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.
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.

@ai-yang
ai-yang marked this pull request as ready for review September 13, 2026 05:39
@ai-yang
ai-yang requested a review from a team as a code owner September 13, 2026 05:39

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Sep 13, 2026
@goutamvenkat-anyscale goutamvenkat-anyscale added the go add ONLY when ready to merge, run all tests label Sep 17, 2026
@goutamvenkat-anyscale
goutamvenkat-anyscale enabled auto-merge (squash) September 17, 2026 21:36
@goutamvenkat-anyscale
goutamvenkat-anyscale merged commit bd2fc9a into ray-project:master Sep 17, 2026
7 checks passed
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community 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.

[Data] Predicate pushdown across Limit silently changes limit().filter() results

2 participants