I'm joining two tables in a MySQL query ( simplified version below ). This query takes ~10sec to execute. Both tables have about a million rows. Properties has a lot of data and is 2GB while geospatial is ~200MB. Geospatial's primary key is mls_id and properties has non-unique indexes on mls_id and rets_feed.
If I remove the and properties.rets_feed = 'san_fran' or the and properties.mls_id < 100 portion of the query, it executes ~100x faster ( ~110ms ). My actual query from my application has a lot more WHERE's and a bunch of HAVING's based on some calculations made in the SELECT statement, but I think I've isolated the processing-time issue to this smaller example query below.
The Query:
SELECT
properties.mls_id,
geospatial.geocoded_address
FROM
properties,
geospatial
WHERE
geospatial.mls_id = properties.mls_id
and properties.rets_feed = 'san_fran'
and properties.mls_id != '';
The Explain Details:
1 SIMPLE geospatial ALL NULL NULL NULL NULL 1089034 NULL
1 SIMPLE properties ref mls_id,rets_feed mls_id 45 func 1 Using index condition; Using where
Properties Table ( abbreviated, cuz it's got 100's of columns ):
CREATE TABLE `properties` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`mls_id` varchar(14) DEFAULT NULL,
`last_downloaded` datetime NOT NULL,
`rets_feed` varchar(25) DEFAULT NULL,
`rets_resource` varchar(25) DEFAULT NULL,
`rets_class` varchar(4) DEFAULT NULL,
`address_full` varchar(50) DEFAULT NULL,
`street_name` varchar(55) DEFAULT NULL,
`street_number` varchar(10) DEFAULT NULL,
`city` varchar(100) DEFAULT NULL,
`county` varchar(30) DEFAULT NULL,
`state` varchar(30) DEFAULT NULL,
`zip` varchar(12) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `mls_id` (`mls_id`),
KEY `rets_feed` (`rets_feed`)
) ENGINE=InnoDB AUTO_INCREMENT=1089499 DEFAULT CHARSET=utf8;
Geospatial Table:
CREATE TABLE `geospatial` (
`mls_id` varchar(20) NOT NULL DEFAULT '',
`geocoded_address` varchar(255) DEFAULT NULL,
`lat` decimal(10,8) DEFAULT NULL,
`lon` decimal(11,8) DEFAULT NULL,
`lat_lon` point NOT NULL,
`street_number` int(11) unsigned DEFAULT NULL,
`street_name` varchar(50) DEFAULT NULL,
`street_name_short` varchar(50) DEFAULT NULL,
`neighborhood` varchar(50) DEFAULT NULL,
`neighborhood_short` varchar(50) DEFAULT NULL,
`city` varchar(50) DEFAULT NULL,
`city_short` varchar(50) DEFAULT NULL,
`county` varchar(50) DEFAULT NULL,
`county_short` varchar(50) DEFAULT NULL,
`state` varchar(50) DEFAULT NULL,
`state_short` varchar(2) DEFAULT NULL,
`country` varchar(50) DEFAULT NULL,
`country_short` varchar(2) DEFAULT NULL,
`zip` int(5) unsigned DEFAULT NULL,
`zip_plus_four` int(4) unsigned DEFAULT NULL,
`last_geocoded` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`source` varchar(25) NOT NULL DEFAULT '',
`geocodio_accuracy` decimal(3,2) unsigned DEFAULT NULL,
PRIMARY KEY (`mls_id`),
KEY `last_geocoded` (`last_geocoded`),
SPATIAL KEY `lat_lon` (`lat_lon`),
KEY `street_number` (`street_number`),
KEY `street_name` (`street_name`),
KEY `neighborhood` (`neighborhood`),
KEY `city` (`city`),
KEY `county` (`county`),
KEY `state` (`state`),
KEY `state_short` (`state_short`),
KEY `zip` (`zip`),
KEY `zip_plus_four` (`zip_plus_four`),
KEY `country` (`country`),
KEY `country_short` (`country_short`),
KEY `source` (`source`),
KEY `accuracy` (`geocodio_accuracy`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Aucun commentaire:
Enregistrer un commentaire