How to improve INSERT performance on a very large MySQL table

后端 未结 4 637
刺人心
刺人心 2020-12-17 21:14

I am working on a large MySQL database and I need to improve INSERT performance on a specific table. This one contains about 200 Millions rows and its structure is as follow

4条回答
  •  臣服心动
    2020-12-17 21:54

    You can use the following methods to speed up inserts:

    1. If you are inserting many rows from the same client at the same time, use INSERT statements with multiple VALUES lists to insert several rows at a time. This is considerably faster (many times faster in some cases) than using separate single-row INSERT statements. If you are adding data to a nonempty table, you can tune the bulk_insert_buffer_size variable to make data insertion even faster.

    2. When loading a table from a text file, use LOAD DATA INFILE. This is usually 20 times faster than using INSERT statements.

    3. Take advantage of the fact that columns have default values. Insert values explicitly only when the value to be inserted differs from the default. This reduces the parsing that MySQL must do and improves the insert speed.

    Reference: MySQL.com: 8.2.4.1 Optimizing INSERT Statements

提交回复
热议问题