Skip to content

fix(temp): keep ALTER COPY DDL in executor transaction - #28356

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-temp-ddl-auto-increment-28336
Sep 7, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-temp-ddl-auto-increment-28336

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

Summary

Fixes #28352

ALTER TABLE on a session temporary table uses an internal CREATE/DROP
sequence while copying the table. These constituent DDL statements must stay
in the transaction supplied by the SQL executor. Previously they could be
classified as top-level frontend temporary-table DDL and publish or retire
session metadata in an independent transaction, leaving auto-increment
metadata inconsistent with the copied table.

This change adds an explicit compile-local executor-transaction policy. It is
kept separate from isInternal, applies to both temporary CREATE and
DROP, is inherited by retry compiles, and is cleared at compile-pool release.
Direct client temporary-table DDL keeps the existing session-owned lifecycle.

Validation

  • Focused pkg/sql/compile tests, including executor ownership, retry/pool
    reuse, create/drop failure handling, alias rollback, reconciliation, and
    cancellation: PASS.
  • Focused pkg/frontend temporary-table journal/lifetime tests: PASS.
  • Focused pkg/incrservice allocator reset/epoch/cache tests: PASS.
  • go vet -mod=readonly ./pkg/sql/compile: PASS.
  • Unchanged temporary_table_limitation.sql and .result on a clean
    standalone candidate instance, repeated twice: 137 total, 130 success, 0 failed, 7 ignored on both runs.
  • The same unchanged BVT on a clean 2-CN + Proxy candidate instance, repeated
    twice: 137 total, 130 success, 0 failed, 7 ignored on both runs.
  • Counterfactual mutation checks fail as expected when retry-policy inheritance
    or compile-pool reset is removed; the candidate was restored and rerun
    successfully.

The earlier TestIssue28313EmptyRemoteDispatch report is not claimed by this
PR: the #28313 fix commit 4503c3b2 is already an ancestor of the prior
#28336 head, so this change does not duplicate or mask that separate issue.
No retry, skip, timeout, or expected-result weakening was added.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 555bd76 against base 39225f5 and issue #28352. No blocking finding.

The explicit executor-transaction policy fixes the ownership mismatch without overloading isInternal (and thereby changing routing/auth-related behavior). Traced ALTER COPY through runSqlWithResultAndOptions: its constituent statements use the parent transaction with DisableIncrStatement, and both temporary CREATE and DROP now bypass independent session-DDL publication/retirement. Normal frontend temporary DDL retains the previous path. Checked retry inheritance, compile-pool reset, create-error alias cleanup, and frontend statement/transaction journal restoration.

Audit Conclusion
Q1 ownership Constituent DDL remains with the executor transaction; existing alias journal and transaction completion own rollback/commit.
Q2 termination No new wait, lock, worker or retry loop; existing transaction/cancellation paths are retained.
Q3 lifetime Policy is one compile-local bool, inherited for retries and cleared before pool reuse; no new accumulating registry.

Independent validation: eight focused test functions in pkg/sql/compile passed locally, including client CREATE/CTAS error and panic cases, executor admission, retry/pool reuse, parent-transaction CREATE and DROP/delete failure. Darwin arm64, GOMAXPROCS=2, -p=1, -count=1, -timeout=120s; test runtime 0.092s. git diff --check passed.

Inspected the unchanged temporary_table_limitation SQL/result contract covering allocator preservation, failed COPY, explicit rollback, and leaked-copy checks. The standalone and 2-CN+Proxy executions are author-reported evidence, not independently rerun in this review. CI was still in progress when checked; approval does not claim all CI has passed.

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

mergify Bot pushed a commit that referenced this pull request Sep 7, 2026
### Root cause

Mixed DATA BRANCH and CLONE workflows used inconsistent lock order. DIFF, PICK, MERGE, and ordinary CLONE could first acquire catalog/view/object locks and only later enter nested scratch/restore/drop paths that acquire the existing lineage-owner lifecycle row lock. Concurrent DROP, SNAPSHOT, and branch operations acquire the lineage lock first and then catalog/view/object locks. Across CNs these two orders can form a distributed wait cycle even when the business database names are independent.

The previous revision of this PR tried to merge the view and lineage gates. That changed the restore catalog contract and caused both unit and broad BVT regressions when `mo_feature_registry` was unavailable in tenant/PITR restore contexts. This revision restores the two existing gates and corrects only composite-operation admission order.

### Changes

- Add one shared mutation-admission helper that acquires the existing lineage-owner lifecycle lock before composite autocommit work starts.
- Admit table/database CLONE and DATA BRANCH DIFF/PICK/MERGE before endpoint/catalog resolution.
- Reacquire the lineage lifecycle lock when database-clone target-lock retry restarts its owned transaction.
- Preserve existing explicit user-transaction validation and ownership semantics.
- Add deterministic two-CN regression coverage plus focused admission/retry failure-path unit tests.
- Update the existing concurrent `IF NOT EXISTS` clone regression to observe the new leading lineage lifecycle gate while preserving its transaction-order and result assertions.

### Issue-to-test proof

`TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock` runs authenticated SQL through a real two-CN cluster. It uses lock-service waiter barriers rather than timing sleeps and covers:

- database CLONE with table data, full-text index, and view metadata while an unrelated database DROP runs;
- DIFF while an unrelated database DROP runs;
- PICK and MERGE with a destination-row conflict while an unrelated database DROP waits on the lineage gate;
- completion, result correctness, and unrelated-drop visibility after every interleaving.

The exact external regression set from #26404 was also run for 20 rounds at concurrency 9: 200/200 cases and 4,840/4,840 statements passed, with no deadlock or `20701` in runner/server logs.

### Validation

- rebased cleanly onto `main@0b195e4`; `git range-diff` confirms both issue commits are unchanged
- focused frontend admission and retry tests, including rollback/begin/gate error propagation
- `TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock`: `-count=3`
- `TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock`: `-race -count=1`
- `TestIssue27040ConcurrentIfNotExistsDatabaseClone`: `-count=3`
- `TestIssue27040ConcurrentIfNotExistsDatabaseClone`: focused frontend coverage mode and `-race -count=1`
- full `./pkg/catalog ./pkg/frontend/databranchutils ./pkg/sql/compile ./pkg/frontend` after the shared SNAPSHOT/View-gate change landed
- full `./pkg/frontend`
- full `./pkg/tests/issues`
- exact adjacent regressions: `TestIssue26087ConcurrentDataBranchQuota`, `TestIssue26640AccountPITRUsesCatalogRestoreHandlers`, and `TestIssue28317ViewSnapshotGateOrderSQL`
- `go vet ./pkg/frontend ./pkg/tests/issues` with the repository CGo environment
- `make build`
- exact ten-case MOTR command from #26404 with `--repeat 20 -j 9`
- `temporary_table_clone` BVT after the temporary-DDL transaction change: 166/166 statements passed with JDBC metadata ignored
- `git diff --check`

