Skip to content

ddl: Handle mlog name confliction for materialized view#68841

Open
xzhangxian1008 wants to merge 8 commits into
pingcap:feature/release-8.5-materialized-view-2603from
xzhangxian1008:mlog-name-2603
Open

ddl: Handle mlog name confliction for materialized view#68841
xzhangxian1008 wants to merge 8 commits into
pingcap:feature/release-8.5-materialized-view-2603from
xzhangxian1008:mlog-name-2603

Conversation

@xzhangxian1008
Copy link
Copy Markdown
Contributor

@xzhangxian1008 xzhangxian1008 commented Jun 1, 2026

What problem does this PR solve?

Issue Number: close #68840 #66768

Problem Summary:

What changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Handle mlog name confliction for materialized view

Summary by CodeRabbit

  • Bug Fixes

    • Improved materialized view log creation: deterministic name generation (handles base names with $mlog$), retries on name conflicts, enforces table-name length limits, and returns clearer errors when a log already exists or name allocation fails.
  • Tests

    • Added and updated tests covering name generation, conflict retries, length-edge cases, and creation failure scenarios.

@ti-chi-bot ti-chi-bot Bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jun 1, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Jun 1, 2026

[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 tangenta 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 the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 1, 2026
@tiprow
Copy link
Copy Markdown

tiprow Bot commented Jun 1, 2026

Hi @xzhangxian1008. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

Centralizes MLog name generation and lookup: adds exported generation/lookup primitives, exposes GenerateMLogTableName on executors, changes CreateMaterializedViewLog to accept a generated name, implements retry-on-conflict in DDL executor, updates MV DDL paths to use resolved MLog metadata, and adds tests and small build tweaks.

Changes

Materialized View Log Name Generation and Conflict Handling

Layer / File(s) Summary
MLog naming primitives and validation helpers
pkg/ddl/materialized_view.go
Atomic sequences, exported errors, IsMLogTableNameConflict, GenerateMLogTableName, GetExistenceOfMLogTableNameChecker, and GetMLogTableByBaseTable implement deterministic $mlog$ naming, conflict retries, and rune-length enforcement.
Executor interface changes and GenerateMLogTableName implementation
pkg/ddl/executor.go
ddl.Executor gains GenerateMLogTableName; CreateMaterializedViewLog now accepts mlogTableName. Executor resolves schema/base table, checks MaterializedViewBase.MLogID, and delegates to naming helpers.
Schema tracker interface changes and DDL executor delegation
pkg/ddl/schematracker/checker.go, pkg/ddl/schematracker/dm_tracker.go, pkg/executor/ddl.go
Checker/SchemaTracker expose GenerateMLogTableName; CreateMaterializedViewLog accepts and forwards mlogTableName. DDLExec routes CREATE MATERIALIZED VIEW LOG to executeCreateMaterializedViewLog.
Executor retry loop on name conflicts
pkg/executor/ddl.go
executeCreateMaterializedViewLog loops: call GenerateMLogTableName, attempt CreateMaterializedViewLog with that name, inject a failpoint, and retry on name-conflict errors with exponential backoff.
Materialized view execution path refactoring
pkg/ddl/materialized_view.go, pkg/executor/materialized_view.go, pkg/ddl/create_table.go
CreateMaterializedView, DropMaterializedViewLog, AlterMaterializedViewLog, and purge-resolution use GetMLogTableByBaseTable to resolve MLog metadata and derive mlogName; creation error paths map table-exists to dedicated MLog errors.
Unit tests, integration tests, and build configuration
pkg/ddl/ddl_test.go, pkg/executor/ddl_test.go, pkg/ddl/schematracker/dm_tracker_test.go, pkg/executor/test/ddl/mview_log_ddl_test.go, pkg/ddl/schematracker/BUILD.bazel, pkg/executor/BUILD.bazel
Adds tests for name generation edge cases (conflicts, length, $mlog$ prefix), executor retry behavior, deterministic test sequence reset helpers, schema-tracker conflict rejection test, and minor Bazel test target updates.

Sequence Diagram(s)

sequenceDiagram
  participant Client as DDL Client
  participant DDLExec
  participant Executor
  participant Naming
  Client->>DDLExec: Next(CREATE MATERIALIZED VIEW LOG)
  loop Retry on conflict
    DDLExec->>Executor: GenerateMLogTableName(ctx, stmt)
    Executor->>Naming: compute candidate name
    Naming-->>Executor: mlogTableName
    DDLExec->>Executor: CreateMaterializedViewLog(ctx, stmt, mlogTableName)
    alt Name conflict
      Executor-->>DDLExec: conflict error
      DDLExec->>DDLExec: wait and retry
    else Success
      Executor-->>DDLExec: nil
      DDLExec-->>Client: OK
    else Other error
      Executor-->>DDLExec: error
      DDLExec-->>Client: error
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • pingcap/tidb#68649: Related MV-log purge and MLog resolution changes touching the same execution path.
  • pingcap/tidb#68819: Overlaps on MLog name derivation and related DDL refactors.
  • pingcap/tidb#68766: Modifies MV-log creation path and MV-log column derivation alongside these changes.

Suggested labels

sig/planner

Suggested reviewers

  • windtalker
  • gengliqi
  • wshwsh12

Poem

🐰 I counted names in atomic rows,
If one was taken, off I goes.
A tiny retry, numbers climb,
Rune-safe names in proper time.
Hop—new mlog found, no name fights woes.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description follows the template structure with Issue Number, checked test boxes, and a release note, but lacks substantive content in critical sections. Add detailed problem summary and comprehensive 'What changed and how does it work?' explanation to clarify the mlog name conflict handling implementation.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'ddl: Handle mlog name confliction for materialized view' clearly and concisely describes the main change: handling materialized view log (mlog) name conflicts in the DDL module.
Linked Issues check ✅ Passed The PR changes fully address the linked issue #68840 objectives. The implementation introduces mlog name generation with conflict handling, retry logic with exponential backoff, atomic sequence management, and comprehensive tests validating name generation across multiple scenarios.
Out of Scope Changes check ✅ Passed All changes in the PR are directly related to handling mlog name conflicts for materialized views. The modifications span DDL execution, schema tracking, name generation, and testing—all within the scope of the linked issue #68840.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (1)
pkg/ddl/schematracker/checker.go (1)

279-282: ⚡ Quick win

Compare tracker-generated and real-generated MLog names here.

Right now the checker delegates name generation only to realExecutor, then feeds that same name into d.tracker.CreateMaterializedViewLog. That means a bug in SchemaTracker.GenerateMLogTableName would no longer be caught by this checker, even though name-conflict handling is the main behavior being changed in this PR.

Suggested change
func (d *Checker) GenerateMLogTableName(ctx sessionctx.Context, s *ast.CreateMaterializedViewLogStmt) (string, error) {
-	return d.realExecutor.GenerateMLogTableName(ctx, s)
+	name, err := d.realExecutor.GenerateMLogTableName(ctx, s)
+	if err != nil || d.closed.Load() {
+		return name, err
+	}
+	trackerName, err := d.tracker.GenerateMLogTableName(ctx, s)
+	if err != nil {
+		panic(err)
+	}
+	if name != trackerName {
+		panic(fmt.Sprintf("inconsistent mlog name, real ddl: %s, schematracker: %s", name, trackerName))
+	}
+	return name, nil
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/ddl/schematracker/checker.go` around lines 279 - 282, The current
Checker.GenerateMLogTableName just delegates to
d.realExecutor.GenerateMLogTableName and then passes that same name to
d.tracker.CreateMaterializedViewLog, so mismatches in
SchemaTracker.GenerateMLogTableName are never detected; change
GenerateMLogTableName to call both d.realExecutor.GenerateMLogTableName(ctx, s)
and d.tracker.GenerateMLogTableName(ctx, s), compare the two returned names, and
if they differ return an error (or wrap the discrepancy in the returned error)
so the checker fails fast; keep the successful behavior unchanged by continuing
to use the realExecutor name for downstream calls like
d.tracker.CreateMaterializedViewLog when names match.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/ddl/executor.go`:
- Around line 1122-1123: This path returns infoschema.ErrTableExists for the
case where baseTable.Meta().MaterializedViewBase != nil and baseInfo.MLogID !=
0, which the caller treats as retryable; change it to return a distinct,
non-retryable error so callers won't retry on an already-created MLog. Replace
the infoschema.ErrTableExists return in that branch with a new clearly-named
error (e.g., infoschema.ErrMLogAlreadyExists or a sentinel error variable) or
wrap the message using a non-retryable error constructor, ensuring the condition
references baseInfo, baseTable.Meta().MaterializedViewBase and MLogID so the
returned error is unique from table-name-collision ErrTableExists.

In `@pkg/ddl/materialized_view.go`:
- Around line 104-124: The length checks are using candidate.L (lowercased
string) which can expand in runes for some Unicode characters; update both
occurrences to use utf8.RuneCountInString(candidate.O) instead of candidate.L in
the materialized view log name logic (the block that calls checkTableExistence,
the conditional returning candidate.O, and the loop that generates names via
nextMLogTableNameNumber/MLogShortTableNameSeq/materializedViewLogTablePrefix)
and keep the dbterror.ErrTooLongIdent handling unchanged.

In `@pkg/ddl/schematracker/dm_tracker.go`:
- Around line 234-237: GenerateMLogTableName currently returns a hardcoded "not
implemented" which causes CREATE MATERIALIZED VIEW LOG to fail; implement it in
SchemaTracker to compute and return the correct materialized-view-log table name
from the provided ast.CreateMaterializedViewLogStmt and sessionctx.Context
(validate the stmt, derive schema/name, apply the project's naming convention
and uniqueness rules, and return an error only for validation failures). Locate
the method named GenerateMLogTableName on type SchemaTracker and replace the
stub with logic that extracts the target database/table from the ast node,
constructs the mlog table name (consistent with existing naming helpers used
elsewhere in SchemaTracker), and returns that name and any validation error
instead of the current hardcoded error.

In `@pkg/executor/ddl.go`:
- Around line 340-344: The current retry loop treats any
infoschema.ErrTableExists returned from CreateMaterializedViewLog as a
name-conflict and keeps retrying, but CreateMaterializedViewLog also returns
ErrTableExists for terminal cases like "base table already has an MLog"; change
the contract so GenerateMLogTableName/CreateMaterializedViewLog return a
distinct sentinel error (e.g., ErrMlogNameConflict) for pure table-name races
and keep the existing ErrTableExists for terminal MLog-already-exists
conditions, then update the retry logic in the loop that calls
e.ddlExecutor.CreateMaterializedViewLog(e.Ctx(), stmt, mlogTableName) to only
continue/retry when the error equals the new ErrMlogNameConflict and otherwise
surface/return the error. Ensure the new sentinel is documented and used by
GenerateMLogTableName and CreateMaterializedViewLog consistently.

---

Nitpick comments:
In `@pkg/ddl/schematracker/checker.go`:
- Around line 279-282: The current Checker.GenerateMLogTableName just delegates
to d.realExecutor.GenerateMLogTableName and then passes that same name to
d.tracker.CreateMaterializedViewLog, so mismatches in
SchemaTracker.GenerateMLogTableName are never detected; change
GenerateMLogTableName to call both d.realExecutor.GenerateMLogTableName(ctx, s)
and d.tracker.GenerateMLogTableName(ctx, s), compare the two returned names, and
if they differ return an error (or wrap the discrepancy in the returned error)
so the checker fails fast; keep the successful behavior unchanged by continuing
to use the realExecutor name for downstream calls like
d.tracker.CreateMaterializedViewLog when names match.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ec03e328-3f91-41f3-a33b-7cb1c2be7bb6

📥 Commits

Reviewing files that changed from the base of the PR and between 7a81553 and 2f422c1.

📒 Files selected for processing (12)
  • pkg/ddl/ddl_test.go
  • pkg/ddl/executor.go
  • pkg/ddl/materialized_view.go
  • pkg/ddl/schematracker/BUILD.bazel
  • pkg/ddl/schematracker/checker.go
  • pkg/ddl/schematracker/dm_tracker.go
  • pkg/ddl/schematracker/dm_tracker_test.go
  • pkg/executor/BUILD.bazel
  • pkg/executor/ddl.go
  • pkg/executor/ddl_test.go
  • pkg/executor/materialized_view.go
  • pkg/executor/test/ddl/mview_log_ddl_test.go

Comment thread pkg/ddl/executor.go Outdated
Comment on lines +104 to +124
exists, err := checkTableExistence(candidate)
if err != nil {
return "", err
}

if !exists && utf8.RuneCountInString(candidate.L) <= mysql.MaxTableNameLength {
return candidate.O, nil
}

for {
var err error
number, err := nextMLogTableNameNumber(
&MLogShortTableNameSeq,
"materialized view log short table name number is out of range",
)
if err != nil {
return "", err
}
candidate = pmodel.NewCIStr(materializedViewLogTablePrefix + strconv.FormatUint(number, 10))
if utf8.RuneCountInString(candidate.L) > mysql.MaxTableNameLength {
return "", dbterror.ErrTooLongIdent.GenWithStackByArgs(candidate)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C2 'type CIStr|func NewCIStr|RuneCountInString\(candidate\.[LO]\)' pkg/parser pkg/ddl/materialized_view.go

python - <<'PY'
samples = ["İ", "I", "ß"]
for s in samples:
    print(repr(s), "orig_runes=", len(s), "lower=", repr(s.lower()), "lower_runes=", len(s.lower()))
PY

Repository: pingcap/tidb

Length of output: 1434


Fix identifier length validation to use candidate.O (not candidate.L)

CIStr.L is produced by strings.ToLower, and Unicode lowercasing can increase rune count (e.g. İ -> ). Using utf8.RuneCountInString(candidate.L) at Lines 109 and 123 can therefore incorrectly trigger the short-name fallback / dbterror.ErrTooLongIdent for valid identifiers. Use candidate.O for the length check.

Suggested fix
-	if !exists && utf8.RuneCountInString(candidate.L) <= mysql.MaxTableNameLength {
+	if !exists && utf8.RuneCountInString(candidate.O) <= mysql.MaxTableNameLength {
 		return candidate.O, nil
 	}
@@
-		if utf8.RuneCountInString(candidate.L) > mysql.MaxTableNameLength {
+		if utf8.RuneCountInString(candidate.O) > mysql.MaxTableNameLength {
 			return "", dbterror.ErrTooLongIdent.GenWithStackByArgs(candidate)
 		}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
exists, err := checkTableExistence(candidate)
if err != nil {
return "", err
}
if !exists && utf8.RuneCountInString(candidate.L) <= mysql.MaxTableNameLength {
return candidate.O, nil
}
for {
var err error
number, err := nextMLogTableNameNumber(
&MLogShortTableNameSeq,
"materialized view log short table name number is out of range",
)
if err != nil {
return "", err
}
candidate = pmodel.NewCIStr(materializedViewLogTablePrefix + strconv.FormatUint(number, 10))
if utf8.RuneCountInString(candidate.L) > mysql.MaxTableNameLength {
return "", dbterror.ErrTooLongIdent.GenWithStackByArgs(candidate)
exists, err := checkTableExistence(candidate)
if err != nil {
return "", err
}
if !exists && utf8.RuneCountInString(candidate.O) <= mysql.MaxTableNameLength {
return candidate.O, nil
}
for {
var err error
number, err := nextMLogTableNameNumber(
&MLogShortTableNameSeq,
"materialized view log short table name number is out of range",
)
if err != nil {
return "", err
}
candidate = pmodel.NewCIStr(materializedViewLogTablePrefix + strconv.FormatUint(number, 10))
if utf8.RuneCountInString(candidate.O) > mysql.MaxTableNameLength {
return "", dbterror.ErrTooLongIdent.GenWithStackByArgs(candidate)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/ddl/materialized_view.go` around lines 104 - 124, The length checks are
using candidate.L (lowercased string) which can expand in runes for some Unicode
characters; update both occurrences to use utf8.RuneCountInString(candidate.O)
instead of candidate.L in the materialized view log name logic (the block that
calls checkTableExistence, the conditional returning candidate.O, and the loop
that generates names via
nextMLogTableNameNumber/MLogShortTableNameSeq/materializedViewLogTablePrefix)
and keep the dbterror.ErrTooLongIdent handling unchanged.

Comment on lines +234 to +237
// GenerateMLogTableName implements the DDL interface.
func (*SchemaTracker) GenerateMLogTableName(sessionctx.Context, *ast.CreateMaterializedViewLogStmt) (string, error) {
return "", errors.New("not implemented")
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Implement GenerateMLogTableName before wiring it into the executor path.

The new DDL flow now calls this method first, so returning "not implemented" makes every schema-tracker CREATE MATERIALIZED VIEW LOG fail at runtime.

Proposed direction
-// GenerateMLogTableName implements the DDL interface.
-func (*SchemaTracker) GenerateMLogTableName(sessionctx.Context, *ast.CreateMaterializedViewLogStmt) (string, error) {
-	return "", errors.New("not implemented")
-}
+// GenerateMLogTableName implements the DDL interface.
+func (d *SchemaTracker) GenerateMLogTableName(ctx sessionctx.Context, s *ast.CreateMaterializedViewLogStmt) (string, error) {
+	// Mirror the same schema/base-table validation used by CreateMaterializedViewLog,
+	// then delegate the actual conflict-free name generation to ddl.GenerateMLogTableName
+	// with ddl.GetExistenceOfMLogTableNameChecker(..., InfoStoreAdaptor{inner: d.InfoStore}, ...).
+}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/ddl/schematracker/dm_tracker.go` around lines 234 - 237,
GenerateMLogTableName currently returns a hardcoded "not implemented" which
causes CREATE MATERIALIZED VIEW LOG to fail; implement it in SchemaTracker to
compute and return the correct materialized-view-log table name from the
provided ast.CreateMaterializedViewLogStmt and sessionctx.Context (validate the
stmt, derive schema/name, apply the project's naming convention and uniqueness
rules, and return an error only for validation failures). Locate the method
named GenerateMLogTableName on type SchemaTracker and replace the stub with
logic that extracts the target database/table from the ast node, constructs the
mlog table name (consistent with existing naming helpers used elsewhere in
SchemaTracker), and returns that name and any validation error instead of the
current hardcoded error.

Comment thread pkg/executor/ddl.go
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

❌ Patch coverage is 0% with 181 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (feature/release-8.5-materialized-view-2603@7a81553). Learn more about missing BASE report.

⚠️ Current head 2f422c1 differs from pull request most recent head 717fe24

Please upload reports for the commit 717fe24 to get more accurate results.

Additional details and impacted files
@@                               Coverage Diff                               @@
##             feature/release-8.5-materialized-view-2603     #68841   +/-   ##
===============================================================================
  Coverage                                              ?   22.2740%           
===============================================================================
  Files                                                 ?       1712           
  Lines                                                 ?     645266           
  Branches                                              ?          0           
===============================================================================
  Hits                                                  ?     143727           
  Misses                                                ?     483490           
  Partials                                              ?      18049           
Flag Coverage Δ
integration 22.2740% <0.0000%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling ∅ <0.0000%> (?)
parser ∅ <0.0000%> (?)
br 23.5629% <0.0000%> (?)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Jun 3, 2026

@xzhangxian1008: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-br-integration-test 717fe24 link true /test pull-br-integration-test
idc-jenkins-ci-tidb/mysql-test 717fe24 link true /test mysql-test
pull-unit-test-ddlv1 717fe24 link true /test pull-unit-test-ddlv1
idc-jenkins-ci-tidb/unit-test 717fe24 link true /test unit-test
idc-jenkins-ci-tidb/check_dev 717fe24 link true /test check-dev
idc-jenkins-ci-tidb/build 717fe24 link true /test build
idc-jenkins-ci-tidb/check_dev_2 717fe24 link true /test check-dev2

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/ddl/schematracker/dm_tracker.go (1)

252-275: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Preserve the new MLog error contract here.

This existence check now runs before the base-table guard and returns infoschema.ErrTableExists, which collapses two distinct cases: retryable generated-name conflicts and “base table already has an MLog”. For the duplicate-create case, this masks ddl.ErrMLogAlreadyExists; for genuine name clashes, callers lose the ddl.ErrMLogTableNameConflict sentinel that pkg/ddl/create_table.go now emits.

Suggested fix
  mlogNameCIStr := pmodel.NewCIStr(mlogTableName)
- mlogExists, err := ddl.GetExistenceOfMLogTableNameChecker(
- 	context.Background(),
- 	InfoStoreAdaptor{inner: d.InfoStore},
- 	schemaName,
- )(mlogNameCIStr)
-
- if err != nil {
- 	return err
- }
-
- if mlogExists {
- 	return infoschema.ErrTableExists.GenWithStackByArgs(ast.Ident{Schema: schemaName, Name: mlogNameCIStr})
- }
-
  baseTable, err := d.TableClonedByName(schemaName, s.Table.Name)
  if err != nil {
  	return err
  }
  if baseTable.IsView() || baseTable.IsSequence() || baseTable.TempTableType != model.TempTableNone {
  	return dbterror.ErrWrongObject.GenWithStackByArgs(schemaName, s.Table.Name, "BASE TABLE")
  }
  if baseTable.MaterializedViewBase != nil && baseTable.MaterializedViewBase.MLogID != 0 {
  	return ddl.ErrMLogAlreadyExists.GenWithStackByArgs(ast.Ident{Schema: schemaName, Name: baseTable.Name})
  }
+ mlogExists, err := ddl.GetExistenceOfMLogTableNameChecker(
+ 	context.Background(),
+ 	InfoStoreAdaptor{inner: d.InfoStore},
+ 	schemaName,
+ )(mlogNameCIStr)
+ if err != nil {
+ 	return err
+ }
+ if mlogExists {
+ 	return ddl.ErrMLogTableNameConflict.GenWithStackByArgs(ast.Ident{Schema: schemaName, Name: mlogNameCIStr})
+ }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/ddl/schematracker/dm_tracker.go` around lines 252 - 275, The existence
check for mlog currently runs before validating the base table, which masks the
specific ddl errors; move the call to d.TableClonedByName and the base-table
guards (checks using baseTable.IsView(), IsSequence(), TempTableType and
baseTable.MaterializedViewBase.MLogID) to run before invoking
ddl.GetExistenceOfMLogTableNameChecker/mlogExists so you can return
ddl.ErrMLogAlreadyExists when the base table already has an MLog; afterwards run
the mlog existence check and, on name conflict, return the specific
ddl.ErrMLogTableNameConflict (using the same ast.Ident arguments) instead of
infoschema.ErrTableExists so callers retain the new MLog error contract.
♻️ Duplicate comments (1)
pkg/ddl/schematracker/dm_tracker.go (1)

233-235: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Implement SchemaTracker.GenerateMLogTableName.

This still returns "not implemented", so any schema-tracker/checker path that follows the new GenerateMLogTableNameCreateMaterializedViewLog flow fails immediately.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/ddl/schematracker/dm_tracker.go` around lines 233 - 235, Implement
SchemaTracker.GenerateMLogTableName so it no longer returns the placeholder
error: use the receiver (*SchemaTracker) to compute the materialized view log
table name by invoking the existing CreateMaterializedViewLog flow (or the
internal helper that derives MLog names) with the provided
*ast.CreateMaterializedViewLogStmt and sessionctx.Context, and return the
resulting name and any error; ensure the method signature matches
GenerateMLogTableName(sessionctx.Context, *ast.CreateMaterializedViewLogStmt)
(string, error) and propagate errors instead of returning "not implemented".
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@pkg/ddl/schematracker/dm_tracker.go`:
- Around line 252-275: The existence check for mlog currently runs before
validating the base table, which masks the specific ddl errors; move the call to
d.TableClonedByName and the base-table guards (checks using baseTable.IsView(),
IsSequence(), TempTableType and baseTable.MaterializedViewBase.MLogID) to run
before invoking ddl.GetExistenceOfMLogTableNameChecker/mlogExists so you can
return ddl.ErrMLogAlreadyExists when the base table already has an MLog;
afterwards run the mlog existence check and, on name conflict, return the
specific ddl.ErrMLogTableNameConflict (using the same ast.Ident arguments)
instead of infoschema.ErrTableExists so callers retain the new MLog error
contract.

---

Duplicate comments:
In `@pkg/ddl/schematracker/dm_tracker.go`:
- Around line 233-235: Implement SchemaTracker.GenerateMLogTableName so it no
longer returns the placeholder error: use the receiver (*SchemaTracker) to
compute the materialized view log table name by invoking the existing
CreateMaterializedViewLog flow (or the internal helper that derives MLog names)
with the provided *ast.CreateMaterializedViewLogStmt and sessionctx.Context, and
return the resulting name and any error; ensure the method signature matches
GenerateMLogTableName(sessionctx.Context, *ast.CreateMaterializedViewLogStmt)
(string, error) and propagate errors instead of returning "not implemented".

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7b28c68f-bd39-47b9-97e3-98524ff647a6

📥 Commits

Reviewing files that changed from the base of the PR and between 2f422c1 and 717fe24.

📒 Files selected for processing (7)
  • pkg/ddl/create_table.go
  • pkg/ddl/executor.go
  • pkg/ddl/materialized_view.go
  • pkg/ddl/schematracker/dm_tracker.go
  • pkg/executor/ddl.go
  • pkg/executor/ddl_test.go
  • pkg/executor/test/ddl/mview_log_ddl_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • pkg/executor/ddl.go
  • pkg/ddl/executor.go
  • pkg/ddl/materialized_view.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant