How do you handle the issue where the new data ID with TIDB auto_increment might actually be smaller?

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

Original topic: TIDB auto_increment 新数据 id 反而可能会小 的问题,大家怎么处理的呀?

| username: tidb狂热爱好者

[TiDB Usage Environment] Production Environment
[TiDB Version] 4.0
[Reproduction Path] What operations were performed when the issue occurred
The auto-increment in TiDB is not continuous

[Encountered Issue: Issue Phenomenon and Impact]
[Resource Configuration]
[Attachments: Screenshots/Logs/Monitoring]

| username: ealam_小羽 | Original post link

In our business, this ID is only used as a data ID and will not be used for range queries. If a unique ID for range queries is needed, we currently use the Snowflake algorithm to generate a unique business ID. The new version supports a certain degree of auto-increment (though it seems that using auto_random in a distributed database might be better, as it can reduce hotspots):

| username: jaybing926 | Original post link

Wife, you are awesome~ :kiss: :kiss: :kiss:

| username: tidb狂热爱好者 | Original post link

Actually, upgrading can solve the problem. If you don’t upgrade, just use one TiDB and configure it in primary-secondary mode.

| username: zhimadi | Original post link

How do you handle a large number of old tables?

| username: ealam_小羽 | Original post link

It depends on the specific scenario. Do a lot of old tables rely on this ID for pagination and sorting? If sorting by ID is not required, I personally understand that the issue is not particularly significant. If it is required, you can refer to the TiDB enthusiast’s suggestion: either set up a TiDB primary-secondary configuration or upgrade.

| username: zhimadi | Original post link

AUTO_ID_CACHE is added when creating the table. If a large number of old tables also want this, should we use the method of rebuilding the table, migrating, and importing data to handle it?

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.