After upstream #28322 unified SNAPSHOT -> View locking, the shared lock packages, frontend/compile packages, the real two-CN issue test, all three adjacent regressions, and the race case were rerun successfully. After upstream #28332 made temporary DDL transaction-independent, focused/full frontend and compile tests, the real two-CN issue test, `make build`, and the existing 166-statement temporary-clone BVT were rerun. The local machine has JDK 17 rather than the tester-required JDK 8: normal BVT comparison reported 12 JDBC display-width-only differences, each inspected against the SQL and expected data/DDL/error semantics; `-n` then proved all 166 semantic results. No result file was regenerated or changed.

The old-head Ubuntu UT, UT coverage, and pessimistic multi-CN BVT failures in workflow run 34098109436 all traced to the discarded shared-gate revision; local exact regression tests pass with this revision. They are not unrelated CI blockers.

Workflow run 34125753066 exposed one stale assertion in the existing #27040 regression: it still expected the second clone to wait at the target `mo_database` key, but this PR intentionally admits clone at the lineage lifecycle gate first. Commit `d71f4dbd` updates only that observation point; the original early-return, commit-order, uniqueness, and payload assertions remain intact. The same job also reproduced the unrelated #28313 shuffle-pool failure, while its pessimistic BVT job reproduced the then-unresolved #28352 temporary-table ALTER failure; the aggregate Coverage failure was a consequence of those failed producers.

After rebasing onto upstream #28343's remote-bind convergence change and #28096's frontend `MEMBER OF` support, the eight focused frontend admission/retry/error-path tests and the full `pkg/frontend` package passed. The real two-CN #26404 regression and the adjacent #27040 clone regression each passed three normal runs and one race run, validating the current lockservice dependency rather than reusing the older topology evidence. Main then advanced with #28356's executor-owned temporary ALTER COPY transaction fix, which resolved #28352. A second `range-diff` remained unchanged; the eight focused frontend tests and both two-CN regressions were rerun on `main@fdc1e0c`, with three normal runs per regression and a combined race run passing.

Pre-rebase workflow run 34150466865 passed Linux UT, coverage UT, SCA, Proxy and pessimistic multi-CN BVT, and aggregate Coverage; the remaining completed jobs were successful, neutral, or intentionally skipped. Main then added only #28355's correlated scalar-aggregate planner optimization. A third `range-diff` remained unchanged, and the eight focused frontend tests plus both real two-CN regressions passed on `main@0b195e4`; the existing race evidence remains valid because neither the PR's synchronization code nor its lockservice dependency changed.

### Residual risk

The corrected order intentionally serializes these composite autocommit workflows at the existing global lineage lifecycle boundary for their owned transaction. The 20-round exact workload completed without stalls. Explicit user-transaction behavior is unchanged and is outside the reported autocommit workload.

Approved by: @XuPeng-SH
XuPeng-SH pushed a commit that referenced this pull request Sep 8, 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 #28044
issue #28045

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

Return `JSON_QUOTE` as `utf8mb4_bin` text instead of binary JSON.
Validate UTF-8 and the runtime string domain, emit JSON string escapes,
preserve SQL NULL, derive the expanding result bound, and retain full
prepared values without a synthetic narrowing execution cast. Existing
ENUM/SET-to-JSON planner consumers explicitly cast quoted display text
back to JSON.

### Landing status

- The required JSON_UNQUOTE predecessor #28090 is merged as
`3d2e5c336ed6b6d034908cd4d2012bc9737fe958` and is an ancestor of this
exact head.
- Main was integrated through commit
`2a12a06aa1931c93c53c11d34465e832a9713cf8`, resolving the latest
upstream test-file conflict while retaining the JSON_QUOTE regression
and upstream prepared-interval coverage. It includes merged #28356
(`fdc1e0ca8f9696ada9668408e8caffc1d3b7c924`) for temporary ALTER COPY
transaction ownership.
- Exact current head: `2a12a06aa1931c93c53c11d34465e832a9713cf8`; this
PR remains Ready and must continue through normal merge protections.
- The prior CI run on `fb6a10200e86073c5954288c74718daca7f3c2c8`
reported `func_json_quote.test` 54/54 PASS. Its PROXY job failed only in
the unrelated temporary-table ALTER path (16 failures, including
allocator metadata errors), UT Coverage timed out after repeated
dependency-download `curl` timeouts before a terminal coverage report,
and Utils Coverage was downstream (`PREREQUISITES_READY=false`). Fresh
CI for this head is pending.
- The fresh CI run `34207581205` on the preceding exact head
`c8eaf2cf515d235ed1ee5da0d4b69043993bfc17` passed SCA, main UT, PROXY
BVT, and standalone pessimistic BVT. UT Coverage alone failed on
unrelated `pkg/common/mpool/TestReallocPhysicalFailureRestoresOwnership`
with runner `fatal error: runtime: cannot allocate memory`; its
diagnostics showed a 15 GiB runner with no swap. A new exact-head run is
required after this upstream sync.

### Validation at exact head `2a12a06aa1931c93c53c11d34465e832a9713cf8`

- Focused CGo tests for JSON_QUOTE domain rejection, UTF-8 escaping,
NULL/masked rows, prepared rebinding, planner consumers, and protocol
metadata on validation head `2a5842b8c69ce793aadc5fd1a0b01668e9318be5`:
PASS; the later `c8eaf2cf` result-only update and upstream-only sync did
not change these production paths.
- Full owning-package CGo tests for `pkg/sql/plan/function`,
`pkg/sql/plan`, and `pkg/frontend` on that validation code: PASS.
- Temporary ALTER ownership/retry/pool-reuse focused tests from #28356:
PASS.
- Targeted `pkg/tests/issues` CGo coverage invocation for
`TestIssue23861FulltextSnapshotRestore` and
`TestIssue28317ViewSnapshotGateOrderSQL`: PASS; the local report is `[no
statements]`, so it is functional targeted evidence and does not replace
CI's full `coverpkg` mode.
- Canonical local BVT with a fresh single-CN data directory on
validation head `2a5842b8c69ce793aadc5fd1a0b01668e9318be5`:
`func_json_quote.test` 54/54 PASS; `temporary_table_limitation.sql` 137
total, 130 success, 7 ignored, 0 failed, 100% success. The later
result-only and upstream test merge do not alter these BVT production
paths.
- Exact-head semantic preflight after the upstream sync: PASS, diff hash
`87525d7984b1850cb10ce44eda17b7244e26fe9fdccf366060b137a4d773d6df`.
- `git diff --check`: PASS. Fresh exact-head CI is pending after this
update.

