Phoenix500526 opened a new pull request, #23185:
URL: https://github.com/apache/datafusion/pull/23185
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases. You can
link an issue to this PR using the GitHub syntax. For example `Closes #123`
indicates that this PR will close issue #123.
-->
- Closes #23010
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in
the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your
changes and offer better suggestions for fixes.
-->
`try_pushdown_through_join` (`datafusion/physical-plan/src/projection.rs`)
decided whether each projected join-output column belonged to the left or
right
child by comparing its output index against the left child's field count
(`join_table_borders`) — i.e. it assumed the join output is a plain
`left ++ right` concatenation.
That assumption does not hold for all join types. A `LeftMark` / `RightMark`
join appends a synthetic `mark` boolean column that has `JoinSide::None` and
originates from neither child, so reasoning from output position can route
the
`mark` column to the wrong child. This is the panic that #22902 worked
around by
**disabling** projection pushdown for `LeftMark` / `RightMark` in
`HashJoinExec`
and `NestedLoopJoinExec` — correct, but it left the helper reasoning from
output
position rather than from the join's actual output-origin contract.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is
sometimes worth providing a summary of the individual changes in this PR.
-->
- Thread the join's output-origin metadata (`&[ColumnIndex]`, already
computed by
`build_join_schema`) into `try_pushdown_through_join`.
- Replace the output-position split (`join_table_borders` +
`index < left_field_count`) with grouping by `ColumnIndex.side`:
- `Left` / `Right` columns are collected per child using the child-relative
`ColumnIndex.index`;
- a `JoinSide::None` (synthetic, e.g. `mark`) column makes the pushdown
decline
(`Ok(None)`), so the projection is embedded into the join instead — no
panic,
no mis-routing.
- Remove the `LeftMark | RightMark` bypass from
`HashJoinExec::try_swapping_with_projection` and
`NestedLoopJoinExec::try_swapping_with_projection`; they now call
`try_pushdown_through_join` uniformly.
- The shared helpers used by cross / symmetric-hash / sort-merge join
pushdown
(`new_join_children`, `join_table_borders`, `join_allows_pushdown`,
`update_join_on`, `update_join_filter`) keep their signatures. The
side-grouped
path uses a new private `new_join_children_from_groups` and reuses
`update_join_on` / `update_join_filter` with a zero column-index offset
(the
groups already carry child-relative indices).
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are
they covered by existing tests)?
-->
Yes.
- New `subquery.slt` cases place a subset/reordering projection over a mark
join
— hash `LeftMark` (`IN` under `OR`), negated mark (`NOT EXISTS` under
`OR`),
and nested-loop mark (non-equi correlated) — asserting both the query
result
and the `EXPLAIN` plan shape.
- Existing coverage is preserved: `cargo test -p datafusion-physical-plan
projection` (incl. the filter-pushdown and `join_table_borders` unit
tests),
the join `*.slt` suite, and `subquery.slt` all pass.
- `cargo clippy -p datafusion-physical-plan -- -D warnings` and `cargo fmt
--all`
are clean.
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
No behavior change: the produced physical plans are unchanged for the
supported
cases (mark joins keep falling back to the same embedded-projection plan as
before, regular joins push down as before).
One signature change to a `pub` helper: `try_pushdown_through_join` gains a
`column_indices: &[ColumnIndex]` parameter (all in-tree callers are
updated). If
the project treats this helper as part of the public API surface, please add
the
`api change` label.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]