Re: Slow simple query in 4000000 records table
Posted by:
Rick James
Date: November 30, 2010 09:50AM
Regardless of FORCE INDEX or not, your query has to step over 4023950 rows to get the 50 you want. The "step over" may involve scanning the table, scanning an index (in your case), or scanning a temp table (if an ORDER BY needs a sort).
Skipping over 4M rows takes time. Period.
If, on the other hand, you pre-compute some flavor of sequence number, and index it, then you might be able to efficiently use that index. But not with OFFSET/LIMIT syntax:
id INT UNSIGNED NOT NULL PRIMARY KEY(id)
SELECT ... WHERE id BETWEEN 4023950 AND 4023950 + 50 - 1;
Caveat: If you ever delete rows, then BETWEEN and OFFSET will give you different rows.
Do you really have a use case for fetching page #80,478?
If it is the "last" page, then ORDER BY DESC LIMIT 0,50 would be immensely faster.
Subject
Views
Written By
Posted
3689
November 24, 2010 04:56PM
1698
November 26, 2010 08:02AM
2513
November 27, 2010 01:42PM
1951
November 29, 2010 09:16AM
1705
November 29, 2010 10:55AM
1727
November 30, 2010 05:43AM
1688
November 30, 2010 08:11AM
Re: Slow simple query in 4000000 records table
2335
November 30, 2010 09:50AM
1707
November 30, 2010 10:06AM
1606
December 01, 2010 12:32AM
Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.