BVT: extended — `test/distributed/cases/function/func_json_quote.test`
and `.result`; integrated-main metadata expectations in
`test/distributed/cases/temporary/temporary_table_limitation.result` are
refreshed and the full canonical case passes.

QA required: yes — after required CI and merge protections are
satisfied, verify text/protocol metadata, prepared execution,
charset/escaping, CTAS and persisted consumers on the merged version.
Keep the associated issues under formal QA validation.

---------

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
…28356)

## Summary

Fixes matrixorigin#28352

`ALTER TABLE` on a session temporary table uses an internal
`CREATE`/`DROP`
sequence while copying the table. These constituent DDL statements must
stay
in the transaction supplied by the SQL executor. Previously they could
be
classified as top-level frontend temporary-table DDL and publish or
retire
session metadata in an independent transaction, leaving auto-increment
metadata inconsistent with the copied table.

This change adds an explicit compile-local executor-transaction policy.
It is
kept separate from `isInternal`, applies to both temporary `CREATE` and
`DROP`, is inherited by retry compiles, and is cleared at compile-pool
release.
Direct client temporary-table DDL keeps the existing session-owned
lifecycle.

## Validation

- Focused `pkg/sql/compile` tests, including executor ownership,
retry/pool
reuse, create/drop failure handling, alias rollback, reconciliation, and
  cancellation: PASS.
- Focused `pkg/frontend` temporary-table journal/lifetime tests: PASS.
- Focused `pkg/incrservice` allocator reset/epoch/cache tests: PASS.
- `go vet -mod=readonly ./pkg/sql/compile`: PASS.
- Unchanged `temporary_table_limitation.sql` and `.result` on a clean
standalone candidate instance, repeated twice: `137 total, 130 success,
  0 failed, 7 ignored` on both runs.
- The same unchanged BVT on a clean 2-CN + Proxy candidate instance,
repeated
  twice: `137 total, 130 success, 0 failed, 7 ignored` on both runs.
- Counterfactual mutation checks fail as expected when retry-policy
inheritance
  or compile-pool reset is removed; the candidate was restored and rerun
  successfully.

The earlier `TestIssue28313EmptyRemoteDispatch` report is not claimed by
this
PR: the matrixorigin#28313 fix commit `4503c3b2` is already an ancestor of the prior
matrixorigin#28336 head, so this change does not duplicate or mask that separate
issue.
No retry, skip, timeout, or expected-result weakening was added.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…28325)

### Root cause

Mixed DATA BRANCH and CLONE workflows used inconsistent lock order. DIFF, PICK, MERGE, and ordinary CLONE could first acquire catalog/view/object locks and only later enter nested scratch/restore/drop paths that acquire the existing lineage-owner lifecycle row lock. Concurrent DROP, SNAPSHOT, and branch operations acquire the lineage lock first and then catalog/view/object locks. Across CNs these two orders can form a distributed wait cycle even when the business database names are independent.

The previous revision of this PR tried to merge the view and lineage gates. That changed the restore catalog contract and caused both unit and broad BVT regressions when `mo_feature_registry` was unavailable in tenant/PITR restore contexts. This revision restores the two existing gates and corrects only composite-operation admission order.

### Changes

- Add one shared mutation-admission helper that acquires the existing lineage-owner lifecycle lock before composite autocommit work starts.
- Admit table/database CLONE and DATA BRANCH DIFF/PICK/MERGE before endpoint/catalog resolution.
- Reacquire the lineage lifecycle lock when database-clone target-lock retry restarts its owned transaction.
- Preserve existing explicit user-transaction validation and ownership semantics.
- Add deterministic two-CN regression coverage plus focused admission/retry failure-path unit tests.
- Update the existing concurrent `IF NOT EXISTS` clone regression to observe the new leading lineage lifecycle gate while preserving its transaction-order and result assertions.

### Issue-to-test proof

`TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock` runs authenticated SQL through a real two-CN cluster. It uses lock-service waiter barriers rather than timing sleeps and covers:

- database CLONE with table data, full-text index, and view metadata while an unrelated database DROP runs;
- DIFF while an unrelated database DROP runs;
- PICK and MERGE with a destination-row conflict while an unrelated database DROP waits on the lineage gate;
- completion, result correctness, and unrelated-drop visibility after every interleaving.

The exact external regression set from matrixorigin#26404 was also run for 20 rounds at concurrency 9: 200/200 cases and 4,840/4,840 statements passed, with no deadlock or `20701` in runner/server logs.

### Validation

- rebased cleanly onto `main@0b195e4`; `git range-diff` confirms both issue commits are unchanged
- focused frontend admission and retry tests, including rollback/begin/gate error propagation
- `TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock`: `-count=3`
- `TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock`: `-race -count=1`
- `TestIssue27040ConcurrentIfNotExistsDatabaseClone`: `-count=3`
- `TestIssue27040ConcurrentIfNotExistsDatabaseClone`: focused frontend coverage mode and `-race -count=1`
- full `./pkg/catalog ./pkg/frontend/databranchutils ./pkg/sql/compile ./pkg/frontend` after the shared SNAPSHOT/View-gate change landed
- full `./pkg/frontend`
- full `./pkg/tests/issues`
- exact adjacent regressions: `TestIssue26087ConcurrentDataBranchQuota`, `TestIssue26640AccountPITRUsesCatalogRestoreHandlers`, and `TestIssue28317ViewSnapshotGateOrderSQL`
- `go vet ./pkg/frontend ./pkg/tests/issues` with the repository CGo environment
- `make build`
- exact ten-case MOTR command from matrixorigin#26404 with `--repeat 20 -j 9`
- `temporary_table_clone` BVT after the temporary-DDL transaction change: 166/166 statements passed with JDBC metadata ignored
- `git diff --check`

