简体   繁体   English

在 MyISAM 中使用或不使用附加条件可以更快地更新哪个?

[英]Which can be updated faster, using or not using additional condition in MyISAM?

I'm trying to update multiple records using a single query in MySQL(Engine: MyISAM).我正在尝试使用 MySQL(引擎:MyISAM)中的单个查询来更新多条记录。

It looks like:看起来像:

UPDATE table_name SET delete_flag=true WHERE column_1={value}

I'd like to set all delete_flag to true .我想将所有delete_flag设置为true And then, I came up with adding WHERE clause like this:然后,我想出了像这样添加 WHERE 子句:

UPDATE table_name SET delete_flag=true WHERE column_1={value} AND delete_flag=false

(delete_flag doesn't have any indexes.) (delete_flag 没有任何索引。)

Though it could depend on the number of records, I wonder which is the faster way.虽然它可能取决于记录的数量,但我想知道哪种方法更快。

Could you give me your advice?你能给我你的建议吗? If it depends the situations, please tell me them.如果取决于情况,请告诉我。

Thanks.谢谢。

Presumably, id is unique in the table, so MySQL is going to find the one row that needs to be updated based on that condition.据推测, id在表中是唯一的,因此 MySQL 将根据该条件查找需要更新的一行。

MySQL then checks if the value changes before doing an update. MySQL 然后在进行更新之前检查值是否更改。 So, the MySQL engine does not do extra work (logging for example) when the record does not change.因此,当记录没有改变时,MySQL 引擎不会做额外的工作(例如记录)。

Any difference in performance is negligible, and would be rather hard to quantify.性能上的任何差异都可以忽略不计,而且很难量化。

If you add INDEX(delete_flag, id) , then your second option will run faster because it will look at fewer rows.如果您添加INDEX(delete_flag, id) ,那么您的第二个选项将运行得更快,因为它会查看更少的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM