简体   繁体   English

什么是空间索引,我应该什么时候使用它?

[英]What is a SPATIAL INDEX and when should I use it?

Like most of the average PHP web developers I use MySql as a RDBMS.像大多数普通 PHP Web 开发人员一样,我使用 MySql 作为 RDBMS。 MySql (as other RDBMS also) offers SPATIAL INDEX features, but I'm don't get it very well. MySql(与其他 RDBMS 一样)也提供空间索引功能,但我不太了解。 I have googled for it but didn't find clear real world examples to clarify my bad knowledge about it.我已经用谷歌搜索了它,但没有找到清晰的现实世界的例子来澄清我对它的不了解。

Could someone explain me a little bit what is a SPATIAL INDEX and when should I use it?有人可以向我解释一下什么是空间索引,我应该什么时候使用它?

You can use a spatial index for indexing geo-objects - shapes.您可以使用空间索引来索引地理对象 - 形状。 The spatial index makes it possible to efficiently search for objects that overlap in space空间索引使高效搜索空间重叠的对象成为可能

Spatial Index is like an ordinary index with this difference that Spatial objects are not 1D data points rather are in higher dimension space (eg 2D) and thus Ordinary indexes such as BTree are not appropriate for indexing such data.空间索引就像普通索引,区别在于空间对象不是一维数据点,而是位于更高维度的空间(例如2D)中,因此普通索引(例如BTree)不适合对此类数据进行索引。 The well-known spatial Index technique is R-tree ( Google it on wikipedia )著名的空间索引技术是 R-tree(在 wikipedia 上搜索)

When we need to store some geographic data for storing locations OR we need to store shape related data then we can use it.当我们需要存储一些用于存储位置的地理数据或者我们需要存储与形状相关的数据时,我们就可以使用它。

For Instance, Imagine that you are trying to develop an application that helps people find restaurants, pubs, bars and other hangout places near them.例如,假设您正在尝试开发一个应用程序,帮助人们找到附近的餐馆、酒吧、酒吧和其他聚会场所。 In nutshell, this will be a location discovery platform.简而言之,这将是一个位置发现平台。

Looking from a back-end perspective, we would be needing to store geographic data of these locations like Latitude and Longitude.从后端的角度来看,我们需要存储这些位置的地理数据,如纬度和经度。 Then we would need to write functions that calculate the distance between the user and the location (to show how far the location is from him/her).然后我们需要编写函数来计算用户和位置之间的距离(以显示位置离他/她有多远)。 Using the same function, we can design an algorithm that finds closest places near to the user or within a given radius from him/her.使用相同的函数,我们可以设计一个算法来找到离用户最近的地方或距离他/她给定半径内的最近地点。

You may find the better idea with example over here :- https://medium.com/sysf/playing-with-geometry-spatial-data-type-in-mysql-645b83880331您可能会在这里找到更好的想法:- https://medium.com/sysf/playing-with-geometry-spatial-data-type-in​​-mysql-645b83880331

The use of spacial index is best for searching exact matching value look-up,not for range scan.It is mainly supported in MyISAM tables but from MySQL 5.7.4 LAB release,it is also supported by Innodb.使用空间索引最适合搜索精确匹配值查找,而不是范围扫描。它主要在 MyISAM 表中支持,但从 MySQL 5.7.4 LAB 版本开始,Innodb 也支持。

References:- http://dev.mysql.com/doc/refman/5.5/en/creating-spatial-indexes.html http://mysqlserverteam.com/innodb-spatial-indexes-in-5-7-4-lab-release/参考资料:- http://dev.mysql.com/doc/refman/5.5/en/creating-spatial-indexes.html http://mysqlserverteam.com/innodb-spatial-indexes-in-5-7-4-实验室发布/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM