当前位置:网站首页>提高INSERT速度
提高INSERT速度
2022-06-24 07:03:00 【一个不靠谱的程序员】
当我采集的数据量达到8000万时,往一张具有唯一索引的表里批量插入数据时,需要检查重复,因此插入速度越来越慢。今天就来聊下如何提高INSERT的执行速度。
批量插入比单条插入速度快
INSERT INTO table (field1,field2,field3) VALUES (‘a’,“b”,“c”), (‘a’,“b”,“c”),(‘a’,“b”,“c”);
INSERT INTO table (field1,field2,field3) VALUES (‘a’,“b”,“c”);INSERT INTO table (field1,field2,field3) VALUES (‘a’,“b”,“c”);INSERT INTO table (field1,field2,field3) VALUES (‘a’,“b”,“c”);
使用1的批量插入写法,能大大提高插入速度。
合理利用数据库buffer
可以调大bulk_insert_buffer_size这个参数。默认为8M。
这个参数仅作用于使用 MyISAM存储引擎,用来缓存批量插入数据的时候临时缓存写入数据。mysql会使用这个内存区域来缓存批量结构的数据以帮助批量写入数据文件。
例如将该buffer大小设置为100M。
set global bulk_insert_buffer_size = 1024*1024*100;
用INSERT DELAYED延迟插入
当一个客户端使用INSERT DELAYED时,会立刻从服务器处得到一个确定。并且行被排入队列,当表没有被其它线程使用时,此行被插入。
使用INSERT DELAYED的另一个重要的好处是,来自许多客户端的插入被集中在一起,并被编写入一个块。这比执行许多独立的插入要快很多。
需要注意:
- INSERT DELAYED应该仅用于指定值清单的INSERT语句。服务器忽略用于INSERT DELAYED…SELECT语句的DELAYED。
- 服务器忽略用于INSERT DELAYED…ON DUPLICATE UPDATE语句的DELAYED。
- 因为在行被插入前,语句立刻返回,所以您不能使用LAST_INSERT_ID()来获取AUTO_INCREMENT值。AUTO_INCREMENT值可能由语句生成。
- 对于SELECT语句,DELAYED行不可见,直到这些行确实被插入了为止。
- DELAYED在从属复制服务器中被忽略了,因为DELAYED不会在从属服务器中产生与主服务器不一样的数据。
- 目前在队列中的各行只保存在存储器中,直到它们被插入到表中为止。这意味着,如果您强行中止了mysqld(例如,使用kill -9) 或者如果mysqld意外停止,则所有没有被写入磁盘的行都会丢失。
边栏推荐
- ZUCC_ Principles of compiling language and compilation_ Experiment 01 language analysis and introduction
- 13 -- remove invalid parentheses
- 独立站运营中如何提升客户留存率?客户细分很重要!
- List of Li Bai's 20 most classic poems
- Three categories of financial assets under the new standards: AMC, fvoci and FVTPL
- Live broadcast appointment: growth of Mengxin Product Manager
- ZUCC_编译语言原理与编译_实验06 07 语法分析 LL 分析
- The reason why the qtimer timer does not work
- 05-ubuntu安装mysql8
- 05 Ubuntu installing mysql8
猜你喜欢

ZUCC_编译语言原理与编译_实验03 编译器入门

ZUCC_编译语言原理与编译_实验02 FSharp OCaml语言

Redis的Cluster集群数据倾斜

Question 3 - MessageBox pop-up box, modify the default background color

JUC个人简单笔记

OpenCV to realize the basic transformation of image

LabVIEW finds prime numbers in an array of n elements

How to improve the customer retention rate in the operation of independent stations? Customer segmentation is very important!

独立站运营中如何提升客户留存率?客户细分很重要!

Maya re deployment
随机推荐
中国芯片独角兽公司
LabVIEW finds prime numbers in an array of n elements
Battle history between redis and me under billion level traffic
Pyqt common system events
The article takes you to understand the security of Windows operating system and protect your computer from infringement
IIS build wordpress5.7 manually
Permission model DAC ACL RBAC ABAC
List of Li Bai's 20 most classic poems
How to mount a USB hard disk with NTFS file format under RHEL5 system
[real estate opening online house selection, WiFi coverage temporary network] 500 people are connected to WiFi at the same time
QTimer定时器不起作用的原因
5 minutes, excellent customer service chat handling skills
JS merge multiple objects and remove duplicates
独立站运营中如何提升客户留存率?客户细分很重要!
饼状统计图,带有标注线,都可以自行设定其多种参数选项
Common misconceptions in Tencent conference API - signature error_ code 200003
图片工具
pyQt 常用系统的事件
Application of tidb in Netease games
ZUCC_编译语言原理与编译_实验01 语言分析与简介