I have a movies
table. It has 1.3 million rows in it.
The table has an INDEX
on the title
column, order asc
, length 255
.
The title
column itself is a VARCHAR(1000)
.
Even with that setup, the following query takes 8 second to run. Anyone ideas or shots in the dark as to why this may be? I'm stumped because it seems like such a basic problem to solve.
SELECT title
FROM movies
ORDER BY title
LIMIT 150000, 50000
When I take out the ORDER BY
, the query is super fast (0.05 seconds):
SELECT title
FROM movies
LIMIT 150000, 50000
The problem with performance is the offset value expressed in the
limit
clause. If you are reading through the table, then you can store the values and use a>
before theorder by
:If
$title
is the title at row 150,000 then this should go fast. Based on the results from this query, you would reset$title
for the next query.I am surprised that relatively few rows takes tens of seconds. It should go faster once the index is in memory. One additional complicating factor is that the
title
might be long -- so the index might be occupying many tens or hundreds of megabytes. That is still not that big, but it would introduce a noticeable delay.