mysql - 數(shù)據(jù)庫(kù)批量插入數(shù)據(jù)的速度是否與索引有關(guān)?
問題描述
在數(shù)據(jù)庫(kù)批量插入數(shù)據(jù)時(shí),插入數(shù)據(jù)的速度是否與創(chuàng)建的索引有關(guān)?如果有關(guān)請(qǐng)給出指相關(guān)文檔,謝謝!
問題解答
回答1:當(dāng)然會(huì)有影響,插入數(shù)據(jù)的時(shí)候會(huì)導(dǎo)致索性的更新。索性越多,插入會(huì)越慢。可以看文檔描述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:索引對(duì)批量插入數(shù)據(jù)的影響非常大,道理很簡(jiǎn)單,一方面是寫表的時(shí)候需要同時(shí)寫索引,另外就對(duì)于唯一索引需要檢查數(shù)據(jù)是否有重復(fù)。
對(duì)于大批量的數(shù)據(jù)導(dǎo)入,一般都是先把索引去掉,等數(shù)據(jù)導(dǎo)入完成后再重建索引。
相關(guān)文章:
1. macOS Sierra 10.12 安裝mysql 5.7.1出現(xiàn)錯(cuò)誤2. mysql - 拖拽重排序后怎么插入數(shù)據(jù)庫(kù)?3. android - 安卓做前端,PHP做后臺(tái)服務(wù)器 有什么需要注意的?4. javascript - 微信小程序 wx.downloadFile下載文件大小有限制嗎5. mysql 獲取時(shí)間函數(shù)unix_timestamp 問題?6. mysql - 僅僅只是把單引號(hào)與反斜杠轉(zhuǎn)義不用prepare statement能否避免sql注入?7. php - 生產(chǎn)環(huán)境下,給MySQL添加索引,修改表結(jié)構(gòu)操作,如何才能讓線上業(yè)務(wù)不受影響?8. mysql主主同步,從庫(kù)不同步應(yīng)該怎么解決?9. mysql在限制條件下篩選某列數(shù)據(jù)相同的值10. 新入手layuiadmin,部署到tp中。想用php自已寫一個(gè)后臺(tái)管理系統(tǒng)。
