This query should give me the closest element to a given :x
, :y
in cartesian coordinates.
SELECT `type`
FROM `mapgen_centers`
ORDER BY SQRT(POW((:x - `x`), 2) + POW((:y - `y`), 2))
LIMIT 1
It currently takes 0.002s on average which is okay, but I have the feeling this can be better, especially because I currently fire it very, very often and frequent, so that the whole execution of the script piles of to several minutes.
Can (and if, how) this be optimized through any means available on a standard MySQL installation (procedures, functions, indexes, configuration, ...)