mySQL如何加速功能字段> x和字段< ÿ

时间:2010-11-09 10:26:56

标签: mysql

这是我的查询

SELECT PadID FROM Pads WHERE ((RemoveMeDate='2001-01-01 00:00:00') 
AND (catid in (0,1,2,3,4,5,6,7,8,9,10,11)) AND ((ProgramName)<>'')) 
ORDER BY VersionAddDate DESC LIMIT 0,20;

自从我添加了

catID in (0,1,2,3,4,5,6,7,8,9,10,11)

它放慢了很多。

我试过......

SELECT PadID FROM Pads WHERE RemoveMeDate='2001-01-01 00:00:00' AND 
catid >= 0 and catid <= 11 ORDER BY VersionAddDate DESC LIMIT 0,20

但那只是一个缓慢。

我以为我可能能够coalesce,但我不确定如何?

有什么想法吗?

EDITS

分类表 alt text

垫表 alt text

4 个答案:

答案 0 :(得分:0)

我猜你必须先说服MySQL过滤RemoveMeDate。尝试:

SELECT  PadID 
FROM    (
        SELECT  *
        FROM    Pads
        WHERE   RemoveMeDate = '2001-01-01 00:00:00' 
        ) as SubQuery
WHERE   catid >= 0 and catid <= 11 
ORDER BY 
        VersionAddDate DESC 
LIMIT   0, 20

答案 1 :(得分:0)

尝试在

之间使用
SELECT PadID FROM Pads WHERE RemoveMeDate='2001-01-01 00:00:00' AND 
catid between 0 and 11  ORDER BY VersionAddDate DESC LIMIT 0,20

答案 2 :(得分:0)

您可以使用between子句而不是&gt; =&lt; =。

catid between ? and ?

您可以在RemoveDate和catid中添加索引

ALTER TABLE Pads ADD INDEX RemoveDate (RemoveDate);

答案 3 :(得分:0)

(removemedate, catid)上创建综合索引。