SELECT vs UPDATE performance with index

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

    The comment by Michael J.V is the best description. This answer assumes a is a column that is not indexed and 'id' is.

    The WHERE clause in the first UPDATE command is working off the primary key of the table, id

    The WHERE clause in the second UPDATE command is working off a non-indexed column. This makes the finding of the columns to be updated significantly slower.

    Never underestimate the power of indexes. A table will perform better if the indexes are used correctly than a table a tenth the size with no indexing.

提交回复
热议问题