Skip to content

[4.2-dev] Bound wide payload batches in broadcast hash joins - #33242

Merged
XuPeng-SH merged 4 commits into
matrixorigin:4.2-devfrom
LeftHandCold:fix/32143-broadcast-varlen-42
Nov 25, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:4.2-devfrom
LeftHandCold:fix/32143-broadcast-varlen-42

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • 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.

Backport matrixorigin#32917 to the 4.2 hash build and import memory accounting paths. Keep payload batches within the per-allocation limit and resolve retained build rows across variable-size batches.

Fixes matrixorigin#32143

Co-authored-by: lin <[email protected]>
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 8353ba7facd549ad0e0bac89cd528677f917b9b2

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: 8353ba7facd549ad0e0bac89cd528677f917b9b2

Assessment: approve

The broadcast hash-build path now splits retained variable-length columns at allocation boundaries and carries logical row positions through probing and right-join finalization. The row directory is allocated only for nonuniform retained batches; the selected-payload checks and continuation state reuse the existing vector, batch, and query-budget owners. I found no actionable correctness or design defect in the reviewed scope.

Model: gpt-6.1-terra / max

Session: 01a212e9-10a4-7203-9194-162fe0e55042 · slot 0 · generation 13

Validation:

  • The assigned private-/tmp and loopback preflight passed; receipt checks/1795615904860139484-4.json records head 8353ba7 and exit 0.

  • Focused Go tests passed for TestHashBuildRetainedVarlenAllocationBoundary, TestHashJoinRetainedVarlenAcrossBatches, TestJoinOutputProbeResume, TestJoinEmptyOutputRowLimit, and TestJoinMapBuildPayloadChecks, including boundary, budget rejection, continuation, reset, residual, and right-finalization subcases. Full output is focused-tests-noindex.log; checks/1795617058184382820-2.json records the command, frozen head, and exit 0.

  • The reused native libraries were checked against all 170 frozen native inputs and their build ledger; native-provenance.log and checks/1795615928349100039-3.json record the result. A cold dependency fetch timed out and an interrupted cache copy caused later setup failures; the affected module was repaired and verified before the successful run.

Limitations:

  • The PR body reports full-scale single-CN MySQL controls, hard-budget/session reuse, related-package tests, and focused race runs; their raw logs were not supplied in local_validation and those runs were not independently repeated here.

  • The reported performance comparison covers the author's stated narrow local workloads and was not independently reproduced.

@mergify mergify Bot added the queued label Nov 25, 2026
@mergify

mergify Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

17 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Wed 25 Nov, 14:32 · rule release-4.2 · triggered by rule Automatic queue on approval for release-4.2
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 14:49 · a985c66

Reason

Pull request #33242 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

@XuPeng-SH
XuPeng-SH merged commit c56af3c into matrixorigin:4.2-dev Nov 25, 2026
@mergify mergify Bot added dequeued and removed queued labels Nov 25, 2026
XuPeng-SH pushed a commit that referenced this pull request Nov 25, 2026
## 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>

This branch was successfully deployed

No deployments
ci — a985c664 Deployed Nov 25, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants