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. mysql 查詢身份證號(hào)字段值有效的數(shù)據(jù)2. python bottle跑起來(lái)以后,定時(shí)執(zhí)行的任務(wù)為什么每次都重復(fù)(多)執(zhí)行一次?3. 視頻文件不能播放,怎么辦?4. html5 - HTML代碼中的文字亂碼是怎么回事?5. python - 爬蟲模擬登錄后,爬取csdn后臺(tái)文章列表遇到的問題6. visual-studio - Python OpenCV: 奇怪的自動(dòng)補(bǔ)全問題7. mysql - 分庫(kù)分表、分區(qū)、讀寫分離 這些都是用在什么場(chǎng)景下 ,會(huì)帶來(lái)哪些效率或者其他方面的好處8. javascript - 彈出一個(gè)子窗口,操作之后關(guān)閉,主窗口會(huì)得到相應(yīng)的響應(yīng),例如網(wǎng)站的某些登錄界面,django后臺(tái)的管理等,這是怎么實(shí)現(xiàn)的呢?9. javascript - ios返回不執(zhí)行js怎么解決?10. android - 分享到微信,如何快速轉(zhuǎn)換成字節(jié)數(shù)組
