I’ve created a table:
CREATE TABLE IF NOT EXISTS `markersStorage2` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
`surname` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
`id_vk` int(10) NOT NULL,
`activity_link` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
`message` varchar(256) COLLATE utf8_unicode_ci NOT NULL,
`lat` float(10,6) NOT NULL,
`lng` float(10,6) NOT NULL,
`type` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
`id_tile` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
I’m using it to store google maps markers by tiles.
This table is frequently updated, i mean that new markers are added into it
I’m using this query a lot:
SELECT id, lat,lng FROM markersStorage2 WHERE id_tile LIKE '$tileNumber%'
How can i speed up this query? Maybe i need to create another table or reorganise this one?
Tiles are numbered like here:
http://msdn.microsoft.com/en-us/library/bb259689.aspx
Example: I’m using the max zoom 15, so therefore when i add a new marker to DB the server
determine in which tile this marker will be located for example we will get smth like this
id_tile = 002013111032032
All markers have id_tile with 15 numbers no less no more.
Later when user look through the map tiles are being requested via ajax, but this tiles can
be on different zoom levels and for example we will get this request:
SELECT id, lat,lng FROM markersStorage2 WHERE id_tile LIKE '002013111032%'
So using this request i can get all the markers in this big tile.
you need to put an index on id_tile field.
You can check if your query uses an index or not like this:
without index
with index