After upstream matrixorigin#28322 unified SNAPSHOT -> View locking, the shared lock packages, frontend/compile packages, the real two-CN issue test, all three adjacent regressions, and the race case were rerun successfully. After upstream matrixorigin#28332 made temporary DDL transaction-independent, focused/full frontend and compile tests, the real two-CN issue test, `make build`, and the existing 166-statement temporary-clone BVT were rerun. The local machine has JDK 17 rather than the tester-required JDK 8: normal BVT comparison reported 12 JDBC display-width-only differences, each inspected against the SQL and expected data/DDL/error semantics; `-n` then proved all 166 semantic results. No result file was regenerated or changed.

The old-head Ubuntu UT, UT coverage, and pessimistic multi-CN BVT failures in workflow run 34098109436 all traced to the discarded shared-gate revision; local exact regression tests pass with this revision. They are not unrelated CI blockers.

Workflow run 34125753066 exposed one stale assertion in the existing matrixorigin#27040 regression: it still expected the second clone to wait at the target `mo_database` key, but this PR intentionally admits clone at the lineage lifecycle gate first. Commit `d71f4dbd` updates only that observation point; the original early-return, commit-order, uniqueness, and payload assertions remain intact. The same job also reproduced the unrelated matrixorigin#28313 shuffle-pool failure, while its pessimistic BVT job reproduced the then-unresolved matrixorigin#28352 temporary-table ALTER failure; the aggregate Coverage failure was a consequence of those failed producers.

After rebasing onto upstream matrixorigin#28343's remote-bind convergence change and matrixorigin#28096's frontend `MEMBER OF` support, the eight focused frontend admission/retry/error-path tests and the full `pkg/frontend` package passed. The real two-CN matrixorigin#26404 regression and the adjacent matrixorigin#27040 clone regression each passed three normal runs and one race run, validating the current lockservice dependency rather than reusing the older topology evidence. Main then advanced with matrixorigin#28356's executor-owned temporary ALTER COPY transaction fix, which resolved matrixorigin#28352. A second `range-diff` remained unchanged; the eight focused frontend tests and both two-CN regressions were rerun on `main@fdc1e0c`, with three normal runs per regression and a combined race run passing.

Pre-rebase workflow run 34150466865 passed Linux UT, coverage UT, SCA, Proxy and pessimistic multi-CN BVT, and aggregate Coverage; the remaining completed jobs were successful, neutral, or intentionally skipped. Main then added only matrixorigin#28355's correlated scalar-aggregate planner optimization. A third `range-diff` remained unchanged, and the eight focused frontend tests plus both real two-CN regressions passed on `main@0b195e4`; the existing race evidence remains valid because neither the PR's synchronization code nor its lockservice dependency changed.

### Residual risk

The corrected order intentionally serializes these composite autocommit workflows at the existing global lineage lifecycle boundary for their owned transaction. The 20-round exact workload completed without stalls. Explicit user-transaction behavior is unchanged and is outside the reported autocommit workload.

Approved by: @XuPeng-SH
VioletQwQ-0 added 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#28044
issue matrixorigin#28045

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

Return `JSON_QUOTE` as `utf8mb4_bin` text instead of binary JSON.
Validate UTF-8 and the runtime string domain, emit JSON string escapes,
preserve SQL NULL, derive the expanding result bound, and retain full
prepared values without a synthetic narrowing execution cast. Existing
ENUM/SET-to-JSON planner consumers explicitly cast quoted display text
back to JSON.

### Landing status

- The required JSON_UNQUOTE predecessor matrixorigin#28090 is merged as
`3d2e5c336ed6b6d034908cd4d2012bc9737fe958` and is an ancestor of this
exact head.
- Main was integrated through commit
`2a12a06aa1931c93c53c11d34465e832a9713cf8`, resolving the latest
upstream test-file conflict while retaining the JSON_QUOTE regression
and upstream prepared-interval coverage. It includes merged matrixorigin#28356
(`fdc1e0ca8f9696ada9668408e8caffc1d3b7c924`) for temporary ALTER COPY
transaction ownership.
- Exact current head: `2a12a06aa1931c93c53c11d34465e832a9713cf8`; this
PR remains Ready and must continue through normal merge protections.
- The prior CI run on `fb6a10200e86073c5954288c74718daca7f3c2c8`
reported `func_json_quote.test` 54/54 PASS. Its PROXY job failed only in
the unrelated temporary-table ALTER path (16 failures, including
allocator metadata errors), UT Coverage timed out after repeated
dependency-download `curl` timeouts before a terminal coverage report,
and Utils Coverage was downstream (`PREREQUISITES_READY=false`). Fresh
CI for this head is pending.
- The fresh CI run `34207581205` on the preceding exact head
`c8eaf2cf515d235ed1ee5da0d4b69043993bfc17` passed SCA, main UT, PROXY
BVT, and standalone pessimistic BVT. UT Coverage alone failed on
unrelated `pkg/common/mpool/TestReallocPhysicalFailureRestoresOwnership`
with runner `fatal error: runtime: cannot allocate memory`; its
diagnostics showed a 15 GiB runner with no swap. A new exact-head run is
required after this upstream sync.

### Validation at exact head `2a12a06aa1931c93c53c11d34465e832a9713cf8`

- Focused CGo tests for JSON_QUOTE domain rejection, UTF-8 escaping,
NULL/masked rows, prepared rebinding, planner consumers, and protocol
metadata on validation head `2a5842b8c69ce793aadc5fd1a0b01668e9318be5`:
PASS; the later `c8eaf2cf` result-only update and upstream-only sync did
not change these production paths.
- Full owning-package CGo tests for `pkg/sql/plan/function`,
`pkg/sql/plan`, and `pkg/frontend` on that validation code: PASS.
- Temporary ALTER ownership/retry/pool-reuse focused tests from matrixorigin#28356:
PASS.
- Targeted `pkg/tests/issues` CGo coverage invocation for
`TestIssue23861FulltextSnapshotRestore` and
`TestIssue28317ViewSnapshotGateOrderSQL`: PASS; the local report is `[no
statements]`, so it is functional targeted evidence and does not replace
CI's full `coverpkg` mode.
- Canonical local BVT with a fresh single-CN data directory on
validation head `2a5842b8c69ce793aadc5fd1a0b01668e9318be5`:
`func_json_quote.test` 54/54 PASS; `temporary_table_limitation.sql` 137
total, 130 success, 7 ignored, 0 failed, 100% success. The later
result-only and upstream test merge do not alter these BVT production
paths.
- Exact-head semantic preflight after the upstream sync: PASS, diff hash
`87525d7984b1850cb10ce44eda17b7244e26fe9fdccf366060b137a4d773d6df`.
- `git diff --check`: PASS. Fresh exact-head CI is pending after this
update.

