我有一张HISTORY
有 900 万条记录的表。我需要找到按年、按月创建的记录。我正在使用查询 1,但是它超时了几次。
SELECT
year(created) as year,
MONTHNAME(created) as month,
count(*) as ymcount
FROM
HISTORY
GROUP BY
year(created), MONTHNAME(created);
我决定添加where year(created)
,这次查询需要 30 分钟(是的,需要很长时间)才能执行。
SELECT
year(created) as year,
MONTHNAME(created) as month,
count(*) as ymcount
FROM
HISTORY
WHERE
year(created) = 2010
GROUP BY
year(created), MONTHNAME(created) ;
我打算在created
时间戳列上添加一个索引,但是在这样做之前,我需要意见(因为索引这么大的表需要很长时间)。
created(timestamp)
考虑到列上使用了年份函数,在列上添加索引会提高性能吗?