Skip to content

checker(dm): improve same table precheck error#12729

Open
GMHDBJD wants to merge 1 commit into
pingcap:masterfrom
GMHDBJD:fix-dm-precheck-same-table-20260617212415
Open

checker(dm): improve same table precheck error#12729
GMHDBJD wants to merge 1 commit into
pingcap:masterfrom
GMHDBJD:fix-dm-precheck-same-table-20260617212415

Conversation

@GMHDBJD

@GMHDBJD GMHDBJD commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #12737

DM precheck can report a confusing raw table-router error when route rules only differ by table-name case under case-insensitive matching, for example:

RawCause: table test.T matches more than one rule

This hides the existing clearer same-target-table diagnostic.

What is changed and how it works?

Add a checker-side preflight for case-insensitive route rules before building the regular-expression table router.

The preflight detects source table patterns that collide after case folding and map to target tables that differ only by case, then returns the existing ErrTaskCheckSameTableName error with actionable details such as:

same target table `test`.`T` vs `test`.`t`

This preserves the clearer DM precheck error path and avoids exposing the router's ambiguous duplicate-rule message.

Check List

Tests

  • Unit test

Commands run:

go test ./dm/checker -run 'TestSameTargetTableDetection(BeforeRouteDupMatch)?$' -count=1
go test ./dm/checker -count=1
make fmt
git diff --check

Questions

Will it cause performance regression or break compatibility?

No. The change only adds a lightweight route-rule validation step during checker initialization and reuses the existing same-table-name error type.

Do you need to update user documentation, design documentation or monitoring documentation?

No.

Release note

Fix a confusing DM precheck error message when case-insensitive route rules for the same source table differ only by table-name case.

@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jun 18, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign joechenrh for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found 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 area/dm Issues or PRs related to DM. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 18, 2026

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

Copy link
Copy Markdown

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 a pre-check (sameTargetTableNameDetectionForRouteRules) to detect case-insensitive target table name conflicts in route rules before the table router is initialized. This prevents confusing "matches more than one rule" errors from being thrown by regexprrouter during precheck. Feedback on the changes suggests changing the condition else if nameO != name to a simple else to ensure that duplicate or colliding rules mapping to the exact same target table name (including case) are also caught and reported.

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.

Comment thread dm/checker/checker.go
Comment on lines +924 to +928
if nameO, ok := tableNameSets[nameL]; !ok {
tableNameSets[nameL] = name
} else if nameO != name {
messages = append(messages, fmt.Sprintf("same target table %v vs %s", nameO, name))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

If two route rules collide under case-insensitive matching but map to the exact same target table name (including case), nameO == name will be true. Because of the else if nameO != name condition, this collision will not be detected by this preflight check, and the user will still encounter the confusing matches more than one rule error from regexprrouter.

Changing this to a simple else ensures that any duplicate or colliding rules for the same source table pattern are caught and reported with a clear error message.

Suggested change
if nameO, ok := tableNameSets[nameL]; !ok {
tableNameSets[nameL] = name
} else if nameO != name {
messages = append(messages, fmt.Sprintf("same target table %v vs %s", nameO, name))
}
if nameO, ok := tableNameSets[nameL]; !ok {
tableNameSets[nameL] = name
} else {
messages = append(messages, fmt.Sprintf("same target table %v vs %s", nameO, name))
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, this is reasonable. Updated the preflight to catch any case-insensitive source-rule collision, including collisions that map to the exact same target table name, and added regression coverage for that case.

@GMHDBJD GMHDBJD force-pushed the fix-dm-precheck-same-table-20260617212415 branch from 563f2d1 to fd049f8 Compare June 22, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/dm Issues or PRs related to DM. do-not-merge/needs-triage-completed release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DM precheck reports confusing error for case-insensitive route conflicts

1 participant