Skip to content

perf: use DynComparator in sort-merge join (SMJ), microbenchmark queries up to 12% faster, TPC-H overall ~5% faster#21484

Open
mbutrovich wants to merge 11 commits intoapache:mainfrom
mbutrovich:dyncomparator
Open

perf: use DynComparator in sort-merge join (SMJ), microbenchmark queries up to 12% faster, TPC-H overall ~5% faster#21484
mbutrovich wants to merge 11 commits intoapache:mainfrom
mbutrovich:dyncomparator

Conversation

@mbutrovich
Copy link
Copy Markdown
Contributor

@mbutrovich mbutrovich commented Apr 8, 2026

Which issue does this PR close?

Closes the last item I had on #20910.

Rationale for this change

Sort merge join comparisons (compare_join_arrays, is_join_arrays_equal) do a match DataType + downcast_ref on every call, per column. These are called per-row in hot join loops across SMJ, semi/anti/mark SMJ, and piecewise merge join.

arrow_ord::ord::make_comparator does the type dispatch once at construction and returns a DynComparator closure that goes straight to typed value comparison. Arrow's own LexicographicalComparator uses this pattern for sorting — we should use it for joins too.

What changes are included in this PR?

Adds JoinKeyComparator to joins/utils.rs: a thin wrapper around Vec<DynComparator> built once per batch pair. Null handling (NullEqualsNothing both-null -> Less override) is baked into the closures at construction time so compare() is a branchless loop.

Integrated into all hot-path call sites:

  • materializing_stream.rs: streamed_buffered_cmp (streamed vs buffered) and buffered_equality_cmp (head vs tail equality)
  • bitwise_stream.rs: outer_inner_cmp, outer_self_cmp, inner_self_cmp; simplified find_key_group_end signature (takes &JoinKeyComparator, returns usize instead of Result<usize> since type errors are now caught at construction)
  • piecewise_merge_join/classic_join.rs: single comparator built per batch pair

compare_join_arrays is kept for the one-off keys_match call (once per batch boundary).

Deleted is_join_arrays_equal (75-line per-row type dispatch function), replaced by JoinKeyComparator::is_equal.

Are these changes tested?

  • 4 unit tests for JoinKeyComparator: multi-column mixed types, NullEqualsNull, NullEqualsNothing, nulls_first ordering
  • Existing SMJ test suites pass
  • Existing sqllogictest join tests pass

Are there any user-facing changes?

No.

@github-actions github-actions bot added the physical-plan Changes to the physical-plan crate label Apr 8, 2026
@mbutrovich
Copy link
Copy Markdown
Contributor Author

run benchmark smj

@mbutrovich
Copy link
Copy Markdown
Contributor Author

run benchmark tpch tpcds

env:
   PREFER_HASH_JOIN: false

@adriangbot
Copy link
Copy Markdown

🤖 Benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4209143327-967-w5bzm 6.12.55+ #1 SMP Sun Feb 1 08:59:41 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing dyncomparator (3947c7e) to 91c2e04 (merge-base) diff using: tpcds
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot
Copy link
Copy Markdown

🤖 Benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4209142420-965-hq6g9 6.12.55+ #1 SMP Sun Feb 1 08:59:41 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing dyncomparator (3947c7e) to 91c2e04 (merge-base) diff using: smj
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot
Copy link
Copy Markdown

🤖 Benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4209143327-966-fhq27 6.12.55+ #1 SMP Sun Feb 1 08:59:41 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing dyncomparator (3947c7e) to 91c2e04 (merge-base) diff using: tpch
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot
Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

Comparing HEAD and dyncomparator
--------------------
Benchmark tpch_sf1.json
--------------------
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query     ┃                              HEAD ┃                     dyncomparator ┃        Change ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 1  │    45.25 / 45.66 ±0.52 / 46.66 ms │    45.22 / 45.74 ±0.67 / 47.00 ms │     no change │
│ QQuery 2  │    61.50 / 62.11 ±0.48 / 62.97 ms │    57.41 / 58.20 ±0.44 / 58.78 ms │ +1.07x faster │
│ QQuery 3  │    66.18 / 68.54 ±1.48 / 70.54 ms │    62.67 / 64.23 ±1.15 / 65.66 ms │ +1.07x faster │
│ QQuery 4  │    49.94 / 51.54 ±0.98 / 52.71 ms │    42.91 / 44.27 ±0.93 / 45.46 ms │ +1.16x faster │
│ QQuery 5  │ 110.60 / 112.13 ±1.38 / 113.88 ms │  98.76 / 101.95 ±2.98 / 107.25 ms │ +1.10x faster │
│ QQuery 6  │    16.98 / 17.65 ±0.77 / 19.14 ms │    17.01 / 17.29 ±0.36 / 17.98 ms │     no change │
│ QQuery 7  │ 131.91 / 134.95 ±1.98 / 137.44 ms │ 126.51 / 130.56 ±2.09 / 132.03 ms │     no change │
│ QQuery 8  │ 122.29 / 125.33 ±3.83 / 132.72 ms │ 119.32 / 122.74 ±2.75 / 126.65 ms │     no change │
│ QQuery 9  │ 173.16 / 176.10 ±2.06 / 179.32 ms │ 164.24 / 168.07 ±2.55 / 170.87 ms │     no change │
│ QQuery 10 │    85.36 / 86.33 ±1.05 / 88.35 ms │    83.31 / 83.76 ±0.36 / 84.35 ms │     no change │
│ QQuery 11 │    45.15 / 46.00 ±0.47 / 46.48 ms │    43.81 / 43.98 ±0.19 / 44.25 ms │     no change │
│ QQuery 12 │    37.65 / 38.52 ±0.60 / 39.32 ms │    35.18 / 36.41 ±0.94 / 38.09 ms │ +1.06x faster │
│ QQuery 13 │    48.97 / 49.60 ±0.63 / 50.67 ms │    47.27 / 48.34 ±0.66 / 49.04 ms │     no change │
│ QQuery 14 │    28.52 / 28.90 ±0.31 / 29.44 ms │    28.22 / 28.47 ±0.27 / 28.96 ms │     no change │
│ QQuery 15 │    30.14 / 31.18 ±0.79 / 32.56 ms │    30.42 / 31.22 ±0.83 / 32.58 ms │     no change │
│ QQuery 16 │    21.42 / 21.72 ±0.27 / 22.08 ms │    20.76 / 21.42 ±0.60 / 22.30 ms │     no change │
│ QQuery 17 │ 116.40 / 119.50 ±2.71 / 123.77 ms │ 112.93 / 115.74 ±2.11 / 119.39 ms │     no change │
│ QQuery 18 │ 145.31 / 147.29 ±1.53 / 149.62 ms │ 127.81 / 130.40 ±1.55 / 132.48 ms │ +1.13x faster │
│ QQuery 19 │    39.23 / 39.69 ±0.35 / 40.18 ms │    38.41 / 39.43 ±0.79 / 40.84 ms │     no change │
│ QQuery 20 │    57.28 / 59.18 ±1.37 / 60.94 ms │    54.74 / 58.11 ±2.26 / 61.47 ms │     no change │
│ QQuery 21 │ 263.80 / 266.85 ±2.99 / 271.99 ms │ 245.83 / 249.31 ±2.49 / 252.30 ms │ +1.07x faster │
│ QQuery 22 │    37.22 / 38.44 ±1.02 / 39.94 ms │    35.84 / 37.25 ±1.67 / 40.20 ms │     no change │
└───────────┴───────────────────────────────────┴───────────────────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Benchmark Summary            ┃           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ Total Time (HEAD)            │ 1767.20ms │
│ Total Time (dyncomparator)   │ 1676.92ms │
│ Average Time (HEAD)          │   80.33ms │
│ Average Time (dyncomparator) │   76.22ms │
│ Queries Faster               │         7 │
│ Queries Slower               │         0 │
│ Queries with No Change       │        15 │
│ Queries with Failure         │         0 │
└──────────────────────────────┴───────────┘

Resource Usage

tpch — base (merge-base)

Metric Value
Wall time 9.1s
Peak memory 4.9 GiB
Avg memory 4.0 GiB
CPU user 73.8s
CPU sys 4.0s
Peak spill 0 B

tpch — branch

Metric Value
Wall time 8.6s
Peak memory 4.7 GiB
Avg memory 3.9 GiB
CPU user 68.9s
CPU sys 3.8s
Peak spill 0 B

File an issue against this benchmark runner

@adriangbot
Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

