Skip to content

v8.5.6: dm experimentally supports foreign key (#22616)#22740

Merged
ti-chi-bot[bot] merged 6 commits intopingcap:feature/preview-v8.5.6from
ti-chi-bot:cherry-pick-22616-to-release-8.5
Apr 13, 2026
Merged

v8.5.6: dm experimentally supports foreign key (#22616)#22740
ti-chi-bot[bot] merged 6 commits intopingcap:feature/preview-v8.5.6from
ti-chi-bot:cherry-pick-22616-to-release-8.5

Conversation

@ti-chi-bot
Copy link
Copy Markdown
Member

This is an automated cherry-pick of #22616

First-time contributors' checklist

What is changed, added or deleted? (Required)

  • Update four docs pages to document DM's experimental foreign key support shipping in v8.5.6
  • Covers three engineering PRs: tiflow#12351 (safe mode FK), tiflow#12414 (multi-worker causality), tiflow#12329 (DDL whitelist)
  • All behaviors validated against a live build (v8.5.5-12-gd6d53adbe) with 13 test scenarios, all passing
File Change
dm/dm-safe-mode.md Add "Foreign key handling (experimental)" section: non-key UPDATE optimization, session-level FK_CHECKS toggle, multi-worker causality. Add forward-reference from Working principle.
dm/dm-compatibility-catalog.md Rename "Incompatibility with FK CASCADE" to "FK CASCADE operations". Add experimental support with validated constraints (PK/UK guardrail, DDL rejection, routing, BAL ancestor, ON UPDATE CASCADE mismatch).
dm/dm-precheck.md Update FK warning: TiDB supports FKs (GA since v8.5.0), DM experimental since v8.5.6.
foreign-key.md Replace "DM does not support foreign keys" with experimental v8.5.6 support, warning, and backward-compat note.

Which TiDB version(s) do your changes apply to? (Required)

Tips for choosing the affected version(s):

By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.

For details, see tips for choosing the affected versions.

  • master (the latest development version)
  • v9.0 (TiDB 9.0 versions)
  • v8.5 (TiDB 8.5 versions)
  • v8.1 (TiDB 8.1 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)
  • v6.1 (TiDB 6.1 versions)
  • v5.4 (TiDB 5.4 versions)

What is the related PR or file link(s)?

  • This PR is translated from:
  • Other reference link(s):

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

alastori and others added 6 commits April 13, 2026 04:11
Update four docs pages to reflect DM's experimental FK support shipping
in v8.5.6 (PRs pingcap#12351, pingcap#12414, pingcap#12329). All behaviors validated against
a live build (v8.5.5-12-gd6d53adbe, 13 test scenarios, all passing).

dm/dm-safe-mode.md:
- Add "Foreign key handling (experimental)" section with three subsections:
  non-key UPDATE optimization, session-level foreign_key_checks toggle,
  and multi-worker FK causality
- Add forward-reference from Working principle section to FK handling
- Document PK/UK guardrail: task pauses, not silent cascade

dm/dm-compatibility-catalog.md:
- Rename section from "Incompatibility with foreign key CASCADE operations"
  to "Foreign key CASCADE operations"
- Add experimental support description with safe mode and causality details
- List validated constraints: PK/UK guardrail, DDL rejection, routing
  limitation, BAL ancestor requirement, ON UPDATE CASCADE mismatch
- Preserve pre-v8.5.6 behavior description for older versions

dm/dm-precheck.md:
- Update FK warning: TiDB supports FKs (GA since v8.5.0), DM has
  experimental support since v8.5.6. Link to compatibility catalog.

foreign-key.md:
- Replace blanket "DM does not support foreign keys" with experimental
  v8.5.6 support, warning block, and backward-compat note
All 10 suggestions accepted:
- Sentence case headings with backticks for SQL keywords/variables:
  CASCADE, UPDATE, foreign_key_checks
- Second person ("you") in constraint bullets, safe mode intro,
  and foreign-key.md DM section
- Active voice: "DM returns/rejects" instead of passive "is returned"
- Bridge sentence for pre-v8.5.6 backward compat note
Style and clarity improvements across four files per Oreoxmt's review
on pingcap#22616: active voice, second person, sentence-case headings,
consistent terminology (modify/unique key values), anchor fix
(foreign-key-handling), and version-mark span for the new section.
Co-authored-by: Grace Cai <qqzczy@126.com>
@ti-chi-bot ti-chi-bot added lgtm size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR. labels Apr 13, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces documentation for the experimental support of foreign key constraint replication in DM starting from version 8.5.6. The updates cover safe mode optimizations, multi-worker causality, and various operational limitations across several files. The review feedback suggests improving clarity and readability by consistently using the active voice and addressing the user directly as "you," in accordance with the repository's style guide.

Comment on lines +43 to +48
- In safe mode, DM does not support `UPDATE` statements that modify primary key or unique key values. The task is paused with the error `safe-mode update with foreign_key_checks=1 and PK/UK changes is not supported`. To replicate such statements, set `safe-mode: false`.
- When `foreign_key_checks=1`, DM does not support DDL statements that create, modify, or drop foreign key constraints during replication.
- Table routing is not supported when `worker-count > 1`. If you use table routing with tables that include foreign keys, set `worker-count` to `1`.
- The block-allow list must include all ancestor tables in the foreign key dependency chain. If ancestor tables are filtered out, the task is paused with an error during incremental replication.
- Foreign key metadata must be consistent between the source and downstream. If inconsistencies are detected, run `binlog-schema update --from-target` to resynchronize metadata.
- `ON UPDATE CASCADE` is not correctly replicated in safe mode when an `UPDATE` modifies primary key or unique key values. DM rewrites such statements as `DELETE` + `REPLACE`, which triggers `ON DELETE` actions instead of `ON UPDATE` actions. In this case, DM rejects the statement and pauses the task. `UPDATE` statements that do not modify key values are replicated correctly.
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.

low

This list of limitations contains several sentences that use passive voice, such as "The task is paused" and "ON UPDATE CASCADE is not correctly replicated". According to the style guide (lines 43-46), it's better to use active voice for clarity. Addressing the user with "you" where appropriate would also improve readability, as per line 22 of the style guide.

Suggested change
- In safe mode, DM does not support `UPDATE` statements that modify primary key or unique key values. The task is paused with the error `safe-mode update with foreign_key_checks=1 and PK/UK changes is not supported`. To replicate such statements, set `safe-mode: false`.
- When `foreign_key_checks=1`, DM does not support DDL statements that create, modify, or drop foreign key constraints during replication.
- Table routing is not supported when `worker-count > 1`. If you use table routing with tables that include foreign keys, set `worker-count` to `1`.
- The block-allow list must include all ancestor tables in the foreign key dependency chain. If ancestor tables are filtered out, the task is paused with an error during incremental replication.
- Foreign key metadata must be consistent between the source and downstream. If inconsistencies are detected, run `binlog-schema update --from-target` to resynchronize metadata.
- `ON UPDATE CASCADE` is not correctly replicated in safe mode when an `UPDATE` modifies primary key or unique key values. DM rewrites such statements as `DELETE` + `REPLACE`, which triggers `ON DELETE` actions instead of `ON UPDATE` actions. In this case, DM rejects the statement and pauses the task. `UPDATE` statements that do not modify key values are replicated correctly.
- In safe mode, DM does not support `UPDATE` statements that modify primary key or unique key values. DM pauses the task with the error `safe-mode update with foreign_key_checks=1 and PK/UK changes is not supported`. To replicate such statements, set `safe-mode: false`.
- When `foreign_key_checks=1`, DM does not support DDL statements that create, modify, or drop foreign key constraints during replication.
- Table routing is not supported when `worker-count > 1`. If you use table routing with tables that include foreign keys, set `worker-count` to `1`.
- The block-allow list must include all ancestor tables in the foreign key dependency chain. If ancestor tables are filtered out, DM pauses the task with an error during incremental replication.
- Foreign key metadata must be consistent between the source and downstream. If you detect inconsistencies, run `binlog-schema update --from-target` to resynchronize metadata.
- DM does not correctly replicate `ON UPDATE CASCADE` in safe mode when an `UPDATE` modifies primary key or unique key values. DM rewrites such statements as `DELETE` + `REPLACE`, which triggers `ON DELETE` actions instead of `ON UPDATE` actions. In this case, DM rejects the statement and pauses the task. DM replicates `UPDATE` statements that do not modify key values correctly.
References
  1. The style guide recommends using active voice instead of passive voice (e.g., 'TiUP starts the cluster' instead of 'The cluster is started by TiUP'). It also recommends addressing users in the second person ('you'). (link)

- Foreign key metadata must be consistent between the source and downstream. If inconsistencies are detected, run `binlog-schema update --from-target` to resynchronize metadata.
- `ON UPDATE CASCADE` is not correctly replicated in safe mode when an `UPDATE` modifies primary key or unique key values. DM rewrites such statements as `DELETE` + `REPLACE`, which triggers `ON DELETE` actions instead of `ON UPDATE` actions. In this case, DM rejects the statement and pauses the task. `UPDATE` statements that do not modify key values are replicated correctly.

In versions earlier than v8.5.6, DM creates foreign key constraints in the downstream but does not enforce them because it sets the session variable [`foreign_key_checks=OFF`](/system-variables.md#foreign_key_checks). As a result, cascading operations are not replicated to the downstream.
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.

low

The phrase "cascading operations are not replicated to the downstream" uses passive voice. According to the style guide (lines 43-46), it's better to use active voice.

Suggested change
In versions earlier than v8.5.6, DM creates foreign key constraints in the downstream but does not enforce them because it sets the session variable [`foreign_key_checks=OFF`](/system-variables.md#foreign_key_checks). As a result, cascading operations are not replicated to the downstream.
In versions earlier than v8.5.6, DM creates foreign key constraints in the downstream but does not enforce them because it sets the session variable [`foreign_key_checks=OFF`](/system-variables.md#foreign_key_checks). As a result, DM does not replicate cascading operations to the downstream.
References
  1. The style guide recommends using active voice instead of passive voice (e.g., 'TiUP starts the cluster' instead of 'The cluster is started by TiUP'). (link)

Comment thread dm/dm-safe-mode.md

### Non-key `UPDATE` optimization

For `UPDATE` statements that do not modify primary key or unique key values, DM skips the `DELETE` step and executes only `REPLACE INTO`. Because the primary key remains unchanged, `REPLACE INTO` overwrites the existing row without triggering foreign key cascade deletes. This optimization is applied automatically in safe mode.
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.

low

The sentence "This optimization is applied automatically in safe mode" uses passive voice. According to the style guide (lines 43-46), it's better to use active voice.

Suggested change
For `UPDATE` statements that do not modify primary key or unique key values, DM skips the `DELETE` step and executes only `REPLACE INTO`. Because the primary key remains unchanged, `REPLACE INTO` overwrites the existing row without triggering foreign key cascade deletes. This optimization is applied automatically in safe mode.
For `UPDATE` statements that do not modify primary key or unique key values, DM skips the `DELETE` step and executes only `REPLACE INTO`. Because the primary key remains unchanged, `REPLACE INTO` overwrites the existing row without triggering foreign key cascade deletes. DM applies this optimization automatically in safe mode.
References
  1. The style guide recommends using active voice instead of passive voice (e.g., 'TiUP starts the cluster' instead of 'The cluster is started by TiUP'). (link)

Comment thread dm/dm-safe-mode.md

> **Warning:**
>
> When `foreign_key_checks=1`, DM does not support replicating `UPDATE` statements that modify primary key or unique key values. In this case, the replication task is paused with the error `safe-mode update with foreign_key_checks=1 and PK/UK changes is not supported`. To replicate such `UPDATE` statements on tables with foreign keys, set `safe-mode: false`.
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.

low

The phrase "the replication task is paused" uses passive voice. The style guide (lines 43-46) recommends using active voice. Also, addressing the user directly with "you" would improve clarity, as per line 22 of the style guide.

Suggested change
> When `foreign_key_checks=1`, DM does not support replicating `UPDATE` statements that modify primary key or unique key values. In this case, the replication task is paused with the error `safe-mode update with foreign_key_checks=1 and PK/UK changes is not supported`. To replicate such `UPDATE` statements on tables with foreign keys, set `safe-mode: false`.
> When `foreign_key_checks=1`, DM does not support replicating `UPDATE` statements that modify primary key or unique key values. In this case, DM pauses the replication task with the error `safe-mode update with foreign_key_checks=1 and PK/UK changes is not supported`. To replicate such `UPDATE` statements on tables with foreign keys, you need to set `safe-mode: false`.
References
  1. The style guide recommends using active voice instead of passive voice (e.g., 'TiUP starts the cluster' instead of 'The cluster is started by TiUP'). It also recommends addressing users in the second person ('you'). (link)

Comment thread dm/dm-safe-mode.md

### Multi-worker foreign key causality

When you set `worker-count` to a value greater than 1 and the replication task includes tables with foreign keys, DM reads foreign key relationships from the downstream `CREATE TABLE` schema when the task starts. For each DML operation, DM injects causality keys based on these relationships. This ensures that operations on parent rows and their dependent child rows are assigned to the same DML worker queue.
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.

low

The phrase "are assigned to the same DML worker queue" uses passive voice. The style guide (lines 43-46) recommends using active voice for better clarity.

Suggested change
When you set `worker-count` to a value greater than 1 and the replication task includes tables with foreign keys, DM reads foreign key relationships from the downstream `CREATE TABLE` schema when the task starts. For each DML operation, DM injects causality keys based on these relationships. This ensures that operations on parent rows and their dependent child rows are assigned to the same DML worker queue.
When you set `worker-count` to a value greater than 1 and the replication task includes tables with foreign keys, DM reads foreign key relationships from the downstream `CREATE TABLE` schema when the task starts. For each DML operation, DM injects causality keys based on these relationships. This ensures that DM assigns operations on parent rows and their dependent child rows to the same DML worker queue.
References
  1. The style guide recommends using active voice instead of passive voice (e.g., 'TiUP starts the cluster' instead of 'The cluster is started by TiUP'). (link)

Comment thread foreign-key.md
<CustomContent platform="tidb">

- [DM](/dm/dm-overview.md) does not support foreign keys. DM disables the [`foreign_key_checks`](/system-variables.md#foreign_key_checks) of the downstream TiDB when replicating data to TiDB. Therefore, the cascading operations caused by foreign keys are not replicated from the upstream to the downstream, which might cause data inconsistency.
- [DM](/dm/dm-overview.md): starting from v8.5.6, DM supports replicating tables that use foreign key constraints as an experimental feature. For supported scenarios and limitations, see [DM Compatibility Catalog](/dm/dm-compatibility-catalog.md#foreign-key-cascade-operations). In versions earlier than v8.5.6, DM disables the [`foreign_key_checks`](/system-variables.md#foreign_key_checks) system variable when replicating data to TiDB, so cascading operations are not replicated to the downstream cluster.
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.

low

The phrase "cascading operations are not replicated to the downstream cluster" uses passive voice. According to the style guide (lines 43-46), it's better to use active voice.

Suggested change
- [DM](/dm/dm-overview.md): starting from v8.5.6, DM supports replicating tables that use foreign key constraints as an experimental feature. For supported scenarios and limitations, see [DM Compatibility Catalog](/dm/dm-compatibility-catalog.md#foreign-key-cascade-operations). In versions earlier than v8.5.6, DM disables the [`foreign_key_checks`](/system-variables.md#foreign_key_checks) system variable when replicating data to TiDB, so cascading operations are not replicated to the downstream cluster.
- [DM](/dm/dm-overview.md): starting from v8.5.6, DM supports replicating tables that use foreign key constraints as an experimental feature. For supported scenarios and limitations, see [DM Compatibility Catalog](/dm/dm-compatibility-catalog.md#foreign-key-cascade-operations). In versions earlier than v8.5.6, DM disables the [`foreign_key_checks`](/system-variables.md#foreign_key_checks) system variable when replicating data to TiDB, so DM does not replicate cascading operations to the downstream cluster.
References
  1. The style guide recommends using active voice instead of passive voice (e.g., 'TiUP starts the cluster' instead of 'The cluster is started by TiUP'). (link)

@Oreoxmt Oreoxmt changed the base branch from release-8.5 to feature/preview-v8.5.6 April 13, 2026 05:59
@Oreoxmt Oreoxmt self-assigned this Apr 13, 2026
@Oreoxmt
Copy link
Copy Markdown
Collaborator

Oreoxmt commented Apr 13, 2026

/cc @Oreoxmt

@ti-chi-bot ti-chi-bot bot requested a review from Oreoxmt April 13, 2026 06:00
@Oreoxmt
Copy link
Copy Markdown
Collaborator

Oreoxmt commented Apr 13, 2026

/approve

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Apr 13, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Oreoxmt

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Apr 13, 2026
@ti-chi-bot ti-chi-bot bot merged commit 08a4a89 into pingcap:feature/preview-v8.5.6 Apr 13, 2026
12 checks passed
@ti-chi-bot ti-chi-bot bot deleted the cherry-pick-22616-to-release-8.5 branch April 13, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants