in my mysql database i've got the geonames database, containing all countries, states and cities.
i am using this to create a cascading menu so the user could select where he is from: country -> state -> county -> city.
but the main problem is that the query will search through all the 7 millions rows in that table each time i want to get the list of children rows, and that is taking a while 10-15 seconds.
i wonder how i could speed this up: caching? table views? reorganizing table structure somehow?
and most important, how do i do these things? are there good tutorials you could link to me?
i appreciate all help and feedback discussing smart ways of handling this issue!
UPDATE: here is my table structure:
CREATE TABLE `geonames_copy` (
`geoname_id` mediumint(9) NOT NULL,
`parent_id` mediumint(9) DEFAULT NULL,
`name` varchar(200) DEFAULT NULL,
`ascii_name` varchar(200) DEFAULT NULL,
`alternate_names` varchar(4000) DEFAULT NULL,
`latitude` decimal(10,7) DEFAULT NULL,
`longitude` decimal(10,7) DEFAULT NULL,
`feature_class` char(1) DEFAULT NULL,
`feature_code` varchar(10) DEFAULT NULL,
`country_code` varchar(2) DEFAULT NULL,
`cc2` varchar(60) DEFAULT NULL,
`admin1_code` varchar(20) DEFAULT NULL,
`admin2_code` varchar(80) DEFAULT NULL,
`admin3_code` varchar(20) DEFAULT NULL,
`admin4_code` varchar(20) DEFAULT NULL,
`population` bigint(20) DEFAULT NULL,
`elevation` int(11) DEFAULT NULL,
`gtopo30` smallint(6) DEFAULT NULL,
`time_zone` varchar(40) DEFAULT NULL,
`modification_date` date DEFAULT NULL,
PRIMARY KEY (`geoname_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
and here is the sql query:
$query = "SELECT geoname_id, name
FROM geonames
WHERE parent_id = '$geoname_id'
AND (feature_class = 'A')";
should i just create index for 2 columns: parent_id and feature_class?
one question: isn´t it better to create an index with solr instead of using mysql? one benefit is that im already using solr and another is that it supports full text search. so maybe it's better so i dont use both solr and mysql (2 things to be good at)?