How does one create an index on the date part of DATETIME field in 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.

What I would do is something like:

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

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

Leave a Comment