开发者

How to optimize this MySQL query .It takes nearly 2 secs to execute

I recented converted my project from SQL SErver to MySQL .

I do see one my query which was executing faster in SQL server takes more time( 2 sec ) in mysql.

Am I doing anything wrong here .Help me to optimize it . Thank s

SELECT ReadingDateTime, SUM(DATA) AS PowerTotal FROM
LTMeterReading WHERE MeterID IN(59) and DataTypeID=48 and
ReadingDateTime >= '2010-04-01 12:00:00 AM' AND
ReadingDateTime < '2010-04-02 12:00:00 AM'
GROUP BY ReadingDateTime ORDER BY Read开发者_开发知识库ingDateTime


you can put indexes on the columns you check for, it might effect your insert time though.


Try to add index, that covers DataTypeID + MeterID + ReadingDateTime in this particular order

Also - ORDER BY clause is obsolete here: after you have groupped by ReadingDateTime - data is already sorted ascendant by this field.


how many rows in the table? what's the data type of DATA? any indexes on ReadingDateTime, MeterID, DataTypeID?


I finally fixed it by Changing the MySQL table engine to MyISAM ,after which its very fast . Thanks guys .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