Create a BTREE index in the date column and the query will be launched in the wind .
CREATE INDEX date ON stuff(date) USING BTREE
UPDATE: here is the test I just did:
CREATE TABLE test( d DATE, i INT, INDEX(d) );
Filling a table with two thousand rows with different unique i and d s
mysql> SELECT * FROM test LIMIT 1000000, 1; +------------+---------+ | d | i | +------------+---------+ | 1897-07-22 | 1000000 | +------------+---------+ 1 row in set (0.66 sec) mysql> SELECT * FROM test ORDER BY d LIMIT 1000000, 1; +------------+--------+ | d | i | +------------+--------+ | 1897-07-22 | 999980 | +------------+--------+ 1 row in set (1.68 sec)
And here is an interesting observation:
mysql> EXPLAIN SELECT * FROM test ORDER BY d LIMIT 1000, 1; +----+-------------+-------+-------+---------------+------+---------+------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+-------+---------------+------+---------+------+------+-------+ | 1 | SIMPLE | test | index | NULL | d | 4 | NULL | 1001 | | +----+-------------+-------+-------+---------------+------+---------+------+------+-------+ mysql> EXPLAIN SELECT * FROM test ORDER BY d LIMIT 10000, 1; +----+-------------+-------+------+---------------+------+---------+------+---------+----------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+---------+----------------+ | 1 | SIMPLE | test | ALL | NULL | NULL | NULL | NULL | 2000343 | Using filesort | +----+-------------+-------+------+---------------+------+---------+------+---------+----------------+
MySql uses the index for OFFSET 1000, but not for 10000.
Even more interesting if I make a FORCE INDEX request takes longer:
mysql> SELECT * FROM test FORCE INDEX(d) ORDER BY d LIMIT 1000000, 1; +------------+--------+ | d | i | +------------+--------+ | 1897-07-22 | 999980 | +------------+--------+ 1 row in set (2.21 sec)
nobody
source share