Skip to content

[4.2-dev] Fix transactional index authorization and utf8mb4 column modification - #33163

Merged
XuPeng-SH merged 13 commits into
matrixorigin:4.2-devfrom
aptend:fix/4.2-dev-ddl-index-auth-charset
Nov 26, 2026
Merged

XuPeng-SH merged 13 commits into
matrixorigin:4.2-devfrom
aptend:fix/4.2-dev-ddl-index-auth-charset

Conversation

@aptend

@aptend aptend commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #29479.

What this PR does / why we need it:

  • Check standalone index DDL against the INDEX privilege. CREATE INDEX and DROP INDEX can also use the current transaction's ownership grant for its newly created table. The target's physical and logical IDs and the role checked at the authorization snapshot must match. The local grant is never cached.
  • Support explicit utf8mb4 / utf8mb4_bin on text columns in ADD COLUMN, MODIFY COLUMN, and CHANGE COLUMN. Use the same persisted text selector as fix(sql): persist charset defaults and implement table conversion #29374 and the branch's existing UTF-8 storage and binary comparison. Existing implicit column declarations keep their legacy metadata. SHOW FULL COLUMNS exposes the explicit collation. Fresh tenants get the updated information_schema.COLUMNS view. The tenant upgrade to catalog 4.0.6/5 also refreshes information_schema.COLUMNS. Deployments entering 4.0.6/5 from an earlier catalog receive the new view. Deployments already at 4.0.6/5 skip the step and continue to report utf8 / utf8_bin through their existing view. The catalog identity remains 4.0.6/5 for both paths. The catalog has a fixed release scope that accepts legacy metadata for clusters already at the target. SHOW CREATE TABLE preserves the declaration through DDL replay and COPY.

Review fixes

  • Apply the same storage-scale comparison to foreign-key cascades and DATA BRANCH DIFF. For matching character types in 4.2, an implicit declaration and explicit utf8mb4_bin use the same text storage.

  • Add SQL regressions for both paths and for renaming a populated column with CHANGE COLUMN. The rename case checks the four-byte value, charset, collation, and comment.

  • Compare equivalent text charset selectors in the ancestor probe while reading the original ancestor storage type. The SQL regression updates an inherited row after one branch changes only its charset declaration and verifies the diff returns the update.

  • Keep temporal precision independent of the charset selector. EXTRACT parses temporal strings at microsecond precision. ADDTIME and SUBTIME keep the precision of the typed temporal operand.

  • Apply the common text storage comparison to renamed-column resolution. DIFF OUTPUT AS preserves explicit column charset metadata using the same clause as SHOW CREATE TABLE.

  • Permit INPLACE widening of compatible character columns with explicit charset metadata. The same physical table retains its data and records the declaration requested by ALTER.

  • Keep the charset selector out of the MySQL protocol Decimals field for string columns.

  • Keep charset selectors out of data-branch hash ingestion, key matching and generated-expression comparisons. A branch change stream can read both pre-ALTER and post-ALTER batches. DIFF, PICK and MERGE continue to use the same text key after a charset-only ALTER. Generated columns keep their catalog declarations, and data-branch compatibility ignores selector-only casts.

Validation

  • Passed the branch hashmap, frontend and planner unit tests. The branch SQL cases cover a parent-only update after a text-primary-key charset change and DIFF and MERGE over rows written before and after COPY ALTER. The affected branch cases passed again on the same instance with catalog cleanup verified. A SQL probe also applied both historical rows through PICK and verified their values.
  • This revision passed focused ALTER and protocol-metadata unit tests. A MySQL client probe kept the physical table ID, preserved four-byte text, and reported Decimals=0 for both string columns.
  • Passed local SCA with the repository-pinned tools and configuration. The CI selector chose the full graph against main and 4.2-dev. GOFLAGS=-p=4 GOMAXPROCS=5 make static-check-selected GOLANGCI_LINT_CONCURRENCY=4 STATIC_CHECK_PACKAGES=./... completed successfully.
  • Passed the bootstrap and sysview unit tests and fifteen focused BVT cases (1,598 passing statements and 7 existing skips).
  • Tested shutdown upgrades from the v4.1.4 and v4.2.8 images, followed by a restart. Both reached catalog 4.0.6/5. After altering a populated LONGTEXT column, the tenant from v4.1.4 returned the new charset and collation through information_schema.COLUMNS. The tenant from v4.2.8 retained the old view. Both SHOW statements reported the explicit collation and the four-byte value was preserved on both paths.

@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

