Skip to content

[Data] Derive required columns through Join in ProjectionPushdown - #68158

Merged
owenowenisme merged 4 commits into
ray-project:masterfrom
400Ping:data/join-projection-derivation
Nov 20, 2026
Merged

owenowenisme merged 4 commits into
ray-project:masterfrom
400Ping:data/join-projection-derivation

Conversation

@400Ping

@400Ping 400Ping commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Description

ProjectionPushdown now derives the columns each operator needs from what its consumers reference, and carries that set down through Join, Aggregate, Sort and the other pass-through operators to the reads. A multi-table query no longer needs a hand-written select_columns on every table.

Before

Derivation stopped at the first non-Project operator (the one exception was directly below an Aggregate). Every TPC-H script therefore opens with load_table(...).select_columns([...]) per table; without it, scans and shuffles run at full width.

After

  • New trait LogicalOperatorSupportsProjectionPassThrough.required_input_columns(): given the output columns its consumers need, an operator returns the columns each input must provide, or declines.
  • ProjectionPushdown._derive_required_columns walks the plan top-down once and inserts a pruning Project below shuffles and on top of reads that can absorb it. The existing fuse and push-into-read steps do the rest.
  • Join splits the set by side and adds what it reads itself: the on keys, the condition keys and the condition columns ([Data] Add condition to Dataset.join and extract equi-join keys from it #67590). It keeps both members of a suffixed collision, prunes the non-emitted side of a semi/anti join to its keys, and is left alone when its output schema can't be inferred.
  • The rule stays idempotent: it inserts only for a strict subset, and reverts a subtree that would no longer emit a required column.
flowchart TD
    subgraph Before
        subgraph BS[Subsystem: logical planning]
            subgraph BR[ProjectionPushdown]
                B0[Project: select a, b] --> B1[Join on id]
                B1 --> B2["ReadParquet(left): id, a, unused_left"]
                B1 --> B3["ReadParquet(right): id, b, unused_right"]
            end
        end
    end
    subgraph After
        subgraph AS[Subsystem: logical planning]
            subgraph AR[ProjectionPushdown + required_input_columns]
                A0[Project: select a, b] --> A1[Join on id]
                A1 --> A2["ReadParquet(left): id, a"]
                A1 --> A3["ReadParquet(right): id, b"]
            end
        end
    end
    classDef changed fill:#fff9c4,stroke:#f9a825,color:#000
    classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000
    class A1 added
    class A2,A3 changed
Loading

Subsystems

Logical planning / query optimization. The behavioral change is in rules/projection_pushdown.py; the operator files only gain trait implementations.

Benchmark

TPC-H Q7 (release/nightly_tests/dataset/tpch/tpch_q7.py) on SF1 local Parquet, one 20-core node.

Q7 variant master This PR Shuffled bytes
As is, hand-written select_columns kept 7.43 s 7.39 s 107 MB → 107 MB
select_columns removed from the 5 scans 7.78 s 7.53 s 482 MB → 107 MB
All 9 select_columns removed 11.98 s 7.37 s 709 MB → 107 MB

Related issues

Closes #66833

Additional information

@400Ping
400Ping marked this pull request as ready for review November 18, 2026 06:33
@400Ping
400Ping requested a review from a team as a code owner November 18, 2026 06:33
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit d96b301. Configure here.

@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Nov 18, 2026
required: pruning the other would make the physical join stop
suffixing the survivor, changing the output name the consumer uses.
"""
output_schema = self.infer_schema()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I just find out we didnt cache join inferred schema in the op, can you add that in a follow up?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, I'll do that in a follow-up.

# prune when every aggregation declares the column it reads.
if not isinstance(agg, AggregateFnV2):
new_op = op._with_new_input_dependencies(new_inputs)
if required is not None and op.infer_schema() is not None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why skip check when op.infer_schema() is None? I think we should still return original op if we cannot infer?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in f75150f, with one difference from your suggestion. Returning op whenever the schema is unknown would also drop pruning below UDF maps and below aggregates with undeclared output types (Unique, Quantile, ...). Instead, when the output schema is unknown it checks that each input the operator narrowed still provides what was asked, and returns op if not.

@400Ping
400Ping requested a review from owenowenisme November 20, 2026 07:21
@owenowenisme owenowenisme added the go add ONLY when ready to merge, run all tests label Nov 20, 2026
@owenowenisme
owenowenisme enabled auto-merge (squash) November 20, 2026 09:17
@owenowenisme
owenowenisme merged commit dd2e802 into ray-project:master Nov 20, 2026
7 checks passed
elliot-barn added a commit that referenced this pull request Nov 23, 2026
…nto releases/2.61.0 (#68472)

## Description

Cherry-pick of #68433 (`1729626bbb`) onto `releases/2.61.0`. Lets the
upstream read or map fuse into the disk-shuffle writer, and sets the
polars thread limit inside the task rather than through the runtime env.

The pick applied without conflicts. Seven master commits that touch the
same files are not on the release branch (#67143, #68158, #68202 and its
revert #68383, #68319, #67570, #68118), so the picked files differ from
master in five places. Reviewers from Data, please confirm none of those
is a prerequisite.

## Testing

Ran locally against the `releases/2.61.0` wheel (`7c8ca5ea51`) with the
picked files overlaid: `test_hash_shuffle_v2.py`,
`test_operator_fusion.py` and `test_execution_optimizer_advanced.py`,
232 passed, 2 skipped.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: You-Cheng Lin <[email protected]>
Signed-off-by: elliot-barn <[email protected]>
Co-authored-by: You-Cheng Lin <[email protected]>
owenowenisme added a commit that referenced this pull request Nov 24, 2026
## Description
With #68158 we dont have to hand-prune unused columns anymore, it
automatically push projection down. So we don't have to manually write
projection in test scripts
Can be merged after #68455 

## Related issues
> Link related issues: "Fixes #1234", "Closes #1234", or "Related to
#1234".

## Additional information
> Optional: Add implementation details, API changes, usage examples,
screenshots, etc.

Signed-off-by: You-Cheng Lin <[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] Derive required columns through Join in ProjectionPushdown

2 participants