简体   繁体   中英

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).

It looks like:

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

I'd like to set all delete_flag to true . And then, I came up with adding WHERE clause like this:

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

(delete_flag doesn't have any indexes.)

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.

MySQL then checks if the value changes before doing an update. So, the MySQL engine does not do extra work (logging for example) when the record does not change.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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