Skip to content

fix data branch worker pool leak - #26369

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-26060
Jul 30, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-26060

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Jul 29, 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 #26060

What this PR does / why we need it:

getTableStuff created a per-statement ants worker pool, but the production Data Branch DIFF, MERGE, and PICK path did not originally release it. Each statement therefore retained the pool's purge and ticktock maintenance goroutines.

The first fix registered pool release after the normal producer/consumer shutdown path. Review then identified two earlier exits: invalid DIFF projections and PICK statements on tables without a primary key returned before release was registered.

This PR now:

  • validates DIFF projections and PICK primary-key requirements before allocating the pool;
  • creates the pool in a single preparation function;
  • registers Release immediately after successful preparation;
  • preserves the existing shutdown order so producers and consumers finish before release;
  • covers both rejected-statement paths and the valid allocation/release path.

Validation:

  • go test ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)' -count=1
  • go test -race ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)' -count=1
  • go test ./pkg/frontend -count=1
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s -run 'TestDataBranch|TestHashDiff|TestPrepareDataBranchWorker' ./pkg/frontend
  • .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=300s -run 'TestPrepareDataBranchWorkerValidatesBeforeAllocation|TestDataBranchOutputValidateProjectedColumns' ./pkg/frontend

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

Re-reviewed exact head 22c687e4ac456a444658b637b670a4306151a740 after reading the author's response. The response matches the implementation: prepareDataBranchWorker now performs invalid DIFF projection and no-primary-key PICK validation before allocating the ants pool, and diffMergeAgency registers Release immediately after successful preparation. getTableStuff no longer owns allocation, and it has no other production call sites that expect a worker. This closes both early-return leaks from the previous review while preserving the producer/consumer shutdown order.

The added regressions verify no allocation on both rejected statements and a releasable worker on the valid path. Complete frontend tests pass locally, as do the DataBranch/HashDiff focused suite and the ownership/projection tests under -race -count=100; exact-head CI is green and the PR is mergeable.

@mergify

mergify Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

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

@gouhongshen

Copy link
Copy Markdown
Contributor Author

@Mergifyio refresh

@mergify

mergify Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

refresh

✅ Pull request refreshed

@mergify mergify Bot added kind/bug Something isn't working queued labels Jul 30, 2026
@mergify

mergify Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-30 06:22 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-07-30 07:19 UTC · at 5b5ba90b783ed8b4e287c084b4fcbd217ff4885d

This pull request spent 56 minutes 14 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 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
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 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
  • #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 / 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)

Reason

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

Failing checks:

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

@XuPeng-SH
XuPeng-SH merged commit 09855ae into matrixorigin:main Jul 30, 2026
22 of 25 checks passed
@mergify mergify Bot added dequeued and removed queued labels Jul 30, 2026
XuPeng-SH pushed a commit that referenced this pull request Sep 4, 2026
# What type of PR is this?

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

# Which issue(s) this PR fixes:

Related to #25244

# What this PR does / why we need it:

## Root cause

When `DATA BRANCH DIFF` used `COLUMNS`, `resolveProjectedIdxes` returned
only the requested visible columns. The row path temporarily extracted
primary-key values for `OUTPUT LIMIT` sorting, but final row compaction
and result-schema construction still used the requested-only list.
Composite primary-key values were therefore absent from both the result
rows and their metadata. `OUTPUT AS` reused the same incomplete list.

The older worker-pool leak finding recorded in #25244 is already
addressed on current `main` by #26369 (`09855ae9b1`) and is not changed
here.

## Changes

- Make the shared projection resolver emit explicit primary-key columns
first in primary-key definition order, then requested non-PK visible
columns in request order, with deduplication.
- Reuse that effective projection for ordinary diff result rows, result
metadata, and `OUTPUT AS` table schemas.
- Preserve existing fake-PK/no-PK behavior and leave `COUNT`, `SUMMARY`,
and `OUTPUT FILE` behavior unchanged.
- Add focused unit coverage, an exact composite-PK regression BVT,
related boundary assertions, and update the documented `OUTPUT AS`
contract.

## Issue-to-test proof

