Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does LIMIT 1 have any performance boost?

Does appended LIMIT 1 after query have any performance boost?

...if there could be only one possible entry that matched (WHERE clause for primary key)?

SELECT `x`
FROM `unicorns`
WHERE `id` = 123
LIMIT 1

...the same, but now it's DELETE:

DELETE FROM `unicorns`
WHERE `id` = 123
LIMIT 1

...and UPDATE:

UPDATE `unicorns`
SET `rainbows` = `rainbows` + 1
WHERE `id` = 123
LIMIT 1

P.S. Column id is primary key so it's unique.

Thanks in an advice!

like image 304
daGrevis Avatar asked Oct 17 '11 19:10

daGrevis


1 Answers

it depends do you have index on column or not

DELETE FROM `unicorns` WHERE `id` = 123 LIMIT 1

is pointless if id is Primary Key, but

DELETE FROM `unicorns` WHERE `noindexoclumn` = 123 LIMIT 1

will give u perfomance boost

like image 51
Peter Avatar answered Oct 11 '22 10:10

Peter