Recently, a service reports that using load data to import DATA is slow. Later I found that the table had a primary key, so I used innodb plugin + fast index creation, which greatly improved the speed.
Time Comparison:
|
|
Import time |
Index creation time |
|
BuildinDirect import(Primary Key) |
154.6 min |
0 |
|
BuildinImport to create Index |
13 min |
2 h, 16 min, 35.64 sec |
|
PluginImport to create Index |
11 min 39 s |
8 min 27 s |
Compared with the initial buildin + primary key, plugin + fast index creation has more than seven times improved.
Therefore, for load data, do not create a primary key at first. After the import is complete, create a secondary index, which will strike a good balance between the import and query.
For more information about fast index creation, see the MySQL manual. In addition, the implementation of fast index creation has been described in detail in this article MySQL InnoDB Add Index implementation survey.