Suppose I have a table ‘Tasks’ with a DATETIME column approve_time. I have an index on said column.
If I were to write a query of the form:
SELECT task_id, task_desc, task_owner, approve_time
FROM Tasks
WHERE DATE(approve_time) = '2011-08-31'
My question is about the performance of such a query:
Does MYSQL index DATETIME columns in a way that allows constraining by the date component to be fast?
Or does MYSQL know how to optimize the query into something like the following?
WHERE approve_time >= '2011-08-31 00:00:00'
AND approve_time < '2011-09-01 00:00:00'
Or does the query incur a tablescan?
NO
YES
the second query will lead to range filter,
try
vs
the value of
DATE(approve_time)only can determined after the function applied to column approve_time in all the row, which mean there is not going to make use on index