[SERVER-20843] $geoIntersects performs poorly on polygons with lots of coordinates Created: 09/Oct/15  Updated: 28/Dec/23

Status: Backlog
Project: Core Server
Component/s: Geo
Affects Version/s: 3.0.6
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Casoa Makaso Assignee: Backlog - Query Integration
Resolution: Unresolved Votes: 6
Labels: qi-geo, query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File polygonabstracted.png     Zip Archive polygondescription.zip    
Issue Links:
Related
related to SERVER-57938 Skip polygon validation for stored Ge... Closed
is related to SERVER-21120 Improve performance of $geoWithin que... Backlog
Assigned Teams:
Query Integration
Operating System: ALL
Steps To Reproduce:

Import the attached database and run the query:

db.PolygonDescription.find({
    $query: {
        geo: {
            $geoIntersects: {
                $geometry: {
                    type: "Point",
                    coordinates: [
                        10.5891,
                        49.77997
                    ]
                }
            }
        }
    },
    $explain: true
},
{
    _id: 1
}) 

Delete the last document (id=56179fa25495b1184924b03e) and rerun the query. You'll see a marginal speedup, by just removing this one document.

Participants:
Case:

 Description   

Test Environment: Windows 10 x64, MongoDB 3.0.6

I have a very small database with 9999 Polygons (their coordinate consists of just 5 Points).

Querying the set with geointersects (using a geosphere index) is fast, until I add one more polygon (which covers all others and has a large coordinate set > 130000 points).

I'll add the mongoexport of my database.

Explain without the last "huge" polygon:

{ 
    "queryPlanner" : {
        "plannerVersion" : NumberInt(1), 
        "namespace" : "test.PolygonDescription", 
        "indexFilterSet" : false, 
        "parsedQuery" : {
            "geo" : {
                "$geoIntersects" : {
                    "$geometry" : {
                        "type" : "Point", 
                        "coordinates" : [
                            10.5891, 
                            49.77997
                        ]
                    }
                }
            }
        }, 
        "winningPlan" : {
            "stage" : "PROJECTION", 
            "transformBy" : {
                "_id" : NumberInt(1)
            }, 
            "inputStage" : {
                "stage" : "FETCH", 
                "filter" : {
                    "geo" : {
                        "$geoIntersects" : {
                            "$geometry" : {
                                "type" : "Point", 
                                "coordinates" : [
                                    10.5891, 
                                    49.77997
                                ]
                            }
                        }
                    }
                }, 
                "inputStage" : {
                    "stage" : "IXSCAN", 
                    "keyPattern" : {
                        "geo" : "2dsphere"
                    }, 
                    "indexName" : "geo_2dsphere", 
                    "isMultiKey" : true, 
                    "isUnique" : false, 
                    "isSparse" : false, 
                    "isPartial" : false, 
                    "indexVersion" : NumberInt(1), 
                    "direction" : "forward", 
                    "indexBounds" : {
                        "geo" : [
                            "[5116089176692883456, 5116089176692883456]", 
                            "[5161758491664187392, 5161758491664187392]", 
                            "[5161806870175809536, 5161806870175809536]", 
                            "[5161807601393991680, 5161807601393991680]", 
                            "[5161807601943445504, 5161807601943445504]", 
                            "[5161807601946329088, 5161807601946329088]", 
                            "[5161807601946525696, 5161807601946525696]", 
                            "[5161807601946525697, 5161807601946558463]", 
                            "[5161807601946591232, 5161807601946591232]", 
                            "[5161807601947639808, 5161807601947639808]", 
                            "[5161807601997971456, 5161807601997971456]", 
                            "[5161807602199298048, 5161807602199298048]", 
                            "[5161807604615217152, 5161807604615217152]", 
                            "[5161807608910184448, 5161807608910184448]", 
                            "[5161807626090053632, 5161807626090053632]", 
                            "[5161807694809530368, 5161807694809530368]", 
                            "[5161807969687437312, 5161807969687437312]", 
                            "[5161811268222320640, 5161811268222320640]", 
                            "[5161969597896720384, 5161969597896720384]", 
                            "[5162251072873431040, 5162251072873431040]", 
                            "[5165628772593958912, 5165628772593958912]", 
                            "[5170132372221329408, 5170132372221329408]"
                        ]
                    }
                }
            }
        }, 
        "rejectedPlans" : [
 
        ]
    }, 
    "executionStats" : {
        "executionSuccess" : true, 
        "nReturned" : NumberInt(4), 
        "executionTimeMillis" : NumberInt(1), 
        "totalKeysExamined" : NumberInt(239), 
        "totalDocsExamined" : NumberInt(233), 
        "executionStages" : {
            "stage" : "PROJECTION", 
            "nReturned" : NumberInt(4), 
            "executionTimeMillisEstimate" : NumberInt(0), 
            "works" : NumberInt(240), 
            "advanced" : NumberInt(4), 
            "needTime" : NumberInt(235), 
            "needYield" : NumberInt(0), 
            "saveState" : NumberInt(1), 
            "restoreState" : NumberInt(1), 
            "isEOF" : NumberInt(1), 
            "invalidates" : NumberInt(0), 
            "transformBy" : {
                "_id" : NumberInt(1)
            }, 
            "inputStage" : {
                "stage" : "FETCH", 
                "filter" : {
                    "geo" : {
                        "$geoIntersects" : {
                            "$geometry" : {
                                "type" : "Point", 
                                "coordinates" : [
                                    10.5891, 
                                    49.77997
                                ]
                            }
                        }
                    }
                }, 
                "nReturned" : NumberInt(4), 
                "executionTimeMillisEstimate" : NumberInt(0), 
                "works" : NumberInt(240), 
                "advanced" : NumberInt(4), 
                "needTime" : NumberInt(235), 
                "needYield" : NumberInt(0), 
                "saveState" : NumberInt(1), 
                "restoreState" : NumberInt(1), 
                "isEOF" : NumberInt(1), 
                "invalidates" : NumberInt(0), 
                "docsExamined" : NumberInt(233), 
                "alreadyHasObj" : NumberInt(0), 
                "inputStage" : {
                    "stage" : "IXSCAN", 
                    "nReturned" : NumberInt(233), 
                    "executionTimeMillisEstimate" : NumberInt(0), 
                    "works" : NumberInt(240), 
                    "advanced" : NumberInt(233), 
                    "needTime" : NumberInt(6), 
                    "needYield" : NumberInt(0), 
                    "saveState" : NumberInt(1), 
                    "restoreState" : NumberInt(1), 
                    "isEOF" : NumberInt(1), 
                    "invalidates" : NumberInt(0), 
                    "keyPattern" : {
                        "geo" : "2dsphere"
                    }, 
                    "indexName" : "geo_2dsphere", 
                    "isMultiKey" : true, 
                    "isUnique" : false, 
                    "isSparse" : false, 
                    "isPartial" : false, 
                    "indexVersion" : NumberInt(1), 
                    "direction" : "forward", 
                    "indexBounds" : {
                        "geo" : [
                            "[5116089176692883456, 5116089176692883456]", 
                            "[5161758491664187392, 5161758491664187392]", 
                            "[5161806870175809536, 5161806870175809536]", 
                            "[5161807601393991680, 5161807601393991680]", 
                            "[5161807601943445504, 5161807601943445504]", 
                            "[5161807601946329088, 5161807601946329088]", 
                            "[5161807601946525696, 5161807601946525696]", 
                            "[5161807601946525697, 5161807601946558463]", 
                            "[5161807601946591232, 5161807601946591232]", 
                            "[5161807601947639808, 5161807601947639808]", 
                            "[5161807601997971456, 5161807601997971456]", 
                            "[5161807602199298048, 5161807602199298048]", 
                            "[5161807604615217152, 5161807604615217152]", 
                            "[5161807608910184448, 5161807608910184448]", 
                            "[5161807626090053632, 5161807626090053632]", 
                            "[5161807694809530368, 5161807694809530368]", 
                            "[5161807969687437312, 5161807969687437312]", 
                            "[5161811268222320640, 5161811268222320640]", 
                            "[5161969597896720384, 5161969597896720384]", 
                            "[5162251072873431040, 5162251072873431040]", 
                            "[5165628772593958912, 5165628772593958912]", 
                            "[5170132372221329408, 5170132372221329408]"
                        ]
                    }, 
                    "keysExamined" : NumberInt(239), 
                    "dupsTested" : NumberInt(233), 
                    "dupsDropped" : NumberInt(0), 
                    "seenInvalidated" : NumberInt(0)
                }
            }
        }, 
        "allPlansExecution" : [
 
        ]
    }
}

Explain with the 10000ths large polygon:

