Skip to content

fix(data branch): support binary primary keys - #26559

Merged
XuPeng-SH merged 1 commit into
matrixorigin:mainfrom
gouhongshen:agent/issue-26075
Aug 1, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:mainfrom
gouhongshen:agent/issue-26075

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #26075

What this PR does / why we need it:

Root cause

DATA BRANCH CREATE TABLE copies rows through the sinker spill-sort path. The ordinary batch sorter already supports BINARY and VARBINARY, but mergeutil.MergeSortBatches omitted both OIDs from its varlena dispatch. When either type was the primary-key sort key, multi-batch merge initialization reached the default branch and panicked with invalid type: BINARY or invalid type: VARBINARY.

Changes

  • Route BINARY and VARBINARY sort keys through the existing varlena merge implementation, preserving the same raw-byte lexicographic ordering used by the ordinary sorter.
  • Add a focused merge-sort unit test for both types, including interleaved batches, byte prefixes, NUL bytes, high bytes, and payload/key association.
  • Add a self-contained Data Branch BVT covering fixed-binary padding, variable-binary byte preservation, ordering, successful table branch creation, and branch isolation.

Tests

  • Pre-fix regression proof: TestMergeSortBatchesBinaryTypes/binary panicked at pkg/objectio/mergeutil/types.go:120 with invalid type: BINARY.
  • go build ./pkg/objectio/mergeutil with the repository CGo environment.
  • go vet ./pkg/objectio/mergeutil with the repository CGo environment.
  • After rebasing onto ffad68fdb, .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=180s ./pkg/objectio/mergeutil.
  • After rebasing, .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=100 -timeout=300s -run '^TestMergeSortBatchesBinaryTypes$' ./pkg/objectio/mergeutil.
  • After rebasing, .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=300s ./pkg/objectio/mergeutil.
  • After rebasing, .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/objectio/ioutil.
  • mo-tester BVT branch_binary_pk.sql: 3/3 runs passed, each 18/18 statements at 100%.
  • CI follow-up: run 30699038757 attempt 1 reproduced an unrelated morpc options-slice race tracked in [Bug]: concurrent morpc backend creation races on factory options #26562; the failed Ubuntu/x86 UT job passed on attempt 2, and the completed SCA, coverage, and BVT checks are green.

Residual risks

No known residual correctness risk. The change only admits two already-supported varlena types into the merge-sort dispatch; it does not alter storage formats, comparison rules, or behavior for unsupported types.

@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 →

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

Deep review complete; no merge-blocking findings.

The new dispatch uses the same raw-byte lexicographic order as the ordinary batch sorter. BINARY(n) padding remains at the DML/cast boundary, VARBINARY length is preserved, and merge/sinker ownership and error propagation are unchanged. The unit and BVT coverage jointly exercise cross-batch ordering, byte prefixes, NUL/high bytes, fixed-binary padding, payload association, and branch isolation.

Independent verification on this exact head: build and vet passed; TestMergeSortBatchesBinaryTypes passed with -race -count=100; the complete mergeutil package passed under race; and the dependent objectio/ioutil package passed. Additional diagnostic coverage for out-of-line varlena values (BINARY(32) / VARBINARY(64)) also passed.

Q1: no new resource owner or cleanup edge. Q2: no new wait dependency. Q3: heap/output/staging bounds remain unchanged.

@XuPeng-SH
XuPeng-SH merged commit 49f9e33 into matrixorigin:main Aug 1, 2026
65 of 66 checks passed
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#26075

## What this PR does / why we need it:

### Root cause

`DATA BRANCH CREATE TABLE` copies rows through the sinker spill-sort
path. The ordinary batch sorter already supports `BINARY` and
`VARBINARY`, but `mergeutil.MergeSortBatches` omitted both OIDs from its
varlena dispatch. When either type was the primary-key sort key,
multi-batch merge initialization reached the default branch and panicked
with `invalid type: BINARY` or `invalid type: VARBINARY`.

### Changes

- Route `BINARY` and `VARBINARY` sort keys through the existing varlena
merge implementation, preserving the same raw-byte lexicographic
ordering used by the ordinary sorter.
- Add a focused merge-sort unit test for both types, including
interleaved batches, byte prefixes, NUL bytes, high bytes, and
payload/key association.
- Add a self-contained Data Branch BVT covering fixed-binary padding,
variable-binary byte preservation, ordering, successful table branch
creation, and branch isolation.

### Tests

- Pre-fix regression proof: `TestMergeSortBatchesBinaryTypes/binary`
panicked at `pkg/objectio/mergeutil/types.go:120` with `invalid type:
BINARY`.
- `go build ./pkg/objectio/mergeutil` with the repository CGo
environment.
- `go vet ./pkg/objectio/mergeutil` with the repository CGo environment.
- After rebasing onto `ffad68fdb`,
`.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=180s
./pkg/objectio/mergeutil`.
- After rebasing, `.agents/skills/mo-dev/scripts/mo-cgo-test -race
-count=100 -timeout=300s -run '^TestMergeSortBatchesBinaryTypes$'
./pkg/objectio/mergeutil`.
- After rebasing, `.agents/skills/mo-dev/scripts/mo-cgo-test -race
-count=1 -timeout=300s ./pkg/objectio/mergeutil`.
- After rebasing, `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1
-timeout=300s ./pkg/objectio/ioutil`.
- `mo-tester` BVT `branch_binary_pk.sql`: 3/3 runs passed, each 18/18
statements at 100%.
- CI follow-up: run 30699038757 attempt 1 reproduced an unrelated
`morpc` options-slice race tracked in matrixorigin#26562; the failed Ubuntu/x86 UT
job passed on attempt 2, and the completed SCA, coverage, and BVT checks
are green.

