Hello,
I have a table containing approx. 87000 records, with a indexed varchar(5)
column.
A prefix search using the 3 first characters will use the index.
A prefix search using the 2 first characters won't use the index.
Is that a limitation on varchar keys ? I guess it has something to do with
the B-tree implementation, but I haven't found anything discussing this in
the online manual.
Is there a way to make the second search use a index (without duplicating
too much) ?
mysql> describe my_table;
Field Type Null Key Default Extra
----- ---- ---- --- ------- -----
[...]
cp varchar(5) MUL
> explain select * from my_table where cp like '347%';
table type possible_keys key key_len ref rows Extra
----- ---- ------------- --- ------- --- ---- -----
my_table range cp NULL NULL NULL 1157 range used on key cp
> explain select * from my_table where cp like '34%';
table type possible_keys key key_len ref rows Extra
----- ---- ------------- --- ------- --- ---- -----
my_table ALL cp NULL NULL NULL 87101 where used
Thanks for your help,
Patrice
Montpellier, France