Commit 11c2fbc
authored
Misc minor optimization in the Physical Optimizer (#21216)
## Which issue does this PR close?
- Closes #.
## Rationale for this change
Similar to #21128, just trying to shave time off the optimizer. Locally,
it improves some sql-planner benchmarks by up to 10% but they seem
relatively noisy on my laptop.
## What changes are included in this PR?
1. Avoid allocation `plan.children()` in a loop in `sort_pushdown.rs`.
2. Try and avoid some expensive tree rewrites in `join_selection.rs`
3. Avoid deep clones of exec limit nodes in `limit_pushdown.rs`, and
only mutate the plan if it was actually changed.
4. Use cheaper code path to change the limit on an `AggregateExec` in
`limited_distinct_aggregation.rs`.
5. Use a read-only traversal in `sanity_checker.rs`. Its read only and
`transform_up` is always more expensive. I've considered extending
`TreeNode` but this seems to be basically the only place in the codebase
that does something like this.
There are a few places where we unconditionally return
`Transformed::yes` which might unintended downstream consequences
because it breaks pointer equality and I think it also just end up
allocating more memory, but they are harder to untangle so I'll try and
do them in followups.
## Are these changes tested?
One new test for limits, otherwise the existing tests.
## Are there any user-facing changes?
Removes the `LimitExec` type, I can't imagine why someone would use it,
and its only used in one place. Happy to bring it back as a deprecated
type.
---------
Signed-off-by: Adam Gutglick <adamgsal@gmail.com>1 parent 2c08ddb commit 11c2fbc
File tree
10 files changed
+135
-105
lines changed- datafusion
- core/tests/physical_optimizer
- physical-optimizer/src
- enforce_sorting
10 files changed
+135
-105
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1256 | 1256 | | |
1257 | 1257 | | |
1258 | 1258 | | |
1259 | | - | |
| 1259 | + | |
| 1260 | + | |
1260 | 1261 | | |
1261 | 1262 | | |
1262 | 1263 | | |
| |||
Lines changed: 35 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
682 | 682 | | |
683 | 683 | | |
684 | 684 | | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
548 | 548 | | |
549 | 549 | | |
550 | 550 | | |
551 | | - | |
552 | | - | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
553 | 554 | | |
554 | 555 | | |
555 | 556 | | |
| |||
Lines changed: 8 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
680 | 680 | | |
681 | 681 | | |
682 | 682 | | |
| 683 | + | |
| 684 | + | |
683 | 685 | | |
684 | | - | |
| 686 | + | |
685 | 687 | | |
686 | 688 | | |
687 | 689 | | |
| |||
699 | 701 | | |
700 | 702 | | |
701 | 703 | | |
702 | | - | |
703 | | - | |
| 704 | + | |
704 | 705 | | |
705 | 706 | | |
706 | 707 | | |
| |||
734 | 735 | | |
735 | 736 | | |
736 | 737 | | |
737 | | - | |
| 738 | + | |
738 | 739 | | |
739 | 740 | | |
740 | 741 | | |
| |||
809 | 810 | | |
810 | 811 | | |
811 | 812 | | |
| 813 | + | |
| 814 | + | |
812 | 815 | | |
813 | 816 | | |
814 | 817 | | |
815 | 818 | | |
816 | 819 | | |
817 | 820 | | |
818 | | - | |
| 821 | + | |
819 | 822 | | |
820 | 823 | | |
821 | 824 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
563 | 563 | | |
564 | 564 | | |
565 | 565 | | |
| 566 | + | |
566 | 567 | | |
567 | 568 | | |
568 | 569 | | |
569 | | - | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
570 | 574 | | |
571 | 575 | | |
572 | 576 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | | - | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
81 | | - | |
| 82 | + | |
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | | - | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
173 | 133 | | |
174 | 134 | | |
175 | 135 | | |
| |||
184 | 144 | | |
185 | 145 | | |
186 | 146 | | |
187 | | - | |
| 147 | + | |
188 | 148 | | |
189 | 149 | | |
190 | 150 | | |
191 | 151 | | |
192 | 152 | | |
193 | | - | |
194 | | - | |
| 153 | + | |
| 154 | + | |
195 | 155 | | |
196 | 156 | | |
197 | 157 | | |
198 | | - | |
| 158 | + | |
199 | 159 | | |
200 | 160 | | |
201 | 161 | | |
202 | | - | |
203 | | - | |
| 162 | + | |
| 163 | + | |
204 | 164 | | |
205 | 165 | | |
206 | | - | |
| 166 | + | |
207 | 167 | | |
208 | 168 | | |
209 | 169 | | |
| |||
253 | 213 | | |
254 | 214 | | |
255 | 215 | | |
256 | | - | |
| 216 | + | |
257 | 217 | | |
258 | 218 | | |
259 | 219 | | |
| |||
341 | 301 | | |
342 | 302 | | |
343 | 303 | | |
| 304 | + | |
344 | 305 | | |
345 | 306 | | |
346 | | - | |
347 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
348 | 315 | | |
349 | 316 | | |
350 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
351 | 323 | | |
352 | 324 | | |
353 | | - | |
| 325 | + | |
354 | 326 | | |
355 | | - | |
| 327 | + | |
356 | 328 | | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
362 | 335 | | |
363 | 336 | | |
364 | 337 | | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
370 | 343 | | |
371 | 344 | | |
372 | 345 | | |
| |||
Lines changed: 2 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 57 | + | |
| 58 | + | |
67 | 59 | | |
68 | 60 | | |
69 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
433 | | - | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
434 | 441 | | |
435 | 442 | | |
436 | 443 | | |
| |||
0 commit comments