MySQL Forums
Forum List  »  Performance

Index on varchar is not used when column compares to literal integer
Posted by: Panayotis Matsinopoulos
Date: June 04, 2011 02:07PM

Hi,

I have a select on a table as follows:

select x from t where x = 13;

I already have an index on x and x is varchar(255).

However, explain shows that my query does not use index. And the query runs very slow.

When I replace the query with

select x from t where x = '13';

it runs lightning fast and index is used.

Why is that? Is there a global mysql configuration to convert integer literals to varchars in such cases and automatically use the index?

Thanks in advance
Panayotis

Options: ReplyQuote


Subject
Views
Written By
Posted
Index on varchar is not used when column compares to literal integer
2345
June 04, 2011 02:07PM


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.