Benefits of SPATIAL over using standard bounding box query
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开发者_如何学JAVA 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?
Advantages:
- You can use shapes other than points and rectangles, and operations other than "is-in".
- If you can use SPATIAL indexes, performance is orders of magnitude better (depending of course on the size and nature of your data).
Disadvantages:
- Spatial objects are binary blobs - some care is needed handling them (e.g. you typically can't copy-paste a value).
- Spatial indexes in mySQL are only available for MyISAM tables.
- 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.
精彩评论