Commit 37d11af
refactor: make join projection pushdown schema-aware via ColumnIndex/… (#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.
---------
Signed-off-by: Jiawei Zhao <Phoenix500526@163.com>
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>1 parent dd1c30b commit 37d11af
5 files changed
Lines changed: 418 additions & 134 deletions
File tree
- datafusion
- physical-plan/src
- joins
- hash_join
- sqllogictest/test_files
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
1564 | 1564 | | |
1565 | 1565 | | |
1566 | 1566 | | |
1567 | | - | |
1568 | 1567 | | |
1569 | | - | |
1570 | | - | |
1571 | | - | |
1572 | | - | |
1573 | | - | |
1574 | | - | |
1575 | | - | |
1576 | | - | |
1577 | | - | |
1578 | | - | |
1579 | | - | |
1580 | | - | |
1581 | | - | |
1582 | | - | |
1583 | | - | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
1584 | 1582 | | |
1585 | 1583 | | |
1586 | 1584 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
741 | 741 | | |
742 | 742 | | |
743 | 743 | | |
744 | | - | |
745 | 744 | | |
746 | | - | |
747 | | - | |
748 | | - | |
749 | | - | |
750 | | - | |
751 | | - | |
752 | | - | |
753 | | - | |
754 | | - | |
755 | | - | |
756 | | - | |
757 | | - | |
758 | | - | |
759 | | - | |
760 | | - | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
761 | 759 | | |
762 | 760 | | |
763 | 761 | | |
| |||
Lines changed: 29 additions & 63 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | | - | |
| 50 | + | |
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
| |||
598 | 597 | | |
599 | 598 | | |
600 | 599 | | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
648 | 608 | | |
649 | 609 | | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
664 | 630 | | |
665 | 631 | | |
666 | 632 | | |
| |||
0 commit comments