Unix Technical Forum

MySQL spatial is glacial....ly slow

This is a discussion on MySQL spatial is glacial....ly slow within the MySQL forums, part of the Database Server Software category; --> Spatial Extensions in MySQL 5.0.16 (the version I'm on) seem really slow. I must be missing something, but can't ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:10 AM
rdf
 
Posts: n/a
Default MySQL spatial is glacial....ly slow

Spatial Extensions in MySQL 5.0.16 (the version I'm on) seem really
slow. I must be missing something, but can't figure out what. Some
background:

I'm trying to speed up a query that fetches the nearest 10 records
(essentially, latitude/longitude pairs, stored in a Geometry point
column) to a given point (latitude/longitude). Here's the query I'm
using right now, which works but is slow:

SELECT latitude, longitude,
GLength(LineStringFromWKB(LineString(AsBinary(coor dinates),
AsBinary(GeomFromText('POINT(51 -114)'))))) AS distance FROM places
ORDER BY distance ASC LIMIT 10

latitude longitude distance
51.00137160 -114.00182421 0.0022823296615694
50.99412759 -114.00182513 0.0061494958106356
51.00859980 -114.00181734 0.0087897260887692
....

It takes about 2.3 seconds to execute on a MacBook Pro. Now, the table
is big--over 800,000 rows. And the above query is a one-second
improvement over this original one:

SELECT latitude, longitude, SQRT( POW( 69.1 * ( latitude - 51) , 2 ) +
POW( 69.1 * (-114 - longitude) * COS( latitude / 57.3 ) , 2 ) ) AS
distance FROM places ORDER BY distance ASC LIMIT 0,10

But I expected much better. I created a spatial index on the
coordinates column, but it is not being used (I did EXPLAIN). This is
not surprising, since there's a calculation that needs to be performed
on every single row. But is there a faster way to fetch the closest
records to a given point? The MySQL docs are incredibly terse and I
can't find any other examples or code to copy.

Any help is much appreciated.

....R

PS: For clarity, here is the table structure:

CREATE TABLE `places` (
`id` mediumint(8) unsigned NOT NULL auto_increment,
`latitude` decimal(10,8) NOT NULL,
`longitude` decimal(12,8) NOT NULL,
`coordinates` point NOT NULL,
PRIMARY KEY (`id`),
SPATIAL KEY `latlng` (`coordinates`(32))
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
AUTO_INCREMENT=845891 ;

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:15 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com