首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

SQL 加了Order By超慢,去掉飞快,如何解决

2012-10-11 
SQL 加了Order By超慢,去掉飞快,怎么解决SQL codeSELECTnovel_booklist.ID AS aID,novel_chapter.ID AS bI

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.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 ...

热点排行