List:General Discussion« Previous MessageNext Message »
From:Patrice Bulat Date:August 27 1999 5:33pm
Subject:Are char columns indexed on 3 chars minimum ?
View as plain text  
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
Thread
Are char columns indexed on 3 chars minimum ?Patrice Bulat27 Aug
  • Are char columns indexed on 3 chars minimum ?Michael Widenius29 Aug