mergify Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@aptend
aptend force-pushed the fix/4.2-dev-ddl-index-auth-charset branch from 8bd8db1 to d303c25 Compare November 25, 2026 02:37

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

mo-bot review · mo-bot-local · review

Commit: 3c0e438d61e6696d60b66bb0ef8c833106d86a25

Assessment: request_changes

The change reuses existing authorization and text-storage mechanisms, and the earlier foreign-key, no-common-ancestor branch-diff, and rename concerns have targeted fixes. Two issues remain: the view migration changes a released catalog handler while missing tenants already at that catalog version, and the common-ancestor branch-diff path still rejects equivalent text selectors. The cluster-table DUMP fingerprint exception is accepted and non-blocking.

Model: gpt-6.1-terra / max

Session: 01a2110f-4081-7e00-8415-e36a337ad118 · slot 0 · generation 12

  • P2 pkg/bootstrap/versions/v4_0_6/tenant_upgrade_list.go:29: Upgrade a v4.2.9 deployment already at catalog 4.0.6/5, then create or modify a text column with CHARACTER SET utf8mb4 COLLATE utf8mb4_bin.
    Impact: The existing information_schema.COLUMNS view continues to report utf8 and utf8_bin, while SHOW statements and freshly initialized tenants expose the explicit utf8mb4 declaration. Schema-inspection clients therefore receive inconsistent metadata. For deployments crossing 4.0.6 from an older catalog, the added entry also changes the effects of an already released migration.
    Evidence: The released v4.2.9 catalog handler has four tenant entries and offset 5; this change adds a fifth entry while retaining that identity. service_upgrade.go:195 skips an already-current 4.0.6/5 deployment, and service_upgrade_tenant.go:58 skips tenants at the current version. The PR description confirms the old view remains after its v4.2.8 upgrade test; it does not explicitly accept that behavior. The pinned upgrade-compatibility policy freezes released migration effects. Restore the released handler and put the view refresh in a new catalog target that reaches already-upgraded tenants. v4.2.9 release

  • P2 pkg/frontend/data_branch.go:1576: Create a table with an implicit VARCHAR column and a row, branch it, modify the branch column to explicit utf8mb4_bin, then update or delete the inherited row on the original table and run DATA BRANCH DIFF.
    Impact: The diff can fail with an LCA column type mismatch even though the two column declarations use the same text storage and pass the new endpoint compatibility check.
    Evidence: The changed endpoint check accepts scales 0 and 1 via ColumnStorageScalesEqual, but data_branch_hashdiff.go:216 still uses isDataBranchLogicalTypeEquivalent, which requires equal scales. An update or deletion of an inherited row reaches that LCA probe through findDeleteAndUpdateBat. The new SQL regression covers independent tables without a common ancestor, so it does not exercise this path. Apply the storage-equivalence rule to the LCA probe as well and cover a branched-table update or deletion.

Validation:

  • Private-runtime preflight and git diff --check passed; receipts are retained under checks/1795604898417730168-3.json and checks/1795604898417357418-3.json.

  • Compared the v4.2.9 catalog inputs with the pinned base; the checked files match. Receipt: checks/1795604898356978559-3.json.

  • Reused an earlier passing parser-formatting probe after verifying the relevant parser, common, type, and module inputs were unchanged; prior-parser-check.log and checks/1795605510917728734-3.json.

  • Verified 170 tracked native inputs against the retained stage and reconciled all 16 discussion keys; native-inputs.log and discussion-check.log.

Limitations:

  • The focused LCA probe timed out during dependency downloads before any test ran; lca-probe.log and checks/1795605429070907726-2.json. The branch finding is based on source tracing.

  • No live SQL or upgrade was executed in this review. The author-reported BVT, bootstrap, SCA, and upgrade runs have no matching receipts in the supplied local-validation evidence.

@aptend

aptend commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@XuPeng-SH The catalog decision for this release is final. 4.0.6/5 is the only target.

The information_schema.COLUMNS refresh runs for tenants that enter this upgrade handler. We explicitly accept that clusters already at 4.0.6/5 skip the refresh and continue to expose the legacy values through their existing view. The version and offset must stay fixed on both release branches.

Please record the catalog item as an accepted release decision and assess the implementation against this constraint. The common-ancestor DATA BRANCH DIFF finding is a separate correctness issue.

@XuPeng-SH

XuPeng-SH commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 1995ba64591b5bb9131791e999ab3a4b25db8d2d

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 1995ba64591b5bb9131791e999ab3a4b25db8d2d

Assessment: request_changes

