文章詳情頁
mysql - 數據庫批量插入數據的速度是否與索引有關?
瀏覽:131日期:2022-06-16 09:46:08
問題描述
在數據庫批量插入數據時,插入數據的速度是否與創建的索引有關?如果有關請給出指相關文檔,謝謝!
問題解答
回答1:當然會有影響,插入數據的時候會導致索性的更新。索性越多,插入會越慢。可以看文檔描述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:索引對批量插入數據的影響非常大,道理很簡單,一方面是寫表的時候需要同時寫索引,另外就對于唯一索引需要檢查數據是否有重復。
對于大批量的數據導入,一般都是先把索引去掉,等數據導入完成后再重建索引。
相關文章:
1. [python2]local variable referenced before assignment問題2. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?3. mysql - 如何在有自增id的情況下,讓其他某些字段能不重復插入4. python小白,關于函數問題5. django - Python error: [Errno 99] Cannot assign requested address6. angular.js - 百度支持_escaped_fragment_嗎?7. java - 線上應用,如果數據庫操作失敗的話應該如何處理?8. node.js - win 下 npm install 遇到了如下錯誤 會導致 無法 run dev么?9. python小白 關于類里面的方法獲取變量失敗的問題10. Python2中code.co_kwonlyargcount的等效寫法
排行榜
