I have 4000 rows for example, and I define X limit.
The query stops after it finds X rows? or the query finds all the rows and then takes X rows from the found rows?
I'm assuming you're thinking about MySQL, in which according to the documentation, the answer is it depends. If you're using a LIMIT
(without a HAVING
), then:
LIMIT
, MySQL uses indexes
in some cases when normally it would prefer to do a full table scan.SQL_CALC_FOUND_ROWS
.There are a few other cases which you should read about in the documentation.