Commit 13fea4f
[SPARK-54383][SQL] Add precomputed schema variant for InternalRowComparableWrapper util
### What changes were proposed in this pull request?
The InternalRowComparableWrapper util is often used in a very hot-path for physical planning (most often, to compare partition values for key-grouped partitioned scans). While the current implementation does schema lookup that each instance uses to create a new instance of this object, this cache lookup itself can become a bottleneck for planning when there are large numbers of partitions. This PR adds a new InternalRowComparableWrapper factory for this util that has a precomputed schema and ordering that can be shared across multiple objects, removing this schema or cache lookup from the hot-path for physical planning.
### Why are the changes needed?
Removes a physical planning bottleneck.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
This change should not change any behavior (existing tests should suffice).
This PR also includes changes to the `InternalRowComparableWrapperBenchmark` to use these new utils. Results before change:
```
[info] internal row comparable wrapper: Best Time(ms) Avg Time(ms) Stdev(ms) Rate(M/s) Per Row(ns) Relative
[info] ------------------------------------------------------------------------------------------------------------------------
[info] toSet 74 76 2 2.7 367.5 1.0X
[info] mergePartitions 136 143 11 1.5 680.0 0.5X
[success] Total time: 11 s, completed Nov 17, 2025, 2:29:22 PM
```
Results after change:
```
[info] internal row comparable wrapper: Best Time(ms) Avg Time(ms) Stdev(ms) Rate(M/s) Per Row(ns) Relative
[info] ------------------------------------------------------------------------------------------------------------------------
[info] toSet 13 13 1 15.9 62.9 1.0X
[info] mergePartitions 17 17 1 11.8 84.7 0.7X
```
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #53097 from chirag-s-db/birc.
Authored-by: Chirag Singh <[email protected]>
Signed-off-by: Chao Sun <[email protected]>1 parent 1012a5f commit 13fea4f
File tree
5 files changed
+94
-42
lines changed- sql
- catalyst/src
- main/scala/org/apache/spark/sql/catalyst
- plans/physical
- util
- test/scala/org/apache/spark/sql/catalyst/util
- core/src/main/scala/org/apache/spark/sql/execution
- exchange
5 files changed
+94
-42
lines changedLines changed: 20 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
431 | 434 | | |
432 | | - | |
| 435 | + | |
433 | 436 | | |
434 | 437 | | |
435 | 438 | | |
| |||
448 | 451 | | |
449 | 452 | | |
450 | 453 | | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
451 | 457 | | |
452 | 458 | | |
453 | | - | |
454 | | - | |
455 | | - | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
456 | 462 | | |
457 | 463 | | |
458 | 464 | | |
| |||
867 | 873 | | |
868 | 874 | | |
869 | 875 | | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
870 | 879 | | |
871 | 880 | | |
872 | 881 | | |
873 | 882 | | |
874 | | - | |
875 | | - | |
| 883 | + | |
876 | 884 | | |
877 | 885 | | |
878 | 886 | | |
| |||
957 | 965 | | |
958 | 966 | | |
959 | 967 | | |
960 | | - | |
961 | | - | |
962 | | - | |
963 | | - | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
964 | 973 | | |
965 | 974 | | |
966 | 975 | | |
967 | 976 | | |
968 | | - | |
| 977 | + | |
969 | 978 | | |
970 | 979 | | |
971 | 980 | | |
| |||
Lines changed: 29 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
38 | 41 | | |
39 | | - | |
40 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
41 | 53 | | |
42 | 54 | | |
43 | 55 | | |
| |||
96 | 108 | | |
97 | 109 | | |
98 | 110 | | |
| 111 | + | |
| 112 | + | |
99 | 113 | | |
100 | | - | |
| 114 | + | |
101 | 115 | | |
102 | 116 | | |
103 | 117 | | |
104 | | - | |
| 118 | + | |
105 | 119 | | |
106 | 120 | | |
107 | 121 | | |
| |||
111 | 125 | | |
112 | 126 | | |
113 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
114 | 136 | | |
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
51 | 54 | | |
52 | | - | |
| 55 | + | |
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
| |||
Lines changed: 22 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
53 | 57 | | |
54 | 58 | | |
55 | | - | |
| 59 | + | |
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
| |||
83 | 87 | | |
84 | 88 | | |
85 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
86 | 93 | | |
87 | 94 | | |
88 | 95 | | |
89 | 96 | | |
90 | | - | |
| 97 | + | |
91 | 98 | | |
92 | 99 | | |
93 | 100 | | |
| |||
99 | 106 | | |
100 | 107 | | |
101 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
102 | 112 | | |
103 | 113 | | |
104 | 114 | | |
105 | | - | |
| 115 | + | |
| 116 | + | |
106 | 117 | | |
107 | 118 | | |
108 | 119 | | |
| |||
118 | 129 | | |
119 | 130 | | |
120 | 131 | | |
121 | | - | |
| 132 | + | |
122 | 133 | | |
123 | 134 | | |
124 | 135 | | |
125 | | - | |
126 | | - | |
| 136 | + | |
127 | 137 | | |
128 | 138 | | |
129 | 139 | | |
130 | | - | |
131 | | - | |
| 140 | + | |
132 | 141 | | |
133 | 142 | | |
134 | 143 | | |
| |||
143 | 152 | | |
144 | 153 | | |
145 | 154 | | |
146 | | - | |
| 155 | + | |
147 | 156 | | |
148 | 157 | | |
149 | 158 | | |
| |||
152 | 161 | | |
153 | 162 | | |
154 | 163 | | |
155 | | - | |
| 164 | + | |
156 | 165 | | |
157 | 166 | | |
158 | 167 | | |
159 | 168 | | |
160 | 169 | | |
161 | 170 | | |
162 | | - | |
| 171 | + | |
163 | 172 | | |
164 | 173 | | |
165 | 174 | | |
| |||
168 | 177 | | |
169 | 178 | | |
170 | 179 | | |
171 | | - | |
172 | | - | |
| 180 | + | |
173 | 181 | | |
174 | 182 | | |
175 | 183 | | |
| |||
Lines changed: 19 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
579 | 579 | | |
580 | 580 | | |
581 | 581 | | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
582 | 585 | | |
583 | 586 | | |
584 | | - | |
| 587 | + | |
585 | 588 | | |
586 | 589 | | |
587 | 590 | | |
588 | 591 | | |
589 | 592 | | |
590 | | - | |
| 593 | + | |
591 | 594 | | |
592 | 595 | | |
593 | 596 | | |
| |||
679 | 682 | | |
680 | 683 | | |
681 | 684 | | |
682 | | - | |
683 | | - | |
684 | | - | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
685 | 694 | | |
686 | 695 | | |
687 | 696 | | |
| |||
737 | 746 | | |
738 | 747 | | |
739 | 748 | | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
740 | 752 | | |
741 | 753 | | |
742 | 754 | | |
743 | 755 | | |
744 | 756 | | |
745 | | - | |
746 | | - | |
747 | | - | |
748 | | - | |
| 757 | + | |
| 758 | + | |
749 | 759 | | |
750 | 760 | | |
751 | 761 | | |
| |||
0 commit comments