且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 MySql 中的 DATETIME 字段的日期部分创建索引

更新时间:2023-01-29 14:57:25

如果我没记错的话,这将运行整个表扫描,因为您通过函数传递列.MySQL 会乖乖地为每一列运行函数,绕过索引,因为查询优化器无法真正知道函数的结果.

If I remember correctly, that will run a whole table scan because you're passing the column through a function. MySQL will obediently run the function for each and every column, bypassing the index since the query optimizer can't really know the results of the function.

我会做的是:

SELECT * FROM transactionlist 
WHERE TranDateTime BETWEEN '2008-08-17' AND '2008-08-17 23:59:59.999999';

这应该会告诉你 2008-08-17 发生的一切.

That should give you everything that happened on 2008-08-17.