Repository navigation
fix: bound wide payload batches in broadcast hash joins - #32917
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
…c3c8089231b76b80a056980b220428be728c908
|
Queue requested — the merge queue status continues in this comment ↓. |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: ba0acacf9d0405c19a39cf7282128e70d927502f
Assessment: request_changes
Bounded build batches fix the reported allocator failure in the scaled SQL test while preserving join results and query-budget rejection. The output limit introduces a batching regression when a wide build value never matches.
Model: gpt-6.2-sol / xhigh
Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3
- P2
pkg/sql/colexec/hashjoin/join.go:612: A broadcast hash join projects a build column containing a 64 MiB value whose key never matches. Every emitted value in that column is short.
Impact: At the default allocator limit, the candidate emits 265 batches for the same 8,192 rows that the merge base emits in one batch. This adds 264 result-batch resets and downstream deliveries even though the selected output fits in one batch.
Evidence: The build-wide scan sets a 31-row cap from the unmatched value, and the probe applies it to every match. The paired operator probe verified identical row contents, and the no-outlier control emitted one batch on both revisions. Bound batches using the bytes of rows selected for output and keep the existing continuation when the next append would cross the limit.
Validation:
-
The focused retained-payload and budget-rejection tests passed. Normal CGo tests passed for vector, colexec, hashbuild, hashjoin, spillutil, dedupjoin, loopjoin, message, and compile.
-
The single-CN MySQL probe verified row IDs, payload lengths, NULL extension, and connection health with a 33,554,416-byte allocation limit. Both revisions passed the 33,331,200-byte control. At 34,406,400 bytes, the candidate passed and the merge base returned allocator error 20101.
-
The default-limit batching probe ran on both revisions. Terminal receipts and logs are matched in validation-reconciliation.json.
Limitations:
- The SQL probe used a reduced allocator cap and two input tables to keep storage appends below that cap. The original 2 GiB SQL crossover, end-to-end latency, and multi-CN performance remain unmeasured.
|
Follow-up to review 5969328627. Commit |
|
mo-bot review · Commit: {"message": "You\u2019ve hit your usage limit. Visit https://chatgpt.com/settings/usage to purchase more credits or try again at Nov 20th, 2026 9:12 PM.", "codexErrorInfo": "usageLimitExceeded", "additionalDetails": null, "misalignment": null} |
There was a problem hiding this comment.
Re-review of 4a3475dfec12a7339a2cdc19c11c1b24332afb95 against main ae9e665f3093094ba3286e72bf1af8e111463180.
The earlier review findings are addressed: output batches account for selected payloads; flat membership, unique-key and eligible fan-out projections avoid unnecessary probe-side scans; empty INNER probes avoid the build-side scan; and consumers share the per-column check on the immutable JoinMap. I traced publication/refcount cleanup, byte accounting and continuation through ordinary, RIGHT-finalization and ASOF build-left paths, including dictionary and repeated values. I found no remaining blocker in the follow-up or its interaction with the previously reviewed change map.
Validation at 4a3475dfec: CI passed UT, SCA, PROXY and PESSIMISTIC BVT. Locally, TestJoinMapBuildPayloadChecks and TestHashJoinProbeOutputArea each passed 100 repetitions under -race; TestHashJoinRetainedVarlenAcrossBatches passed for duplicate/residual continuation, RIGHT finalization and the unmatched outlier. git diff --check passed. Earlier operator/public-path results and author performance measurements are reused for unchanged closures. The published timing is a single-worker microbenchmark; original-scale 2 GiB and end-to-end multi-worker performance remain unmeasured.
Follow-up for merged head c823aa78d1c32832d9062307fd15ca145ddd2201: the merge contains no manual conflict resolution, and the PR's added/removed lines are identical against the new base. I checked the intervening bitmap ownership and allocation changes and rebuilt native CGo artifacts from this head. The JoinMap payload, HashBuild allocation boundary/site and HashJoin retained-payload/output-area tests passed 25 times under -race; git diff --check passed. I found no additional blocker. The new head's CI is still running; the CI results cited above apply to 4a3475dfec, not this merge.
✅ Merged into
|
…c3c8089231b76b80a056980b220428be728c908
## What type of PR is this? - [x] BUG ## Which issue(s) does this PR fix? Fixes #32143 Backport of #32917 to `4.2-dev`. ## What changed? A broadcast hash join could have enough query memory and still fail when the retained values in one variable-length column crossed the MPool single-allocation limit. Packing 8,192 rows into one batch was sufficient to trigger it. The same limit matters when projecting duplicate matches into the output. - Split retained build batches by row count and physical bytes per column. Create an allocation-accounted row directory only when an interior batch is short. Hashing, probing, and right-join finalization resolve logical ordinals against those batches. - Bound output for the selected rows and resume partially emitted match groups. Preserve 4.2's import-memory accounting across split batches and its hard query budget. - Port the broadcast path available on 4.2. The patch does not require a catalog migration, a new RPC, or a configuration change. ## Validation - On unpatched target commit `d2bc81d9f0`, the scaled MySQL reproducer returned error 20101 for 8,192 values of 4,100 bytes with a 512 MiB query budget (33,585,150-byte allocation limit, 33,587,200 bytes required). Both controls passed. The backport passed all three cases with the same fixture. - Single CN over the MySQL protocol, default per-allocation limit (2,147,483,631 bytes), 8 GiB query budget. A LEFT JOIN with 8,192 build values of 262,150 bytes each returned all 8,192 matches and all 16,383 NULL-extended rows. The client checked every ID for duplicates and compared each complete value. The 8,191-row boundary control and the three-column control also passed. - Operator tests cover duplicate and unique keys, residual predicates, RIGHT JOIN finalization, an unmatched wide value, import-memory output continuation, and budget failure and release. All nine related packages passed. Focused race tests in three packages passed three times. The SQL hard-budget test checked the error and continued on the same connection. - A local single-CN narrow-column comparison on `ef9dac896b` used 65,536 probe rows with 64-byte build values. Across two runs per version and 16 timed queries per case, median latency was 8.45 → 8.66 ms for unique keys and 13.07 → 13.44 ms for duplicate keys. All counts and checksums matched. This measures those two local workloads. ## Follow-up for #33246 This branch includes the two broadcast JOIN fixes from the main counterpart #33250. Key-only builds now use bounded temporary batches. A probe that stops within a duplicate group drops its pending matches when it releases the owning join map. - Both new regression cases failed on the previous PR head and passed on this head. On both branches, a single CN using the MySQL protocol with the default allocation limit returned the expected count of 24,556 and control sum of 33,558,528. The client independently checked every source ID and key byte. - Four alternating executions of one prepared LEFT JOIN on one connection returned the expected rows and NULLs. The hard query-budget error and connection reuse also passed. Eight related packages passed with vet, focused race tests passed three times, and the incremental linter reported zero issues. - A local ABBA comparison against the previous PR head 5ad4415 used 65,536 probe rows and 8,192 build rows, with single-CN DOP 1. Each query returned the expected 131,072 matches and checksum. Across 16 timed queries per version and key type, median latency for integer keys moved from 5.875 to 5.998 ms (+2.10%) and for 64-byte string keys from 8.351 to 8.671 ms (+3.84%). These timings cover this workload only. --------- Co-authored-by: lin <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
## What type of PR is this? - [x] BUG ## Which issue(s) does this PR fix? Fixes #33246 Follow-up to #32917. The 4.2-dev backport is #33242. ## What changed? Broadcast HashBuild stages input while constructing the map even when the probe needs only keys. Apply the existing byte limit to those temporary batches. Build the ordinal-to-batch directory only for consumers that retain payload. Keep shuffle recovery and dedup rewrite batching on their current paths. Discard the probe's remaining matches when releasing the JoinMap that owns them. This also covers an upstream LIMIT ending a probe before it drains the current group. ## Validation - Both new regression cases failed before the fix. The wide-key build exceeded the allocator limit, and resetting after 11 of 13 wide matches retained two pending selections. Both pass with the fix. - Single CN over MySQL, default per-allocation limit and an 8 GiB query budget. The build side had 8,192 keys of 262,150 bytes each. The client checked every source ID and every key byte on both tables. The key-only LEFT JOIN returned the expected count of 24,556 and the build-column control returned the expected sum of 33,558,528. - Executed one prepared LEFT JOIN four times on the same connection, alternating a one-row LIMIT over duplicate matches and a single matching build key. Both full executions returned 16,384 distinct probe rows with the correct nine matches and NULL-extended rows. - Eight related packages passed with vet. Three repetitions of the focused race tests passed. The MySQL hard-budget regression passed and the incremental linter reported zero issues. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
What this PR does / why we need it:
Broadcast HashBuild can accumulate a varlen column in one contiguous area that exceeds MPool's 2 GiB per-allocation limit, even when each value fits and the query has enough memory budget. The reported query fails when one build column reaches 2,147,532,800 bytes.
HashBuild retains wide payloads in physical batches sized against each column's allocation limit. JoinMap keeps dense logical build row ordinals and uses cumulative batch row counts to locate payloads when physical batches have uneven lengths. HashJoin sizes each projected result batch by the payload actually selected and can resume within a match group on the next call. The existing query memory budget still accounts for the full build and returns an explicit resource error when exhausted.
Validation
At a 1 MiB allocation limit, the baseline HashBuild failed on a 1,130,496-byte column and passed the below-limit and three-column controls. The candidate passed all three cases and preserved every row ID and payload byte. Focused operator tests also covered multi-batch LEFT and RIGHT output, residual predicates and NULLs, and rollback and cleanup after budget rejection.
Single-CN MySQL LEFT JOIN tests used a reduced effective per-allocation limit of 33,585,136 bytes. They verified row IDs, payload lengths and NULL-extended rows for a column just below and just above that limit, and for three smaller columns with 38,700,000 bytes combined. A separate hard-budget test returned MySQL 3015 / HY000 with
hash build memory budget exceeded. The same connection returnedSELECT 1after each successful join and after the budget error.Local CGo tests passed for
vector,colexec,hashbuild,hashjoin,spillutil,dedupjoin,loopjoin,message, andcompileacross the reviewed changes. HashBuild and HashJoin were rerun before the review follow-ups. Incremental lint reported zero issues.Five paired runs of the ordinary build-copy and unique-key gather microbenchmarks retained their allocation counts and bytes. These measurements cover those paths. End-to-end wide multi-worker throughput, peak memory at the original scale, the candidate SQL at the default 2 GiB limit, and the same-fixture baseline SQL remain unmeasured.
Review follow-up,
4f0927cfa0: a paired local operator probe at the default allocation limit produced the same 8,192 rows with a 64 MiB unmatched build value. The reviewed head emitted 265 batches and this revision emitted one. The committed smaller-cap regression also checks byte-limited LEFT and RIGHT continuation, residual predicates, and NULL extension.Fresh checks at
4f0927cfa0:mo-cgo-test -vet=allpassed forhashbuildandhashjoin, focused-racetests passed, and incremental lint reported zero issues. Five single-CPU samples of the SEMI/ANTI membership microbenchmark retained 8 B/op and 1 alloc/op. Required CI passed on the previous head.Review follow-up,
c57c10c066: flat SEMI/ANTI input with disjoint payloads can use its existing area bound when each input row contributes at most once. In a paired single-workerHashJoin.Callbenchmark with one match among 8,192 probe rows (-benchmem -benchtime=300ms -count=5 -cpu=1), median 64-byte TEXT time went from 70.1 to 27.3 µs per batch. The 24-byte control went from 27.0 to 27.1 µs. Each case used 8 B/op and one allocation.Fresh checks at
c57c10c066:mo-cgo-test -vet=allpassed forhashjoin, focused race tests passed, and incremental lint reported zero issues. The new test covers the disjoint bound and byte-limited continuation when a dictionary repeats one wide payload. Required CI passed on the reviewed head.Review follow-up,
fbd18d6ceb: the existing disjoint-area bound now covers flat probe projections for unique build keys and residual-free fan-out. A pairedHashJoin.Callbenchmark on one worker and one matching probe row out of 8,192 (-benchmem -benchtime=300ms -count=5 -cpu=1) measured median time per batch. Unique-key INNER with 64-byte TEXT fell from 73.0 to 26.9 µs, its 24-byte control measured 28.0 and 26.9 µs, and the 64-byte SEMI control measured 27.5 and 27.0 µs. The two-match INNER fan-out went from 83.9 to 36.3 µs. All cases used 8 B/op and one allocation.Fresh checks at
fbd18d6ceb:mo-cgo-test -vet=allpassed forhashjoinandhashbuild. Focused race and incremental lint passed. Regression cases verify repeated dictionary probe values, repeated build values, and residual fan-out still split at the allocation bound. Required CI passed on the reviewed head.Review follow-up,
4a3475dfec. An empty INNER probe skips the retained build payload check. When output can use retained payloads, the shared JoinMap caches the per-column size check. Repeated values still use selected-byte accounting when required.Fresh local verification at
4a3475dfec.mo-cgo-test -vet=allpassed forvector,message,hashjoin, andhashbuild. Focused race tests passed for concurrent JoinMap access and join output boundaries, and incremental lint reported zero issues. The empty-probe regression test fails on the reviewed source and passes on the fix.A paired
HashJoin.Callstartup microbenchmark with an empty probe and 32 × 8,192 retained rows measured medians on the reviewed head and this fix (-benchmem -benchtime=250ms -count=5 -cpu=1). The 64-byte TEXT case went from 1.47 ms to 0.244 µs. The 24-byte control went from 0.499 to 0.263 µs. All cases measured 44 B/op and three allocations. This isolates one worker's empty-probe startup. Required CI passed on the reviewed head, attempt 2.