Answer the question
In order to leave comments, you need to log in
How to make sure that there are no gaps in the generated values of an auto-incrementing primary key?
MySQL 5.7 has an InnoDB table with an auto-increment surrogate primary key: id INT UNSIGNED NOT NULL AUTO_INCREMENT. An application writes data to this table through a stored function in single-threaded mode, making records to the table one by one. How can I make sure that there are no gaps in the generated id values (I am not responsible for the operation of the external application, but it may try to write data that does not pass validation to the table)?
The stored function through which the application writes to the database table looks like this:
CREATE FUNCTION insert_material (n VARCHAR(255), d DATE) RETURNS INT UNSIGNED
BEGIN
INSERT INTO Material(name, date) VALUE(n, d);
RETURN LAST_INSERT_ID();
END
Answer the question
In order to leave comments, you need to log in
Stop doing nonsense ;)
Stop paying attention to the holes in the auto-increment and focus on the application logic.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question