UPDATE with LIMIT 1

Given a table with a primary key, if I do an UPDATE with WHERE primaryKey = “unique value”, would LIMIT 1 give any speed optimization? I was told that LIMIT 1 would speed up the query under certain circumstances but if so, under which circumstances?

Hi smares;

The LIMIT 1 clause would cause the update to stop as soon as it found the first (and likely only) matching row in your case. So depending on the size of the table and your hardware, it could speed things up significantly. However if your DB is already very fast, and the table is not very large, you may see no difference. But planning for future growth / scalability is always good, so even if you see no significant difference now it would not hurt to leave it as a future safeguard.

-Scott