- `TestDataBranchOutputColumnsIncludeCompositePrimaryKey` asserts the
exact five-column metadata (`diff`, `flag`, both PK columns, and `val`)
and the exact update row values.
- `TestDataBranchOutputResolveProjectedIdxes` covers normal and
composite PKs, definition order different from physical order,
duplicate/case-insensitive requests, unknown columns, and the fake-PK
control case. Table-schema tests cover ordinary output and `OUTPUT AS`
ordering.
- `diff_composite_pk_columns.sql` covers the issue reproduction,
partial/duplicate PK requests, UPDATE/DELETE/INSERT rows, projected
`OUTPUT LIMIT`, unrelated tables, and `OUTPUT AS` metadata plus rows.
- Existing `diff_11`, `diff_13`, `diff_17`, `branch_output_limit_order`,
and `merge_generated_column` cases cover the broader data types, lineage
depth, materialized schema, limit ordering, and generated-column
interactions affected by the shared resolver.

## Tests run

- `make build`
- Full `pkg/frontend` CGo test package: passed.
- Focused frontend regression tests: passed.
- New composite-PK BVT twice with metadata comparison enabled: `28/28`
each run.
- Existing related BVTs: `diff_11` `158/158`; `diff_13` `137/137`;
`diff_17` `154/154`; `branch_output_limit_order` `21/21`;
`merge_generated_column` `80/80`; remaining branch edge cases `314/314`.

The existing `diff_13`, `diff_17`, and edge/merge result files use
historical metadata-width encodings that do not compare cleanly with the
current tester. Those runs used `-n`, which still compared all SQL
output, column names/order, and row values. The new regression result
was checked twice with metadata comparison enabled.

## Residual risks

For explicit-PK tables, callers using `COLUMNS` will now receive
additional PK columns, in PK definition order, as required for row
identity. Fake-PK/no-PK tables and non-row output modes retain their
prior behavior. This change does not alter concurrency, storage, or
resource-lifecycle code; #25244 remains open for manual validation.

## CI follow-up

- Updated the existing `pkg/tests/dml` output-limit regression assertion
to expect the retained primary-key column introduced by this fix;
focused `TestDataBranchDiffAsFile` passes locally.

## Rebase follow-up

- Rebased the issue branch onto origin/main at fa829e5 without
conflicts or scope changes.
- Re-ran the focused frontend regression tests and
TestDataBranchDiffAsFile after the rebase; both passed locally.
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
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26060

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

`getTableStuff` created a per-statement ants worker pool, but the
production Data Branch DIFF, MERGE, and PICK path did not originally
release it. Each statement therefore retained the pool's purge and
ticktock maintenance goroutines.

The first fix registered pool release after the normal producer/consumer
shutdown path. Review then identified two earlier exits: invalid DIFF
projections and PICK statements on tables without a primary key returned
before release was registered.

This PR now:

- validates DIFF projections and PICK primary-key requirements before
allocating the pool;
- creates the pool in a single preparation function;
- registers `Release` immediately after successful preparation;
- preserves the existing shutdown order so producers and consumers
finish before release;
- covers both rejected-statement paths and the valid allocation/release
path.

Validation:

- `go test ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)'
-count=1`
- `go test -race ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)'
-count=1`
- `go test ./pkg/frontend -count=1`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s -run
'TestDataBranch|TestHashDiff|TestPrepareDataBranchWorker'
./pkg/frontend`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1
-timeout=300s -run
'TestPrepareDataBranchWorkerValidatesBeforeAllocation|TestDataBranchOutputValidateProjectedColumns'
./pkg/frontend`

---------

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
…origin#28133)

# What type of PR is this?

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

# Which issue(s) this PR fixes:

Related to matrixorigin#25244

# What this PR does / why we need it:

## Root cause

When `DATA BRANCH DIFF` used `COLUMNS`, `resolveProjectedIdxes` returned
only the requested visible columns. The row path temporarily extracted
primary-key values for `OUTPUT LIMIT` sorting, but final row compaction
and result-schema construction still used the requested-only list.
Composite primary-key values were therefore absent from both the result
rows and their metadata. `OUTPUT AS` reused the same incomplete list.

The older worker-pool leak finding recorded in matrixorigin#25244 is already
addressed on current `main` by matrixorigin#26369 (`09855ae9b1`) and is not changed
here.

## Changes

