文章详情页
mysql - 数据库批量插入数据的速度是否与索引有关?
浏览:299日期:2022-06-16 09:46:08
问题描述
在数据库批量插入数据时,插入数据的速度是否与创建的索引有关?如果有关请给出指相关文档,谢谢!
问题解答
回答1:当然会有影响,插入数据的时候会导致索性的更新。索性越多,插入会越慢。可以看文档描述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:索引对批量插入数据的影响非常大,道理很简单,一方面是写表的时候需要同时写索引,另外就对于唯一索引需要检查数据是否有重复。
对于大批量的数据导入,一般都是先把索引去掉,等数据导入完成后再重建索引。
相关文章:
1. 编辑管理员信息时,为什么没有修改过的内容会为空?2. thinkphp中Controller里面使用Request::File(’image’);3. 求救一下,用新版的phpstudy,数据库过段时间会消失是什么情况?4. node.js - vue项目在c盘外,npm run dev 出错,求指点。5. mysql - 看这条sql有可能被注入吗6. javascript - js中数组的undefined为什么不会被遍历7. java 如何列出jar包中jar包里的所有文件和目录?8. html - angularJS中switch切换开关按钮不能操作9. javascript - 如何将一个长为365的数组对象按月份切割成12组?10. css3不包括
排行榜

网公网安备