我需要计算每天为 mysql 中的一个巨大表创建的行数。我目前正在使用
select count(1) from table_name group by Date
查询需要更多 2000 秒并且还在计数。我想知道是否有任何优化的查询或优化我的查询的方法。
If you're only interested in items that were created on those dates, you could calculate the count at end-of-day and store it another table.
That lets you run the COUNT query on a much smaller data set (Use WHERE DATE(NOW()) = Date
and drop the GROUP BY
)
Then then query the new table when you need the data.
在列上添加索引Date
,我想不到其他方法可以优化此查询。
CREATE INDEX ix_date
ON table_name (Date);