BVT: extended — `test/distributed/cases/function/func_json_quote.test`
and `.result`; integrated-main metadata expectations in
`test/distributed/cases/temporary/temporary_table_limitation.result` are
refreshed and the full canonical case passes.

QA required: yes — after required CI and merge protections are
satisfied, verify text/protocol metadata, prepared execution,
charset/escaping, CTAS and persisted consumers on the merged version.
Keep the associated issues under formal QA validation.

---------

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
…28356)

## Summary

Fixes matrixorigin#28352

`ALTER TABLE` on a session temporary table uses an internal
`CREATE`/`DROP`
sequence while copying the table. These constituent DDL statements must
stay
in the transaction supplied by the SQL executor. Previously they could
be
classified as top-level frontend temporary-table DDL and publish or
retire
session metadata in an independent transaction, leaving auto-increment
metadata inconsistent with the copied table.

This change adds an explicit compile-local executor-transaction policy.
It is
kept separate from `isInternal`, applies to both temporary `CREATE` and
`DROP`, is inherited by retry compiles, and is cleared at compile-pool
release.
Direct client temporary-table DDL keeps the existing session-owned
lifecycle.

## Validation

- Focused `pkg/sql/compile` tests, including executor ownership,
retry/pool
reuse, create/drop failure handling, alias rollback, reconciliation, and
  cancellation: PASS.
- Focused `pkg/frontend` temporary-table journal/lifetime tests: PASS.
- Focused `pkg/incrservice` allocator reset/epoch/cache tests: PASS.
- `go vet -mod=readonly ./pkg/sql/compile`: PASS.
- Unchanged `temporary_table_limitation.sql` and `.result` on a clean
standalone candidate instance, repeated twice: `137 total, 130 success,
  0 failed, 7 ignored` on both runs.
- The same unchanged BVT on a clean 2-CN + Proxy candidate instance,
repeated
  twice: `137 total, 130 success, 0 failed, 7 ignored` on both runs.
- Counterfactual mutation checks fail as expected when retry-policy
inheritance
  or compile-pool reset is removed; the candidate was restored and rerun
  successfully.

The earlier `TestIssue28313EmptyRemoteDispatch` report is not claimed by
this
PR: the matrixorigin#28313 fix commit `4503c3b2` is already an ancestor of the prior
matrixorigin#28336 head, so this change does not duplicate or mask that separate
issue.
No retry, skip, timeout, or expected-result weakening was added.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…28325)

### Root cause

Mixed DATA BRANCH and CLONE workflows used inconsistent lock order. DIFF, PICK, MERGE, and ordinary CLONE could first acquire catalog/view/object locks and only later enter nested scratch/restore/drop paths that acquire the existing lineage-owner lifecycle row lock. Concurrent DROP, SNAPSHOT, and branch operations acquire the lineage lock first and then catalog/view/object locks. Across CNs these two orders can form a distributed wait cycle even when the business database names are independent.

The previous revision of this PR tried to merge the view and lineage gates. That changed the restore catalog contract and caused both unit and broad BVT regressions when `mo_feature_registry` was unavailable in tenant/PITR restore contexts. This revision restores the two existing gates and corrects only composite-operation admission order.

### Changes

- Add one shared mutation-admission helper that acquires the existing lineage-owner lifecycle lock before composite autocommit work starts.
- Admit table/database CLONE and DATA BRANCH DIFF/PICK/MERGE before endpoint/catalog resolution.
- Reacquire the lineage lifecycle lock when database-clone target-lock retry restarts its owned transaction.
- Preserve existing explicit user-transaction validation and ownership semantics.
- Add deterministic two-CN regression coverage plus focused admission/retry failure-path unit tests.
- Update the existing concurrent `IF NOT EXISTS` clone regression to observe the new leading lineage lifecycle gate while preserving its transaction-order and result assertions.

### Issue-to-test proof

`TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock` runs authenticated SQL through a real two-CN cluster. It uses lock-service waiter barriers rather than timing sleeps and covers:

- database CLONE with table data, full-text index, and view metadata while an unrelated database DROP runs;
- DIFF while an unrelated database DROP runs;
- PICK and MERGE with a destination-row conflict while an unrelated database DROP waits on the lineage gate;
- completion, result correctness, and unrelated-drop visibility after every interleaving.

The exact external regression set from matrixorigin#26404 was also run for 20 rounds at concurrency 9: 200/200 cases and 4,840/4,840 statements passed, with no deadlock or `20701` in runner/server logs.

### Validation

- rebased cleanly onto `main@0b195e4`; `git range-diff` confirms both issue commits are unchanged
- focused frontend admission and retry tests, including rollback/begin/gate error propagation
- `TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock`: `-count=3`
- `TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock`: `-race -count=1`
- `TestIssue27040ConcurrentIfNotExistsDatabaseClone`: `-count=3`
- `TestIssue27040ConcurrentIfNotExistsDatabaseClone`: focused frontend coverage mode and `-race -count=1`
- full `./pkg/catalog ./pkg/frontend/databranchutils ./pkg/sql/compile ./pkg/frontend` after the shared SNAPSHOT/View-gate change landed
- full `./pkg/frontend`
- full `./pkg/tests/issues`
- exact adjacent regressions: `TestIssue26087ConcurrentDataBranchQuota`, `TestIssue26640AccountPITRUsesCatalogRestoreHandlers`, and `TestIssue28317ViewSnapshotGateOrderSQL`
- `go vet ./pkg/frontend ./pkg/tests/issues` with the repository CGo environment
- `make build`
- exact ten-case MOTR command from matrixorigin#26404 with `--repeat 20 -j 9`
- `temporary_table_clone` BVT after the temporary-DDL transaction change: 166/166 statements passed with JDBC metadata ignored
- `git diff --check`

After upstream matrixorigin#28322 unified SNAPSHOT -> View locking, the shared lock packages, frontend/compile packages, the real two-CN issue test, all three adjacent regressions, and the race case were rerun successfully. After upstream matrixorigin#28332 made temporary DDL transaction-independent, focused/full frontend and compile tests, the real two-CN issue test, `make build`, and the existing 166-statement temporary-clone BVT were rerun. The local machine has JDK 17 rather than the tester-required JDK 8: normal BVT comparison reported 12 JDBC display-width-only differences, each inspected against the SQL and expected data/DDL/error semantics; `-n` then proved all 166 semantic results. No result file was regenerated or changed.

