Skip to content

perf: bound set and cumulative min-max execution state - #27913

Merged
XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
aptend:perf/tpcds-executor-state-bounds
Aug 31, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
aptend:perf/tpcds-executor-state-bounds

Conversation

@aptend

@aptend aptend commented Aug 31, 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:

Related to #26768

What this PR does / why we need it:

Bound two executor hot paths that become pathological on large analytic inputs:

  • store one compact seen-state per INTERSECT key instead of allocating an
    unused selection buffer for every key;
  • let cumulative MIN/MAX use the source-preserving running aggregate path,
    avoiding a partition-prefix rescan for every output row.

Both changes preserve the existing operator and aggregate semantics and contain
no benchmark- or query-specific conditions.

@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 completed on exact head 27d454c.

Checked both independent changes from correctness, performance, and unhappy-path angles:

  • INTERSECT keeps the existing set semantics: one output per build-side key, duplicate probe rows are suppressed across batches, and NULL/non-match behavior is unchanged. Replacing one pooled selection slice per key with one bool makes retained state O(unique keys) bytes with a much smaller constant; Reset/Free drop the state and hash-map cleanup remains intact.
  • cumulative MIN/MAX opts into the existing running-window path only through the explicit source-preserving Merge contract. Fixed and varlen Merge copy/compare source state without consuming or aliasing it; NULLs, partition resets, chunk boundaries, cancellation/error cleanup, and final state release remain covered.
  • no query- or benchmark-specific branch was introduced.

Validation: git diff --check; exact-head go test for ./pkg/sql/colexec/intersect, ./pkg/sql/colexec/aggexec, and ./pkg/sql/colexec/window passed. CI is green.

@mergify mergify Bot added the queued label Aug 31, 2026
@mergify

mergify Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-31 11:43 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-08-31 11:43 UTC · at 27d454c6caafcd96bbaf86967183c84e182c8149

This pull request spent 9 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/connectorj-pool-reset.yml 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 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-31 12:04 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-08-31 12:05 UTC · at 27d454c6caafcd96bbaf86967183c84e182c8149

This pull request spent 18 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/connectorj-pool-reset.yml 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 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-31 12:05 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-08-31 12:05 UTC · at 27d454c6caafcd96bbaf86967183c84e182c8149

This pull request spent 29 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/connectorj-pool-reset.yml 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 queued and removed queued labels Aug 31, 2026
@aptend

aptend commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the cumulative MIN/MAX allocation review in fb38c39 with a per-partition cost gate: small partitions use direct prefix evaluation, while partitions whose saved Fill work exceeds one AggBatchSize state chunk retain the running aggregate. This keeps the O(N) path for large partitions without allocating one 8192-slot state chunk per singleton partition.

BenchmarkCumulativeMaxPartitionShapes (2048 rows, 5 iterations):

  • singleton: 3.61ms / 2049 mpool allocs / 67.1MB before -> 0.36ms / 1 alloc / 32KB after
  • mixed singleton+255-row partitions: 0.42ms / 9 allocs / 288KB after
  • large 256-row partitions: 0.46ms / 9 allocs / 288KB before -> 0.42ms / 9 allocs / 288KB after

Also extended the regression test across output chunks and a partition boundary, and verified cleanup/mpool reaches zero. Full window and aggexec package tests pass.

@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 fb38c39 against base 34fb540.\n\nThe blocker from my previous review is closed. The cumulative-window path now selects the retained one-group aggregate per partition: partitions up to the cost crossover use direct prefix evaluation, while larger partitions keep the O(N) running path. This removes the 8192-state allocation churn for singleton/high-cardinality partitions without regressing large or mixed partitions.\n\nI also rechecked the change from the other relevant angles:\n\n- Correctness: cumulative state remains sequential across output chunks and resets exactly at partition boundaries; direct/running transitions preserve frame semantics. Fixed-width and varlen MIN/MAX merges copy values/null state into the destination and do not mutate or alias the retained source.\n- Lifecycle/unhappy paths: errors and cancellation release the running state; normal completion, Reset, and Free also close ownership. There are no new goroutines, waits, or lock/channel edges.\n- INTERSECT: replacing per-key pooled count slices with one boolean preserves set semantics (at most one output row per key), while bounding state by distinct build keys and retaining existing batch/hash ownership.\n- Performance: the threshold bounds direct work for small partitions and avoids the former approximately 64 KiB state chunk per singleton partition; the added singleton/mixed/large benchmarks and boundary/cross-chunk tests cover the intended crossover.\n- Validation: exact-head Ubuntu UT, SCA, coverage, shared build, proxy BVT, and pessimistic BVT are green. The local macOS focused wrapper could not start because the isolated worktree has no matching cgo/libmo.dylib; that is native-artifact provenance, not a code/test failure.\n\nNo remaining blocking issue found.

@mergify mergify Bot added the queued label Aug 31, 2026
@mergify

mergify Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-31 16:26 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-08-31 16:27 UTC · at 30b3d51d03bc7010d60ddbbbd3901aa411f97a35

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

Reason

The pull request can't be updated

This pull request seems to come 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, or update the branch manually.

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.

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

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit b23beee into matrixorigin:main Aug 31, 2026
19 of 20 checks passed
@mergify mergify Bot added dequeued and removed queued labels Aug 31, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…27913)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#26768

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

Bound two executor hot paths that become pathological on large analytic
inputs:

- store one compact seen-state per `INTERSECT` key instead of allocating
an
  unused selection buffer for every key;
- let cumulative MIN/MAX use the source-preserving running aggregate
path,
  avoiding a partition-prefix rescan for every output row.

Both changes preserve the existing operator and aggregate semantics and
contain
no benchmark- or query-specific conditions.

---------

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

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#26768

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

Bound two executor hot paths that become pathological on large analytic
inputs:

- store one compact seen-state per `INTERSECT` key instead of allocating
an
  unused selection buffer for every key;
- let cumulative MIN/MAX use the source-preserving running aggregate
path,
  avoiding a partition-prefix rescan for every output row.

Both changes preserve the existing operator and aggregate semantics and
contain
no benchmark- or query-specific conditions.

---------

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

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to matrixorigin#26768

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

Bound two executor hot paths that become pathological on large analytic
inputs:

- store one compact seen-state per `INTERSECT` key instead of allocating
an
  unused selection buffer for every key;
- let cumulative MIN/MAX use the source-preserving running aggregate
path,
  avoiding a partition-prefix rescan for every output row.

Both changes preserve the existing operator and aggregate semantics and
contain
no benchmark- or query-specific conditions.

---------

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants