Is there any harm in resetting the auto-increment?

后端 未结 6 694
北荒
北荒 2020-12-11 18:23

I have a 100 million rows, and it\'s getting too big. I see a lot of gaps. (since I delete, add, delete, add.)

I want to fill these gaps with auto-increment. If I do

6条回答
  •  遥遥无期
    2020-12-11 18:36

    Chances are you wouldn't gain anything from doing this, and you could easily screw up your application by overwriting rows, since you're going to reset the count for the IDs. (In other words, the next time you insert a row, it'll overwrite the row with ID 1, and then 2, etc.) What will you gain from filling the gaps? If the number gets too big, just change it to a larger number (such as BIGINT).


    Edit: I stand corrected. It won't do anything at all, which supports my point that you should just change the type of the column to a larger integer type. The maximum possible value for a BIGINT is 2^64, which is over 18 quintillion. If you only have 100 million rows at the moment, that should be plenty for the foreseeable future.

提交回复
热议问题