The old-head Ubuntu UT, UT coverage, and pessimistic multi-CN BVT failures in workflow run 34098109436 all traced to the discarded shared-gate revision; local exact regression tests pass with this revision. They are not unrelated CI blockers.

Workflow run 34125753066 exposed one stale assertion in the existing matrixorigin#27040 regression: it still expected the second clone to wait at the target `mo_database` key, but this PR intentionally admits clone at the lineage lifecycle gate first. Commit `d71f4dbd` updates only that observation point; the original early-return, commit-order, uniqueness, and payload assertions remain intact. The same job also reproduced the unrelated matrixorigin#28313 shuffle-pool failure, while its pessimistic BVT job reproduced the then-unresolved matrixorigin#28352 temporary-table ALTER failure; the aggregate Coverage failure was a consequence of those failed producers.

After rebasing onto upstream matrixorigin#28343's remote-bind convergence change and matrixorigin#28096's frontend `MEMBER OF` support, the eight focused frontend admission/retry/error-path tests and the full `pkg/frontend` package passed. The real two-CN matrixorigin#26404 regression and the adjacent matrixorigin#27040 clone regression each passed three normal runs and one race run, validating the current lockservice dependency rather than reusing the older topology evidence. Main then advanced with matrixorigin#28356's executor-owned temporary ALTER COPY transaction fix, which resolved matrixorigin#28352. A second `range-diff` remained unchanged; the eight focused frontend tests and both two-CN regressions were rerun on `main@fdc1e0c`, with three normal runs per regression and a combined race run passing.

Pre-rebase workflow run 34150466865 passed Linux UT, coverage UT, SCA, Proxy and pessimistic multi-CN BVT, and aggregate Coverage; the remaining completed jobs were successful, neutral, or intentionally skipped. Main then added only matrixorigin#28355's correlated scalar-aggregate planner optimization. A third `range-diff` remained unchanged, and the eight focused frontend tests plus both real two-CN regressions passed on `main@0b195e4`; the existing race evidence remains valid because neither the PR's synchronization code nor its lockservice dependency changed.

### Residual risk

The corrected order intentionally serializes these composite autocommit workflows at the existing global lineage lifecycle boundary for their owned transaction. The 20-round exact workload completed without stalls. Explicit user-transaction behavior is unchanged and is outside the reported autocommit workload.

Approved by: @XuPeng-SH
VioletQwQ-0 added 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#28044
issue matrixorigin#28045

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

Return `JSON_QUOTE` as `utf8mb4_bin` text instead of binary JSON.
Validate UTF-8 and the runtime string domain, emit JSON string escapes,
preserve SQL NULL, derive the expanding result bound, and retain full
prepared values without a synthetic narrowing execution cast. Existing
ENUM/SET-to-JSON planner consumers explicitly cast quoted display text
back to JSON.

### Landing status

- The required JSON_UNQUOTE predecessor matrixorigin#28090 is merged as
`3d2e5c336ed6b6d034908cd4d2012bc9737fe958` and is an ancestor of this
exact head.
- Main was integrated through commit
`2a12a06aa1931c93c53c11d34465e832a9713cf8`, resolving the latest
upstream test-file conflict while retaining the JSON_QUOTE regression
and upstream prepared-interval coverage. It includes merged matrixorigin#28356
(`fdc1e0ca8f9696ada9668408e8caffc1d3b7c924`) for temporary ALTER COPY
transaction ownership.
- Exact current head: `2a12a06aa1931c93c53c11d34465e832a9713cf8`; this
PR remains Ready and must continue through normal merge protections.
- The prior CI run on `fb6a10200e86073c5954288c74718daca7f3c2c8`
reported `func_json_quote.test` 54/54 PASS. Its PROXY job failed only in
the unrelated temporary-table ALTER path (16 failures, including
allocator metadata errors), UT Coverage timed out after repeated
dependency-download `curl` timeouts before a terminal coverage report,
and Utils Coverage was downstream (`PREREQUISITES_READY=false`). Fresh
CI for this head is pending.
- The fresh CI run `34207581205` on the preceding exact head
`c8eaf2cf515d235ed1ee5da0d4b69043993bfc17` passed SCA, main UT, PROXY
BVT, and standalone pessimistic BVT. UT Coverage alone failed on
unrelated `pkg/common/mpool/TestReallocPhysicalFailureRestoresOwnership`
with runner `fatal error: runtime: cannot allocate memory`; its
diagnostics showed a 15 GiB runner with no swap. A new exact-head run is
required after this upstream sync.

### Validation at exact head `2a12a06aa1931c93c53c11d34465e832a9713cf8`

- Focused CGo tests for JSON_QUOTE domain rejection, UTF-8 escaping,
NULL/masked rows, prepared rebinding, planner consumers, and protocol
metadata on validation head `2a5842b8c69ce793aadc5fd1a0b01668e9318be5`:
PASS; the later `c8eaf2cf` result-only update and upstream-only sync did
not change these production paths.
- Full owning-package CGo tests for `pkg/sql/plan/function`,
`pkg/sql/plan`, and `pkg/frontend` on that validation code: PASS.
- Temporary ALTER ownership/retry/pool-reuse focused tests from matrixorigin#28356:
PASS.
- Targeted `pkg/tests/issues` CGo coverage invocation for
`TestIssue23861FulltextSnapshotRestore` and
`TestIssue28317ViewSnapshotGateOrderSQL`: PASS; the local report is `[no
statements]`, so it is functional targeted evidence and does not replace
CI's full `coverpkg` mode.
- Canonical local BVT with a fresh single-CN data directory on
validation head `2a5842b8c69ce793aadc5fd1a0b01668e9318be5`:
`func_json_quote.test` 54/54 PASS; `temporary_table_limitation.sql` 137
total, 130 success, 7 ignored, 0 failed, 100% success. The later
result-only and upstream test merge do not alter these BVT production
paths.
- Exact-head semantic preflight after the upstream sync: PASS, diff hash
`87525d7984b1850cb10ce44eda17b7244e26fe9fdccf366060b137a4d773d6df`.
- `git diff --check`: PASS. Fresh exact-head CI is pending after this
update.

BVT: extended — `test/distributed/cases/function/func_json_quote.test`
and `.result`; integrated-main metadata expectations in
`test/distributed/cases/temporary/temporary_table_limitation.result` are
refreshed and the full canonical case passes.