{ 
    "queryPlanner" : {
        "plannerVersion" : NumberInt(1), 
        "namespace" : "test.PolygonDescription", 
        "indexFilterSet" : false, 
        "parsedQuery" : {
            "geo" : {
                "$geoIntersects" : {
                    "$geometry" : {
                        "type" : "Point", 
                        "coordinates" : [
                            10.5891, 
                            49.77997
                        ]
                    }
                }
            }
        }, 
        "winningPlan" : {
            "stage" : "PROJECTION", 
            "transformBy" : {
                "_id" : NumberInt(1)
            }, 
            "inputStage" : {
                "stage" : "FETCH", 
                "filter" : {
                    "geo" : {
                        "$geoIntersects" : {
                            "$geometry" : {
                                "type" : "Point", 
                                "coordinates" : [
                                    10.5891, 
                                    49.77997
                                ]
                            }
                        }
                    }
                }, 
                "inputStage" : {
                    "stage" : "IXSCAN", 
                    "keyPattern" : {
                        "geo" : "2dsphere"
                    }, 
                    "indexName" : "geo_2dsphere", 
                    "isMultiKey" : true, 
                    "isUnique" : false, 
                    "isSparse" : false, 
                    "isPartial" : false, 
                    "indexVersion" : NumberInt(1), 
                    "direction" : "forward", 
                    "indexBounds" : {
                        "geo" : [
                            "[5116089176692883456, 5116089176692883456]", 
                            "[5161758491664187392, 5161758491664187392]", 
                            "[5161806870175809536, 5161806870175809536]", 
                            "[5161807601393991680, 5161807601393991680]", 
                            "[5161807601943445504, 5161807601943445504]", 
                            "[5161807601946329088, 5161807601946329088]", 
                            "[5161807601946525696, 5161807601946525696]", 
                            "[5161807601946525697, 5161807601946558463]", 
                            "[5161807601946591232, 5161807601946591232]", 
                            "[5161807601947639808, 5161807601947639808]", 
                            "[5161807601997971456, 5161807601997971456]", 
                            "[5161807602199298048, 5161807602199298048]", 
                            "[5161807604615217152, 5161807604615217152]", 
                            "[5161807608910184448, 5161807608910184448]", 
                            "[5161807626090053632, 5161807626090053632]", 
                            "[5161807694809530368, 5161807694809530368]", 
                            "[5161807969687437312, 5161807969687437312]", 
                            "[5161811268222320640, 5161811268222320640]", 
                            "[5161969597896720384, 5161969597896720384]", 
                            "[5162251072873431040, 5162251072873431040]", 
                            "[5165628772593958912, 5165628772593958912]", 
                            "[5170132372221329408, 5170132372221329408]"
                        ]
                    }
                }
            }
        }, 
        "rejectedPlans" : [
 
        ]
    }, 
    "executionStats" : {
        "executionSuccess" : true, 
        "nReturned" : NumberInt(5), 
        "executionTimeMillis" : NumberInt(87), 
        "totalKeysExamined" : NumberInt(241), 
        "totalDocsExamined" : NumberInt(234), 
        "executionStages" : {
            "stage" : "PROJECTION", 
            "nReturned" : NumberInt(5), 
            "executionTimeMillisEstimate" : NumberInt(80), 
            "works" : NumberInt(241), 
            "advanced" : NumberInt(5), 
            "needTime" : NumberInt(235), 
            "needYield" : NumberInt(0), 
            "saveState" : NumberInt(2), 
            "restoreState" : NumberInt(2), 
            "isEOF" : NumberInt(1), 
            "invalidates" : NumberInt(0), 
            "transformBy" : {
                "_id" : NumberInt(1)
            }, 
            "inputStage" : {
                "stage" : "FETCH", 
                "filter" : {
                    "geo" : {
                        "$geoIntersects" : {
                            "$geometry" : {
                                "type" : "Point", 
                                "coordinates" : [
                                    10.5891, 
                                    49.77997
                                ]
                            }
                        }
                    }
                }, 
                "nReturned" : NumberInt(5), 
                "executionTimeMillisEstimate" : NumberInt(80), 
                "works" : NumberInt(241), 
                "advanced" : NumberInt(5), 
                "needTime" : NumberInt(235), 
                "needYield" : NumberInt(0), 
                "saveState" : NumberInt(2), 
                "restoreState" : NumberInt(2), 
                "isEOF" : NumberInt(1), 
                "invalidates" : NumberInt(0), 
                "docsExamined" : NumberInt(234), 
                "alreadyHasObj" : NumberInt(0), 
                "inputStage" : {
                    "stage" : "IXSCAN", 
                    "nReturned" : NumberInt(234), 
                    "executionTimeMillisEstimate" : NumberInt(0), 
                    "works" : NumberInt(241), 
                    "advanced" : NumberInt(234), 
                    "needTime" : NumberInt(6), 
                    "needYield" : NumberInt(0), 
                    "saveState" : NumberInt(2), 
                    "restoreState" : NumberInt(2), 
                    "isEOF" : NumberInt(1), 
                    "invalidates" : NumberInt(0), 
                    "keyPattern" : {
                        "geo" : "2dsphere"
                    }, 
                    "indexName" : "geo_2dsphere", 
                    "isMultiKey" : true, 
                    "isUnique" : false, 
                    "isSparse" : false, 
                    "isPartial" : false, 
                    "indexVersion" : NumberInt(1), 
                    "direction" : "forward", 
                    "indexBounds" : {
                        "geo" : [
                            "[5116089176692883456, 5116089176692883456]", 
                            "[5161758491664187392, 5161758491664187392]", 
                            "[5161806870175809536, 5161806870175809536]", 
                            "[5161807601393991680, 5161807601393991680]", 
                            "[5161807601943445504, 5161807601943445504]", 
                            "[5161807601946329088, 5161807601946329088]", 
                            "[5161807601946525696, 5161807601946525696]", 
                            "[5161807601946525697, 5161807601946558463]", 
                            "[5161807601946591232, 5161807601946591232]", 
                            "[5161807601947639808, 5161807601947639808]", 
                            "[5161807601997971456, 5161807601997971456]", 
                            "[5161807602199298048, 5161807602199298048]", 
                            "[5161807604615217152, 5161807604615217152]", 
                            "[5161807608910184448, 5161807608910184448]", 
                            "[5161807626090053632, 5161807626090053632]", 
                            "[5161807694809530368, 5161807694809530368]", 
                            "[5161807969687437312, 5161807969687437312]", 
                            "[5161811268222320640, 5161811268222320640]", 
                            "[5161969597896720384, 5161969597896720384]", 
                            "[5162251072873431040, 5162251072873431040]", 
                            "[5165628772593958912, 5165628772593958912]", 
                            "[5170132372221329408, 5170132372221329408]"
                        ]
                    }, 
                    "keysExamined" : NumberInt(241), 
                    "dupsTested" : NumberInt(234), 
                    "dupsDropped" : NumberInt(0), 
                    "seenInvalidated" : NumberInt(0)
                }
            }
        }, 
        "allPlansExecution" : [
 
        ]
    }
}



 Comments   