### Residual risks

No known residual correctness risk. The change only admits two
already-supported varlena types into the merge-sort dispatch; it does
not alter storage formats, comparison rules, or behavior for unsupported
types.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#26075

## What this PR does / why we need it:

### Root cause

`DATA BRANCH CREATE TABLE` copies rows through the sinker spill-sort
path. The ordinary batch sorter already supports `BINARY` and
`VARBINARY`, but `mergeutil.MergeSortBatches` omitted both OIDs from its
varlena dispatch. When either type was the primary-key sort key,
multi-batch merge initialization reached the default branch and panicked
with `invalid type: BINARY` or `invalid type: VARBINARY`.

### Changes

- Route `BINARY` and `VARBINARY` sort keys through the existing varlena
merge implementation, preserving the same raw-byte lexicographic
ordering used by the ordinary sorter.
- Add a focused merge-sort unit test for both types, including
interleaved batches, byte prefixes, NUL bytes, high bytes, and
payload/key association.
- Add a self-contained Data Branch BVT covering fixed-binary padding,
variable-binary byte preservation, ordering, successful table branch
creation, and branch isolation.

### Tests

- Pre-fix regression proof: `TestMergeSortBatchesBinaryTypes/binary`
panicked at `pkg/objectio/mergeutil/types.go:120` with `invalid type:
BINARY`.
- `go build ./pkg/objectio/mergeutil` with the repository CGo
environment.
- `go vet ./pkg/objectio/mergeutil` with the repository CGo environment.
- After rebasing onto `ffad68fdb`,
`.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=180s
./pkg/objectio/mergeutil`.
- After rebasing, `.agents/skills/mo-dev/scripts/mo-cgo-test -race
-count=100 -timeout=300s -run '^TestMergeSortBatchesBinaryTypes$'
./pkg/objectio/mergeutil`.
- After rebasing, `.agents/skills/mo-dev/scripts/mo-cgo-test -race
-count=1 -timeout=300s ./pkg/objectio/mergeutil`.
- After rebasing, `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1
-timeout=300s ./pkg/objectio/ioutil`.
- `mo-tester` BVT `branch_binary_pk.sql`: 3/3 runs passed, each 18/18
statements at 100%.
- CI follow-up: run 30699038757 attempt 1 reproduced an unrelated
`morpc` options-slice race tracked in matrixorigin#26562; the failed Ubuntu/x86 UT
job passed on attempt 2, and the completed SCA, coverage, and BVT checks
are green.

### Residual risks

No known residual correctness risk. The change only admits two
already-supported varlena types into the merge-sort dispatch; it does
not alter storage formats, comparison rules, or behavior for unsupported
types.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#26075

## What this PR does / why we need it:

### Root cause

`DATA BRANCH CREATE TABLE` copies rows through the sinker spill-sort
path. The ordinary batch sorter already supports `BINARY` and
`VARBINARY`, but `mergeutil.MergeSortBatches` omitted both OIDs from its
varlena dispatch. When either type was the primary-key sort key,
multi-batch merge initialization reached the default branch and panicked
with `invalid type: BINARY` or `invalid type: VARBINARY`.

### Changes

- Route `BINARY` and `VARBINARY` sort keys through the existing varlena
merge implementation, preserving the same raw-byte lexicographic
ordering used by the ordinary sorter.
- Add a focused merge-sort unit test for both types, including
interleaved batches, byte prefixes, NUL bytes, high bytes, and
payload/key association.
- Add a self-contained Data Branch BVT covering fixed-binary padding,
variable-binary byte preservation, ordering, successful table branch
creation, and branch isolation.

### Tests

- Pre-fix regression proof: `TestMergeSortBatchesBinaryTypes/binary`
panicked at `pkg/objectio/mergeutil/types.go:120` with `invalid type:
BINARY`.
- `go build ./pkg/objectio/mergeutil` with the repository CGo
environment.
- `go vet ./pkg/objectio/mergeutil` with the repository CGo environment.
- After rebasing onto `ffad68fdb`,
`.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=180s
./pkg/objectio/mergeutil`.
- After rebasing, `.agents/skills/mo-dev/scripts/mo-cgo-test -race
-count=100 -timeout=300s -run '^TestMergeSortBatchesBinaryTypes$'
./pkg/objectio/mergeutil`.
- After rebasing, `.agents/skills/mo-dev/scripts/mo-cgo-test -race
-count=1 -timeout=300s ./pkg/objectio/mergeutil`.
- After rebasing, `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1
-timeout=300s ./pkg/objectio/ioutil`.
- `mo-tester` BVT `branch_binary_pk.sql`: 3/3 runs passed, each 18/18
statements at 100%.
- CI follow-up: run 30699038757 attempt 1 reproduced an unrelated
`morpc` options-slice race tracked in matrixorigin#26562; the failed Ubuntu/x86 UT
job passed on attempt 2, and the completed SCA, coverage, and BVT checks
are green.

### Residual risks

No known residual correctness risk. The change only admits two
already-supported varlena types into the merge-sort dispatch; it does
not alter storage formats, comparison rules, or behavior for unsupported
types.

This branch was previously deployed

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

Labels

kind/bug Something isn't working kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DATA BRANCH CREATE TABLE fails for BINARY and VARBINARY primary keys

3 participants