Question

Benefits of SPATIAL over BOUNDING

What are the benefits of using a SPATIAL query rather than a simple MySQL query that utilised a bounding box?

For example, if I wanted to find all locations that fall within a certain polygon:

Something like this:

Bounding Box Example

SELECT * FROM geoplaces 
WHERE geolat BETWEEN ? AND ?
AND geolng BETWEEN ? AND ?

As I understand, the only real benefit is that spatial will also factor in the earth's curvature?

Which method is fastest also?

Was it helpful?

Solution

Advantages:

  1. You can use shapes other than points and rectangles, and operations other than "is-in".
  2. If you can use SPATIAL indexes, performance is orders of magnitude better (depending of course on the size and nature of your data).

Disadvantages:

  1. Spatial objects are binary blobs - some care is needed handling them (e.g. you typically can't copy-paste a value).
  2. Spatial indexes in mySQL are only available for MyISAM tables.
  3. Support in mySQL is somewhat primitive; many operations are not implemented yet

If your database is large and you need searches like the one in your example to be fast, you should definitely go with SPATIAL indexes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top