List:General Discussion« Previous MessageNext Message »
From:Thimble Smith Date:July 22 1999 7:41am
Subject:Re: string comparison
View as plain text  
At 09:22, 19990722, Luigi Giacobbe wrote:
>I have 2 questions about string comparison with mysql :
>Is it true that a query with a like doesn't use index ?
>EX. : select * from Sites  where Url like '';
>An index  exists for the field Url

The query will use the index.  The reason is because the % is
not at the beginning.

    SELECT * from Sites WHERE Url LIKE '';

That will NOT use the index, because the % is at the beginning.

>If I use a query with an equal (=) with string field, is the index used ?
>EX : select * from Sites where Root = "";
>An index exists for the field Root

Yes, the index is used here as well.

>The main idea is to obtain the best response time ....

If you can use = instead of LIKE, then use it; it will be faster.  If
you need to use LIKE, avoid putting a wildcard (% or _) near the front
of the string.

string comparisonLuigi Giacobbe22 Jul
  • Re: string comparisonThimble Smith22 Jul
  • Re: string comparisonBenjamin Pflugmann23 Jul