Skip to content

fix: avoid mutating shared batches in limit - #26498

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
ck89119:issue-23080-main
Jul 31, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
ck89119:issue-23080-main

Conversation

@ck89119

@ck89119 ck89119 commented Jul 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:

Fixes #23080

What this PR does / why we need it:

LIMIT truncated its input batch in place. Recursive CTE pipelines can fan out the same batch to multiple consumers, so one consumer could shorten the vectors while another consumer still observed the original row count. This caused downstream expression evaluation to access rows beyond the shortened vector and panic.

This change:

  • copies the final truncated batch into a buffer owned by the Limit operator;
  • keeps the shared upstream batch immutable;
  • releases the owned buffer in Free;
  • adds a regression test that verifies limiting the output does not change the input batch row count or vector lengths.

Local validation:

  • gofmt
  • git diff --check
  • focused TestLimitDoesNotMutateInputBatch
  • focused race test with -count=100
  • full pkg/sql/colexec/limit race suite
  • go vet ./pkg/sql/colexec/limit
  • BVT was not run locally.

@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 at b4e7179. No blocking findings.

Verified the LIMIT ownership fix preserves the shared input batch, keeps the copied terminal batch operator-owned across Reset, and releases it exactly once in Free. The added regression test covers input immutability and metadata preservation; the ISCP test cleanup is idempotent.

Local validation passed: focused tests with race repetitions (100x/100x/25x), full owning-package race tests, build, vet, and non-race tests for limit, engine/test, compile, and pipeline.

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

mergify Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-31 13:17 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-07-31 13:54 UTC · at ca13ba100ca8fa733c25a04707a687e7ee41e3fb · squash

This pull request spent 36 minutes 57 seconds in the queue, including 36 minutes 13 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • 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)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86

@mergify
mergify Bot merged commit 244e6e2 into matrixorigin:main Jul 31, 2026
25 of 26 checks passed
@mergify mergify Bot removed the queued label Jul 31, 2026
@ck89119
ck89119 deleted the issue-23080-main branch July 31, 2026 14:01
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
`LIMIT` truncated its input batch in place. Recursive CTE pipelines can fan out the same batch to multiple consumers, so one consumer could shorten the vectors while another consumer still observed the original row count. This caused downstream expression evaluation to access rows beyond the shortened vector and panic.

This change:

- copies the final truncated batch into a buffer owned by the `Limit` operator;
- keeps the shared upstream batch immutable;
- releases the owned buffer in `Free`;
- adds a regression test that verifies limiting the output does not change the input batch row count or vector lengths.

Local validation:

- `gofmt`
- `git diff --check`
- focused `TestLimitDoesNotMutateInputBatch`
- focused race test with `-count=100`
- full `pkg/sql/colexec/limit` race suite
- `go vet ./pkg/sql/colexec/limit`
- BVT was not run locally.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
`LIMIT` truncated its input batch in place. Recursive CTE pipelines can fan out the same batch to multiple consumers, so one consumer could shorten the vectors while another consumer still observed the original row count. This caused downstream expression evaluation to access rows beyond the shortened vector and panic.

This change:

- copies the final truncated batch into a buffer owned by the `Limit` operator;
- keeps the shared upstream batch immutable;
- releases the owned buffer in `Free`;
- adds a regression test that verifies limiting the output does not change the input batch row count or vector lengths.

Local validation:

- `gofmt`
- `git diff --check`
- focused `TestLimitDoesNotMutateInputBatch`
- focused race test with `-count=100`
- full `pkg/sql/colexec/limit` race suite
- `go vet ./pkg/sql/colexec/limit`
- BVT was not run locally.

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
`LIMIT` truncated its input batch in place. Recursive CTE pipelines can fan out the same batch to multiple consumers, so one consumer could shorten the vectors while another consumer still observed the original row count. This caused downstream expression evaluation to access rows beyond the shortened vector and panic.

This change:

- copies the final truncated batch into a buffer owned by the `Limit` operator;
- keeps the shared upstream batch immutable;
- releases the owned buffer in `Free`;
- adds a regression test that verifies limiting the output does not change the input batch row count or vector lengths.

Local validation:

- `gofmt`
- `git diff --check`
- focused `TestLimitDoesNotMutateInputBatch`
- focused race test with `-count=100`
- full `pkg/sql/colexec/limit` race suite
- `go vet ./pkg/sql/colexec/limit`
- BVT was not run locally.

Approved by: @XuPeng-SH

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/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Critical Bug: Panic error in recursive CTE with WHERE conditions

3 participants