Do I need to modify the primary key ID field in MySQL tables before migrating to TiDB?

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

Original topic: 请问从mysql迁移到tidb前是否需要修改mysql里面的表主键id字段?

| username: TiDBer_5GvAkLi0

[Test Environment for TiDB] Testing
[TiDB Version] v5.4.2

[Encountered Issue: Problem Description and Impact]
When migrating data from MySQL to TiDB, is it necessary to modify the table structure? Should the primary key ID field be deleted? The main concern is that after migrating to TiDB, the data might not be evenly distributed.

| username: tomsence | Original post link

It depends on your scenario. If you are worried about uneven distribution, it is likely that you have a high read demand. In that case, you should use a clustered table, which generates keys based on the table name and primary key, so a primary key is required. Without using partitioned tables, regions will automatically split and balance based on the data volume. Generally, for OLTP business, it is recommended to use clustered tables without partitioning.

| username: TiDBer_5GvAkLi0 | Original post link

Thank you for your guidance!

| username: TiDBer_5GvAkLi0 | Original post link

It means that when migrating MySQL, there is no need to delete the auto-increment primary key of MySQL. TiDB will automatically balance the distribution of data across various nodes.

| username: 近墨者zyl | Original post link

On the TiDB side, it is necessary to consider whether there will be write hotspots during migration and whether the business will involve write and read hotspots after migration. Because when migrating MySQL’s auto-increment ID to TiDB, if the TiDB side is a cluster type clustered table, the data will be allocated to regions according to the ID primary key. Subsequent inserts will then be sequentially inserted into one region, and when the region reaches 96MB, it will split, causing a write hotspot.

For more details, refer to:

| username: 近墨者zyl | Original post link

Therefore, you cannot simply migrate the auto-increment ID. Whether to delete it or not, or to migrate only other columns without the auto-increment ID, needs to be considered based on the business read and write operations on the business table. Additionally, try to minimize gRPC and reduce distributed transactions.

| username: alfred | Original post link

You can refer to the best practices for schema design, high compatibility mode, and high performance mode.

| username: TiDBer_5GvAkLi0 | Original post link

Thank you for the guidance.

| username: 我是咖啡哥 | Original post link

For core business tables with large data volumes and frequent access, you need to consider the business characteristics. For regular tables, there’s no need to bother.