我的查询运行大约10秒,这是不可接受的。
我正在寻找一种提高速度的方法,但我没有选择。 我必须在现在和30天之间找到超过1200万行的记录。
以下查询:
SELECT DATE(DATE) AS FDATE,
SUM(VIEW_COUNT) AS COUNT,
COUNT(IP_ADDRESS) AS CLIENTS
FROM VIEWS
WHERE USERID = 'test'
AND DATE BETWEEN ADDDATE(CURDATE(), INTERVAL -30 DAY) AND CURDATE()
GROUP BY FDATE DESC
我也试过,但效果相同:
SELECT DATE(DATE) AS FDATE,
SUM(VIEW_COUNT) AS COUNT,
COUNT(IP_ADDRESS) AS CLIENTS
FROM VIEWS
WHERE USERID = 'test'
AND DATE >= (DATE(NOW() - INTERVAL 30 DAY) + INTERVAL 0 SECOND)
GROUP BY FDATE DESC
答案 0 :(得分:1)
您可以尝试使用MySQL索引在缩短查询执行时间方面获得更好的性能。