The previous same-name common-ancestor issue is addressed, but a renamed-column interaction remains. The new charset selector also conflicts with an existing temporal-precision consumer and is omitted from materialized DIFF output schemas. The accepted cluster-table DUMP/LOAD and catalog 4.0.6/5 exceptions are not findings.

Model: gpt-6.1-terra / max

Session: 01a21244-6c6c-7240-bf19-37c0cdedc87d · slot 1 · generation 15

  • P1 pkg/sql/plan/build_util.go:379: Run EXTRACT(MICROSECOND FROM v) on a VARCHAR column declared CHARACTER SET utf8mb4 COLLATE utf8mb4_bin containing a timestamp with fractional seconds.
    Impact: The selector makes EXTRACT interpret the text column as having one digit of fractional precision. It silently rounds the parsed value, which can change query results, predicates and values written by DML.
    Evidence: CREATE assigns Scale=1 here, and the binder selects the direct VARCHAR overload. ExtractFromVarchar reads that scale as temporal precision in pkg/sql/plan/function/func_binary.go:6762. The parser in pkg/container/types/timestamp.go:130 would round .123456 to .100000; the existing scale-0 regression expects 123456. Prevent the charset selector from being interpreted as precision and add a regression comparing otherwise identical declared and legacy text columns.

  • P2 pkg/frontend/data_branch_hashdiff.go:218: Fork a table, declare utf8mb4_bin on the child, rename the corresponding column on the parent, then update an inherited child row and DIFF the child against the parent.
    Impact: The common-ancestor probe rejects the renamed column instead of returning the differences, even though the two text selectors use equivalent storage.
    Evidence: When the LCA is the current parent endpoint, lcaProbeColumnLayout first resolves the historical name through dataBranchEndpointColumnDef. Its identity fallback in pkg/frontend/data_branch_output.go:645 requires exact Scale equality and returns nil before the new normalization at this line runs. Apply the storage-equivalence rule during that resolution as well, and cover the combined rename and selector case.

  • P2 pkg/sql/plan/build_show_util.go:199: Use DATA BRANCH DIFF ... OUTPUT AS on a table whose projected text column has an explicit utf8mb4_bin declaration.
    Impact: The new result table loses that declaration: its column is recreated with the legacy selector, so its SHOW CREATE and collation metadata differ from the base column even for a freshly initialized tenant.
    Evidence: The new charset suffix is emitted only by this SHOW CREATE formatter. The output-table builder at pkg/frontend/data_branch_output.go:581 instead calls FormatColType, which omits the selector. Include the declaration when generating the output table's DDL while preserving the intended legacy schema-hash spelling.

Validation:

  • Preflight and the frozen-head git diff --check passed; their receipts are checks/1795611361681398846-2.json and checks/1795611447617453045-2.json.

  • The final audit verified the assigned head, a clean source status, all 19 discussion keys, and the retained check logs and receipts: final-review-audit.log and checks/1795613711385329380-2.json.

  • The reused native build inputs matched 170 tracked source files: native-inputs.log and checks/1795611476103987608-2.json.

Limitations:

  • The focused branch and EXTRACT Go probes timed out during build or linking before any tests ran. Their logs and receipts are retained in the diagnostic directory; they are not test passes or product-test failures.

  • The findings are based on source traces. The proposed public SQL scenarios and full upgrade checks were not executed locally, and the author-reported validation was not accompanied by matching local execution artifacts in the supplied evidence.

  • The later timeout receipts could not fingerprint the source because their preliminary git commands timed out. Earlier checks had clean frozen-head fingerprints, and the final audit independently verified the head and clean status.

@XuPeng-SH

XuPeng-SH commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · superseded

Commit: b49b271f24b7d6f5b8785ee7ba9db09308c16385

"interrupted"

@XuPeng-SH

XuPeng-SH commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · superseded

Commit: 597918ba465a5c1c115ba023a200bca7b6e7962e

"interrupted"

@XuPeng-SH

XuPeng-SH commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · failed

Commit: 2cc5e9090f7376e8e0030c0cd4e7253f0a02dce6

ambiguous review submission; remote marker absent; manual reconciliation required

@XuPeng-SH

XuPeng-SH commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 867fc0a4386fd71590bc27d51e8da4664125f8a2

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 867fc0a4386fd71590bc27d51e8da4664125f8a2

Assessment: request_changes

The earlier text-primary-key failure is fixed on this head, but a separate COPY ALTER history fails during DATA BRANCH DIFF. The new SQL regression catches removal of the shared comparator through its forward query; its reverse query does not reproduce the originally reported parent-as-base mismatch. The accepted DUMP/LOAD and catalog-target release decisions were honored.

Model: gpt-6.1-terra / max