QA required: yes — after required CI and merge protections are
satisfied, verify text/protocol metadata, prepared execution,
charset/escaping, CTAS and persisted consumers on the merged version.
Keep the associated issues under formal QA validation.

---------

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
…28356)

## Summary

Fixes matrixorigin#28352

`ALTER TABLE` on a session temporary table uses an internal
`CREATE`/`DROP`
sequence while copying the table. These constituent DDL statements must
stay
in the transaction supplied by the SQL executor. Previously they could
be
classified as top-level frontend temporary-table DDL and publish or
retire
session metadata in an independent transaction, leaving auto-increment
metadata inconsistent with the copied table.

This change adds an explicit compile-local executor-transaction policy.
It is
kept separate from `isInternal`, applies to both temporary `CREATE` and
`DROP`, is inherited by retry compiles, and is cleared at compile-pool
release.
Direct client temporary-table DDL keeps the existing session-owned
lifecycle.

## Validation

- Focused `pkg/sql/compile` tests, including executor ownership,
retry/pool
reuse, create/drop failure handling, alias rollback, reconciliation, and
  cancellation: PASS.
- Focused `pkg/frontend` temporary-table journal/lifetime tests: PASS.
- Focused `pkg/incrservice` allocator reset/epoch/cache tests: PASS.
- `go vet -mod=readonly ./pkg/sql/compile`: PASS.
- Unchanged `temporary_table_limitation.sql` and `.result` on a clean
standalone candidate instance, repeated twice: `137 total, 130 success,
  0 failed, 7 ignored` on both runs.
- The same unchanged BVT on a clean 2-CN + Proxy candidate instance,
repeated
  twice: `137 total, 130 success, 0 failed, 7 ignored` on both runs.
- Counterfactual mutation checks fail as expected when retry-policy
inheritance
  or compile-pool reset is removed; the candidate was restored and rerun
  successfully.

The earlier `TestIssue28313EmptyRemoteDispatch` report is not claimed by
this
PR: the matrixorigin#28313 fix commit `4503c3b2` is already an ancestor of the prior
matrixorigin#28336 head, so this change does not duplicate or mask that separate
issue.
No retry, skip, timeout, or expected-result weakening was added.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…28325)

### Root cause

Mixed DATA BRANCH and CLONE workflows used inconsistent lock order. DIFF, PICK, MERGE, and ordinary CLONE could first acquire catalog/view/object locks and only later enter nested scratch/restore/drop paths that acquire the existing lineage-owner lifecycle row lock. Concurrent DROP, SNAPSHOT, and branch operations acquire the lineage lock first and then catalog/view/object locks. Across CNs these two orders can form a distributed wait cycle even when the business database names are independent.

The previous revision of this PR tried to merge the view and lineage gates. That changed the restore catalog contract and caused both unit and broad BVT regressions when `mo_feature_registry` was unavailable in tenant/PITR restore contexts. This revision restores the two existing gates and corrects only composite-operation admission order.

### Changes

- Add one shared mutation-admission helper that acquires the existing lineage-owner lifecycle lock before composite autocommit work starts.
- Admit table/database CLONE and DATA BRANCH DIFF/PICK/MERGE before endpoint/catalog resolution.
- Reacquire the lineage lifecycle lock when database-clone target-lock retry restarts its owned transaction.
- Preserve existing explicit user-transaction validation and ownership semantics.
- Add deterministic two-CN regression coverage plus focused admission/retry failure-path unit tests.
- Update the existing concurrent `IF NOT EXISTS` clone regression to observe the new leading lineage lifecycle gate while preserving its transaction-order and result assertions.

### Issue-to-test proof

`TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock` runs authenticated SQL through a real two-CN cluster. It uses lock-service waiter barriers rather than timing sleeps and covers:

- database CLONE with table data, full-text index, and view metadata while an unrelated database DROP runs;
- DIFF while an unrelated database DROP runs;
- PICK and MERGE with a destination-row conflict while an unrelated database DROP waits on the lineage gate;
- completion, result correctness, and unrelated-drop visibility after every interleaving.

The exact external regression set from matrixorigin#26404 was also run for 20 rounds at concurrency 9: 200/200 cases and 4,840/4,840 statements passed, with no deadlock or `20701` in runner/server logs.

### Validation

- rebased cleanly onto `main@0b195e4`; `git range-diff` confirms both issue commits are unchanged
- focused frontend admission and retry tests, including rollback/begin/gate error propagation
- `TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock`: `-count=3`
- `TestIssue26404MixedDataBranchLifecycleDoesNotDeadlock`: `-race -count=1`
- `TestIssue27040ConcurrentIfNotExistsDatabaseClone`: `-count=3`
- `TestIssue27040ConcurrentIfNotExistsDatabaseClone`: focused frontend coverage mode and `-race -count=1`
- full `./pkg/catalog ./pkg/frontend/databranchutils ./pkg/sql/compile ./pkg/frontend` after the shared SNAPSHOT/View-gate change landed
- full `./pkg/frontend`
- full `./pkg/tests/issues`
- exact adjacent regressions: `TestIssue26087ConcurrentDataBranchQuota`, `TestIssue26640AccountPITRUsesCatalogRestoreHandlers`, and `TestIssue28317ViewSnapshotGateOrderSQL`
- `go vet ./pkg/frontend ./pkg/tests/issues` with the repository CGo environment
- `make build`
- exact ten-case MOTR command from matrixorigin#26404 with `--repeat 20 -j 9`
- `temporary_table_clone` BVT after the temporary-DDL transaction change: 166/166 statements passed with JDBC metadata ignored
- `git diff --check`

After upstream matrixorigin#28322 unified SNAPSHOT -> View locking, the shared lock packages, frontend/compile packages, the real two-CN issue test, all three adjacent regressions, and the race case were rerun successfully. After upstream matrixorigin#28332 made temporary DDL transaction-independent, focused/full frontend and compile tests, the real two-CN issue test, `make build`, and the existing 166-statement temporary-clone BVT were rerun. The local machine has JDK 17 rather than the tester-required JDK 8: normal BVT comparison reported 12 JDBC display-width-only differences, each inspected against the SQL and expected data/DDL/error semantics; `-n` then proved all 166 semantic results. No result file was regenerated or changed.

The old-head Ubuntu UT, UT coverage, and pessimistic multi-CN BVT failures in workflow run 34098109436 all traced to the discarded shared-gate revision; local exact regression tests pass with this revision. They are not unrelated CI blockers.

