Synchronization of Two Tables in the Same TiDB Database Using TiCDC

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 通过ticdc实现 同一个tidb 数据库下的两个表的同步?

| username: TIDB-Learner

There are two tables, test1 and test2, under the database testdb. The table structures are as follows:

CREATE TABLE `test1` (
  `a` varchar(20),
  `b` varchar(20),
  `c` varchar(50),
  `d` varchar(50),
  `e` varchar(50),
  `f` decimal(14,4),
  `g` varchar(100),
  `h` longtext,
  `i` varchar(50),
  `g` datetime(3),
  `k` varchar(50),
  `l` datetime(3),
  `aa` varchar(20),
  `bb` varchar(20),
  `cc` varchar(50),
  `dd` varchar(50),
  `ee` varchar(50),
  `ff` decimal(14,4),
  `gg` varchar(100),
  `hh` longtext,
  `ii` varchar(50),
  `gg` datetime(3),
  `kk` varchar(50),
  `ll` datetime(3),
  PRIMARY KEY (`aa`)
) ENGINE=InnoDB;

CREATE TABLE `test2` (
  `a` varchar(20),
  `b` varchar(20),
  `c` varchar(50),
  `d` varchar(50),
  `e` varchar(50),
  `f` decimal(14,4),
  `g` varchar(100),
  `h` longtext COLLATE,
  `i` varchar(50),
  `g` datetime(3),
  `k` varchar(50),
  `l` datetime(3),
  PRIMARY KEY (`a`),
  UNIQUE KEY `IX_tb_barcode` (`b`)
) ENGINE=InnoDB;

Explanation: Some fields in test1 need to be synchronized to test2, and the primary keys of the two tables are different. If using TiCDC, do you have any good suggestions? Are there any other synchronization methods?

| username: TIDB-Learner | Original post link

Does this table structure meet the requirements for an effective index?

| username: FutureDB | Original post link

We use TiCDC+Kafka+Flink for synchronization between our tables, which can be used for synchronization between both heterogeneous and homogeneous databases.

| username: 迪迦奥特曼 | Original post link

The upstream and downstream table structures need to be consistent.

If they are not consistent, you can only use TiCDC → Kafka → application to consume.

| username: zhaokede | Original post link

I have only done consistent synchronization between upstream and downstream, mainly replicating the database; for different structures, see if it can be handled through the application.

| username: 像风一样的男子 | Original post link

CDC currently does not support specifying database or table names.

| username: Kongdom | Original post link

:thinking: Does TiCDC support data synchronization within the same cluster? It seems like there would be conflicts.

| username: TIDB-Learner | Original post link

What I understand is that the sink is TiDB, and different databases are needed.

| username: Kongdom | Original post link

:thinking: It might be supported, but I haven’t verified it. However, for the same cluster and same database as the original poster, TiCDC should not be able to support it.