syncer(dm): add MariaDB ddl rewriter#12711
Conversation
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Code Review
This pull request introduces a new mariadbcompat package to handle AST-based compatibility rewriting for MariaDB DDL statements, integrating it into the DM syncer to support MariaDB upstreams. The review feedback highlights several critical improvements, including fixing a potential nil pointer dereference in indexPrefixRule for expression-based indexes, unwrapping parentheses in isJSONGenerated to prevent parsing failures, replacing platform-dependent filepath.Match with strings.HasPrefix, and removing redundant code in collationRule and rewriteDatabaseOptions. Additionally, an optimization was suggested to write directly to strings.Builder in restoreStatements to avoid unnecessary allocations.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
29d21c7 to
fefbd4b
Compare
fefbd4b to
af1fbd9
Compare
|
[FORMAT CHECKER NOTIFICATION] Notice: To remove the 📖 For more info, you can check the "Contribute Code" section in the development guide. |
What problem does this PR solve?
Issue Number: None
MariaDB DDL can contain syntax that TiDB's parser accepts but TiDB later rejects during DDL validation or execution. One example is a non-time column with a time-function default:
Without a compatibility layer, these statements can pass DM parsing and then fail later when applied downstream.
What is changed and how it works?
This PR adds a focused AST-level DDL rewriter for the DM syncer path. The rewriter is a best-effort compatibility layer for known parser-accepted MariaDB DDL patterns, not a replacement for TiDB's parser or DDL validator. SQL that TiDB's parser rejects never reaches this layer, and DDL failures that can be handled by downstream session settings, such as SQL mode, continue through the normal DM flow.
dm/pkg/ddl/rewriterwith aRewriteStmtentry point and explicit rule options.collation_compatible=strictcollation adjustment into the same rewriter package as an independent strict-collation rule, preserving its existing best-effort behavior.SplitDDLrestores SQL for downstream execution and schema tracking.The MariaDB compatibility rules are selected from both MariaDB's own mysql-test cases and the mariadb2tidb rule set, then narrowed to AST-local transformations that fit DM's row-based sync assumptions. Summarized rule coverage and non-goals:
VARCHAR DEFAULT current_timestamp()orDECIMAL DEFAULT CURRENT_TIMESTAMP(6);DEFAULT NULLand TiDB-supported expression defaults such asDEFAULT(json_object(...));JSON_VALUE(json_doc, path)expressions toJSON_UNQUOTE(JSON_EXTRACT(json_doc, path))as a best-effort TiDB-compatible expression, since TiDB does not provide aJSON_VALUEbuiltin.Rules that would silently change semantics, such as removing generated columns, dropping JSON_VALID checks, removing zero-time defaults that can be handled by adjusted downstream SQL mode, rewriting unique/primary index prefixes, or changing column definitions only to satisfy index limits, are intentionally not enabled.
Check List
Tests
Executed:
Questions
Will it cause performance regression or break compatibility?
No expected performance regression. The rewriter only runs on parsed DDL statements. MariaDB compatibility rules are enabled only for MariaDB upstreams, and strict collation rules are enabled only when
collation_compatible=strict.The compatibility rules are best-effort and intentionally conservative to avoid broad semantic changes. Unsupported parser failures, failures that can be handled by downstream session settings, and unsupported TiDB validation failures outside the verified rule scope continue to be handled by the existing DM flow.
Do you need to update user documentation, design documentation or monitoring documentation?
No user-facing documentation is included in this draft. The change is intentionally scoped to an internal AST rewrite layer and syncer integration. Rule coverage and non-goals are documented in https://pingcap.feishu.cn/wiki/JtgQwqbZTiU2qlkcKjWcbiRrnqc.
Release note