SELECT vs UPDATE performance with index

后端 未结 7 1758
有刺的猬
有刺的猬 2020-12-09 04:10

If I SELECT IDs then UPDATE using those IDs, then the UPDATE query is faster than if I would UPDATE using the conditions

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-09 04:55

    Regarding "MySQL doesn't support updating the same table you're selecting from"

    UPDATE table SET field = value 
    WHERE id IN (SELECT id FROM table WHERE a IS NULL LIMIT 10);
    

    Just do this:

    UPDATE table SET field = value 
    WHERE id IN (select id from (SELECT id FROM table WHERE a IS NULL LIMIT 10));
    

提交回复
热议问题