时间查询
百万级数据量 按时间查询(时间加索引)
今天
SELECT * FROM table WHERE TO_DAYS(create_time) = TO_DAYS(NOW()) 耗时3.977s(舍弃 全表扫描)
SELECT * FROM table WHERE DATEDIFF(create_time,NOW()) = 0 耗时 4.17s(舍弃)
SELECT * FROM table WHERE create_time > CURDATE() 耗时0.008s
SELECT * FROM table WHERE create_time > DATE_SUB(CURDATE(),INTERVAL 0 DAY); 耗时 0.048s
昨天
SELECT * FROM table WHERE create_time > DATE_SUB(CURDATE(),INTERVAL 1 DAY);