当前位置:网站首页>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 .
边栏推荐
- QT writing security video monitoring system 36 onvif continuous movement
- 数据库,查询本月借出书的数量,如果高于10本时,显示“本月借出书大于10本”,否则显示“本月借出书小于10本”
- Use cpulimit to free up your CPU
- Two methods of QT exporting PDF files
- DHCP, TFTP Foundation
- jwt(json web token)
- Qt源码分析--QObject(2)
- Scénarios d'utilisation de la promesse
- 487. number of maximum consecutive 1 II ●●
- "Wechat cloud hosting" first practical battle | introduction to minimalist demo
猜你喜欢
随机推荐
Cloudbase database migration scheme
win11在cmder中使用vim查看内容的时候空白
Export MySQL database to xxx SQL, set xxx The SQL file is imported into MySQL on the server. Project deployment.
获取屏幕宽高工具类
Three categories of financial assets under the new standards: AMC, fvoci and FVTPL
JS scroll div scroll bar to bottom
Question 4 - datepicker date selector, disabling two date selectors (start and end dates)
Fundamentals of 3D mathematics [17] inverse square theorem
[real estate opening online house selection, WiFi coverage temporary network] 500 people are connected to WiFi at the same time
QT writing security video monitoring system 36 onvif continuous movement
分布式 | 如何与 DBLE 进行“秘密通话”
dataX使用指南
Glusterfs replacement failure brick
QPS, TPS, concurrent users, throughput relationship
os. path. Pits encountered during the use of join()
利用sonar做代码检查
【力扣10天SQL入门】Day2
Vscode install the remote -wsl plug-in to connect to the local WSL
DHCP, TFTP Foundation
How to configure networkpolicy for nodeport in kubernetes








