Skip to content

schemastore: fix create table like with unqualified source table#5023

Open
lidezhu wants to merge 9 commits into
masterfrom
ldz/fix-schema-store0512
Open

schemastore: fix create table like with unqualified source table#5023
lidezhu wants to merge 9 commits into
masterfrom
ldz/fix-schema-store0512

Conversation

@lidezhu
Copy link
Copy Markdown
Collaborator

@lidezhu lidezhu commented May 12, 2026

What problem does this PR solve?

Issue Number: close #5025

What is changed and how it works?

This pull request addresses issues with 'CREATE TABLE ... LIKE' DDL replication, particularly when the source database is not explicitly specified. By improving the schema resolution logic within the persisted storage handler, the system can now correctly identify and replicate tables across different schemas and databases, including support for partitioned tables. These changes ensure more reliable DDL replication in complex environments.

Highlights

  • Schema Resolution Logic: Introduced a robust helper function to resolve referenced schemas in 'CREATE TABLE ... LIKE' statements, prioritizing explicit schema definitions and falling back to inference from 'InvolvingSchemaInfo' when necessary.
  • Query Rewriting: Added functionality to rewrite and restore the DDL query when the source schema is inferred, ensuring consistent replication behavior.
  • Testing Enhancements: Expanded unit tests to validate query output and schema inference, and added comprehensive integration tests covering cross-database and partitioned table scenarios.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

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

Summary by CodeRabbit

  • Bug Fixes

    • More robust handling of CREATE TABLE ... LIKE across schemas: resolves referenced schema from LIKE clause, involving metadata, or event fallback; rewrites queries when inferred and populates referenced table/partition IDs.
  • Tests

    • Added unit tests verifying refer-schema selection, query rewrite behavior, and preservation when same schema.
    • Extended integration scenarios to cover cross-database and partitioned LIKE replication.
  • Chores

    • Adjusted CI test-group definitions for heavy and light integration runs.

Review Change Stack

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 12, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@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. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels May 12, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5a0ba326-f37f-4b71-94dd-03c11b90cd21

📥 Commits

Reviewing files that changed from the base of the PR and between 08a4a06 and 1373d26.

📒 Files selected for processing (2)
  • logservice/schemastore/persist_storage_ddl_handlers.go
  • logservice/schemastore/persist_storage_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • logservice/schemastore/persist_storage_ddl_handlers.go

📝 Walkthrough

Walkthrough

Refactors persisted DDL handling for CREATE TABLE ... LIKE: add a resolver that selects the referenced schema from the explicit LIKE clause, InvolvingSchemaInfo, or the event schema; optionally rewrite the parsed query when inferring schema. Includes unit tests, integration scenarios, and CI test-group updates.

Changes

CREATE TABLE LIKE Schema Resolution

Layer / File(s) Summary
Schema resolution contract and helper
logservice/schemastore/persist_storage_ddl_handlers.go
Added createTableLikeReferSchemaInfo and implemented resolveCreateTableLikeReferSchema to resolve referenced schema by preferring explicit LIKE clause, then InvolvingSchemaInfo SharedInvolving entries, then falling back to the event schema.
DDL handler integration
logservice/schemastore/persist_storage_ddl_handlers.go
Updated setReferTableForCreateTableLike to call the resolver, conditionally rewrite and restore event.Query when the resolver infers the schema, and use the resolved schema/ID to find referenced table and partition IDs with warnings on failure.
Unit test coverage
logservice/schemastore/persist_storage_test.go
Extended TestBuildPersistedDDLEventForCreateTableLikeSetsReferTableID with expectedQuery to optionally validate ddl.Query; added tests asserting schema inference from InvolvingSchemaInfo and same-schema behavior preserving the original query.
Integration test scenarios
tests/integration_tests/consistent_replicate_ddl/run.sh
Added cross-database CREATE TABLE ... LIKE setup (including a partitioned LIKE), DML around partition truncation, and downstream check_table_exists verifications for the new destination tables.
CI heavy-group additions
tests/integration_tests/run_heavy_it_in_ci.sh
Appended cli_tls_with_auth to multiple heavy integration test-group definitions across MySQL/Kafka/Pulsar/Storage groups.
CI light-group removals
tests/integration_tests/run_light_it_in_ci.sh
Removed cli_tls_with_auth from fail_over_ddl_N-related light test-group entries across sink types.

Sequence Diagram(s)

(omitted — change is focused on resolver and local handler call flow already summarized above)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • pingcap/ticdc#4416: Modifies persist_storage_ddl_handlers.go to improve resolving referenced schema/table names from InvolvingSchemaInfo and to rewrite persisted DDL Query accordingly.

Suggested labels

lgtm

Suggested reviewers

  • wk989898
  • hongyunyan
  • tenfyzhong

Poem

🐰 I hopped through ASTs, sniffed a missing name,
Rewrote a LIKE so cross-db calls stay sane,
Tests chase the casing, partitions then align,
CI runs the groups, the flow now feels fine,
I nibble carrots while TiCDC keeps time.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: fixing CREATE TABLE LIKE support for unqualified source tables in the schema store layer.
Description check ✅ Passed The PR description includes the required Issue Number, explains the problem and solution with highlights, and covers test coverage (unit and integration tests).
Linked Issues check ✅ Passed Changes directly address issue #5025: introduces schema resolution logic for unqualified LIKE references, handles cross-database scenarios, supports partitioned tables, and includes comprehensive test coverage.
Out of Scope Changes check ✅ Passed All code changes focus on fixing CREATE TABLE LIKE schema resolution and related testing; CI script changes only reorganize test group assignments without introducing unrelated functionality.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ldz/fix-schema-store0512

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

