mysql - 數(shù)據(jù)庫批量插入數(shù)據(jù)的速度是否與索引有關(guān)?
問題描述
在數(shù)據(jù)庫批量插入數(shù)據(jù)時,插入數(shù)據(jù)的速度是否與創(chuàng)建的索引有關(guān)?如果有關(guān)請給出指相關(guān)文檔,謝謝!
問題解答
回答1:當(dāng)然會有影響,插入數(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. 我的html頁面一提交,網(wǎng)頁便顯示出了我的php代碼,求問是什么原因?2. 我在centos容器里安裝docker,也就是在容器里安裝容器,報(bào)錯了?3. 數(shù)據(jù)庫 - 使用讀寫分離后, MySQL主從復(fù)制延遲會導(dǎo)致讀不到數(shù)據(jù)嗎?4. tp6表單令牌5. docker 17.03 怎么配置 registry mirror ?6. 老哥們求助啊7. django - 后臺返回的json數(shù)據(jù)經(jīng)過Base64加密,獲取時用python如何解密~!8. node.js - node 客戶端socket一直報(bào)錯Error: read ECONNRESET,用php的socket沒問題哈。。9. 如何解決docker宿主機(jī)無法訪問容器中的服務(wù)?10. javascript - canvas 可以實(shí)現(xiàn) PS 魔法橡皮擦的功能嗎?
