mysql迴圈插入大量測試資料

2021-09-11 08:31:18 字數 942 閱讀 8848

最近業務場景的需要,mysql單錶要插入大量資料,考慮到單條記錄長短對資料儲存量有很大的影響,所以進行了一次插入檢索測試。

插入**procedure

delimiter $$

drop procedure if exists insert_current_data_uuid $$

create procedure insert_current_data_uuid(in item integer)

begin

declare counter int;

set counter = item;

start transaction; -- 整個儲存過程指定為乙個事務

while counter >= 1 do

insert into current_data (id, label, `value`, totvalue, creat_time)

values(uuid(), 10, 10, 1000, 1551081344);

set counter = counter - 1;

end while;

commit; -- 必須主動提交

end$$

call insert_current_data_uuid(10);

大量插入資料時,必須加上有注釋的兩句,這樣速度會加快。

原因:如果不追加事物,每條資料的插入,都會進行磁碟的io互動,受到磁碟io的瓶頸限制,速度很慢。每分鐘也就是8000天左右。

追加事物了,不受磁碟io限制,暫存到了記憶體緩衝區,效能大大提高,每分鐘200萬條不是夢。

最後在單標中追加了2500條資料後,發現非索引檢索,直接掛掉,最後果斷放棄了單錶大資料的想法,果斷拆表儲存。

最後結論:mysql這種級別的資料,要想業務正常能用,單錶最多儲存資料大幾百萬,超過這個數,果斷採取其他方案,設計時根據業務算好資料量。

mysql造大量測試資料

我們在進行測試時候,有時候需要造大量的測試資料,但是資料庫對於大量資料的插入和刪除很耗時間。1.首先實現自動化 肯定想到的是儲存過程 現在利用工具寫儲存過程很方便,框架都搭好了,填填邏輯就好 2.資料插入 利用批量插入 我試了一下,插了30萬資料14.042s的速度還是很快的 3.資料刪除 最好是直...

Oracle迴圈插入測試資料

declare maxrecords constant int 1000 i int 1 begin for i in 1.maxrecords loop insert into userinfo userid,login,password,firstname,lastname,isadminist...

MYSQL 插入百萬測試資料

1.建表 drop table if exists test user create table test user id int auto increment,name varchar 50 gender tinyint,addr varchar 100 primary key id engine...