儲存過程 + insert into values (),(),();插入海量資料
阿新 • • 發佈:2019-02-04
發現該文儲存過程中使用 insert into values
插入資料,但是每次只插入一條資料,因此,決定一次插入十條觀察效率
測試環境: Mysql 5.7, Navicat 12.0.18
插入10萬條資料結果:
其中 set global general_log = on 用於開啟日誌,off 用於關閉日誌。 general_log 將所有到達MySQL Server的SQL語句記錄下來。
程式碼如下
-- 建立插入資料的儲存過程 DROP PROCEDURE IF EXISTS `add_vote_record_memory`; DELIMITER // CREATE PROCEDURE `add_vote_record_memory`(IN n INT) BEGIN DECLARE i INT DEFAULT 1; WHILE i < n DO INSERT INTO `vote_record_memory` VALUES (NULL, rand_string(20), FLOOR(1 + RAND() * 10000), FLOOR(0 + RAND()*3), FLOOR(1 + RAND()*2), NOW()), (NULL, rand_string(20), FLOOR(1 + RAND() * 10000), FLOOR(0 + RAND()*3), FLOOR(1 + RAND()*2), NOW()), (NULL, rand_string(20), FLOOR(1 + RAND() * 10000), FLOOR(0 + RAND()*3), FLOOR(1 + RAND()*2), NOW()), (NULL, rand_string(20), FLOOR(1 + RAND() * 10000), FLOOR(0 + RAND()*3), FLOOR(1 + RAND()*2), NOW()), (NULL, rand_string(20), FLOOR(1 + RAND() * 10000), FLOOR(0 + RAND()*3), FLOOR(1 + RAND()*2), NOW()), (NULL, rand_string(20), FLOOR(1 + RAND() * 10000), FLOOR(0 + RAND()*3), FLOOR(1 + RAND()*2), NOW()), (NULL, rand_string(20), FLOOR(1 + RAND() * 10000), FLOOR(0 + RAND()*3), FLOOR(1 + RAND()*2), NOW()), (NULL, rand_string(20), FLOOR(1 + RAND() * 10000), FLOOR(0 + RAND()*3), FLOOR(1 + RAND()*2), NOW()), (NULL, rand_string(20), FLOOR(1 + RAND() * 10000), FLOOR(0 + RAND()*3), FLOOR(1 + RAND()*2), NOW()), (NULL, rand_string(20), FLOOR(1 + RAND() * 10000), FLOOR(0 + RAND()*3), FLOOR(1 + RAND()*2), NOW()); SET i = i + 10; END WHILE; END // DELIMITER ; -- 改回預設的 MySQL delimiter:';'
站在巨人的肩膀上,才能尿得更遠。。。