Workflow run 34125753066 exposed one stale assertion in the existing matrixorigin#27040 regression: it still expected the second clone to wait at the target `mo_database` key, but this PR intentionally admits clone at the lineage lifecycle gate first. Commit `d71f4dbd` updates only that observation point; the original early-return, commit-order, uniqueness, and payload assertions remain intact. The same job also reproduced the unrelated matrixorigin#28313 shuffle-pool failure, while its pessimistic BVT job reproduced the then-unresolved matrixorigin#28352 temporary-table ALTER failure; the aggregate Coverage failure was a consequence of those failed producers.

After rebasing onto upstream matrixorigin#28343's remote-bind convergence change and matrixorigin#28096's frontend `MEMBER OF` support, the eight focused frontend admission/retry/error-path tests and the full `pkg/frontend` package passed. The real two-CN matrixorigin#26404 regression and the adjacent matrixorigin#27040 clone regression each passed three normal runs and one race run, validating the current lockservice dependency rather than reusing the older topology evidence. Main then advanced with matrixorigin#28356's executor-owned temporary ALTER COPY transaction fix, which resolved matrixorigin#28352. A second `range-diff` remained unchanged; the eight focused frontend tests and both two-CN regressions were rerun on `main@fdc1e0c`, with three normal runs per regression and a combined race run passing.

Pre-rebase workflow run 34150466865 passed Linux UT, coverage UT, SCA, Proxy and pessimistic multi-CN BVT, and aggregate Coverage; the remaining completed jobs were successful, neutral, or intentionally skipped. Main then added only matrixorigin#28355's correlated scalar-aggregate planner optimization. A third `range-diff` remained unchanged, and the eight focused frontend tests plus both real two-CN regressions passed on `main@0b195e4`; the existing race evidence remains valid because neither the PR's synchronization code nor its lockservice dependency changed.

### Residual risk

The corrected order intentionally serializes these composite autocommit workflows at the existing global lineage lifecycle boundary for their owned transaction. The 20-round exact workload completed without stalls. Explicit user-transaction behavior is unchanged and is outside the reported autocommit workload.

Approved by: @XuPeng-SH
VioletQwQ-0 added 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#28044
issue matrixorigin#28045

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

Return `JSON_QUOTE` as `utf8mb4_bin` text instead of binary JSON.
Validate UTF-8 and the runtime string domain, emit JSON string escapes,
preserve SQL NULL, derive the expanding result bound, and retain full
prepared values without a synthetic narrowing execution cast. Existing
ENUM/SET-to-JSON planner consumers explicitly cast quoted display text
back to JSON.

### Landing status

- The required JSON_UNQUOTE predecessor matrixorigin#28090 is merged as
`3d2e5c336ed6b6d034908cd4d2012bc9737fe958` and is an ancestor of this
exact head.
- Main was integrated through commit
`2a12a06aa1931c93c53c11d34465e832a9713cf8`, resolving the latest
upstream test-file conflict while retaining the JSON_QUOTE regression
and upstream prepared-interval coverage. It includes merged matrixorigin#28356
(`fdc1e0ca8f9696ada9668408e8caffc1d3b7c924`) for temporary ALTER COPY
transaction ownership.
- Exact current head: `2a12a06aa1931c93c53c11d34465e832a9713cf8`; this
PR remains Ready and must continue through normal merge protections.
- The prior CI run on `fb6a10200e86073c5954288c74718daca7f3c2c8`
reported `func_json_quote.test` 54/54 PASS. Its PROXY job failed only in
the unrelated temporary-table ALTER path (16 failures, including
allocator metadata errors), UT Coverage timed out after repeated
dependency-download `curl` timeouts before a terminal coverage report,
and Utils Coverage was downstream (`PREREQUISITES_READY=false`). Fresh
CI for this head is pending.
- The fresh CI run `34207581205` on the preceding exact head
`c8eaf2cf515d235ed1ee5da0d4b69043993bfc17` passed SCA, main UT, PROXY
BVT, and standalone pessimistic BVT. UT Coverage alone failed on
unrelated `pkg/common/mpool/TestReallocPhysicalFailureRestoresOwnership`
with runner `fatal error: runtime: cannot allocate memory`; its
diagnostics showed a 15 GiB runner with no swap. A new exact-head run is
required after this upstream sync.

### Validation at exact head `2a12a06aa1931c93c53c11d34465e832a9713cf8`

- Focused CGo tests for JSON_QUOTE domain rejection, UTF-8 escaping,
NULL/masked rows, prepared rebinding, planner consumers, and protocol
metadata on validation head `2a5842b8c69ce793aadc5fd1a0b01668e9318be5`:
PASS; the later `c8eaf2cf` result-only update and upstream-only sync did
not change these production paths.
- Full owning-package CGo tests for `pkg/sql/plan/function`,
`pkg/sql/plan`, and `pkg/frontend` on that validation code: PASS.
- Temporary ALTER ownership/retry/pool-reuse focused tests from matrixorigin#28356:
PASS.
- Targeted `pkg/tests/issues` CGo coverage invocation for
`TestIssue23861FulltextSnapshotRestore` and
`TestIssue28317ViewSnapshotGateOrderSQL`: PASS; the local report is `[no
statements]`, so it is functional targeted evidence and does not replace
CI's full `coverpkg` mode.
- Canonical local BVT with a fresh single-CN data directory on
validation head `2a5842b8c69ce793aadc5fd1a0b01668e9318be5`:
`func_json_quote.test` 54/54 PASS; `temporary_table_limitation.sql` 137
total, 130 success, 7 ignored, 0 failed, 100% success. The later
result-only and upstream test merge do not alter these BVT production
paths.
- Exact-head semantic preflight after the upstream sync: PASS, diff hash
`87525d7984b1850cb10ce44eda17b7244e26fe9fdccf366060b137a4d773d6df`.
- `git diff --check`: PASS. Fresh exact-head CI is pending after this
update.

BVT: extended — `test/distributed/cases/function/func_json_quote.test`
and `.result`; integrated-main metadata expectations in
`test/distributed/cases/temporary/temporary_table_limitation.result` are
refreshed and the full canonical case passes.

QA required: yes — after required CI and merge protections are
satisfied, verify text/protocol metadata, prepared execution,
charset/escaping, CTAS and persisted consumers on the merged version.
Keep the associated issues under formal QA validation.

---------

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

size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: temporary-table ALTER loses auto-increment metadata in Compose+Proxy BVT

3 participants