2dsphere vs 2d Index Performance

I need to perform quick queries to find all documents within a specific radius of a GPS point. The radius will be small, and the accuracy is not critical, so I do not need to take into account spherical geometry. There will be many letters. Will I get better performance with 2d index than 2dsphere?

+7
mongodb gps database-performance
source share
2 answers

If you definitely don't need spherical geometry or multiple fields in a composite geoinformer (see notes in Geospatial Indexes in the MongoDB manual), 2d would be more appropriate. There will also be a slight advantage in storing coordinates as obsolete pairs (longitude, latitude) rather than GeoJSON points. This is probably not enough to significantly affect write performance, but it depends on what you mean by โ€œmany recordsโ€ and whether they will push your I / O limits.

I'm not sure about the relative query performance for different types of geoinformation, but you can easily set up a representative test case in your own development / deployment environment for comparison. Make sure that you average the measurements over a series of iterations so that the documents are loaded into memory, and there is a fair comparison.

You can also consider the haystack index , which is designed to return results for 2d queries in a small area, combined with additional field criteria (for example, "find restaurants near longitude, latitude"). If you are not concerned about accuracy or sorting by distance (and have an additional search field), this type of index may work well for your use case.

+11
source share

2dsphere now has version 3 after MongoDB 3.2

2dsphere is better

data https://jira.mongodb.org/browse/SERVER-18056

more details: https://www.mongodb.com/blog/post/geospatial-performance-improvements-in-mongodb-3-2

3.1.6 - 2dsphere V2

"executeTimeMillis": 1875,

"totalKeysExamined": 24335,

"totalDocsExamined": 41848,

After reindex

3.1.6 - 2dsphere V3

"executeTimeMillis": 94,

"totalKeysExamined": 21676,

"totalDocsExamined": 38176,

Compared to 2d

3.1.6 - 2d

"executeTimeMillis": 359,

"totalKeysExamined": 95671,

"totalDocsExamined": 112968,

+1
source share

All Articles