Why does auto increment jumps by more than the number of rows inserted?
17
votes
3
answers
38467
views
I am very perturbed by this weird behaviour I am seeing in the
auto_increment
value recorded in the bidID of a Bids table after performing bulk insertion using a stored procedure:
INSERT INTO Bids (itemID, buyerID, bidPrice)
SELECT itemID, rand_id(sellerID, user_last_id), FLOOR((1 + RAND())*askPrice)
FROM Items
WHERE closing BETWEEN NOW() AND NOW() + INTERVAL 1 WEEK ORDER BY RAND() LIMIT total_rows;
For example, if the auto_increment
bidID value is 101 at start, and I inserted 100 rows, the ending value becomes 213 instead of 201. However, the bidIDs of those inserted rows runs sequentially to a maximum of 201.
Having check the following,
SHOW VARIABLES LIKE 'auto_inc%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
+--------------------------+-------+
I have no idea why it is happening. What could be causing the jump in the auto increment
value?
Asked by Question Overflow
(1009 rep)
Mar 6, 2014, 10:10 AM
Last activity: May 1, 2023, 04:07 PM
Last activity: May 1, 2023, 04:07 PM