mysql - 數(shù)據(jù)庫批量插入數(shù)據(jù)的速度是否與索引有關(guān)?
問題描述
在數(shù)據(jù)庫批量插入數(shù)據(jù)時,插入數(shù)據(jù)的速度是否與創(chuàng)建的索引有關(guān)?如果有關(guān)請給出指相關(guān)文檔,謝謝!
問題解答
回答1:當然會有影響,插入數(shù)據(jù)的時候會導致索性的更新。索性越多,插入會越慢。可以看文檔描述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ù)是否有重復。
對于大批量的數(shù)據(jù)導入,一般都是先把索引去掉,等數(shù)據(jù)導入完成后再重建索引。
相關(guān)文章:
1. mysql建表報錯,查手冊看不懂,求解?2. 求大神支招,php怎么操作在一個html文件的<head>標記內(nèi)添加內(nèi)容?3. 致命錯誤: Class ’appfacadeTest’ not found4. PHP類屬性聲明?5. php點贊一天一次怎么實現(xiàn)6. 怎么php怎么通過數(shù)組顯示sql查詢結(jié)果呢,查詢結(jié)果有多條,如圖。7. 在應用配置文件 app.php 中找不到’route_check_cache’配置項8. 老師們php,插入數(shù)據(jù)庫mysql,都是空的,要怎么解決9. sql語句 - 如何在mysql中批量添加用戶?10. phpstady在win10上運行
