1

我有下表 - 它包含大约 100 万行:

CREATE TABLE `history` (
   `user` varchar(12) COLLATE latin1_general_ci NOT NULL DEFAULT '',
   `link` text COLLATE latin1_general_ci NOT NULL,
   `query` text COLLATE latin1_general_ci NOT NULL,
   `hits` int(11) DEFAULT NULL,
   `time_of_query` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   `checked` varchar(30) COLLATE latin1_general_ci DEFAULT NULL,
   `subcorpus` blob,
   `typeOfRestriction` char(10) COLLATE latin1_general_ci DEFAULT NULL,
   `items` blob,
   `textOrSpeaker` char(10) COLLATE latin1_general_ci DEFAULT NULL,
   `simple_query` text COLLATE latin1_general_ci,
   `queryMode` char(10) COLLATE latin1_general_ci DEFAULT NULL,
   KEY `user` (`user`),
   KEY `query` (`query`(256)),
   KEY `checked` (`checked`),
   KEY `time_of_query` (`time_of_query`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci

我最近为此添加了一个键来time_of_query加快速度。但是,如下所示,查询中似乎没有使用该键:

mysql> explain SELECT * FROM history ORDER BY time_of_query DESC;
+----+-------------+---------+------+---------------+------+---------+------+--------+----------------+
| id | select_type | table   | type | possible_keys | key  | key_len | ref  | rows   | Extra          |
+----+-------------+---------+------+---------------+------+---------+------+--------+----------------+
|  1 | SIMPLE      | history | ALL  | NULL          | NULL | NULL    | NULL | 969083 | Using filesort |
+----+-------------+---------+------+---------------+------+---------+------+--------+----------------+
1 row in set (0.00 sec)

有人可以解释为什么会这样吗?

4

0 回答 0