Matzberger Marcus: Prüfen ob Datensatz existiert

Beitrag lesen

Hallo,

Und dann kommt es auch noch darauf an, ob ein Index genutzt werden kann, wenn ich vom Handbuchkapitel LIMIT Optimization den ersten Anstrich richtig verstanden habe.

Also ich lese das so:

If you are selecting only a few rows with LIMIT, MySQL uses indexes in some cases when normally it would prefer to do a full table scan.

Gesetzt den Fall, dass MYSQL keinen Index verwendet, weil ein Großteil der Daten der WHERE-Bedingung entspricht, kann es sein, dass mit LIMIT trotzdem über einen Index gesucht wird, was zu einem schnelleren Ergebnis führt.

If you use LIMIT row_count with ORDER BY, MySQL ends the sorting as soon as it has found the first row_count rows of the sorted result, rather than sorting the entire result. ... after the initial rows have been found, there is no need to sort any remainder of the result set, and MySQL does not do so.

Das heißt, dass LIMIT auch bei Verwendung von ORDER BY eine Performancesteigerung bringen kann.

Grüße
Marcus

--
si vis pacem, para iustitiam