Session: 01a212e9-10a4-7203-9194-162fe0e55042 · slot 0 · generation 13

  • P2 pkg/frontend/data_branch.go:1600: Create a table with an integer primary key and a VARCHAR column, branch it, insert a row into the child, COPY ALTER that VARCHAR to declare utf8mb4_bin, then insert another child row and run DATA BRANCH DIFF against the parent.
    Impact: DIFF returns "invalid input: vector type mismatch" instead of comparing the branch. MERGE and PICK can encounter the same failure when their collected changes span both generations.
    Evidence: The embedded SQL probe in review-branch-sql.log reproduced the error; an otherwise identical COPY ALTER without the charset change returned the expected count of 2. The new storage-equivalence check accepts the column types, but equal-layout historical batches retain their generation-specific scales, and validatePutTypesLocked still requires exact types for every inserted vector. Normalize storage-equivalent text metadata during ingestion, or otherwise harmonize the historical batches while retaining the other type checks, and cover this COPY ALTER sequence with a SQL regression.

  • P2 test/distributed/cases/git4data/branch/diff/diff_1.sql:159: The new case updates only the child. Reversing DIFF makes that child the base, but it does not update the ancestor that was the base in the reported failure.
    Impact: The SQL regression does not independently protect the previously failing parent-as-base update path. The existing forward query and hashmap unit test do cover the shared comparator, but a failure specific to the ancestor/base path can escape this SQL case.
    Evidence: The exact reported parent-update scenario succeeds on the current head. In review-key-old-v3-control.log, a diagnostic overlay restoring the old comparator makes that original scenario fail, while the new reverse query still returns 2; the new forward query fails under the same control. Add a separate case that updates the parent after the fork and checks DIFF child AGAINST parent. This is a test-coverage finding; the reported production defect is fixed.

Validation:

  • Private /tmp and loopback preflight passed. Native library provenance matched 170 source inputs.

  • Focused Go tests for branch hash keys, text storage comparison, generated expressions, index authorization and protocol metadata passed on the assigned head; see targeted-go.log and checks/1795624424735629585-2.json.

  • Embedded SQL probes confirmed the original parent-update fix and reproduced the COPY ALTER failure against an unchanged-metadata control; see review-branch-sql.log and checks/1795624620272796529-2.json.

  • A SQL probe mirroring the new bidirectional case passed on the candidate. A deliberately reverted-comparator control established which directions detect the old mismatch; see review-key-candidate.log, review-key-old-v3-control.log and their receipts.

  • git diff --check passed. discussion-assessment.json accounts for all 24 discussion keys.

Limitations:

  • The full BVT, static-analysis and upgrade runs described by the author were not independently rerun; the supplied local_validation list contains no retained receipts for them.

  • Two initial deliberately reverted-comparator controls exited with incorrect assertions about which direction would fail. The corrected control completed successfully; those exits were not candidate failures.

@XuPeng-SH

XuPeng-SH commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: e6d648f37f20ea8579ee3e53cf67eec352a98344

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: e6d648f37f20ea8579ee3e53cf67eec352a98344

Assessment: approve

No actionable defects remain in the reviewed scope. The prior DATA BRANCH mixed-history failure and parent-update coverage gap are addressed. The implementation reuses a shared text-storage equivalence rule across schema and hash operations without adding durable state. The accepted cluster-table DUMP/LOAD fingerprint exception and catalog 4.0.6/5 release scope remain in effect.

Model: gpt-6.1-terra / max

Session: 01a21358-dffa-72f0-8c29-d1bc350fbb60 · slot 3 · generation 4

Validation:

  • Private /tmp and loopback preflight passed; see preflight.log and checks/1795626777407785151-2.json.

  • Staged native inputs matched 170 tracked source files, and the required native libraries were built with repository Make targets; see native-inputs.log and the corresponding checks receipts.

  • TestBranchHashmapTextKeyWithExplicitCharset passed on the assigned head with the isolated test executor; see hashmap-retry.log and checks/1795627707566526562-2.json.

  • git diff --check passed, and discussion-assessment.json accounts for all 26 discussion keys exactly once; see diff-check.log, discussion-audit.log and their checks receipts.

Limitations:

  • The author reports SQL/BVT, static-analysis and shutdown-upgrade runs, but their raw receipts were not supplied in local_validation and were not independently rerun.

  • The first focused Go run timed out while downloading dependencies from the configured proxy. The retry using the official Go proxy passed.

This branch was successfully deployed

No deployments
ci — 678a633a Deployed Nov 26, 2026 by XuPeng-SH
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/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants