mysql - 數(shù)據(jù)庫批量插入數(shù)據(jù)的速度是否與索引有關(guān)?
問題描述
在數(shù)據(jù)庫批量插入數(shù)據(jù)時,插入數(shù)據(jù)的速度是否與創(chuàng)建的索引有關(guān)?如果有關(guān)請給出指相關(guān)文檔,謝謝!
問題解答
回答1:當然會有影響,插入數(shù)據(jù)的時候會導(dǎo)致索性的更新。索性越多,插入會越慢。可以看文檔描述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:索引對批量插入數(shù)據(jù)的影響非常大,道理很簡單,一方面是寫表的時候需要同時寫索引,另外就對于唯一索引需要檢查數(shù)據(jù)是否有重復(fù)。
對于大批量的數(shù)據(jù)導(dǎo)入,一般都是先把索引去掉,等數(shù)據(jù)導(dǎo)入完成后再重建索引。
相關(guān)文章:
1. javascript - 如何使用nodejs 將.html 文件轉(zhuǎn)化成canvas2. 如何解決docker宿主機無法訪問容器中的服務(wù)?3. angular.js - 輸入郵箱地址之后, 如何使其自動在末尾添加分號?4. javascript - Web微信聊天輸入框解決方案5. 在mac下出現(xiàn)了兩個docker環(huán)境6. javascript - 后臺管理系統(tǒng)左側(cè)折疊導(dǎo)航欄數(shù)據(jù)較多,怎么樣直接通過搜索去定位到具體某一個菜單項位置,并展開當前菜單7. java如何生成token?8. python - Scrapy存在內(nèi)存泄漏的問題。9. CSS3 畫如下圖形10. angular.js - $stateChangeSuccess事件在狀態(tài)跳轉(zhuǎn)的時候不執(zhí)行?
