MySQL Forums
Forum List  »  Optimizer & Parser

Re: why don't work for my substring index?
Posted by: Felix Geerinckx
Date: November 07, 2005 05:13AM

zhenxing zhai wrote:

> ...
> where
> LEFT(r.datestr,6)=DATE_FORMAT(now(),'%Y%m')
> ....
> query is so slow because scan full table for table r,but having index on r.datestr and r.datestr(6)

At present, MySQL cannot use an index on a column when this column is the argument of a function (although with the LEFT() function it should be obvious ;-).

> if I change condition
> 'LEFT(r.datestr,6)=DATE_FORMAT(now(),'%Y%m') '
> to
> 'r.datestr=DATE_FORMAT(now(),'%Y%m%d') '

These are not equivalent. You may want to consider

r.datestr LIKE CONCAT(DATE_FORMAT(NOW(), '%Y%m'), '%')

which should use the index on r.datestr.

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Views
Written By
Posted
4117
November 06, 2005 10:09PM
Re: why don't work for my substring index?
3420
November 07, 2005 05:13AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.