Bug #32746 | multi column index ignored in date range using now() | ||
---|---|---|---|
Submitted: | 26 Nov 2007 22:33 | Modified: | 27 Nov 2007 19:38 |
Reporter: | renaud houver | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S2 (Serious) |
Version: | 5.0.50 | OS: | Linux (Red Hat Enterprise Linux Server release 5 (Tikanga)) |
Assigned to: | CPU Architecture: | Any |
[26 Nov 2007 22:33]
renaud houver
[27 Nov 2007 4:31]
Valeriy Kravchuk
Thank you for a problem report. Please, check if the following query: explain select count(*) from test where credit = 'AP' and creation_date BETWEEN date(TIMESTAMPADD(DAY,-3,now())) and date(now()); will have better plan and run faster.
[27 Nov 2007 8:48]
renaud houver
That helped !! Thanks. Is that a bug related to timestamp/date conversion ?
[27 Nov 2007 19:38]
Valeriy Kravchuk
So, this is NOT a bug in optimizer. Some time after 5.0.27 implicit datatypes conversion "rules" were changed, and now column type (DATE) is converted to expression type (DATETIME), if they are different. This prvents proper index usage. This lead to many problems already reported. None of them is optimizer bug, though. Looks like something similar to this (read http://dev.mysql.com/doc/refman/5.0/en/type-conversion.html) works recently: "If one of the arguments is a TIMESTAMP or DATETIME column and the other argument is a constant, the constant is converted to a timestamp before the comparison is performed."