Changefeed DDL Replication

This document describes the rules and special cases of DDL replication in TiCDC.

DDL allow list

Currently, TiCDC uses an allow list to determine whether to replicate a DDL statement. Only the DDL statements in the allow list are replicated to the downstream. The DDL statements not in the allow list are not replicated.

The allow list of DDL statements supported by TiCDC is as follows:

  • create database
  • drop database
  • create table
  • drop table
  • add column
  • drop column
  • create index / add index
  • drop index
  • truncate table
  • modify column
  • rename table
  • alter column default value
  • alter table comment
  • rename index
  • add partition
  • drop partition
  • truncate partition
  • create view
  • drop view
  • alter table character set
  • alter database character set
  • recover table
  • add primary key
  • drop primary key
  • rebase auto id
  • alter table index visibility
  • exchange partition
  • reorganize partition
  • alter table ttl
  • alter table remove ttl

DDL replication considerations

Due to the lack of some context during the replication process, TiCDC has some constraints on the replication of RENAME TABLE DDLs.

Rename a single table in a DDL statement

If a DDL statement renames a single table, TiCDC only replicates the DDL statement when the old table name matches the filter rule. The following is an example.

Assume that the configuration file of your changefeed is as follows:

  1. [filter]
  2. rules = ['test.t*']

TiCDC processes this type of DDL as follows:

DDLWhether to replicateReason for the handling
RENAME TABLE test.t1 TO test.t2Replicatetest.t1 matches the filter rule
RENAME TABLE test.t1 TO ignore.t1Replicatetest.t1 matches the filter rule
RENAME TABLE ignore.t1 TO ignore.t2Ignoreignore.t1 does not match the filter rule
RENAME TABLE test.n1 TO test.t1Report an error and exit the replicationtest.n1 does not match the filter rule, but test.t1 matches the filter rule. This operation is illegal. In this case, refer to the error message for handling.
RENAME TABLE ignore.t1 TO test.t1Report an error and exit the replicationSame reason as above.

Rename multiple tables in a DDL statement

If a DDL statement renames multiple tables, TiCDC only replicates the DDL statement when the old database name, old table names, and the new database name all match the filter rule.

In addition, TiCDC does not support the RENAME TABLE DDL that swaps the table names. The following is an example.

Assume that the configuration file of your changefeed is as follows:

  1. [filter]
  2. rules = ['test.t*']

TiCDC processes this type of DDL as follows:

DDLWhether to replicateReason for the handling
RENAME TABLE test.t1 TO test.t2, test.t3 TO test.t4ReplicateAll database names and table names match the filter rule.
RENAME TABLE test.t1 TO test.ignore1, test.t3 TO test.ignore2ReplicateThe old database name, the old table names, and the new database name match the filter rule.
RENAME TABLE test.t1 TO ignore.t1, test.t2 TO test.t22;Report an errorThe new database name ignore does not match the filter rule.
RENAME TABLE test.t1 TO test.t4, test.t3 TO test.t1, test.t4 TO test.t3;Report an errorThe RENAME TABLE DDL swaps the names of test.t1 and test.t3 in one DDL statement, which TiCDC cannot handle correctly. In this case, refer to the error message for handling.

SQL mode

By default, TiCDC uses the default SQL mode of TiDB to parse DDL statements. If your upstream TiDB cluster uses a non-default SQL mode, you must specify the SQL mode in the TiCDC configuration file. Otherwise, TiCDC might fail to parse DDL statements correctly. For more information about TiDB SQL mode, see SQL Mode.

For example, if the upstream TiDB cluster uses the ANSI_QUOTES mode, you must specify the SQL mode in the changefeed configuration file as follows:

  1. # In the value, "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" is the default SQL mode of TiDB.
  2. # "ANSI_QUOTES" is the SQL mode added to your upstream TiDB cluster.
  3. sql-mode = "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES"

If the SQL mode is not configured, TiCDC might fail to parse some DDL statements correctly. For example:

  1. CREATE TABLE "t1" ("a" int PRIMARY KEY);

Because in the default SQL mode of TiDB, double quotation marks are treated as strings rather than identifiers, TiCDC fails to parse the DDL statement correctly.

Therefore, when creating a replication task, it is recommended that you specify the SQL mode used by the upstream TiDB cluster in the configuration file.