SQL 加了Order By超慢,去掉飞快,怎么解决SQL codeSELECTnovel_booklist.ID AS aID,novel_chapter.ID AS bI
SQL 加了Order By超慢,去掉飞快,怎么解决
SQL codeSELECT 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.UpTimeFROM novel_chapter, novel_booklist, novel_categoryWHERE novel_chapter.BookName = novel_booklist.BookNameAND novel_booklist.Category = novel_category.CategoryNameORDER BY novel_chapter.UpTime DESCLIMIT 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 ...