SQL|Performance optimization method for importing large amounts of data into MySQL

Business scenario: A large number of records need to be written to the table my_table.

Optimization method: First, sort the data that needs to be written into the table my_table by the primary key after writing it into MySQL, and then write it into MySQL one by one. By sorting the primary key, it can be ensured that when writing data, the new data must be written on the last data page, and the completed data page will not require page splitting.

Mysql page splitting process:

When MySQL needs to insert a record, it will first locate the data page corresponding to which leaf node the record should be inserted into; if the data page space is sufficient, the data will be inserted directly. If the data page space is insufficient, the data cannot be directly inserted. Inserting data requires page splitting instead.

When a page is split, you probably need to perform the following process:

  1. Create a new data page
  2. Then transfer some data from the old data page to the new data page
  3. Add new data to the doubly linked list of leaf nodes as well
  4. Updating the index information of internal node records layer by layer

Guess you like

Origin blog.csdn.net/Changxing_J/article/details/133050346