This query should give me the closest element to the 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 an average of 0.002 seconds, but thatโs fine, but I feel it can be better, especially because I am currently running it very, very often and often, so that the entire script runs for several minutes.
It is possible (and if, how) to optimize this using any means available on a standard MySQL installation (procedures, functions, indexes, configuration, ...)
source share