Steve Holdoway
2010-11-19 03:25:10 UTC
I've got a bit of a problem that would best be solved by vector
graphics, but a) it's been 30 years since I've used such stuff, and b)
MySQL doesn't really support it. I have a point with (x,y) coordinates,
and am wanting to find the closest 10 points from it. These ( 8
million ) points are stored in a table.
What I've done is to store an Id, and the sum of the squares in this
table. I can then easily get the 10 closest. As a test,
select abs(XSquaredPlusYSquared-(<value of point X^2>+<value of point
Y^2>)) as Difference, ID From Pythagoras Order By 1 asc limit 10;
Unfortunately this ignores all indexes, etc and uses a plain old
filesort to perform this function. Any ideas on how this can be
improved?
The SQL that is, not the engine, hardware... (:
Cheers
Steve
graphics, but a) it's been 30 years since I've used such stuff, and b)
MySQL doesn't really support it. I have a point with (x,y) coordinates,
and am wanting to find the closest 10 points from it. These ( 8
million ) points are stored in a table.
What I've done is to store an Id, and the sum of the squares in this
table. I can then easily get the 10 closest. As a test,
select abs(XSquaredPlusYSquared-(<value of point X^2>+<value of point
Y^2>)) as Difference, ID From Pythagoras Order By 1 asc limit 10;
Unfortunately this ignores all indexes, etc and uses a plain old
filesort to perform this function. Any ideas on how this can be
improved?
The SQL that is, not the engine, hardware... (:
Cheers
Steve
--
Steve Holdoway BSc(Hons) MNZCS <***@greengecko.co.nz>
http://www.greengecko.co.nz
MSN: ***@greengecko.co.nz
Skype: sholdowa
Steve Holdoway BSc(Hons) MNZCS <***@greengecko.co.nz>
http://www.greengecko.co.nz
MSN: ***@greengecko.co.nz
Skype: sholdowa