Resetting AUTO_INCREMENT is taking a long time in MySQL

家住魔仙堡 提交于 2019-12-19 17:33:01

问题


ALTER TABLE tablename AUTO_INCREMENT = 10000000

This query is taking long time to update. Why? I need to optimize this query.


回答1:


ALTER TABLE causes a rebuild of the entire table - if your table contains many rows,this can take ages.

If you just need to bump up the value of the auto_increment value, the quickest way is to insert a dummy row (and then delete that roow if need be). This will only take a fraction of a second, whereas ALTER TABLE can take days for a large table.

For example, suppose I have a table with an auto_increment ID column and other columns col1, col2...:

insert into autoinc_table set ID = 10000000;
delete from autoinc_table where ID = 10000000;



回答2:


user and admin data must be distinguished not by id, but by another field. If you would treat an id as an abstract identifier with no other meanings it will save you a lot of time and resources, trust me.



来源:https://stackoverflow.com/questions/2681869/resetting-auto-increment-is-taking-a-long-time-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!