- Make the shared projection resolver emit explicit primary-key columns
first in primary-key definition order, then requested non-PK visible
columns in request order, with deduplication.
- Reuse that effective projection for ordinary diff result rows, result
metadata, and `OUTPUT AS` table schemas.
- Preserve existing fake-PK/no-PK behavior and leave `COUNT`, `SUMMARY`,
and `OUTPUT FILE` behavior unchanged.
- Add focused unit coverage, an exact composite-PK regression BVT,
related boundary assertions, and update the documented `OUTPUT AS`
contract.

## Issue-to-test proof

- `TestDataBranchOutputColumnsIncludeCompositePrimaryKey` asserts the
exact five-column metadata (`diff`, `flag`, both PK columns, and `val`)
and the exact update row values.
- `TestDataBranchOutputResolveProjectedIdxes` covers normal and
composite PKs, definition order different from physical order,
duplicate/case-insensitive requests, unknown columns, and the fake-PK
control case. Table-schema tests cover ordinary output and `OUTPUT AS`
ordering.
- `diff_composite_pk_columns.sql` covers the issue reproduction,
partial/duplicate PK requests, UPDATE/DELETE/INSERT rows, projected
`OUTPUT LIMIT`, unrelated tables, and `OUTPUT AS` metadata plus rows.
- Existing `diff_11`, `diff_13`, `diff_17`, `branch_output_limit_order`,
and `merge_generated_column` cases cover the broader data types, lineage
depth, materialized schema, limit ordering, and generated-column
interactions affected by the shared resolver.

## Tests run

- `make build`
- Full `pkg/frontend` CGo test package: passed.
- Focused frontend regression tests: passed.
- New composite-PK BVT twice with metadata comparison enabled: `28/28`
each run.
- Existing related BVTs: `diff_11` `158/158`; `diff_13` `137/137`;
`diff_17` `154/154`; `branch_output_limit_order` `21/21`;
`merge_generated_column` `80/80`; remaining branch edge cases `314/314`.

The existing `diff_13`, `diff_17`, and edge/merge result files use
historical metadata-width encodings that do not compare cleanly with the
current tester. Those runs used `-n`, which still compared all SQL
output, column names/order, and row values. The new regression result
was checked twice with metadata comparison enabled.

## Residual risks

For explicit-PK tables, callers using `COLUMNS` will now receive
additional PK columns, in PK definition order, as required for row
identity. Fake-PK/no-PK tables and non-row output modes retain their
prior behavior. This change does not alter concurrency, storage, or
resource-lifecycle code; matrixorigin#25244 remains open for manual validation.

## CI follow-up

- Updated the existing `pkg/tests/dml` output-limit regression assertion
to expect the retained primary-key column introduced by this fix;
focused `TestDataBranchDiffAsFile` passes locally.

## Rebase follow-up

- Rebased the issue branch onto origin/main at fa829e5 without
conflicts or scope changes.
- Re-ran the focused frontend regression tests and
TestDataBranchDiffAsFile after the rebase; both passed locally.
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
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26060

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

`getTableStuff` created a per-statement ants worker pool, but the
production Data Branch DIFF, MERGE, and PICK path did not originally
release it. Each statement therefore retained the pool's purge and
ticktock maintenance goroutines.

The first fix registered pool release after the normal producer/consumer
shutdown path. Review then identified two earlier exits: invalid DIFF
projections and PICK statements on tables without a primary key returned
before release was registered.

This PR now:

- validates DIFF projections and PICK primary-key requirements before
allocating the pool;
- creates the pool in a single preparation function;
- registers `Release` immediately after successful preparation;
- preserves the existing shutdown order so producers and consumers
finish before release;
- covers both rejected-statement paths and the valid allocation/release
path.

Validation:

- `go test ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)'
-count=1`
- `go test -race ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)'
-count=1`
- `go test ./pkg/frontend -count=1`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s -run
'TestDataBranch|TestHashDiff|TestPrepareDataBranchWorker'
./pkg/frontend`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1
-timeout=300s -run
'TestPrepareDataBranchWorkerValidatesBeforeAllocation|TestDataBranchOutputValidateProjectedColumns'
./pkg/frontend`

---------

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
…origin#28133)

# What type of PR is this?

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

# Which issue(s) this PR fixes:

Related to matrixorigin#25244

# What this PR does / why we need it:

## Root cause

