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 'www.aol.com%';
>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 '%.aol.com';
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 = "www.aol.com";
>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.