Hi! I have a loop in MySQL stored procedure where i insert record almost for each iteration. Well known problem is that inserting row-by-row is inefficient and i'd rather see inserts with multiple value lists instead.
Pseudo-example of current procedure:
CREATE PROCEDURE p_foo_bar()
BEGIN
DECLARE foo VARCHAR(255);
DECLARE my_cursor CURSOR FOR SELECT foo FROM bar;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET not_found = 1;
cursor_loop:
LOOP
FETCH my_cursor INTO foo;
IF not_found THEN
CLOSE my_cursor;
LEAVE
END IF;
IF foo is something ... THEN
INSERT INTO foobar (foo_colum) VALUES (foo);
-- Anyone knows if it is possible to do bulk insert here:
-- For example:
-- INSERT INTO foobar (foo_column) VALUES (foo), ..., (foo123);
END IF;
END LOOP cursor_loop;
END
I'd rather see the INSERT query to grow it's values list for some time and then periodically making inserts in bulks but cannot see the way if it is possible without cooking a huge bowl of spaghetti.