有全文索引的状况下插入数据的图没了,将就着用下其他的。
机器配置:
临时搞了张这样的表
create table big_single_table(
id int not null auto_increment,
owner_id int not null,
title varchar(2000) not null,
create_date datetime not null ,
byte_data blob not null,
num1 double not null ,
content text not null,
int_type int not null,
string_type varchar(200) not null,
is_deleted bit not null ,
primary key pk_id (`id`),
index idx_name (`title`(100)),
index idx_int_type (`int_type`),
index idx_string_type(`string_type`),
index idx_owner_id(`owner_id`),
index idx_num1(`num1`),
index idx_is_deleted(`is_deleted`),
index idx_o_s_i_n(`owner_id`,`string_type`,`int_type`,`num1`)
fulltext index ft_title_content (title,content)
)
COLLATE = 'utf8mb4_unicode_ci'
ENGINE = InnoDB
AUTO_INCREMENT = 1;
然后用 Java 中写了个循环,分批插入,每批 1000 条,循环 10000 次。
数据大概长这个样子:
content 字段用长度 2000 的随机字段填充。
第一次运行后内存占用率不断升高,不久后程序出异常,MySQL 的终端也显示连接断开。
调了半天参数减小了插入速度后总算是跑起来了,虽然插入速度很慢,大致维持在 10m/s 的速度。
MySQL 内存占用 1.6G,但是没有继续增长的迹象。于是就睡觉去了。
今天起来一看,插入程序已经结束了,但是内存占用还是 1.6G,dstat 查看监控信息发现没有写入,CPU 占用率也是 0。
网上查了一票,估计是内存溢出了,解决办法没找到。。。不过大概率是 fulltext 的问题,
注释掉后重新插入速度恢复到 45m/s 左右,内存占用维持在 260m。
总结:fulltext 会极大降低插入速度,且插入大量数据时有导致内存溢出的风险。
如果真的需要 fulltext,应先插入数据,然后使用如下语句创建索引。
ALTER TABLE article ADD FULLTEXT INDEX fdx_xxx(xxx);