Command failed


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.

@ti-chi-bot ti-chi-bot Bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label May 12, 2026
Copy link
Copy Markdown

@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 enhances the integration tests for consistent DDL replication by introducing a cross-database CREATE TABLE ... LIKE test case. The reviewer suggested improving the robustness of the test by specifying explicit character sets and collations for the new database, using fully qualified table names in DDL statements to prevent context-related failures in replication, and adding verification steps for the source table in the downstream environment.

Comment thread tests/integration_tests/consistent_replicate_ddl/run.sh
Comment thread tests/integration_tests/consistent_replicate_ddl/run.sh
Comment thread tests/integration_tests/consistent_replicate_ddl/run.sh
@ti-chi-bot ti-chi-bot Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 12, 2026
@ti-chi-bot ti-chi-bot Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 12, 2026
@lidezhu lidezhu changed the title add some test schemastore: fix create table like when source database is ommited May 12, 2026
@lidezhu lidezhu changed the title schemastore: fix create table like when source database is ommited schemastore: fix create table like when source database is not specified May 12, 2026
@lidezhu lidezhu marked this pull request as ready for review May 12, 2026 04:38
@ti-chi-bot ti-chi-bot Bot removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/needs-linked-issue labels May 12, 2026
@lidezhu
Copy link
Copy Markdown
Collaborator Author

lidezhu commented May 12, 2026

/gemini summary

@lidezhu
Copy link
Copy Markdown
Collaborator Author

lidezhu commented May 12, 2026

@coderabbitai review

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

This pull request addresses issues with 'CREATE TABLE ... LIKE' DDL replication, particularly when the source database is not explicitly specified. By improving the schema resolution logic within the persisted storage handler, the system can now correctly identify and replicate tables across different schemas and databases, including support for partitioned tables. These changes ensure more reliable DDL replication in complex environments.

Highlights

  • Schema Resolution Logic: Introduced a robust helper function to resolve referenced schemas in 'CREATE TABLE ... LIKE' statements, prioritizing explicit schema definitions and falling back to inference from 'InvolvingSchemaInfo' when necessary.
  • Query Rewriting: Added functionality to rewrite and restore the DDL query when the source schema is inferred, ensuring consistent replication behavior.
  • Testing Enhancements: Expanded unit tests to validate query output and schema inference, and added comprehensive integration tests covering cross-database and partitioned table scenarios.
New Features

🧠 You can now enable Memory (public preview) 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.

Activity
  • The pull request was created by lidezhu.
  • Automated CI checks were skipped as the PR was initially in draft status.
  • CodeRabbit provided a summary and suggested improvements, including potential collation settings and more robust SQL syntax for integration tests.
  • Gemini-code-assist provided review comments suggesting explicit character sets, fully qualified table names in tests, and additional verification steps for integration tests.
  • The author requested a summary of the pull request.

@lidezhu
Copy link
Copy Markdown
Collaborator Author

lidezhu commented May 12, 2026

/gemini review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lidezhu lidezhu changed the title schemastore: fix create table like when source database is not specified schemastore: fix create table like with unqualified source table May 12, 2026
Copy link
Copy Markdown

@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 enhances the resolution of the source table's schema for CREATE TABLE ... LIKE statements, particularly for cross-database operations. It introduces logic to infer the source schema from InvolvingSchemaInfo and ensures the resulting DDL query is fully qualified when necessary. The changes include new unit and integration tests to verify these scenarios. Review feedback suggests optimizing the fallback logic in resolveCreateTableLikeReferSchema by using the job's SchemaID directly instead of performing a redundant name-based lookup.

Comment thread logservice/schemastore/persist_storage_ddl_handlers.go Outdated
@lidezhu
Copy link
Copy Markdown
Collaborator Author

lidezhu commented May 12, 2026

/test all

@lidezhu
Copy link
Copy Markdown
Collaborator Author

lidezhu commented May 12, 2026

/retest

@lidezhu
Copy link
Copy Markdown
Collaborator Author

lidezhu commented May 12, 2026

/test all

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented May 12, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wk989898

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
Copy link
Copy Markdown

ti-chi-bot Bot commented May 12, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-05-12 06:59:54.730588974 +0000 UTC m=+162563.263368303: ☑️ agreed by wk989898.

@ti-chi-bot ti-chi-bot Bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels May 12, 2026
@lidezhu
Copy link
Copy Markdown
Collaborator Author

lidezhu commented May 12, 2026

/retest

@lidezhu
Copy link
Copy Markdown
Collaborator Author

lidezhu commented May 12, 2026

/test all

@lidezhu
Copy link
Copy Markdown
Collaborator Author

lidezhu commented May 12, 2026

/retest

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

Labels

approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. 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.

ticdc fail to sync cross-database CREATE TABLE ... LIKE when refer schema is not specified

2 participants