Home > Database > Mysql Tutorial > 如何提高数据库update更新的速度_MySQL

如何提高数据库update更新的速度_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 13:31:15
Original
2126 people have browsed it

bitsCN.com

如何提高数据库update更新的速度

 

不用不知道,一用吓一跳。。看下面这条SQL语句

 

[java] String sql="update cats set name_alias='"+rs.getString(1)+"'where name='"+rs.getString(1)+"'";  
Copy after login

如果数据量很小的话,肯定不会存在什么问题,一眨眼就更新好了。但如果是大一点的表,不用说几百万条,几万条记录就已经要耗费小时级别的时间了。

解决方法就是where条件里面的字段一定要加索引,一般直接利用表的主索引就可以了,例如下面这条SQL语句,id就是主索引。

[java] String sql="update cats set name_alias='00000'where id='"+rs.getInt(1)+"'";  
Copy after login

 

 

这样优化之后,更新的速度就大幅增加,几分钟就可以搞定万级别的更新操作。

 

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
mysql update query update A SET acid = (SELECT);
From 1970-01-01 08:00:00
0
0
0
mysqli cannot update data
From 1970-01-01 08:00:00
0
0
0
User update problem
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template