Comment by Beth Morgan [ 16/Sep/20 ]

+1

We are experiencing this performance bottle neck on production...would be great to have this patched/fixed....

 

Comment by Rafael Acevedo [ 31/May/17 ]

In my case, large polygons mean the ones that >50k vertices. They represent roughly 10% of all polygons in the DB(400k total), some of them being MultiPolygons. A single point-in-polygon query is taking 100ms on average, with no additional queries being executed at the same time. When there are multiple queries running in parallel, the average execution time increases to ~600ms or so.
The explain output for the geoIntersects query is as follows:

{
	"queryPlanner" : {
		"plannerVersion" : 1,
		"namespace" : "<our_collection>",
		"indexFilterSet" : false,
		"parsedQuery" : {
			"geometry" : {
				"$geoIntersects" : {
					"$geometry" : {
						"type" : "Point",
						"coordinates" : [
							-46.7902269,
							-23.5360438
						]
					}
				}
			}
		},
		"winningPlan" : {
			"stage" : "FETCH",
			"filter" : {
				"geometry" : {
					"$geoIntersects" : {
						"$geometry" : {
							"type" : "Point",
							"coordinates" : [
								-46.7902269,
								-23.5360438
							]
						}
					}
				}
			},
			"inputStage" : {
				"stage" : "IXSCAN",
				"keyPattern" : {
					"geometry" : "2dsphere"
				},
				"indexName" : "geometry_2dsphere",
				"isMultiKey" : true,
				"isUnique" : false,
				"isSparse" : false,
				"isPartial" : false,
				"indexVersion" : 1,
				"direction" : "forward",
				"indexBounds" : {
					"geometry" : [
						"[-7728176960567771136, -7728176960567771136]",
						"[-7724799260847243264, -7724799260847243264]",
						"[-7724025204661288960, -7724025204661288960]",
						"[-7723972428103155712, -7723972428103155712]",
						"[-7723959233963622400, -7723959233963622400]",
						"[-7723955935428739072, -7723955935428739072]",
						"[-7723955231054102528, -7723955231054102528]",
						"[-7723955222195732480, -7723955222195732480]",
						"[-7723955222128623616, -7723955222128623616]",
						"[-7723955222111846400, -7723955222111846400]",
						"[-7723955222099263488, -7723955222099263488]",
						"[-7723955222097002495, -7723955222096969729]",
						"[-7723955222096969728, -7723955222096969728]",
						"[-7723955222096904192, -7723955222096904192]",
						"[-7723955222096117760, -7723955222096117760]",
						"[-7723955221390426112, -7723955221390426112]",
						"[-7723955218169200640, -7723955218169200640]",
						"[-7723955179514494976, -7723955179514494976]",
						"[-7723955110795018240, -7723955110795018240]",
						"[-7723954835917111296, -7723954835917111296]",
						"[-7723673360940400640, -7723673360940400640]",
						"[-7710162562058289152, -7710162562058289152]"
					]
				}
			}
		},
		"rejectedPlans" : [ ]
	},
	"executionStats" : {
		"executionSuccess" : true,
		"nReturned" : 8,
		"executionTimeMillis" : 126,
		"totalKeysExamined" : 22,
		"totalDocsExamined" : 12,
		"executionStages" : {
			"stage" : "FETCH",
			"filter" : {
				"geometry" : {
					"$geoIntersects" : {
						"$geometry" : {
							"type" : "Point",
							"coordinates" : [
								-46.7902269,
								-23.5360438
							]
						}
					}
				}
			},
			"nReturned" : 8,
			"executionTimeMillisEstimate" : 120,
			"works" : 22,
			"advanced" : 8,
			"needTime" : 13,
			"needYield" : 0,
			"saveState" : 3,
			"restoreState" : 3,
			"isEOF" : 1,
			"invalidates" : 0,
			"docsExamined" : 12,
			"alreadyHasObj" : 0,
			"inputStage" : {
				"stage" : "IXSCAN",
				"nReturned" : 12,
				"executionTimeMillisEstimate" : 0,
				"works" : 22,
				"advanced" : 12,
				"needTime" : 9,
				"needYield" : 0,
				"saveState" : 3,
				"restoreState" : 3,
				"isEOF" : 1,
				"invalidates" : 0,
				"keyPattern" : {
					"geometry" : "2dsphere"
				},
				"indexName" : "geometry_2dsphere",
				"isMultiKey" : true,
				"isUnique" : false,
				"isSparse" : false,
				"isPartial" : false,
				"indexVersion" : 1,
				"direction" : "forward",
				"indexBounds" : {
					"geometry" : [
						"[-7728176960567771136, -7728176960567771136]",
						"[-7724799260847243264, -7724799260847243264]",
						"[-7724025204661288960, -7724025204661288960]",
						"[-7723972428103155712, -7723972428103155712]",
						"[-7723959233963622400, -7723959233963622400]",
						"[-7723955935428739072, -7723955935428739072]",
						"[-7723955231054102528, -7723955231054102528]",
						"[-7723955222195732480, -7723955222195732480]",
						"[-7723955222128623616, -7723955222128623616]",
						"[-7723955222111846400, -7723955222111846400]",
						"[-7723955222099263488, -7723955222099263488]",
						"[-7723955222097002495, -7723955222096969729]",
						"[-7723955222096969728, -7723955222096969728]",
						"[-7723955222096904192, -7723955222096904192]",
						"[-7723955222096117760, -7723955222096117760]",
						"[-7723955221390426112, -7723955221390426112]",
						"[-7723955218169200640, -7723955218169200640]",
						"[-7723955179514494976, -7723955179514494976]",
						"[-7723955110795018240, -7723955110795018240]",
						"[-7723954835917111296, -7723954835917111296]",
						"[-7723673360940400640, -7723673360940400640]",
						"[-7710162562058289152, -7710162562058289152]"
					]
				},
				"keysExamined" : 22,
				"dupsTested" : 12,
				"dupsDropped" : 0,
				"seenInvalidated" : 0
			}
		}
	},
	"serverInfo" : {
		"host" : "<my_host>",
		"port" : 27017,
		"version" : "3.2.9",
		"gitVersion" : "22ec9e93b40c85fc7cae7d56e7d6a02fd811088c"
	},
	"ok" : 1
}