Comparing HEAD and dyncomparator
--------------------
Benchmark smj.json
--------------------
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query     ┃                                 HEAD ┃                        dyncomparator ┃        Change ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 1  │       31.93 / 32.20 ±0.16 / 32.37 ms │       30.22 / 30.40 ±0.16 / 30.63 ms │ +1.06x faster │
│ QQuery 2  │    181.07 / 189.79 ±5.97 / 198.27 ms │   177.28 / 188.22 ±10.84 / 201.82 ms │     no change │
│ QQuery 3  │    103.37 / 109.23 ±3.73 / 114.22 ms │    103.87 / 109.72 ±4.21 / 114.15 ms │     no change │
│ QQuery 4  │       28.73 / 29.21 ±0.61 / 30.39 ms │       27.23 / 28.09 ±0.63 / 28.75 ms │     no change │
│ QQuery 5  │       22.36 / 22.95 ±0.47 / 23.47 ms │       21.96 / 22.29 ±0.31 / 22.81 ms │     no change │
│ QQuery 6  │    181.24 / 186.62 ±3.73 / 190.71 ms │    173.24 / 179.01 ±5.78 / 186.75 ms │     no change │
│ QQuery 7  │   217.43 / 232.81 ±12.88 / 248.93 ms │    213.46 / 221.03 ±7.81 / 234.82 ms │ +1.05x faster │
│ QQuery 8  │       23.26 / 23.51 ±0.21 / 23.84 ms │       21.62 / 21.68 ±0.05 / 21.76 ms │ +1.08x faster │
│ QQuery 9  │    226.02 / 227.96 ±1.77 / 231.10 ms │    217.65 / 220.92 ±2.29 / 224.00 ms │     no change │
│ QQuery 10 │       81.28 / 84.96 ±3.06 / 88.89 ms │       77.79 / 82.96 ±4.69 / 90.55 ms │     no change │
│ QQuery 11 │       27.28 / 28.02 ±0.43 / 28.46 ms │       26.45 / 27.24 ±0.47 / 27.78 ms │     no change │
│ QQuery 12 │       70.76 / 73.47 ±1.67 / 76.05 ms │       70.48 / 74.34 ±3.22 / 79.60 ms │     no change │
│ QQuery 13 │    109.86 / 113.92 ±2.53 / 117.17 ms │    109.11 / 111.61 ±2.04 / 113.86 ms │     no change │
│ QQuery 14 │       78.56 / 82.61 ±2.98 / 85.43 ms │       76.94 / 84.40 ±5.23 / 92.99 ms │     no change │
│ QQuery 15 │       79.59 / 83.87 ±2.90 / 87.38 ms │       77.50 / 81.89 ±4.97 / 89.82 ms │     no change │
│ QQuery 16 │       15.98 / 16.31 ±0.17 / 16.43 ms │       14.13 / 14.54 ±0.26 / 14.84 ms │ +1.12x faster │
│ QQuery 17 │    142.18 / 143.91 ±1.30 / 145.89 ms │    139.82 / 140.77 ±0.74 / 142.01 ms │     no change │
│ QQuery 18 │    104.70 / 105.13 ±0.36 / 105.64 ms │    103.44 / 104.04 ±0.57 / 105.00 ms │     no change │
│ QQuery 19 │   556.63 / 577.97 ±14.35 / 590.96 ms │    573.66 / 583.78 ±7.99 / 594.82 ms │     no change │
│ QQuery 20 │ 1254.39 / 1270.64 ±8.99 / 1281.68 ms │ 1269.36 / 1279.97 ±7.27 / 1289.61 ms │     no change │
│ QQuery 21 │   360.31 / 382.83 ±24.14 / 429.14 ms │   343.59 / 355.15 ±10.42 / 373.95 ms │ +1.08x faster │
│ QQuery 22 │    368.50 / 383.08 ±8.53 / 392.40 ms │    371.26 / 381.23 ±9.90 / 399.75 ms │     no change │
│ QQuery 23 │    421.20 / 424.01 ±3.14 / 429.66 ms │   404.43 / 428.58 ±16.80 / 448.21 ms │     no change │
│ QQuery 24 │       27.57 / 30.32 ±1.89 / 33.43 ms │       27.08 / 28.48 ±1.35 / 30.79 ms │ +1.06x faster │
│ QQuery 25 │       76.48 / 78.44 ±1.62 / 81.24 ms │       70.69 / 75.55 ±3.50 / 80.16 ms │     no change │
│ QQuery 26 │    108.62 / 117.11 ±4.44 / 121.26 ms │    111.32 / 116.94 ±4.28 / 124.16 ms │     no change │
└───────────┴──────────────────────────────────────┴──────────────────────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Benchmark Summary            ┃           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ Total Time (HEAD)            │ 5050.89ms │
│ Total Time (dyncomparator)   │ 4992.81ms │
│ Average Time (HEAD)          │  194.27ms │
│ Average Time (dyncomparator) │  192.03ms │
│ Queries Faster               │         6 │
│ Queries Slower               │         0 │
│ Queries with No Change       │        20 │
│ Queries with Failure         │         0 │
└──────────────────────────────┴───────────┘

Resource Usage

smj — base (merge-base)

Metric Value
Wall time 25.6s
Peak memory 3.5 GiB
Avg memory 3.2 GiB
CPU user 212.2s
CPU sys 5.7s
Peak spill 0 B

smj — branch

Metric Value
Wall time 25.2s
Peak memory 3.5 GiB
Avg memory 3.2 GiB
CPU user 206.0s
CPU sys 5.7s
Peak spill 0 B

File an issue against this benchmark runner

@adriangbot
Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

