Is there any harm in resetting the auto-increment?

后端 未结 6 697
北荒
北荒 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:45

    Does it really matter if there are gaps?

    If you really want to go back and fill them, you can always turn off auto increment, and manually scan for the next available id every time you want to insert a row -- remembering to lock the table to avoid race conditions, of course. But it's a lot of work to do for not much gain.

    Do you really need a surrogate key anyway? Depending on the data (you haven't mentioned a schema) you can probably find a natural key.

提交回复
热议问题