我有一个约 100 万个条目的 mySQL 数据库。
我运行查询:
SELECT a.id as aid, a.title as atitle, a.slug, summary,
a.link as alink, author, published, image, a.cat as acat,
a.rss as arss, a.site as asite
FROM articles a
ORDER BY published DESC
LIMIT 616150, 50;
加载大约需要 5 分钟或更长时间。
我的表和索引:
CREATE TABLE IF NOT EXISTS `articles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`slug` varchar(255) NOT NULL,
`summary` text NOT NULL,
`link` text NOT NULL,
`author` varchar(255) NOT NULL,
`published` datetime NOT NULL,
`image` text NOT NULL,
`cat` int(11) NOT NULL,
`rss` int(11) NOT NULL,
`site` int(11) NOT NULL,
`bitly` varchar(255) NOT NULL,
`checked` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `title` (`title`),
KEY `cat` (`cat`),
KEY `published` (`published`),
KEY `site` (`site`),
KEY `rss` (`rss`),
KEY `checked` (`checked`),
KEY `id_publ_index` (`id`,`published`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1230234;
什么解释说:
mysql> EXPLAIN EXTENDED SELECT a.id asaid, a.title as atitle, a.slug, summary, a.link as alink, author, published, image, a.cat as acat, a.rss as arss, a.site作为来自文章的站点,已发布 DESC LIMIT 616150, 50 的订单; +----+-------------+--------+-------+-------------- -+-----------+---------+------+--------+---------- +-------+ | 编号 | 选择类型 | 表| 类型 | 可能的键 | 关键 | key_len | 参考 | 行 | 过滤 | 额外 | +----+-------------+--------+-------+-------------- -+-----------+---------+------+--------+---------- +-------+ | 1 | 简单 | 一个 | 索引 | 空 | 发表 | 8 | 空 | 616200 | 152.94 | | +----+-------------+--------+-------+-------------- -+-----------+---------+------+--------+---------- +-------+ 1 行,1 个警告(0.46 秒)
有关如何优化此查询的任何提示?为什么 mySQL 需要读取所有 616200 行,而不仅仅是被询问的 50 行?
感谢您的时间。