I have a table with ONE bigint-field. Now I would like to insert millions of rows with an increment so I came up with this procedure:
CREATE PROCEDURE insertMe()
BEGIN
DECLARE i BIGINT DEFAULT 1;
WHILE (i <= 999999999) DO
INSERT INTO mytable values(i);
SET i=i+1;
END WHILE;
END;
Of course this beast takes way too long, so normally I would do the following:
INSERT INTO mytable values(1),(2),(3) etc
But how do I create the String then and wouldn’t that take too long as well?
You can use an
AUTO_INCREMENTfield. If you attempt to insert aNULLin that field, MySQL generates the auto number for you so there is no need to build the (1), (2), … string. Give this a try:20 iterations of the above queries on a MyISAM table took ~4.5 seconds.