I have table:
CREATE TABLE IF NOT EXISTS `TxtDila` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
...
`Datum` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
...
PRIMARY KEY (`ID`),
KEY `Datum` (`Datum`),
...
FULLTEXT KEY `Titulek` (`Titulek`,`Anotace`,`Txt`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
When I ran:
EXPLAIN SELECT ID FROM TxtDila USE INDEX ( Datum ) ORDER BY Datum
I get:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE TxtDila ALL NULL NULL NULL NULL 214603 Using filesort
Even when I try
EXPLAIN SELECT ID FROM TxtDila use index(Datum) USE INDEX ( Datum ) ORDER BY Datum
I can see filesort.
Table has 200.000 records, and about 700MB. I have fulltext index.
Can anyone help me?
Thank you
You are trying to read 200,000 records’ ID fields (the entire table). The index
Datumdoesn’t include the ID fields, so whichever way you do it this is going to involve reading the ID fields from disc. You’re telling MySQL to use the index on Datum to order the records, then read them. That pretty much means doing up to 200,000 reads from the disc. MySQL decides (correctly) that it’s less work just to read all the(ID, datum)pairs from the table in one big read and order them in memory.I suggest making the
Datumindex a multi-column index on(Datum, ID).