您的位置:首頁技術文章
文章詳情頁

mysql - 數據庫批量插入數據的速度是否與索引有關?

瀏覽:129日期:2022-06-16 09:46:08

問題描述

在數據庫批量插入數據時,插入數據的速度是否與創建的索引有關?如果有關請給出指相關文檔,謝謝!

問題解答

回答1:

當然會有影響,插入數據的時候會導致索性的更新。索性越多,插入會越慢??梢钥次臋n描述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.

回答2:

索引對批量插入數據的影響非常大,道理很簡單,一方面是寫表的時候需要同時寫索引,另外就對于唯一索引需要檢查數據是否有重復。

對于大批量的數據導入,一般都是先把索引去掉,等數據導入完成后再重建索引。

相關文章:
国产综合久久一区二区三区