On Tue, 5 Oct 1999, Moz wrote:
> Hello everybody
>
> I've just a question:
>
> i've created a Table with an index for exemple:
>
> CREATE TABLE test (id not null int, tes text,key(id));
>
> I've also read that MySQL don't use indexes when you use LIKE argument
> and the string starts with a wild char.
> But if I write the follow command:
>
> SELECT * FROM test WHERE id=1 AND tes LIKE '%kdkds%'
>
> Does the index work in this case ?
>
I would assume so, providing the engine concludes that the distribution
of the index will make it worth while. By "worth while" I'm referring
to the fact that if it appears that it would have to scan most of the
rows in the table anyway, because so many of them have an id of 1, then
it would be more expensive to use the index than to ignore it. The
statement about not using indexes refers to the fact that for an index
on the column used in a LIKE '%...' clause, the index would be useless
since index keys one character columns are ordered first by the start of
the columns' values, and in this case the matching values could start
with anything.
Make sense?
--
Bob Kline
mailto:bkline@stripped
http://www.rksystems.com