SELECT vs UPDATE performance with index

后端 未结 7 1724
有刺的猬
有刺的猬 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:51

    The two queries are not identical. You only know that the IDs are unique in the table.

    UPDATE ... LIMIT 10 will update at most 10 records.

    UPDATE ... WHERE id IN (SELECT ... LIMIT 10) may update more than 10 records if there are duplicate ids.

提交回复
热议问题