Possible Faster Query
am 10.07.2009 04:44:46 von uYe
I have this query on my current application:
SELECT count(sql_id) AS total, DATE_FORMAT(insertdate, '%H:%i' ) AS
mydate FROM momt WHERE 1=1 AND insertdate BETWEEN DATE_ADD(NOW(),
INTERVAL - 1 HOUR) AND NOW() AND (sms_type = 1 OR sms_type =2) GROUP BY
mydate ORDER BY insertdate
Is there any possibilities to speed up the query? Because my data become
very huge and this query seems getting slower. TIA.
Willy
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org
Re: Possible Faster Query
am 10.07.2009 10:19:28 von Marcus Bointon
--Apple-Mail-36-471312207
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit
On 10 Jul 2009, at 03:44, sangprabv wrote:
> SELECT count(sql_id) AS total, DATE_FORMAT(insertdate, '%H:%i' ) AS
> mydate FROM momt WHERE 1=1 AND insertdate BETWEEN DATE_ADD(NOW(),
> INTERVAL - 1 HOUR) AND NOW() AND (sms_type = 1 OR sms_type =2) GROUP
> BY
> mydate ORDER BY insertdate
Firstly do an EXPLAIN on that and make sure it's got and is using
appropriate indexes. Straight off a couple of small changes should help:
SELECT count(*) AS total, DATE_FORMAT(insertdate, '%H:%i' ) AS
mydate FROM momt WHERE 1=1 AND insertdate > DATE_ADD(NOW(),
INTERVAL - 1 HOUR) AND (sms_type = 1 OR sms_type =2) GROUP BY
mydate ORDER BY insertdate
This assumes that insertdate can't be in the future...
Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
UK resellers of info@hand CRM solutions
marcus@synchromedia.co.uk | http://www.synchromedia.co.uk/
--Apple-Mail-36-471312207
Content-Disposition: attachment;
filename=smime.p7s
Content-Type: application/pkcs7-signature;
name=smime.p7s
Content-Transfer-Encoding: base64
MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQE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