I am trying to run a query on my MySQL database which is taking 70+ seconds to run, and I'm scratching my head as to why the index isn't being used.
Here's the query:
SELECT PriceId, InstrumentId, Date, Open, High, Low, Close, Volume, UnadjustedClose
FROM price
ORDER BY InstrumentId, Date DESC
The price table has an index with InstrumentId, Date (amongst other indexes). The table itself has 80 million rows, and is made up of 2 ints, a date, a long and 5 decimals.
The explain command has type ALL, Null for possible keys, key and ref, and tells me the system is using filesort.
Is this the best I can get from the system? I expected the index to be used to make the sort faster.
Added:
Here's the table definition:
PriceId int PK, NN, AI
InstrumentId int NN
Date Date NN
Open Decimal(12,4)
High Decimal(12,4)
Low Decimal(12,4)
Close Decimal(12,4)
UnadjustedClose Decimal(12,4)
Volume BigInt
Indexes:
Primary -> PriceId
IX_InstrumentId -> InstrumentId
IX_Date -> Date
IX_InstrumentDate -> InstrumentId, Date
Explain output is:
id: 1
select_type: Simple
table: price
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 77926335
Extra: using filesort
EXPLAINoutput?