Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: fix rename table across database #11964

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cdc/model/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,15 @@ func (d *DDLEvent) FromJobWithArgs(
case model.ActionDropView:
d.Query = fmt.Sprintf("DROP VIEW `%s`.`%s`",
d.TableInfo.TableName.Schema, d.TableInfo.TableName.Table)
case model.ActionRenameTable:
// Note: preTableInfo may not be accurate for rename table.
// after pr: https://github.com/pingcap/tidb/pull/43341,
// assume there is a table `test.t` and a ddl: `rename table t to test2.t;`, and its commit ts is `100`.
// if you get a ddl snapshot at ts `99`, table `t` is already in `test2`.
// so preTableInfo.TableName.Schema will also be `test2`.
d.Query = fmt.Sprintf("RENAME TABLE `%s`.`%s` TO `%s`.`%s`",
job.InvolvingSchemaInfo[0].Database, job.InvolvingSchemaInfo[0].Table,
tableInfo.TableName.Schema, tableInfo.TableName.Table)
case model.ActionRenameTables:
oldTableName := preTableInfo.Name.O
newTableName := tableInfo.Name.O
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/ddl_manager/data/prepare.sql
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ CREATE TABLE t1 (
col0 INT NOT NULL
);

RENAME TABLE `cross_db_1`.`t1` TO `cross_db_2`.`t1`;
RENAME TABLE `t1` TO `cross_db_2`.`t1`;

CREATE TABLE `cross_db_1`.`t2` like `cross_db_2`.`t1`;

Expand Down
Loading