Skip to content

perf(vector): preserve bulk marshal for selected varlen - #28724

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
aptend:fix/28659-varlen-marshal
Sep 11, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
aptend:fix/28659-varlen-marshal

Conversation

@aptend

@aptend aptend commented Sep 11, 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 #28659

What this PR does / why we need it:

UnionInt32 materializes every selected non-const varlen value into a fresh destination-area range, but it conservatively cleared the destination areaDisjoint proof. Since #28145, that makes shuffle and hash-build spill batches use canonical varlen serialization, which scans every descriptor, builds per-row canonical metadata, and emits descriptors individually.

Preserve the disjoint-area proof only when the destination was already owned and disjoint. Const selections and borrowed or aliased destinations remain on the canonical path.

For an 8192-row selected varchar vector, BenchmarkMarshalBinarySelectedVarlena changes from about 2.06 ms/op, 455 KB/op, and 8233 allocs/op to about 35 us/op, 20 B/op, and 6 allocs/op.

Validation:

  • go test ./pkg/container/vector ./pkg/container/batch ./pkg/sql/colexec/shuffle ./pkg/sql/colexec/hashbuild -count=1
  • go test ./pkg/container/vector -run "^TestUnionSelection" -count=1
  • go test ./pkg/container/vector -run "^$" -bench "^BenchmarkMarshalBinarySelectedVarlena$" -benchmem -benchtime=2s -count=5

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

Reviewed 119c47e against main d44f033. No concrete blocker found.

This is a focused restoration of an existing serialization fast-path invariant, not a new storage/wire contract. I read all three changed files and traced unionT (both int32 and int64 selections), varlena append/growth, backing ownership, marshal planning and null normalization. The proof is captured only for an already owned, disjoint destination and restored only after successful non-const materialization. Repeated/out-of-order source rows receive fresh appended ranges; existing aliases/borrowed destinations cannot acquire the proof, const broadcasts return without restoring it, and copy/allocation failure leaves the conservative path. Empty selections and fixed-width behavior remain unchanged. Serialization retains existing size checks and stale NULL-descriptor normalization; there is no added shared state, worker or synchronization dependency.

The new regression checks repeated selections, distinct offsets, NULL/inline payloads, actual bulk-path selection and decoded values; the const case explicitly verifies canonical fallback. The benchmark measures the selected-vector marshal path rather than charging fixture construction to the timed loop. Additional borrowed-destination or repeated-append cases would be useful supplementary coverage, not blockers for the guarded change.

Evidence/limits: source review plus the author's reported vector/batch/shuffle/hashbuild package checks, focused selection tests and five benchmark samples. I did not independently execute native tests or reproduce the reported benchmark. The narrow marshal cost reduction is supported by the eliminated canonical scan/metadata allocations; this review does not establish that the full billion-row workload in #28659 is resolved. Head/base were rechecked immediately before submission; source worktree left unchanged.

@mergify mergify Bot added the queued label Sep 11, 2026
@mergify

mergify Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-11 12:51 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-11 12:52 UTC · at 742cd27af58352fb88d73497c9597039b9ec31fd

This pull request spent 1 minute 30 seconds in the queue, with no time running CI.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Reason

Pull request #28724 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.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

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

  • Requeue this pull request

VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#28724)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#28659

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

`UnionInt32` materializes every selected non-const varlen value into a
fresh destination-area range, but it conservatively cleared the
destination `areaDisjoint` proof. Since matrixorigin#28145, that makes shuffle and
hash-build spill batches use canonical varlen serialization, which scans
every descriptor, builds per-row canonical metadata, and emits
descriptors individually.

Preserve the disjoint-area proof only when the destination was already
owned and disjoint. Const selections and borrowed or aliased
destinations remain on the canonical path.

For an 8192-row selected varchar vector,
`BenchmarkMarshalBinarySelectedVarlena` changes from about 2.06 ms/op,
455 KB/op, and 8233 allocs/op to about 35 us/op, 20 B/op, and 6
allocs/op.

Validation:

- `go test ./pkg/container/vector ./pkg/container/batch
./pkg/sql/colexec/shuffle ./pkg/sql/colexec/hashbuild -count=1`
- `go test ./pkg/container/vector -run "^TestUnionSelection" -count=1`
- `go test ./pkg/container/vector -run "^$" -bench
"^BenchmarkMarshalBinarySelectedVarlena$" -benchmem -benchtime=2s
-count=5`

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#28724)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#28659

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

`UnionInt32` materializes every selected non-const varlen value into a
fresh destination-area range, but it conservatively cleared the
destination `areaDisjoint` proof. Since matrixorigin#28145, that makes shuffle and
hash-build spill batches use canonical varlen serialization, which scans
every descriptor, builds per-row canonical metadata, and emits
descriptors individually.

Preserve the disjoint-area proof only when the destination was already
owned and disjoint. Const selections and borrowed or aliased
destinations remain on the canonical path.

For an 8192-row selected varchar vector,
`BenchmarkMarshalBinarySelectedVarlena` changes from about 2.06 ms/op,
455 KB/op, and 8233 allocs/op to about 35 us/op, 20 B/op, and 6
allocs/op.

Validation:

- `go test ./pkg/container/vector ./pkg/container/batch
./pkg/sql/colexec/shuffle ./pkg/sql/colexec/hashbuild -count=1`
- `go test ./pkg/container/vector -run "^TestUnionSelection" -count=1`
- `go test ./pkg/container/vector -run "^$" -bench
"^BenchmarkMarshalBinarySelectedVarlena$" -benchmem -benchtime=2s
-count=5`

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#28724)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#28659

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

`UnionInt32` materializes every selected non-const varlen value into a
fresh destination-area range, but it conservatively cleared the
destination `areaDisjoint` proof. Since matrixorigin#28145, that makes shuffle and
hash-build spill batches use canonical varlen serialization, which scans
every descriptor, builds per-row canonical metadata, and emits
descriptors individually.

Preserve the disjoint-area proof only when the destination was already
owned and disjoint. Const selections and borrowed or aliased
destinations remain on the canonical path.

For an 8192-row selected varchar vector,
`BenchmarkMarshalBinarySelectedVarlena` changes from about 2.06 ms/op,
455 KB/op, and 8233 allocs/op to about 35 us/op, 20 B/op, and 6
allocs/op.

Validation:

- `go test ./pkg/container/vector ./pkg/container/batch
./pkg/sql/colexec/shuffle ./pkg/sql/colexec/hashbuild -count=1`
- `go test ./pkg/container/vector -run "^TestUnionSelection" -count=1`
- `go test ./pkg/container/vector -run "^$" -bench
"^BenchmarkMarshalBinarySelectedVarlena$" -benchmem -benchtime=2s
-count=5`

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

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 size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 10Y composite-PK INSERT SELECT exceeds 7200s under sustained CN memory-limit pressure

3 participants