Skip to content

perf(group): reduce fixed-width DISTINCT spill overhead - #28108

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
aptend:perf/group-spill-columnar-codec
Sep 4, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
aptend:perf/group-spill-columnar-codec

Conversation

@aptend

@aptend aptend commented Sep 4, 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:

issue #26768

What this PR does / why we need it:

TPC-DS 1T Q75 spends most of its time repeatedly serializing and re-spilling
fixed-width, high-NDV DISTINCT keys. This change:

  • batches the private fixed-width selected-row spill codec;
  • coalesces sparse fixed-width spill writes into bounded buffers;
  • adds an allocation-free fast path for flat nullable fixed keys;
  • widens spill fanout from 32 to 64 only for aggregation-free DISTINCT and
    keeps the selected fanout stable across spill waves.

The optimization is independent of planner cardinality estimates. Aggregate
group spill remains at 32 partitions, limiting the change to the workload shape
that benefits and avoiding extra fanout for aggregate-heavy queries.

On TPC-DS 1T Q75, wall time fell from 1127.935 s to 546.935 s (51.5%). Against
the comparable optimized 32-partition run, it fell from 768.150 s to 546.935 s
(28.8%); Group spill serialization fell from 27.756 GB to 13.853 GB and re-spill
events from 64 to 0.

Controlled current-main A/B runs on the same data and 128 MiB spill limit also
showed Q97 improving from 228.200 s to 160.351 s (29.7%) and Q87 from 323.889 s
to 241.683 s (25.4%). Q38 was neutral within run-to-run variance (271.555 s to
277.852 s), and Q54 did not enter Group spill. Compared query outputs were
byte-for-byte identical, and scan rows/bytes were unchanged.

Validation:

  • package tests for vector codec, hash map, aggregate spill, and Group;
  • codec/key-path equivalence and malformed-input coverage;
  • stable fanout and cleanup/error-path tests;
  • TPC-DS 1T Q75, Q97, Q87, and Q38 result/plan comparisons, plus Q54 and Q64
    no-spill controls;
  • focused spill-writer and flat-key microbenchmarks.

@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 of exact head 56f61f1a822e9bf67791f211a2078fa70646c2c8 with counterexample-oriented checks across fixed-width hash-key sizing/encoding, DISTINCT versus aggregate spill fanout, recursive repartition/reload, selection codec wire symmetry, null/grouping/string-source/prepare-kind metadata, empty/all-null/乱序 selections, short writes/truncated input, cancellation, allocation bounds, and cleanup.

The 64-way DISTINCT fanout is consistent from initial bucket creation through partitioning and recursive reload; aggregate paths retain 32-way fanout. Fixed-width selection metadata is written and read symmetrically, while row metadata correctly falls back to the general path. I found no reachable correctness, data-loss, bounds, leak, hang, or compatibility blocker.

The exact-head repository CI run 33834102710 passed its substantive checks, including UT, SCA, coverage, and BVT. Local focused execution was not available in the isolated macOS worktree because thirdparties/install/lib/libmo.dylib is absent.

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

mergify Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-04 08:55 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-09-04 08:55 UTC · at 56f61f1a822e9bf67791f211a2078fa70646c2c8

This pull request spent 12 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/sca-go-module-cache.yaml without workflows permission

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

@mergify mergify Bot added dequeued and removed queued labels Sep 4, 2026
@mergify

mergify Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-04 11:01 UTC · Rule: main · triggered by @aptend with the merge queue checkbox
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-04 11:34 UTC · at 85e48c3542094c4ec25d13a441d4a6337c6106a5

This pull request spent 32 minutes 45 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]

Reason

Pull request #28108 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

@mergify mergify Bot added queued and removed dequeued labels Sep 4, 2026
@XuPeng-SH
XuPeng-SH merged commit 0fdc39e into matrixorigin:main Sep 4, 2026
25 of 26 checks passed
@mergify mergify Bot added dequeued and removed queued labels Sep 4, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#28108)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#26768

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

TPC-DS 1T Q75 spends most of its time repeatedly serializing and
re-spilling
fixed-width, high-NDV DISTINCT keys.  This change:

- batches the private fixed-width selected-row spill codec;
- coalesces sparse fixed-width spill writes into bounded buffers;
- adds an allocation-free fast path for flat nullable fixed keys;
- widens spill fanout from 32 to 64 only for aggregation-free DISTINCT
and
  keeps the selected fanout stable across spill waves.

The optimization is independent of planner cardinality estimates.
Aggregate
group spill remains at 32 partitions, limiting the change to the
workload shape
that benefits and avoiding extra fanout for aggregate-heavy queries.

On TPC-DS 1T Q75, wall time fell from 1127.935 s to 546.935 s (51.5%).
Against
the comparable optimized 32-partition run, it fell from 768.150 s to
546.935 s
(28.8%); Group spill serialization fell from 27.756 GB to 13.853 GB and
re-spill
events from 64 to 0.

Controlled current-main A/B runs on the same data and 128 MiB spill
limit also
showed Q97 improving from 228.200 s to 160.351 s (29.7%) and Q87 from
323.889 s
to 241.683 s (25.4%). Q38 was neutral within run-to-run variance
(271.555 s to
277.852 s), and Q54 did not enter Group spill. Compared query outputs
were
byte-for-byte identical, and scan rows/bytes were unchanged.

Validation:

- package tests for vector codec, hash map, aggregate spill, and Group;
- codec/key-path equivalence and malformed-input coverage;
- stable fanout and cleanup/error-path tests;
- TPC-DS 1T Q75, Q97, Q87, and Q38 result/plan comparisons, plus Q54 and
Q64
  no-spill controls;
- focused spill-writer and flat-key microbenchmarks.

---------

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
…#28108)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#26768

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

TPC-DS 1T Q75 spends most of its time repeatedly serializing and
re-spilling
fixed-width, high-NDV DISTINCT keys.  This change:

- batches the private fixed-width selected-row spill codec;
- coalesces sparse fixed-width spill writes into bounded buffers;
- adds an allocation-free fast path for flat nullable fixed keys;
- widens spill fanout from 32 to 64 only for aggregation-free DISTINCT
and
  keeps the selected fanout stable across spill waves.

The optimization is independent of planner cardinality estimates.
Aggregate
group spill remains at 32 partitions, limiting the change to the
workload shape
that benefits and avoiding extra fanout for aggregate-heavy queries.

On TPC-DS 1T Q75, wall time fell from 1127.935 s to 546.935 s (51.5%).
Against
the comparable optimized 32-partition run, it fell from 768.150 s to
546.935 s
(28.8%); Group spill serialization fell from 27.756 GB to 13.853 GB and
re-spill
events from 64 to 0.

Controlled current-main A/B runs on the same data and 128 MiB spill
limit also
showed Q97 improving from 228.200 s to 160.351 s (29.7%) and Q87 from
323.889 s
to 241.683 s (25.4%). Q38 was neutral within run-to-run variance
(271.555 s to
277.852 s), and Q54 did not enter Group spill. Compared query outputs
were
byte-for-byte identical, and scan rows/bytes were unchanged.

Validation:

- package tests for vector codec, hash map, aggregate spill, and Group;
- codec/key-path equivalence and malformed-input coverage;
- stable fanout and cleanup/error-path tests;
- TPC-DS 1T Q75, Q97, Q87, and Q38 result/plan comparisons, plus Q54 and
Q64
  no-spill controls;
- focused spill-writer and flat-key microbenchmarks.

---------

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
…#28108)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#26768

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

TPC-DS 1T Q75 spends most of its time repeatedly serializing and
re-spilling
fixed-width, high-NDV DISTINCT keys.  This change:

- batches the private fixed-width selected-row spill codec;
- coalesces sparse fixed-width spill writes into bounded buffers;
- adds an allocation-free fast path for flat nullable fixed keys;
- widens spill fanout from 32 to 64 only for aggregation-free DISTINCT
and
  keeps the selected fanout stable across spill waves.

The optimization is independent of planner cardinality estimates.
Aggregate
group spill remains at 32 partitions, limiting the change to the
workload shape
that benefits and avoiding extra fanout for aggregate-heavy queries.

On TPC-DS 1T Q75, wall time fell from 1127.935 s to 546.935 s (51.5%).
Against
the comparable optimized 32-partition run, it fell from 768.150 s to
546.935 s
(28.8%); Group spill serialization fell from 27.756 GB to 13.853 GB and
re-spill
events from 64 to 0.

Controlled current-main A/B runs on the same data and 128 MiB spill
limit also
showed Q97 improving from 228.200 s to 160.351 s (29.7%) and Q87 from
323.889 s
to 241.683 s (25.4%). Q38 was neutral within run-to-run variance
(271.555 s to
277.852 s), and Q54 did not enter Group spill. Compared query outputs
were
byte-for-byte identical, and scan rows/bytes were unchanged.

Validation:

- package tests for vector codec, hash map, aggregate spill, and Group;
- codec/key-path equivalence and malformed-input coverage;
- stable fanout and cleanup/error-path tests;
- TPC-DS 1T Q75, Q97, Q87, and Q38 result/plan comparisons, plus Q54 and
Q64
  no-spill controls;
- focused spill-writer and flat-key microbenchmarks.

---------

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/enhancement size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants