Skip to content

Conversation

@wlwilliamx
Copy link
Collaborator

What problem does this PR solve?

Issue Number: close #3832

What is changed and how it works?

Fix downstream schema inconsistency for CREATE TABLE ... LIKE ... when the referenced table has a long-running ADD INDEX that is still running/queueing in downstream TiDB. In this case, CREATE TABLE b LIKE a may copy the current downstream schema of a before the index becomes visible, causing b to miss the index.

This PR makes CREATE TABLE ... LIKE ... wait for any running async ADD INDEX on the referenced table before executing the CREATE TABLE ... LIKE ....

  • Detect CREATE TABLE ... LIKE ... in schemastore when building DDLEvent, extract the referenced table, and populate BlockedTableNames with that referenced table.
  • Adjust mysql/TiDB sink behavior so CREATE TABLE is eligible for async-DDL waiting logic; for normal create table (no LIKE), this is a no-op because BlockedTableNames is empty. For CREATE TABLE ... LIKE ..., it triggers waiting on the referenced table’s running ADD
    INDEX job.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test

Questions

Will it cause performance regression or break compatibility?

None

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

None

Release note

Please refer to [Release Notes Language Style Guide](https://pingcap.github.io/tidb-dev-guide/contribute-to-tidb/release-notes-style-guide.html) to write a quality release note.

If you don't think this PR needs a release note then fill it with `None`.

@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 Dec 31, 2025
@ti-chi-bot
Copy link

ti-chi-bot bot commented Dec 31, 2025

[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 lidezhu 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

@wlwilliamx wlwilliamx requested a review from lidezhu December 31, 2025 09:55
@ti-chi-bot ti-chi-bot bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 31, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @wlwilliamx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical schema consistency problem in TiCDC where a CREATE TABLE ... LIKE ... statement might not correctly replicate the schema of a source table if that source table is undergoing an asynchronous ADD INDEX operation. The changes ensure that such CREATE TABLE operations will now pause and wait for any in-progress index additions on the referenced table to complete, guaranteeing that the newly created table accurately reflects the complete schema, including all indexes, of its source. This prevents potential data integrity issues and ensures reliable schema replication.

Highlights

  • Schema Inconsistency Fix: Resolves an issue where CREATE TABLE ... LIKE ... could lead to schema inconsistencies if the referenced table had a long-running ADD INDEX operation that was not yet visible.
  • Referenced Table Detection: Implements logic to detect CREATE TABLE ... LIKE ... statements, identify the referenced table, and populate BlockedTableNames in the DDL event to trigger waiting.
  • Async DDL Waiting for CREATE TABLE: Modifies the sink behavior to allow CREATE TABLE statements (specifically CREATE TABLE ... LIKE ... when a referenced table is blocked) to wait for pending async DDL operations on the referenced table.
  • Integration Test Enhancement: Adds an integration test to validate that CREATE TABLE ... LIKE ... correctly waits for and inherits indexes from the source table, ensuring the fix works as expected.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@wlwilliamx wlwilliamx changed the title Fix/create table like dont wait add index fix(ddl): wait running add index before CREATE TABLE LIKE Dec 31, 2025
Copy link

@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 effectively addresses the schema inconsistency issue with CREATE TABLE ... LIKE ... by ensuring it waits for any ongoing ADD INDEX operations on the referenced table. The approach of identifying the referenced table in the schemastore and adjusting the sink's waiting logic is sound. The changes are well-supported by both unit and integration tests, which provides good confidence in the fix. I have one minor suggestion to improve code readability.

@wlwilliamx
Copy link
Collaborator Author

/retest

@wlwilliamx
Copy link
Collaborator Author

/test all

@ti-chi-bot
Copy link

ti-chi-bot bot commented Dec 31, 2025

@wlwilliamx: 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-cdc-kafka-integration-light 318ea9b link true /test pull-cdc-kafka-integration-light
pull-cdc-mysql-integration-heavy 318ea9b link true /test pull-cdc-mysql-integration-heavy
pull-cdc-mysql-integration-light 318ea9b link true /test pull-cdc-mysql-integration-light
pull-cdc-mysql-integration-light-next-gen 318ea9b link false /test pull-cdc-mysql-integration-light-next-gen
pull-cdc-kafka-integration-heavy 318ea9b link true /test pull-cdc-kafka-integration-heavy

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.

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

fix create table like in schemastore

1 participant