Typically, database servers are tied to IOs, not tied to CPUs. YMMV, but if your case is typical, it would be advisable to perform a Haversine calculation on the database server.
I would recommend using a custom lookup table for your arcsine calculations, since you can probably provide approximate distances on a logarithmic scale, for example:
For typical distances found in one metropolitan area, you can use only 2 or 3 members of the Taylor extension for sin and sose and not more accurate calculations:
- sin (x) = ~ x - x ^ 3/6 + x ^ 5/120
- cos (x) = ~ 1 - x ^ 2/2 + x ^ 4/24
Recall also that for a converging Taylor series, the error after the nth term is strictly less than the value of the (n + 1) โterm. This allows you to effectively stop the calculation as soon as the desired accuracy is achieved, which in general for the Haversin formula is only 0.5% due to the fact that the Earth is not a homogeneous sphere.
source share