Repository navigation
Commit cda4dd6
perf: compare nested ScalarValues by type before converting to ArrayData (#26066)
## Which issue does this PR close?
- Closes #26065.
## Rationale for this change
Physical planning slows down, faster than the query grows, when
projections carry many typed NULL struct literals: a `UNION ALL` of 35
branches with 35 struct columns of 20 fields takes 862 ms in
`create_physical_plan` on `main`. `EquivalenceGroup::add_constant`
compares each new constant with every existing class, and
`ScalarValue::eq` compares nested values with arrow's array equality,
which converts both arrays to `ArrayData` before it compares anything,
even when the two values have different types.
## What changes are included in this PR?
`ScalarValue::eq` compares the nested variants (`List`, `LargeList`,
`FixedSizeList`, `ListView`, `LargeListView`, `Struct`, `Map`) through a
helper that returns early for the same `Arc`, and compares lengths and
data types before arrow's array equality. Results are unchanged; only
values of the same type and length reach the `ArrayData` comparison.
With the reproducer from the issue (release build, Apple M1 Max),
`create_physical_plan`:
| struct columns x fields | main | this PR |
|---|---:|---:|
| 10 x 20 | 31 ms | 17 ms |
| 20 x 20 | 179 ms | 47 ms |
| 35 x 20 | 862 ms | 147 ms |
| 35 x 40 | 1,766 ms | 253 ms |
## What is the testing strategy for this PR?
`test_nested_scalar_eq` covers typed NULL structs of the same and of
different types, struct values that are equal and unequal, and lists of
different element types. The scalar tests in `datafusion-common` pass.
## Are there any user-facing changes?
No.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>1 parent c280a4b commit cda4dd6
1 file changed
Lines changed: 63 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
484 | 497 | | |
485 | 498 | | |
486 | 499 | | |
| |||
552 | 565 | | |
553 | 566 | | |
554 | 567 | | |
555 | | - | |
| 568 | + | |
556 | 569 | | |
557 | | - | |
| 570 | + | |
558 | 571 | | |
559 | | - | |
| 572 | + | |
560 | 573 | | |
561 | | - | |
| 574 | + | |
562 | 575 | | |
563 | | - | |
| 576 | + | |
564 | 577 | | |
565 | | - | |
| 578 | + | |
566 | 579 | | |
567 | | - | |
| 580 | + | |
568 | 581 | | |
569 | 582 | | |
570 | 583 | | |
| |||
9929 | 9942 | | |
9930 | 9943 | | |
9931 | 9944 | | |
| 9945 | + | |
| 9946 | + | |
| 9947 | + | |
| 9948 | + | |
| 9949 | + | |
| 9950 | + | |
| 9951 | + | |
| 9952 | + | |
| 9953 | + | |
| 9954 | + | |
| 9955 | + | |
| 9956 | + | |
| 9957 | + | |
| 9958 | + | |
| 9959 | + | |
| 9960 | + | |
| 9961 | + | |
| 9962 | + | |
| 9963 | + | |
| 9964 | + | |
| 9965 | + | |
| 9966 | + | |
| 9967 | + | |
| 9968 | + | |
| 9969 | + | |
| 9970 | + | |
| 9971 | + | |
| 9972 | + | |
| 9973 | + | |
| 9974 | + | |
| 9975 | + | |
| 9976 | + | |
| 9977 | + | |
| 9978 | + | |
| 9979 | + | |
| 9980 | + | |
| 9981 | + | |
| 9982 | + | |
| 9983 | + | |
| 9984 | + | |
| 9985 | + | |
| 9986 | + | |
| 9987 | + | |
9932 | 9988 | | |
9933 | 9989 | | |
9934 | 9990 | | |
| |||
0 commit comments