当前位置:网站首页>Increase insert speed
Increase insert speed
2022-06-24 08:40:00 【An unreliable programmer】
When the amount of data I collect reaches 8000 When all , When batch inserting data into a table with a unique index , Need to check for duplicates , So the insertion speed becomes slower and slower . Today, let's talk about how to improve INSERT Execution speed of .
Batch insert is faster than single 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”);
Use 1 Batch insert writing of , It can greatly improve the insertion speed .
Make rational use of the database buffer
It can be turned up bulk_insert_buffer_size This parameter . The default is 8M.
This parameter only applies to the use of MyISAM Storage engine , It is used to temporarily cache the write data when the batch insert data is cached .mysql This memory area will be used to cache the data of batch structure to help batch write data files .
For example, the buffer The size is set to 100M.
set global bulk_insert_buffer_size = 1024*1024*100;
use INSERT DELAYED Delay insertion
When a client uses INSERT DELAYED when , Will immediately get a confirmation from the server . And the rows are queued , When the table is not used by other threads , This line is inserted .
Use INSERT DELAYED Another important benefit of is , The insertions from many clients are lumped together , And written into a block . It's much faster than doing a lot of independent insertions .
We need to pay attention to :
- INSERT DELAYED Should only be used to specify the value list INSERT sentence . Server ignored for INSERT DELAYED…SELECT Of the statement DELAYED.
- Server ignored for INSERT DELAYED…ON DUPLICATE UPDATE Of the statement DELAYED.
- Because before the row is inserted , Statement immediately returns , So you cannot use LAST_INSERT_ID() To get AUTO_INCREMENT value .AUTO_INCREMENT Values may be generated by statements .
- about SELECT sentence ,DELAYED Row invisible , Until these lines are actually inserted .
- DELAYED Ignored in secondary replication server , because DELAYED The secondary server will not generate data different from the primary server .
- Currently, the rows in the queue are only saved in memory , Until they are inserted into the table . It means , If you forcibly abort mysqld( for example , Use kill -9) Or if mysqld The accident stopped , All rows that have not been written to the disk will be lost .
边栏推荐
- [micro services ~nacos] Nacos service providers and service consumers
- 【力扣10天SQL入门】Day3
- How to implement approval function in Tekton
- OpenCV to realize the basic transformation of image
- Rust procedure macro simply imitates Lombok function
- jwt(json web token)
- "Wechat cloud hosting" first practical battle | introduction to minimalist demo
- JUC个人简单笔记
- Common misconceptions in Tencent conference API - signature error_ code 200003
- One development skill a day: how to establish P2P communication based on webrtc?
猜你喜欢

OpenCV to realize the basic transformation of image

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

2022 mobile crane driver special operation certificate examination question bank and online simulation examination

Permission model DAC ACL RBAC ABAC

Small sample fault diagnosis - attention mechanism code - Implementation of bigru code parsing
![Fundamentals of 3D mathematics [17] inverse square theorem](/img/59/bef931d96883288766fc94e38e0ace.png)
Fundamentals of 3D mathematics [17] inverse square theorem

JUC personal simple notes

Synthesize video through ffmpeg according to m3u8 file of video on the network

12-- merge two ordered linked lists

ZUCC_ Principles of compiling language and compilation_ Experiment 01 language analysis and introduction
随机推荐
[explain the difference between operation and maintenance and network engineering]
Qt源码分析--QObject(2)
Scénarios d'utilisation de la promesse
2021-03-11 comp9021 class 8 notes
2021-06-24: find the length of the longest non repeating character substring in a string.
Introduction to RCNN, fast RCNN and fast RCNN
新技术实战,一步步用Activity Results API封装权限申请库
常用日期格式符与Qt获取当前时间的办法
Rescue system -- the application of read-write separation
Redis cluster data skew
Easydss anonymous live channel data volume instability optimization scheme sharing
leetcode 1642. Furthest Building You Can Reach(能到达的最远的建筑)
api平台通用签名机制
QTimer定时器不起作用的原因
WPS的JS宏实现图片正文在同一段落的分离方法
Final review and key points of software process and project management
Common misconceptions in Tencent conference API - signature error_ code 200003
(PKCS1) RSA 公私钥 pem 文件解析
Promise的使用場景
提高INSERT速度