Hi in MySQL, when I do LIMIT x, how does the database work?
1) Does it pull everything relevant, then only takes the x starting from 0 or.
2) Does it only pull the first x amount out and stops?
| SitePoint Sponsor |
Hi in MySQL, when I do LIMIT x, how does the database work?
1) Does it pull everything relevant, then only takes the x starting from 0 or.
2) Does it only pull the first x amount out and stops?


#2 whenever possible.
17-29% of paid ad clicks are fraudulent. Get protected with Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more.
In the case of something like, ORDER BY column LIMIT 5, would it do #1. And if so is there a more efficient method of doing such?
And if there's no column and it's just like SELECT * FROM tbl WHERE x=1 LIMIT 5, it would do #2?


it would use #2 if there is an ORDER BY and the order by column has an index
i've always wondered why people would want to use LIMIT without ORDER BY -- it's not like you're going to get a random selection, you're not, you will probably get the earliest rows, but this isn't guaranteed
Bookmarks