Which is faster: LIMIT 1
or LIMIT 20
?
Presumably, fetching less rows is faster than fetching more rows.
But for 16 years (since 2007) the MySQL query optimizer has had
a “bug”† that not only makes LIMIT 1
slower
than LIMIT 20
but can also make the former a table
scan, which tends to cause problems. This happened last week
where I work, and although MySQL DBAs are familiar with this bug,
I’m writing this blog post for developers to more clearly
illustrate and explain what’s going on and why because it’s
really counterintuitive.
Which is faster: LIMIT 1
or LIMIT 20
?
Presumably, fetching less rows is faster than fetching more rows.
But for 16 years (since 2007) the MySQL query optimizer has had
a “bug”† that not only makes LIMIT 1
slower
than LIMIT 20
but can also make the former a table
scan, which tends to cause problems. This happened last week
where I work, and although MySQL DBAs are familiar with this bug,
I’m writing this blog post for developers to more clearly
illustrate and explain what’s going on and why because it’s
really counterintuitive.
Which is faster: LIMIT 1
or LIMIT 20
?
Presumably, fetching less rows is faster than fetching more rows.
But for 16 years (since 2007) the MySQL query optimizer has had
a “bug”† that not only makes LIMIT 1
slower
than LIMIT 20
but can also make the former a table
scan, which tends to cause problems. This happened last week
where I work, and although MySQL DBAs are familiar with this bug,
I’m writing this blog post for developers to more clearly
illustrate and explain what’s going on and why because it’s
really counterintuitive.