mysql中增加全文索引_不要在有全文索引的情况下往 mysql 中插入大量数据

有全文索引的状况下插入数据的图没了,将就着用下其他的。

机器配置:

e07165651c7a4babbe6d0bab994b2d69_image.png

临时搞了张这样的表

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 次。

数据大概长这个样子:

009213603b69456ab7172414a1f02c0b_image.png

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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值