Comparing HEAD and dyncomparator
--------------------
Benchmark tpcds_sf1.json
--------------------
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query     ┃                                    HEAD ┃                          dyncomparator ┃        Change ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 1  │          51.89 / 52.39 ±0.58 / 53.49 ms │         51.70 / 52.35 ±0.57 / 53.31 ms │     no change │
│ QQuery 2  │       147.24 / 147.79 ±0.39 / 148.19 ms │      145.11 / 146.20 ±0.84 / 147.48 ms │     no change │
│ QQuery 3  │       167.29 / 169.40 ±1.77 / 172.48 ms │      163.73 / 165.31 ±1.53 / 168.01 ms │     no change │
│ QQuery 4  │   1729.86 / 1764.04 ±24.62 / 1803.51 ms │  1718.59 / 1743.47 ±14.01 / 1759.30 ms │     no change │
│ QQuery 5  │       284.65 / 291.35 ±5.05 / 297.22 ms │      278.32 / 284.40 ±3.86 / 288.02 ms │     no change │
│ QQuery 6  │       245.03 / 250.61 ±3.89 / 256.87 ms │      238.75 / 244.11 ±3.16 / 248.64 ms │     no change │
│ QQuery 7  │       381.29 / 388.70 ±5.12 / 397.37 ms │      382.94 / 384.35 ±1.69 / 387.59 ms │     no change │
│ QQuery 8  │       186.76 / 187.99 ±1.55 / 190.89 ms │      181.69 / 185.69 ±3.87 / 191.40 ms │     no change │
│ QQuery 9  │       104.76 / 110.50 ±6.41 / 122.28 ms │      103.81 / 108.80 ±2.64 / 111.25 ms │     no change │
│ QQuery 10 │       258.63 / 265.11 ±6.17 / 274.26 ms │      249.97 / 259.26 ±4.86 / 263.25 ms │     no change │
│ QQuery 11 │      882.39 / 892.20 ±11.12 / 913.24 ms │      874.10 / 880.71 ±6.05 / 891.91 ms │     no change │
│ QQuery 12 │          54.39 / 56.02 ±1.69 / 59.12 ms │         52.82 / 53.72 ±1.21 / 55.96 ms │     no change │
│ QQuery 13 │       417.54 / 421.46 ±3.06 / 426.93 ms │      423.66 / 428.52 ±3.57 / 433.25 ms │     no change │
│ QQuery 14 │   2107.84 / 2133.74 ±14.10 / 2150.65 ms │  2064.01 / 2093.01 ±18.35 / 2114.98 ms │     no change │
│ QQuery 15 │          94.98 / 96.05 ±1.00 / 97.73 ms │         93.88 / 95.11 ±2.16 / 99.42 ms │     no change │
│ QQuery 16 │       159.39 / 161.21 ±1.36 / 162.91 ms │      159.06 / 163.42 ±2.47 / 165.57 ms │     no change │
│ QQuery 17 │       383.17 / 385.28 ±1.44 / 386.70 ms │      376.44 / 380.47 ±3.65 / 386.59 ms │     no change │
│ QQuery 18 │       293.48 / 298.55 ±3.88 / 303.37 ms │      290.78 / 297.80 ±3.55 / 300.37 ms │     no change │
│ QQuery 19 │       248.56 / 252.43 ±3.66 / 258.99 ms │      240.40 / 244.88 ±3.05 / 248.05 ms │     no change │
│ QQuery 20 │          92.43 / 93.76 ±1.12 / 95.08 ms │         91.39 / 92.26 ±0.99 / 93.73 ms │     no change │
│ QQuery 21 │       848.30 / 857.20 ±5.90 / 862.83 ms │     807.17 / 826.86 ±13.16 / 848.56 ms │     no change │
│ QQuery 22 │       409.34 / 416.82 ±5.36 / 422.29 ms │      394.85 / 409.53 ±8.28 / 420.07 ms │     no change │
│ QQuery 23 │    1158.22 / 1169.56 ±8.05 / 1181.69 ms │  1149.26 / 1172.75 ±11.98 / 1181.44 ms │     no change │
│ QQuery 24 │       927.91 / 934.17 ±6.61 / 945.02 ms │      928.63 / 936.63 ±7.71 / 948.73 ms │     no change │
│ QQuery 25 │       445.03 / 449.70 ±4.19 / 456.56 ms │      440.96 / 444.91 ±2.37 / 447.53 ms │     no change │
│ QQuery 26 │       209.77 / 210.83 ±0.62 / 211.73 ms │      204.24 / 207.06 ±1.90 / 209.04 ms │     no change │
│ QQuery 27 │       374.60 / 384.59 ±7.37 / 395.41 ms │      379.60 / 383.73 ±4.36 / 390.73 ms │     no change │
│ QQuery 28 │       155.87 / 158.43 ±2.41 / 162.60 ms │      157.99 / 160.84 ±2.67 / 165.41 ms │     no change │
│ QQuery 29 │       384.56 / 388.42 ±3.71 / 395.26 ms │      377.00 / 383.01 ±4.12 / 389.09 ms │     no change │
│ QQuery 30 │          58.56 / 59.84 ±0.97 / 61.16 ms │         57.01 / 58.35 ±1.73 / 61.72 ms │     no change │
│ QQuery 31 │       657.57 / 660.87 ±1.73 / 662.59 ms │      651.28 / 655.01 ±3.13 / 659.44 ms │     no change │
│ QQuery 32 │       148.27 / 149.80 ±1.12 / 150.97 ms │      149.48 / 150.40 ±0.61 / 151.16 ms │     no change │
│ QQuery 33 │       221.10 / 223.83 ±2.45 / 228.01 ms │      219.20 / 223.19 ±2.85 / 227.19 ms │     no change │
│ QQuery 34 │       192.34 / 193.97 ±1.60 / 196.91 ms │      194.29 / 195.39 ±1.40 / 198.02 ms │     no change │
│ QQuery 35 │       248.31 / 252.37 ±2.88 / 256.38 ms │      247.30 / 248.05 ±0.60 / 249.08 ms │     no change │
│ QQuery 36 │       283.69 / 286.19 ±2.39 / 289.38 ms │      278.95 / 280.47 ±1.57 / 283.14 ms │     no change │
│ QQuery 37 │       282.65 / 285.38 ±1.95 / 288.13 ms │      278.01 / 282.52 ±3.00 / 285.90 ms │     no change │
│ QQuery 38 │       201.42 / 205.01 ±2.71 / 208.04 ms │      201.46 / 202.53 ±1.02 / 204.14 ms │     no change │
│ QQuery 39 │   3838.15 / 3873.68 ±23.25 / 3908.47 ms │  3741.04 / 3758.62 ±11.29 / 3771.54 ms │     no change │
│ QQuery 40 │       170.12 / 172.62 ±1.65 / 174.98 ms │      169.86 / 172.15 ±2.01 / 175.45 ms │     no change │
│ QQuery 41 │          15.86 / 18.15 ±2.84 / 23.76 ms │         15.52 / 17.01 ±1.83 / 20.25 ms │ +1.07x faster │
│ QQuery 42 │       170.47 / 172.30 ±1.32 / 173.81 ms │      166.52 / 168.27 ±1.65 / 170.92 ms │     no change │
│ QQuery 43 │       150.39 / 153.66 ±2.65 / 158.22 ms │      147.59 / 149.74 ±2.05 / 153.55 ms │     no change │
│ QQuery 44 │          14.65 / 15.93 ±1.11 / 17.88 ms │         14.79 / 16.48 ±1.61 / 19.50 ms │     no change │
│ QQuery 45 │          68.21 / 70.54 ±1.68 / 72.54 ms │         68.34 / 69.91 ±1.48 / 72.45 ms │     no change │
│ QQuery 46 │       364.89 / 370.40 ±3.13 / 374.05 ms │      366.01 / 372.26 ±3.76 / 376.91 ms │     no change │
│ QQuery 47 │       785.61 / 792.34 ±6.55 / 803.70 ms │      762.70 / 779.75 ±9.44 / 789.38 ms │     no change │
│ QQuery 48 │       300.66 / 303.64 ±2.14 / 306.89 ms │      300.77 / 304.93 ±3.09 / 310.18 ms │     no change │
│ QQuery 49 │       264.74 / 266.43 ±1.46 / 268.26 ms │      262.29 / 266.39 ±3.34 / 271.29 ms │     no change │
│ QQuery 50 │       231.63 / 234.35 ±1.87 / 236.62 ms │      228.52 / 231.65 ±2.70 / 234.60 ms │     no change │
│ QQuery 51 │       232.27 / 235.62 ±2.18 / 238.27 ms │      233.97 / 237.07 ±2.80 / 241.23 ms │     no change │
│ QQuery 52 │       167.73 / 173.36 ±6.36 / 185.15 ms │      167.57 / 169.09 ±1.06 / 170.49 ms │     no change │
│ QQuery 53 │       170.84 / 173.33 ±1.40 / 174.83 ms │      170.42 / 173.10 ±1.47 / 174.84 ms │     no change │
│ QQuery 54 │       268.74 / 272.52 ±4.51 / 279.66 ms │      265.03 / 269.90 ±3.75 / 276.59 ms │     no change │
│ QQuery 55 │       167.46 / 169.81 ±1.60 / 172.46 ms │      165.62 / 168.27 ±2.57 / 172.87 ms │     no change │
│ QQuery 56 │       225.18 / 226.72 ±1.33 / 229.20 ms │      219.92 / 224.12 ±3.56 / 228.95 ms │     no change │
│ QQuery 57 │       370.02 / 376.81 ±3.70 / 380.42 ms │      367.03 / 368.86 ±1.22 / 370.63 ms │     no change │
│ QQuery 58 │       408.44 / 412.14 ±4.02 / 418.80 ms │      396.42 / 400.60 ±2.47 / 403.32 ms │     no change │
│ QQuery 59 │       301.41 / 302.74 ±1.69 / 306.08 ms │      297.22 / 298.65 ±1.09 / 300.15 ms │     no change │
│ QQuery 60 │       221.33 / 226.09 ±5.34 / 236.27 ms │      219.62 / 223.06 ±2.89 / 228.22 ms │     no change │
│ QQuery 61 │       296.05 / 300.24 ±2.91 / 303.80 ms │     295.72 / 309.23 ±10.59 / 324.29 ms │     no change │
│ QQuery 62 │          87.03 / 87.68 ±0.58 / 88.64 ms │         83.34 / 86.16 ±1.89 / 88.57 ms │     no change │
│ QQuery 63 │       174.76 / 175.90 ±0.76 / 177.05 ms │      172.63 / 174.03 ±1.04 / 175.29 ms │     no change │
│ QQuery 64 │    1540.75 / 1548.76 ±6.81 / 1558.86 ms │   1513.47 / 1525.28 ±8.59 / 1535.29 ms │     no change │
│ QQuery 65 │       339.52 / 344.68 ±4.47 / 350.84 ms │      333.85 / 340.80 ±4.82 / 347.06 ms │     no change │
│ QQuery 66 │       308.29 / 318.13 ±6.21 / 325.35 ms │      299.18 / 310.29 ±6.37 / 317.85 ms │     no change │
│ QQuery 67 │       276.58 / 280.35 ±3.68 / 286.95 ms │      270.41 / 274.77 ±2.36 / 277.33 ms │     no change │
│ QQuery 68 │       423.42 / 429.15 ±3.33 / 433.70 ms │      419.63 / 431.70 ±7.34 / 438.73 ms │     no change │
│ QQuery 69 │       249.20 / 253.61 ±3.66 / 259.79 ms │      248.84 / 254.99 ±3.34 / 258.46 ms │     no change │
│ QQuery 70 │       452.30 / 456.74 ±3.86 / 461.98 ms │      439.99 / 446.13 ±4.71 / 452.60 ms │     no change │
│ QQuery 71 │       216.11 / 218.31 ±1.62 / 220.66 ms │      210.67 / 215.24 ±4.36 / 223.08 ms │     no change │
│ QQuery 72 │ 9205.42 / 9744.91 ±288.24 / 10002.22 ms │ 8793.98 / 9500.40 ±371.95 / 9861.58 ms │     no change │
│ QQuery 73 │       188.57 / 192.33 ±2.27 / 195.10 ms │      188.34 / 191.72 ±2.21 / 194.90 ms │     no change │
│ QQuery 74 │       608.11 / 614.99 ±6.75 / 624.72 ms │      595.49 / 600.38 ±3.97 / 607.58 ms │     no change │
│ QQuery 75 │       517.97 / 529.97 ±6.78 / 537.05 ms │     518.25 / 538.13 ±20.31 / 575.87 ms │     no change │
│ QQuery 76 │       139.02 / 142.85 ±2.09 / 145.43 ms │      143.47 / 148.70 ±5.67 / 159.32 ms │     no change │
│ QQuery 77 │       277.52 / 282.93 ±4.63 / 290.37 ms │      281.24 / 283.26 ±1.37 / 285.01 ms │     no change │
│ QQuery 78 │       582.18 / 587.79 ±4.83 / 593.89 ms │      576.52 / 584.88 ±4.24 / 588.22 ms │     no change │
│ QQuery 79 │       361.89 / 366.13 ±5.70 / 377.20 ms │      357.64 / 364.46 ±7.59 / 378.30 ms │     no change │
│ QQuery 80 │      459.81 / 474.06 ±14.46 / 498.03 ms │      470.00 / 478.06 ±5.00 / 482.76 ms │     no change │
│ QQuery 81 │          59.69 / 61.94 ±2.26 / 65.79 ms │         62.29 / 65.95 ±3.03 / 70.75 ms │  1.06x slower │
│ QQuery 82 │       327.85 / 333.64 ±4.29 / 339.22 ms │      322.93 / 324.11 ±1.42 / 326.86 ms │     no change │
│ QQuery 83 │          68.46 / 70.81 ±1.88 / 73.86 ms │         68.49 / 69.61 ±0.75 / 70.83 ms │     no change │
│ QQuery 84 │          71.90 / 72.50 ±0.38 / 73.01 ms │         67.76 / 69.49 ±1.23 / 71.08 ms │     no change │
│ QQuery 85 │       181.92 / 184.65 ±1.88 / 187.68 ms │      180.63 / 182.54 ±1.93 / 185.23 ms │     no change │
│ QQuery 86 │          47.13 / 48.96 ±1.66 / 51.92 ms │         47.29 / 47.65 ±0.31 / 48.13 ms │     no change │
│ QQuery 87 │       204.11 / 207.87 ±3.93 / 214.69 ms │      201.10 / 207.12 ±5.57 / 217.63 ms │     no change │
│ QQuery 88 │       318.93 / 326.56 ±5.58 / 333.90 ms │      311.59 / 317.87 ±3.96 / 322.13 ms │     no change │
│ QQuery 89 │       179.49 / 184.10 ±5.36 / 193.66 ms │      175.53 / 180.97 ±5.90 / 192.03 ms │     no change │
│ QQuery 90 │          42.33 / 43.70 ±1.03 / 45.06 ms │         41.35 / 42.72 ±1.91 / 46.48 ms │     no change │
│ QQuery 91 │          73.08 / 74.30 ±1.28 / 76.73 ms │         72.36 / 73.99 ±1.05 / 75.42 ms │     no change │
│ QQuery 92 │          84.54 / 87.68 ±4.06 / 95.64 ms │         83.96 / 85.83 ±1.77 / 89.18 ms │     no change │
│ QQuery 93 │       398.80 / 399.78 ±0.84 / 400.70 ms │      396.11 / 398.20 ±1.99 / 400.81 ms │     no change │
│ QQuery 94 │          95.47 / 97.15 ±0.87 / 97.98 ms │         95.28 / 96.78 ±1.41 / 99.08 ms │     no change │
│ QQuery 95 │       177.81 / 179.29 ±1.80 / 182.82 ms │      170.66 / 171.69 ±0.61 / 172.35 ms │     no change │
│ QQuery 96 │       132.73 / 133.62 ±0.95 / 135.30 ms │      130.14 / 133.76 ±2.48 / 136.89 ms │     no change │
│ QQuery 97 │       214.05 / 215.05 ±0.93 / 216.80 ms │      208.28 / 210.69 ±2.40 / 215.28 ms │     no change │
│ QQuery 98 │       190.30 / 194.37 ±2.51 / 197.09 ms │      186.11 / 189.07 ±1.80 / 191.67 ms │     no change │
│ QQuery 99 │       220.45 / 221.87 ±1.92 / 225.55 ms │      212.05 / 214.27 ±1.81 / 216.30 ms │     no change │
└───────────┴─────────────────────────────────────────┴────────────────────────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Benchmark Summary            ┃            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Total Time (HEAD)            │ 45206.12ms │
│ Total Time (dyncomparator)   │ 44505.83ms │
│ Average Time (HEAD)          │   456.63ms │
│ Average Time (dyncomparator) │   449.55ms │
│ Queries Faster               │          1 │
│ Queries Slower               │          1 │
│ Queries with No Change       │         97 │
│ Queries with Failure         │          0 │
└──────────────────────────────┴────────────┘

Resource Usage

tpcds — base (merge-base)

Metric Value
Wall time 226.6s
Peak memory 28.3 GiB
Avg memory 6.8 GiB
CPU user 940.4s
CPU sys 96.3s
Peak spill 0 B

tpcds — branch

Metric Value
Wall time 222.9s
Peak memory 29.0 GiB
Avg memory 6.4 GiB
CPU user 914.2s
CPU sys 95.7s
Peak spill 0 B

File an issue against this benchmark runner

let stream_values = stream_batch.compare_key_values();

// Build comparator once for the batch pair
let cmp = JoinKeyComparator::new(
Copy link
Copy Markdown
Contributor Author

@mbutrovich mbutrovich Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: piecewise merge join rebuilds the JoinKeyComparator on each resolve_classic_join re-entry (when output exceeds batch size mid-scan), even though the batch pair hasn't changed. Could lift it to ClassicPWMJStream and rebuild only in fetch_stream_batch, but the cost is one make_comparator call per ~8192 rows of output, so probably not worth the added lifecycle coupling. Left as-is for now.

@mbutrovich
Copy link
Copy Markdown
Contributor Author

mbutrovich commented Apr 8, 2026

I'm confused why I'm failing this extended test:

failures:

---- memory_limit::sort_merge_join_spill stdout ----

thread 'memory_limit::sort_merge_join_spill' (28536) panicked at datafusion/core/tests/memory_limit/mod.rs:884:21:
Unexpected success when running, expected memory limit failure

I shouldn't have changed the memory consumption with this PR.

@mbutrovich mbutrovich marked this pull request as ready for review April 8, 2026 20:38
@@ -213,6 +213,7 @@ async fn sort_merge_join_spill() {
.with_config(config)
.with_disk_manager_builder(DiskManagerBuilder::default())
.with_scenario(Scenario::AccessLogStreaming)
Copy link
Copy Markdown
Contributor Author

@mbutrovich mbutrovich Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_join_arrays_equal didn't support Dictionary keys — it hit the not_impl_err! fallthrough. This test was passing because that error counted as the expected "failure." JoinKeyComparator uses make_comparator which handles all Arrow types, so the query now correctly spills and succeeds.

If you add this on main:

.with_expected_errors(vec!["Unsupported data type in sort merge join comparator"])

the test passes, confirming it was failing for the wrong reason on main all along.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude's assessment:

The test's original intent was to verify SMJ fails with OOM when memory is too tight even for spilling. But at 1000 bytes with this data, spilling works fine — there's no "too tight to spill" threshold we can easily hit because the spill path writes to disk before the reservation grows.

The reservation system works like: try_grow fails → spill to disk → no reservation needed. As long as the disk manager works, there's no minimum memory floor that would cause OOM. Even at 1 byte, the first try_grow would fail and spill immediately.

So the test as-is can't be made to fail with OOM under SMJ spilling — it was only "working" because of the Dictionary bug.

I'm not sure if the test is worth keeping, but maybe that's a different PR.

@github-actions github-actions bot added the core Core DataFusion crate label Apr 8, 2026
@mbutrovich mbutrovich requested a review from comphead April 8, 2026 20:54
@mbutrovich mbutrovich changed the title perf: use DynComparator in sort-merge join (SMJ) perf: use DynComparator in sort-merge join, SMJ benchmark queries up to 12% faster, TPC-H overall ~5% faster Apr 8, 2026
@mbutrovich mbutrovich changed the title perf: use DynComparator in sort-merge join, SMJ benchmark queries up to 12% faster, TPC-H overall ~5% faster perf: use DynComparator in sort-merge join, microbenchmark queries up to 12% faster, TPC-H overall ~5% faster Apr 8, 2026
@mbutrovich mbutrovich changed the title perf: use DynComparator in sort-merge join, microbenchmark queries up to 12% faster, TPC-H overall ~5% faster perf: use DynComparator in sort-merge join (SMJ), microbenchmark queries up to 12% faster, TPC-H overall ~5% faster Apr 8, 2026
@Dandandan
Copy link
Copy Markdown
Contributor

run benchmark tpch10

env:
   PREFER_HASH_JOIN: false

@adriangbot
Copy link
Copy Markdown

🤖 Benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4211800615-976-wp2gf 6.12.55+ #1 SMP Sun Feb 1 08:59:41 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing dyncomparator (e0d06ee) to 4b1901f (merge-base) diff using: tpch10
Results will be posted here when complete


File an issue against this benchmark runner

@Dandandan
Copy link
Copy Markdown
Contributor

Results look really good!

I wonder if you thought about the following:

  • Conversion to row format for multiple columns (like SPM, topk, etc.) . DynComparator is faster but still does dynamic dispatch and for a larger number of columns does a bigger number of comparisions.
  • specializing for single-column case

@adriangbot
Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

Comparing HEAD and dyncomparator
--------------------
Benchmark tpch_sf10.json
--------------------
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query     ┃                                   HEAD ┃                          dyncomparator ┃        Change ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 1  │      375.59 / 377.72 ±2.04 / 380.32 ms │      372.98 / 375.02 ±1.10 / 375.83 ms │     no change │
│ QQuery 2  │      520.30 / 532.22 ±7.02 / 542.12 ms │      492.36 / 503.66 ±8.45 / 517.06 ms │ +1.06x faster │
│ QQuery 3  │     606.11 / 706.28 ±50.14 / 735.40 ms │     569.91 / 615.57 ±47.96 / 687.57 ms │ +1.15x faster │
│ QQuery 4  │     629.78 / 661.39 ±17.61 / 680.44 ms │     420.21 / 493.90 ±40.29 / 536.83 ms │ +1.34x faster │
│ QQuery 5  │  1142.12 / 1196.96 ±31.23 / 1235.02 ms │  1092.44 / 1139.41 ±38.34 / 1200.74 ms │     no change │
│ QQuery 6  │      137.84 / 140.69 ±3.37 / 147.28 ms │      137.21 / 140.10 ±4.01 / 147.94 ms │     no change │
│ QQuery 7  │  1620.83 / 1656.69 ±24.06 / 1683.52 ms │  1561.45 / 1579.62 ±11.78 / 1596.81 ms │     no change │
│ QQuery 8  │ 1509.30 / 1822.37 ±369.50 / 2279.01 ms │ 1453.81 / 1880.94 ±348.65 / 2181.44 ms │     no change │
│ QQuery 9  │ 2074.11 / 2339.20 ±178.04 / 2520.41 ms │ 2047.41 / 2273.00 ±135.61 / 2405.50 ms │     no change │
│ QQuery 10 │     568.65 / 583.75 ±14.96 / 605.82 ms │     535.75 / 549.02 ±12.38 / 572.51 ms │ +1.06x faster │
│ QQuery 11 │      483.81 / 494.55 ±8.98 / 508.41 ms │      457.39 / 468.60 ±7.60 / 479.36 ms │ +1.06x faster │
│ QQuery 12 │      319.90 / 322.19 ±1.78 / 324.72 ms │      292.84 / 296.49 ±3.04 / 299.86 ms │ +1.09x faster │
│ QQuery 13 │      393.49 / 398.04 ±4.69 / 403.93 ms │      373.48 / 384.45 ±6.86 / 393.93 ms │     no change │
│ QQuery 14 │      206.41 / 209.72 ±2.35 / 213.43 ms │      199.79 / 202.94 ±2.83 / 208.20 ms │     no change │
│ QQuery 15 │      345.48 / 348.26 ±2.88 / 353.72 ms │      328.46 / 332.14 ±2.54 / 336.07 ms │     no change │
│ QQuery 16 │      131.96 / 134.95 ±2.31 / 139.10 ms │      120.75 / 125.77 ±3.34 / 131.22 ms │ +1.07x faster │
│ QQuery 17 │ 1693.10 / 1993.85 ±150.49 / 2075.47 ms │ 1617.05 / 1844.77 ±175.82 / 2003.93 ms │ +1.08x faster │
│ QQuery 18 │  1734.84 / 1764.60 ±23.45 / 1806.43 ms │  1549.54 / 1568.39 ±18.42 / 1597.05 ms │ +1.13x faster │
│ QQuery 19 │     285.72 / 293.64 ±12.50 / 318.45 ms │      284.60 / 291.66 ±8.31 / 307.65 ms │     no change │
│ QQuery 20 │     477.89 / 491.92 ±20.20 / 531.91 ms │      460.63 / 465.56 ±5.05 / 473.24 ms │ +1.06x faster │
│ QQuery 21 │ 3264.24 / 3556.39 ±242.53 / 3834.45 ms │  3305.90 / 3382.03 ±61.93 / 3462.76 ms │     no change │
│ QQuery 22 │      198.50 / 206.07 ±7.45 / 217.59 ms │      188.30 / 196.35 ±6.65 / 205.66 ms │     no change │
└───────────┴────────────────────────────────────────┴────────────────────────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Benchmark Summary            ┃            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Total Time (HEAD)            │ 20231.46ms │
│ Total Time (dyncomparator)   │ 19109.40ms │
│ Average Time (HEAD)          │   919.61ms │
│ Average Time (dyncomparator) │   868.61ms │
│ Queries Faster               │         10 │
│ Queries Slower               │          0 │
│ Queries with No Change       │         12 │
│ Queries with Failure         │          0 │
└──────────────────────────────┴────────────┘

Resource Usage

tpch10 — base (merge-base)

Metric Value
Wall time 101.6s
Peak memory 12.4 GiB
Avg memory 8.6 GiB
CPU user 943.6s
CPU sys 73.9s
Peak spill 0 B

tpch10 — branch

Metric Value
Wall time 95.9s
Peak memory 12.2 GiB
Avg memory 8.7 GiB
CPU user 887.7s
CPU sys 72.4s
Peak spill 0 B

File an issue against this benchmark runner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants