Skip to content

chore: refactor SortMergeJoin bitwise stream to generators and simplify to be textbook like as possible#23761

Draft
rluvaton wants to merge 6 commits into
apache:mainfrom
rluvaton:let-claude-try-refactor-bitwise-stream-to-use-generator
Draft

chore: refactor SortMergeJoin bitwise stream to generators and simplify to be textbook like as possible#23761
rluvaton wants to merge 6 commits into
apache:mainfrom
rluvaton:let-claude-try-refactor-bitwise-stream-to-use-generator

Conversation

@rluvaton

@rluvaton rluvaton commented Jul 21, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

N/A

Rationale for this change

SortMergeJoin bitwise stream implementation is very complex and hard to understand while on paper it should be pretty simple.

the reason for that is we have to store state between polls (we had boundary) and handle the case where both can get Poll::Pending from child and Poll::Ready from child which further complicate the code

What changes are included in this PR?

  1. Move to async generators
  2. Rewrote main loop to be textbook like as possible

(this was entirely written by Claude Fable, sorry 😅 )

Are these changes tested?

existing tests

Are there any user-facing changes?

no

@github-actions github-actions Bot added the physical-plan Changes to the physical-plan crate label Jul 21, 2026
@rluvaton

Copy link
Copy Markdown
Member Author

run benchmark smj

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c5035366186-1210-zh2ds 6.12.85+ #1 SMP Mon May 11 08:17:35 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 let-claude-try-refactor-bitwise-stream-to-use-generator (d3e32e9) to ed22a4a (merge-base) diff using: smj
Results will be posted here when complete


File an issue against this benchmark runner

@mbutrovich
mbutrovich self-requested a review July 21, 2026 14:54
@mbutrovich

Copy link
Copy Markdown
Contributor

Love to see a negative line count!

@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 let-claude-try-refactor-bitwise-stream-to-use-generator
--------------------
Benchmark smj.json
--------------------
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query     ┃                                 HEAD ┃ let-claude-try-refactor-bitwise-stream-to-use-generator ┃        Change ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 1  │          8.67 / 8.78 ±0.11 / 9.00 ms │                             8.51 / 8.62 ±0.06 / 8.68 ms │     no change │
│ QQuery 2  │    160.82 / 162.68 ±1.51 / 164.41 ms │                       160.60 / 162.90 ±2.17 / 166.47 ms │     no change │
│ QQuery 3  │    102.85 / 104.99 ±1.14 / 106.20 ms │                       103.37 / 104.21 ±0.95 / 105.87 ms │     no change │
│ QQuery 4  │       28.01 / 28.16 ±0.14 / 28.33 ms │                          28.18 / 28.32 ±0.11 / 28.48 ms │     no change │
│ QQuery 5  │       20.44 / 20.70 ±0.20 / 21.01 ms │                          20.43 / 20.64 ±0.12 / 20.78 ms │     no change │
│ QQuery 6  │    158.63 / 160.95 ±1.61 / 162.78 ms │                       156.35 / 158.72 ±1.92 / 160.53 ms │     no change │
│ QQuery 7  │   198.19 / 207.84 ±17.87 / 243.53 ms │                       197.47 / 198.75 ±1.97 / 202.67 ms │     no change │
│ QQuery 8  │       19.42 / 20.02 ±0.49 / 20.62 ms │                          18.72 / 18.96 ±0.16 / 19.16 ms │ +1.06x faster │
│ QQuery 9  │   204.45 / 211.38 ±10.53 / 232.26 ms │                       202.64 / 204.24 ±1.01 / 205.43 ms │     no change │
│ QQuery 10 │       57.92 / 58.15 ±0.17 / 58.37 ms │                          57.80 / 57.91 ±0.09 / 58.03 ms │     no change │
│ QQuery 11 │       27.02 / 30.57 ±6.70 / 43.96 ms │                          26.84 / 27.01 ±0.15 / 27.29 ms │ +1.13x faster │
│ QQuery 12 │       66.89 / 70.20 ±4.25 / 78.49 ms │                          66.99 / 70.53 ±2.41 / 74.53 ms │     no change │
│ QQuery 13 │    103.38 / 107.06 ±2.83 / 111.45 ms │                       105.03 / 107.11 ±1.60 / 109.49 ms │     no change │
│ QQuery 14 │       58.17 / 61.68 ±5.45 / 72.39 ms │                          57.53 / 58.55 ±1.47 / 61.46 ms │ +1.05x faster │
│ QQuery 15 │       58.09 / 58.32 ±0.18 / 58.63 ms │                          57.75 / 57.97 ±0.15 / 58.21 ms │     no change │
│ QQuery 16 │       11.57 / 11.64 ±0.04 / 11.69 ms │                          11.36 / 11.42 ±0.06 / 11.54 ms │     no change │
│ QQuery 17 │    145.34 / 149.69 ±8.14 / 165.96 ms │                       145.09 / 146.44 ±2.14 / 150.69 ms │     no change │
│ QQuery 18 │    110.40 / 110.62 ±0.18 / 110.86 ms │                       110.07 / 110.74 ±0.34 / 111.02 ms │     no change │
│ QQuery 19 │    288.93 / 295.86 ±5.88 / 305.91 ms │                       288.20 / 296.69 ±6.69 / 305.20 ms │     no change │
│ QQuery 20 │ 1252.41 / 1261.46 ±6.61 / 1269.78 ms │                    1253.21 / 1259.24 ±3.67 / 1264.36 ms │     no change │
│ QQuery 21 │      94.00 / 99.30 ±8.43 / 116.07 ms │                          93.89 / 94.55 ±0.68 / 95.82 ms │     no change │
│ QQuery 22 │    101.14 / 103.54 ±1.99 / 106.18 ms │                       100.72 / 104.62 ±6.00 / 116.55 ms │     no change │
│ QQuery 23 │    110.18 / 110.54 ±0.29 / 110.98 ms │                       108.03 / 110.56 ±2.67 / 115.65 ms │     no change │
│ QQuery 24 │       27.15 / 27.25 ±0.11 / 27.45 ms │                          27.18 / 27.31 ±0.10 / 27.46 ms │     no change │
│ QQuery 25 │       64.21 / 69.89 ±4.05 / 76.54 ms │                          62.73 / 69.56 ±5.81 / 80.22 ms │     no change │
│ QQuery 26 │     96.12 / 107.22 ±5.86 / 112.20 ms │                      107.21 / 117.12 ±12.02 / 140.08 ms │  1.09x slower │
└───────────┴──────────────────────────────────────┴─────────────────────────────────────────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Benchmark Summary                                                      ┃           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ Total Time (HEAD)                                                      │ 3658.49ms │
│ Total Time (let-claude-try-refactor-bitwise-stream-to-use-generator)   │ 3632.67ms │
│ Average Time (HEAD)                                                    │  140.71ms │
│ Average Time (let-claude-try-refactor-bitwise-stream-to-use-generator) │  139.72ms │
│ Queries Faster                                                         │         3 │
│ Queries Slower                                                         │         1 │
│ Queries with No Change                                                 │        22 │
│ Queries with Failure                                                   │         0 │
└────────────────────────────────────────────────────────────────────────┴───────────┘

Resource Usage

smj — base (merge-base)

Metric Value
Wall time 20.0s
Peak memory 1.2 GiB
Avg memory 455.1 MiB
CPU user 156.8s
CPU sys 3.5s
Peak spill 0 B

smj — branch

Metric Value
Wall time 20.0s
Peak memory 1.1 GiB
Avg memory 454.7 MiB
CPU user 157.7s
CPU sys 3.4s
Peak spill 0 B

File an issue against this benchmark runner

@codecov-commenter

codecov-commenter commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.35088% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.71%. Comparing base (ed22a4a) to head (c3e1934).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...l-plan/src/joins/sort_merge_join/bitwise_stream.rs 80.28% 18 Missing and 38 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #23761      +/-   ##
==========================================
+ Coverage   80.69%   80.71%   +0.01%     
==========================================
  Files        1089     1089              
  Lines      368447   368653     +206     
  Branches   368447   368653     +206     
==========================================
+ Hits       297332   297556     +224     
+ Misses      53405    53338      -67     
- Partials    17710    17759      +49     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rluvaton

Copy link
Copy Markdown
Member Author

Love to see a negative line count!

Now its not due to added tests to make sure we are not counting child/consumer time, but the stream file still have negative line count!

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

Labels

physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants