Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when an auto-incrementing column runs out?

Tags:

Consider a simple table with an auto-increment column like this:

CREATE TABLE foo  (   `fooid` bigint unsigned NOT NULL auto_increment,    ....snipped.... other columns   PRIMARY KEY (`fooid`) )  ENGINE=InnoDB AUTO_INCREMENT=10 

How does one redesign this so that we don't hit the max of the bigint datatype ? The unsigned range is 0 to 18446744073709551615. I don't know how long it will take to reach 18446744073709551615, but like the Y2K problem, I want to be ready for it.

like image 634
ashitaka Avatar asked Dec 12 '08 07:12

ashitaka


1 Answers

Suppose you insert one row every millisecond.

18446744073709551615 millseconds = 18446744073709552 seconds = 307445734561826 minutes = 5124095576030 hours = 213503982335 days = 584942417 years

So it's not really like the Y2K problem

You could insert a million rows per millisecond and still be okay for over 500 years.

In other words: don't worry about it.

like image 170
Jon Skeet Avatar answered Sep 26 '22 06:09

Jon Skeet