When `DATA BRANCH DIFF` used `COLUMNS`, `resolveProjectedIdxes` returned
only the requested visible columns. The row path temporarily extracted
primary-key values for `OUTPUT LIMIT` sorting, but final row compaction
and result-schema construction still used the requested-only list.
Composite primary-key values were therefore absent from both the result
rows and their metadata. `OUTPUT AS` reused the same incomplete list.

The older worker-pool leak finding recorded in matrixorigin#25244 is already
addressed on current `main` by matrixorigin#26369 (`09855ae9b1`) and is not changed
here.

## Changes

- Make the shared projection resolver emit explicit primary-key columns
first in primary-key definition order, then requested non-PK visible
columns in request order, with deduplication.
- Reuse that effective projection for ordinary diff result rows, result
metadata, and `OUTPUT AS` table schemas.
- Preserve existing fake-PK/no-PK behavior and leave `COUNT`, `SUMMARY`,
and `OUTPUT FILE` behavior unchanged.
- Add focused unit coverage, an exact composite-PK regression BVT,
related boundary assertions, and update the documented `OUTPUT AS`
contract.

## Issue-to-test proof

- `TestDataBranchOutputColumnsIncludeCompositePrimaryKey` asserts the
exact five-column metadata (`diff`, `flag`, both PK columns, and `val`)
and the exact update row values.
- `TestDataBranchOutputResolveProjectedIdxes` covers normal and
composite PKs, definition order different from physical order,
duplicate/case-insensitive requests, unknown columns, and the fake-PK
control case. Table-schema tests cover ordinary output and `OUTPUT AS`
ordering.
- `diff_composite_pk_columns.sql` covers the issue reproduction,
partial/duplicate PK requests, UPDATE/DELETE/INSERT rows, projected
`OUTPUT LIMIT`, unrelated tables, and `OUTPUT AS` metadata plus rows.
- Existing `diff_11`, `diff_13`, `diff_17`, `branch_output_limit_order`,
and `merge_generated_column` cases cover the broader data types, lineage
depth, materialized schema, limit ordering, and generated-column
interactions affected by the shared resolver.

## Tests run

- `make build`
- Full `pkg/frontend` CGo test package: passed.
- Focused frontend regression tests: passed.
- New composite-PK BVT twice with metadata comparison enabled: `28/28`
each run.
- Existing related BVTs: `diff_11` `158/158`; `diff_13` `137/137`;
`diff_17` `154/154`; `branch_output_limit_order` `21/21`;
`merge_generated_column` `80/80`; remaining branch edge cases `314/314`.

The existing `diff_13`, `diff_17`, and edge/merge result files use
historical metadata-width encodings that do not compare cleanly with the
current tester. Those runs used `-n`, which still compared all SQL
output, column names/order, and row values. The new regression result
was checked twice with metadata comparison enabled.

## Residual risks

For explicit-PK tables, callers using `COLUMNS` will now receive
additional PK columns, in PK definition order, as required for row
identity. Fake-PK/no-PK tables and non-row output modes retain their
prior behavior. This change does not alter concurrency, storage, or
resource-lifecycle code; matrixorigin#25244 remains open for manual validation.

## CI follow-up

- Updated the existing `pkg/tests/dml` output-limit regression assertion
to expect the retained primary-key column introduced by this fix;
focused `TestDataBranchDiffAsFile` passes locally.

## Rebase follow-up

- Rebased the issue branch onto origin/main at fa829e5 without
conflicts or scope changes.
- Re-ran the focused frontend regression tests and
TestDataBranchDiffAsFile after the rebase; both passed locally.
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
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26060

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

`getTableStuff` created a per-statement ants worker pool, but the
production Data Branch DIFF, MERGE, and PICK path did not originally
release it. Each statement therefore retained the pool's purge and
ticktock maintenance goroutines.

The first fix registered pool release after the normal producer/consumer
shutdown path. Review then identified two earlier exits: invalid DIFF
projections and PICK statements on tables without a primary key returned
before release was registered.

This PR now:

- validates DIFF projections and PICK primary-key requirements before
allocating the pool;
- creates the pool in a single preparation function;
- registers `Release` immediately after successful preparation;
- preserves the existing shutdown order so producers and consumers
finish before release;
- covers both rejected-statement paths and the valid allocation/release
path.

Validation:

