Delete and update Limit Limit in mysql query

Suppose I have a MySQL user table with several columns, of which one is the user ID (there can be no duplicate record on this). When deleting or updating a specific row, should LIMIT 1 be used, is it faster than without restrictions on delete and update requests?

So, << 20> is faster than DELETE FROM users WHERE id=123 ?

Same thing with the update?

+4
source share
1 answer

There is (and never has been) the advantage of LIMIT 1 for updating / removing PCs. This makes your requests look weird (e.g. user_id not PK).

You can confirm my opinion by running EXPLAIN ... with and without LIMIT 1 .

That's all for PK and UNIQUE keys only. In the case of INDEX LIMIT can be a huge optimization.

+4
source

Source: https://habr.com/ru/post/1382110/


All Articles