Commit 6e943ae
Preserve column order in projection embedding to eliminate redundant ProjectionExec nodes
When `try_embed_projection` embeds a projection into a HashJoinExec (or
other operators), `collect_column_indices` previously collected column
indices into a HashSet and sorted them, losing the original column
ordering from the projection. This meant that when a projection simply
reordered columns, the embedded projection would output columns in
sorted index order instead of the desired order, requiring a residual
ProjectionExec just to reorder them.
This change preserves the insertion order of column indices:
- For simple Column expressions: the index is taken directly in
projection order
- For complex expressions referencing multiple columns: indices are
sorted for determinism (since `collect_columns` returns a HashSet)
Additionally, the final embedding decision now checks whether the
embedding actually reduced the number of columns. If the residual
ProjectionExec is not removable AND no columns were eliminated, the
embedding is skipped (it would only add an unnecessary column reorder).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 1e93a67 commit 6e943ae
42 files changed
Lines changed: 456 additions & 520 deletions
File tree
- datafusion
- physical-plan/src
- sqllogictest/test_files
- spark/map
- tpch
- plans
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
607 | 607 | | |
608 | 608 | | |
609 | 609 | | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
| 610 | + | |
617 | 611 | | |
618 | 612 | | |
619 | 613 | | |
| |||
648 | 642 | | |
649 | 643 | | |
650 | 644 | | |
| 645 | + | |
651 | 646 | | |
652 | | - | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
653 | 650 | | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
654 | 655 | | |
655 | 656 | | |
656 | 657 | | |
| |||
1080 | 1081 | | |
1081 | 1082 | | |
1082 | 1083 | | |
1083 | | - | |
1084 | | - | |
1085 | | - | |
1086 | | - | |
1087 | | - | |
1088 | | - | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
1092 | 1116 | | |
1093 | 1117 | | |
1094 | 1118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8780 | 8780 | | |
8781 | 8781 | | |
8782 | 8782 | | |
8783 | | - | |
| 8783 | + | |
8784 | 8784 | | |
8785 | 8785 | | |
8786 | 8786 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
| 134 | + | |
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
223 | | - | |
| 223 | + | |
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
| |||
712 | 712 | | |
713 | 713 | | |
714 | 714 | | |
715 | | - | |
| 715 | + | |
716 | 716 | | |
717 | 717 | | |
718 | 718 | | |
| |||
772 | 772 | | |
773 | 773 | | |
774 | 774 | | |
775 | | - | |
| 775 | + | |
776 | 776 | | |
777 | 777 | | |
778 | 778 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
673 | 673 | | |
674 | 674 | | |
675 | 675 | | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
680 | 679 | | |
681 | 680 | | |
682 | 681 | | |
| |||
717 | 716 | | |
718 | 717 | | |
719 | 718 | | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
724 | 722 | | |
725 | 723 | | |
726 | 724 | | |
| |||
1110 | 1108 | | |
1111 | 1109 | | |
1112 | 1110 | | |
1113 | | - | |
1114 | | - | |
| 1111 | + | |
| 1112 | + | |
1115 | 1113 | | |
1116 | 1114 | | |
1117 | 1115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
0 commit comments