Home  >  Q&A  >  body text

mysql - 数据库批量插入数据的速度是否与索引有关?

在数据库批量插入数据时,插入数据的速度是否与创建的索引有关?
如果有关请给出指相关文档,谢谢!

伊谢尔伦伊谢尔伦2741 days ago598

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 16:14:56

    Of course it will have an impact, and it will cause a simple update when inserting data. The more strings there are, the slower the insertion will be. See the document description
    Although it can be tempting to create an indexes for every possible column used in a query, unnecessary indexes waste space and waste time for MySQL to determine which indexes to use. Indexes also add to the cost of inserts, updates, and deletes because each index must be updated. You must find the right balance to achieve fast queries using the optimal set of indexes.

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 16:14:56

    Indexes have a great impact on batch insertion of data. The reason is very simple. On the one hand, the index needs to be written at the same time when writing the table. On the other hand, for unique indexes, it is necessary to check whether the data is duplicated.

    For large batches of data import, the index is usually removed first, and then the index is rebuilt after the data import is completed.

    reply
    0
  • Cancelreply