I have this table :
CREATE TABLE `villes_france` (
`code_postal` varchar(10) NOT NULL DEFAULT '',
`code_insee` varchar(10) DEFAULT NULL,
`ville` varchar(255) DEFAULT NULL,
`region_rsi` varchar(2) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
It contains 36826 rows, one for each french city.
The interesting fields here are code_postal
(zipcode) and ville
(city).
I use it mainly for autocompletion : when something in written in one input, both input are filled.
Here is my query :
if($source == 'cp'){
$searchSQL = "SELECT code_postal as cp, ville FROM villes_france
WHERE code_postal LIKE :cp LIMIT 20";
}else{
$searchSQL = "SELECT code_postal as cp, ville FROM villes_france
WHERE ville LIKE :ville LIMIT 20";
}
(FYI a "%" is appended to :cp
or :ville
)
Neither of these field is unique (french cities can share a same zipcode) This table will be almost never updated, but a lot of select will be performed.
How would you index this table ?
I have read a lot about indexes but I would like some insight before using them for real.