Look at these articles and insert a lot of data into the same table in mysql database.
Multi-threaded insertion is faster than single-threaded insertion.
My feeling is that threads should be exclusive in writing the same table
Otherwise, how to check the unique index
How does mysql determine the primary key id when it grows its own id?
Why is multi-threaded insertion faster than single-threaded insertion?
The use of the word thread here may give rise to some ambiguities. The official saying is: operations. In other words, the integration of [multiple single entry insertion operations] into [one multiple entry insertion operation] is the basis for improving the speed of Insert. The reason is very simple. When inserting the data inside, the overall time allocation is as follows:
- Link Time (30%)
- Send query to Server (20%)
- Resolve query (20%)
- Insert operation (10% x number of entries)
- Insert index (10% x number of indexes)
- Close link (10%)
The above percentages are the approximate ones given by the government. It can be seen from here that the real time-consuming process is not the operation, but the linking and parsing process, which is the root cause why the time-consuming time of [multiple single entry insertion operation] is higher than that of [one multiple entry insertion operation].