Recently we came uncomfortably close to running out of auto increment values in a MySQL table. The following is a description of how it happened and what we did about it.
Cause
We thought the table had been created with plenty of auto
increment values. We used an unsigned int for the auto increment
primary key, so it had a maximum value of about 4 billion. We
happen to use an auto_increment_increment
of 4 in
this particular environment, so I figured the table could
accomodate about 1 billion rows before we ran out of values. Six
years of data in that table totalled 100 Million rows, and given
the nature of the data the row count will not increase much
faster than that even if our business grows dramatically, so I
wasn't worried about running out of auto increment values in this
table for at least 20 years.
Those assumptions are fine as long as we're only inserting data into the table and never deleting from …
[Read more]