日期:2014-05-16  浏览次数:20846 次

SQL 加了Order By超慢,去掉飞快,怎么解决
SQL code

SELECT
    novel_booklist.ID AS aID,
    novel_chapter.ID AS bID,
    novel_category.ID AS cID,
    novel_booklist.Author,
    novel_booklist.Category,
    novel_chapter.BookName,
    novel_chapter.ChapterName,
    novel_chapter.ID,
    novel_chapter.UpTime
FROM
    novel_chapter,
    novel_booklist,
    novel_category
WHERE
    novel_chapter.BookName = novel_booklist.BookName
AND novel_booklist.Category = novel_category.CategoryName
ORDER BY
    novel_chapter.UpTime DESC
LIMIT 20


加了Order By超慢,去掉飞快,怎么解决,加了 ORDER BY novel_chapter.UpTime Desc 执行速度是 1.2ms 去掉后 0.023ms
UpTime也做了索引,不过试了下,UpTime有索引跟没索引速度基本上一样,有何解决办法呢

converting HEAP to MyISAM 1.333%
Copying to tmp table 34.268%
Copying to tmp table on disk 60.152%

------解决方案--------------------
创建 (BookName, UpTime)的复合索引
------解决方案--------------------
参考一下这个贴子。

http://topic.csdn.net/u/20110827/17/739bd667-703b-4ca1-89ff-e625e724d00b.html
------解决方案--------------------
强制索引

select *
from A force index(1楼的索引)
where ...