There are many self-incrementing ids in MySQL, and each self-increasing id defines an initial value, and then keeps increasing the step size. Although there is no upper limit for natural numbers, in a computer, as long as the byte length representing this number is defined, it has an upper limit. For example, unsigned integer (unsigned int) is 4 bytes, the upper limit is 232-1.
Since the auto-increment id has an upper limit, it may be used up. But what happens when the self-incrementing id is used up? In today's article, let's take a look at several self-increasing ids in MySQL, and analyze what happens when their values reach the upper limit.
Table definition self-increment id
When it comes to auto-increment id, the first thing you think of should be the auto-increment field in the table structure definition, that is, my previous article "Why is the auto-increment primary key not continuous?" "In and the self-incrementing primary key id you introduced.
The logic after the self-increment value defined by the table reaches the upper limit is: when applying for the next id, the obtained value remains unchanged.
We can verify it through the following statement sequence:
create table t(id int unsigned auto_increment primary key) auto_increment=4294967295;
insert into t values(null);
//Successfully insert a row 4294967295
show create table t;
/* CREATE TABLE t
(
id
int (10) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY ( id
)
) ENGINE=InnoDB AUTO_INCREMENT=4294967295;
*/
insert into t values(null);
//Duplicat