3

When deleting, should I use LIMIT, or not (MySQL INNODB tables)

  • Each customer has a unique hash.
  • Each customer can have one or more records in a single table.

If I know in advance a customer can have up to 100 records maximum, and my DELETE query has LIMIT 100, then I presume once 100 records were deleted, the query will end without going to end of table.

However, if my customer only has 50records, and my DELETE query has LIMIT 100, the delete will continue until end of table is found since it will spend effort chasing the 51st record which does not exist.

Thus... If I do not use LIMIT does MySQL INNODB know in advance that after having deleted 50 records it need not continue further?

The answer can either create or eliminate performance issues...

asked Jan 1, 2017 at 20:18
0

1 Answer 1

3

The limit is only going to help with exactly 100 so it is probably not worth the overhead.

If you put an index on the hash then it should know to stop (and where to start).

answered Jan 1, 2017 at 21:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.