Hank Eskin wrote:
>
> Easy question:
>
> I have a datetime column in a table of 150,000 rows,
> and I want to query records for a certain day AND use
> the index on the column.. Anytime I do this:
>
> SELECT * FROM tables where TO_DAYS(NOW()) = TO_DAYS(entry_time) ; <today's
> records>
> Or
> SELECT * FROM tables where TO_DAYS(entry_time) = 730249;
> <records for some other day, using from_days() function)>
>
> The explain does not use the index on entry_time, and I don't want to add
> another column just for day number..
>
> Thanks in advance!
>
The problem is that MySQL cannot use the index on an expression in where
clause. Think of re-writing the where clause of your query in the form
of constant = entry_time.
--
Sasha Pachev
http://www.sashanet.com