When to fix auto-increment gaps in MYSQL

后端 未结 2 1676
再見小時候
再見小時候 2021-01-23 04:19

The database I am working on right now has records being added and removed by the 10s of thousands and because of this there are gaps in the auto-incremented key hundreds of tho

2条回答
  •  抹茶落季
    2021-01-23 04:43

    I don't know what the growth rate of your autoincrement field is, but it should be simple math for you to estimate when you will hit the 4294967295 limit.

    If you still feel that you need to do something, you have the following options:

    1. reset the current count to 1. Do this ideally by dropping the column and recreating it. Since you are not using this field for referential integrity, should be a quick and simple fix until the next time...
    2. Change the datatype to an unsigned BIGINT. Now you can go up to 18446744073709551615. But you need more space in the heap to store this increased amount of data, and you have only postponed your problem.
    3. Change from an autoincrement (INT / BIGINT) to a UUID. Then you can stop worrying about numbers and the nature of infinity, but you most likely will have to change all of your client code.

    On a separate note, I sense a poor decision or two somewhere earlier up the line here.

提交回复
热议问题