mysql - 數(shù)據(jù)庫批量插入數(shù)據(jù)的速度是否與索引有關(guān)?
問題描述
在數(shù)據(jù)庫批量插入數(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. docker-compose中volumes的問題2. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””3. boot2docker無法啟動(dòng)4. java - SSH框架中寫分頁時(shí)service層中不能注入分頁類5. javascript - vue生成一維碼?求助!!!!!急6. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.7. docker網(wǎng)絡(luò)端口映射,沒有方便點(diǎn)的操作方法么?8. nignx - docker內(nèi)nginx 80端口被占用9. javascript - mock.js可以存儲(chǔ)數(shù)據(jù)嗎10. java - Eclipse中的 “context root” 和 “content directory” 的作用是什么?

網(wǎng)公網(wǎng)安備