- `go test ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)'
-count=1`
- `go test -race ./pkg/frontend -run '^(TestDataBranch|TestHashDiff)'
-count=1`
- `go test ./pkg/frontend -count=1`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s -run
'TestDataBranch|TestHashDiff|TestPrepareDataBranchWorker'
./pkg/frontend`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1
-timeout=300s -run
'TestPrepareDataBranchWorkerValidatesBeforeAllocation|TestDataBranchOutputValidateProjectedColumns'
./pkg/frontend`

---------

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
…origin#28133)

# What type of PR is this?

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

# Which issue(s) this PR fixes:

Related to matrixorigin#25244

# What this PR does / why we need it:

## Root cause

When `DATA BRANCH DIFF` used `COLUMNS`, `resolveProjectedIdxes` returned
only the requested visible columns. The row path temporarily extracted
primary-key values for `OUTPUT LIMIT` sorting, but final row compaction
and result-schema construction still used the requested-only list.
Composite primary-key values were therefore absent from both the result
rows and their metadata. `OUTPUT AS` reused the same incomplete list.

The older worker-pool leak finding recorded in matrixorigin#25244 is already
addressed on current `main` by matrixorigin#26369 (`09855ae9b1`) and is not changed
here.

## Changes

- Make the shared projection resolver emit explicit primary-key columns
first in primary-key definition order, then requested non-PK visible
columns in request order, with deduplication.
- Reuse that effective projection for ordinary diff result rows, result
metadata, and `OUTPUT AS` table schemas.
- Preserve existing fake-PK/no-PK behavior and leave `COUNT`, `SUMMARY`,
and `OUTPUT FILE` behavior unchanged.
- Add focused unit coverage, an exact composite-PK regression BVT,
related boundary assertions, and update the documented `OUTPUT AS`
contract.

## Issue-to-test proof

- `TestDataBranchOutputColumnsIncludeCompositePrimaryKey` asserts the
exact five-column metadata (`diff`, `flag`, both PK columns, and `val`)
and the exact update row values.
- `TestDataBranchOutputResolveProjectedIdxes` covers normal and
composite PKs, definition order different from physical order,
duplicate/case-insensitive requests, unknown columns, and the fake-PK
control case. Table-schema tests cover ordinary output and `OUTPUT AS`
ordering.
- `diff_composite_pk_columns.sql` covers the issue reproduction,
partial/duplicate PK requests, UPDATE/DELETE/INSERT rows, projected
`OUTPUT LIMIT`, unrelated tables, and `OUTPUT AS` metadata plus rows.
- Existing `diff_11`, `diff_13`, `diff_17`, `branch_output_limit_order`,
and `merge_generated_column` cases cover the broader data types, lineage
depth, materialized schema, limit ordering, and generated-column
interactions affected by the shared resolver.

## Tests run

- `make build`
- Full `pkg/frontend` CGo test package: passed.
- Focused frontend regression tests: passed.
- New composite-PK BVT twice with metadata comparison enabled: `28/28`
each run.
- Existing related BVTs: `diff_11` `158/158`; `diff_13` `137/137`;
`diff_17` `154/154`; `branch_output_limit_order` `21/21`;
`merge_generated_column` `80/80`; remaining branch edge cases `314/314`.

The existing `diff_13`, `diff_17`, and edge/merge result files use
historical metadata-width encodings that do not compare cleanly with the
current tester. Those runs used `-n`, which still compared all SQL
output, column names/order, and row values. The new regression result
was checked twice with metadata comparison enabled.

## Residual risks

For explicit-PK tables, callers using `COLUMNS` will now receive
additional PK columns, in PK definition order, as required for row
identity. Fake-PK/no-PK tables and non-row output modes retain their
prior behavior. This change does not alter concurrency, storage, or
resource-lifecycle code; matrixorigin#25244 remains open for manual validation.

## CI follow-up

- Updated the existing `pkg/tests/dml` output-limit regression assertion
to expect the retained primary-key column introduced by this fix;
focused `TestDataBranchDiffAsFile` passes locally.

## Rebase follow-up

- Rebased the issue branch onto origin/main at fa829e5 without
conflicts or scope changes.
- Re-ran the focused frontend regression tests and
TestDataBranchDiffAsFile after the rebase; both passed locally.

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.

3 participants