MySQL 什么是空间索引,我应该什么时候使用它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2256364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is a SPATIAL INDEX and when should I use it?
提问by demian
Like most of the average PHP web developers I use MySql as a RDBMS. MySql (as other RDBMS also) offers SPATIAL INDEX features, but I'm don't get it very well. I have googled for it but didn't find clear real world examples to clarify my bad knowledge about it.
像大多数普通 PHP Web 开发人员一样,我使用 MySql 作为 RDBMS。MySql(与其他 RDBMS 一样)也提供空间索引功能,但我不太了解。我已经用谷歌搜索了它,但没有找到清晰的现实世界的例子来澄清我对它的不了解。
Could someone explain me a little bit what is a SPATIAL INDEX and when should I use it?
有人可以向我解释一下什么是空间索引,我应该什么时候使用它?
回答by Roland Bouman
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
您可以使用空间索引来索引地理对象 - 形状。空间索引使高效搜索空间重叠的对象成为可能
回答by user2077168
Spatial Index is like an ordinary index with this difference that Spatial objects are not 1D data points rather are in higher dimension space (e.g. 2D) and thus Ordinary indexes such as BTree are not appropriate for indexing such data. The well-known spatial Index technique is R-tree ( Google it on wikipedia )
空间索引就像普通索引,区别在于空间对象不是一维数据点,而是位于更高维度的空间(例如2D)中,因此普通索引(例如BTree)不适合对此类数据进行索引。著名的空间索引技术是 R-tree(在 wikipedia 上搜索)
回答by Abhishek Sharma
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.htmlhttp://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-实验室发布/