Comment by Siyuan Zhou [ 30/May/17 ]

racevedoo, thanks for reporting the issue. Although we don't have any plan to fix this issue in near future, could you please share more details about the performance in your case (e.g. how large/complex the polygons are) and (perhaps) the dataset and queries to help us understand your issue better and prioritize this ticket accordingly? The output of find(...).explain("executionStats") would be helpful as well.

Comment by Rafael Acevedo [ 24/May/17 ]

+1

I'm having similar issues while querying for point-in-polygon with ~40k large polygons running mongo 3.2.9. Any updates on this issue?

Comment by Casoa Makaso [ 09/Feb/16 ]

siyuan.zhou thanks for the response.

Maybe I didn't explain our needs correctly.

I attached a screenshot of a very abstract model of our polygons in the database. (Each colored border represents a polygon).

The blue star is the position of a user (Lat/Lng) who requests information about his current place. (Kinda a reverse geocoding approach).

Because we have only parts of the countries covered with counties/cities, we need to have huge polygons for the countries (ofc the world isn't needed currently).

I don't see how we could solve this precomputed?

Comment by Siyuan Zhou [ 09/Feb/16 ]

casoo, if the hierarchy is always world -> country -> county -> in your case, I still think it's possible to precompute the hierarchy in advance by computing a given city $within which country / county. Another easier solution would be to cache the hierarchy result for cities in a separate collection and reuse it whenever it's possible.

GeoNear is more expensive than point-in-polygon check as it computes the distance to a polygon.

Comment by Casoa Makaso [ 07/Feb/16 ]

Let me add that I also tried it with a geoNear query (which returns the same results in our case as geoIntersects)

{geo: { $near: {$geometry:

{type: "Point", coordinates: [ 10.5891, 49.77997 ]}

, $maxDistance: 1}}}

but I did not see any improvements.

Comment by Casoa Makaso [ 03/Feb/16 ]

siyuan.zhou, thanks for your fast response.

I see that the workaround you describe makes completly sense, if I want to know which POI's are in which county/country.

But our main use case is a different one (see the above query):

1) We have polygons describing the world/countries/counties/cities etc.

2) A user e.g. is located in 37.7576948,-122.4726194 (San Francisco)

3) He then wants to know which areas intersect with his coordinates

4) Therefore the query is: Give me all polygons that intersect with 37.7576948,-122.4726194

5) The result would be: "World", "USA", "San Francisco County", "San Francisco City"

There is no way I know to precompute this e.g. in a string field.

Comment by Siyuan Zhou [ 02/Feb/16 ]

casoo, thanks for providing the details about your use case. Point-in-polygon check is very computationally expensive for complex polygons. SERVER-21120 tracks future work to improve the performance on complex polygons.

The complex polygon given above is "the world" or a country, I suppose? As a workaround, it gives a better performance to query the point's country once and store the country in a string field. Subsequent queries on the string field and simpler polygons (county, POI) can be very fast.

Comment by Casoa Makaso [ 02/Feb/16 ]

Hello anonymous.user,

I see some improvements with 3.2.0 (final now), but they don't give us the expected boost while running our queries.

The above mentioned query with the large polygon included still takes ~80ms on my powerful dev machines (compared to 1ms for the query without the large polygon).
That's a huge factor when we get a lot of queries in parallel from users.

I tested the case, where I added exact the same large polygon twice and the execution time doubles to 160ms.

ramon.fernandez, basically we have polygons describing the world.
It starts with a large polygon "the world", which contains "country" polygons which then break down to county borders and POI's within.

Comment by Ramon Fernandez Marina [ 09/Jan/16 ]

camak, is there any additional information about your use case you can provide that may help us improve the performance of geospatial queries?

Comment by Kelsey Schubert [ 11/Nov/15 ]

Hi camak,

I've run the queries and confirmed the increase in execution time when the large polygon is included in the collection on 3.0.6 and in the master branch. However, on our master branch we have made substantial improvements to our geospatial queries.

On my machine, with the large polygon included, 3.0.6 executed the query in 680 ms and master executed in the same query in 78 ms. Our master branch is at 3.2.0-rc2. I would recommend that you test whether this new version fits your needs. Please let us know a bit more about your use cases and whether 3.2.0-rc2 works for you.

Kind regards,
Thomas

Comment by Casoa Makaso [ 10/Oct/15 ]

Just another note: I have an 2dsphere index on the geo field.

Even if I add the document with id=56179fa25495b1184924b03e (which has > 130000 coordinates) to an empty collection and run the same query, I get the same slow query returns.

The above output stats of ""executionTimeMillis" : NumberInt(87)", may not seem slow. But on our production servers which are not as powerful as my development machine I have query times above 1000ms, which makes it kinda unusable.

Generated at Thu Feb 08 03:55:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.