Hey guys,
I have a problem with a query - it takes over 30 seconds to execute and I have to fix that.
My table has 4 million records, 18 fields (one of which is account_id) and this is the query I’d like to do:
SELECT id, ok, created, account_id, error FROM the_table WHERE account_id = "some_string" ORDER BY created desc LIMIT 0, 850;
There are 120 000 records that match the query according to explain. Here is the output of explain:
explain SELECT id, ok, created, account_id, error FROM the_table WHERE account_id = "some_string" ORDER BY created desc LIMIT 0, 850;
1 SIMPLE the_table ref account_id,account_id-ok-created,account_id-created account_id-created 33 const 119900 Using where
As you see I have indices over account_id and account_id-created. The latter is used as “key”, but it’s still taking way too long to execute. I have tried adding a date range to the mix (with a long date interval), but it doesn’t help:
explain SELECT id, ok, created, account_id, error FROM the_table WHERE account_id = "some_string" and created >= '2012-06-10 20:00:00' ORDER BY created desc LIMIT 0, 850;
1 SIMPLE the_table ref account_id,created,account_id-ok-created,account_id-created account_id-created 33 const 119900 Using where
What can I do? Any help is greatly appreciated.
Kind regards