我们使用$nearSphere
选择器查询了约100万个项目。返回200个项目大约需要3到20秒。
从请求的解释计划中,我们可以看到它正在通过相同的索引进行6次。
这是mongodb查询计划程序的预期行为吗?
我们想知道是否有一种方法可以强制mongo首先通过endDate
之类的字段进行过滤以缩小集合,然后再使用$nearSphere
?
在我们的监视系统上,我们可以看到一些页面错误和断言,但它们可能与硬盘驱动器的IOPS不足有关。
谢谢您的帮助。
这是explan计划(我删除了被拒绝的计划,并在BinData行上加了注)
{
"queryPlanner": {
"plannerVersion": 1.0,
"namespace": "myCollection.Post",
"indexFilterSet": false,
"parsedQuery": {
"$and": [
{
"$or": [
{
"availableToUsers": {
"$eq": "M76zJCedq4"
}
},
{
"$nor": [
{
"availableToUsers": {
"$exists": true
}
}
]
}
]
},
{
"startDate": {
"$lt": ISODate(
"2019-03-01T01:02:00.000+0000"
)
}
},
{
"availableSubmitNumber": {
"$gt": 0.0
}
},
{
"endDate": {
"$gt": ISODate(
"2019-03-01T01:02:00.000+0000"
)
}
},
{
"name": {
"$in": ["Post1", "Post2"]
}
},
{
"$nor": [
{
"acceptedByUserId": {
"$eq": "M76zJCedq4"
}
}
]
},
{
"locationGeoPoint": {
"$nearSphere": [
174.9084055,
-36.9293289
]
}
}
]
},
"winningPlan": {
"stage": "FETCH",
"filter": {
"$and": [
{
"$or": [
{
"availableToUsers": {
"$eq": "M76zJCedq4"
}
},
{
"$nor": [
{
"availableToUsers": {
"$exists": true
}
}
]
}
]
},
{
"$nor": [
{
"acceptedByUserId": {
"$eq": "M76zJCedq4"
}
}
]
}
]
},
"inputStage": {
"stage": "GEO_NEAR_2D",
"keyPattern": {
"locationGeoPoint": "2d",
"endDate": 1.0,
"startDate": 1.0,
"availableSubmitNumber": 1.0,
"name": 1.0
},
"indexName": "locationGeoPoint_2d_endDate_1_startDate_1_availableSubmitNumber_1_name_1",
"indexVersion": 2.0,
"inputStages": [
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"filter": {
"$and": [
{
"endDate": {
"$gt": ISODate(
"2019-03-01T01:02:00.000+0000"
)
}
},
{
"startDate": {
"$lt": ISODate(
"2019-03-01T01:02:00.000+0000"
)
}
},
{
"availableSubmitNumber": {
"$gt": 0.0
}
},
{
"name": {
"$in": ["Post1", "Post2"]
}
}
]
},
"keyPattern": {
"locationGeoPoint": "2d",
"endDate": 1.0,
"startDate": 1.0,
"availableSubmitNumber": 1.0,
"name": 1.0
},
"indexName": "locationGeoPoint_2d_endDate_1_startDate_1_availableSubmitNumber_1_name_1",
"isMultiKey": false,
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": 2.0,
"direction": "forward",
"indexBounds": {
"locationGeoPoint": [
"[BinData(128, BEB167B000000000), BinData(128, BEB167BFFFFFFFFF)]"
],
"endDate": [
"[MinKey, MaxKey]"
],
"startDate": [
"[MinKey, MaxKey]"
],
"availableSubmitNumber": [
"[MinKey, MaxKey]"
],
"name": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"filter": {
"$and": [
{
"endDate": {
"$gt": ISODate(
"2019-03-01T01:02:00.000+0000"
)
}
},
{
"startDate": {
"$lt": ISODate(
"2019-03-01T01:02:00.000+0000"
)
}
},
{
"availableSubmitNumber": {
"$gt": 0.0
}
},
{
"name": {
"$in": ["Post1", "Post2"]
}
}
]
},
"keyPattern": {
"locationGeoPoint": "2d",
"endDate": 1.0,
"startDate": 1.0,
"availableSubmitNumber": 1.0,
"name": 1.0
},
"indexName": "locationGeoPoint_2d_endDate_1_startDate_1_availableSubmitNumber_1_name_1",
"isMultiKey": false,
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": 2.0,
"direction": "forward",
"indexBounds": {
"locationGeoPoint": [
"[BinData(128, BEB1658000000000), BinData(128, BEB165BFFFFFFFFF)]",
"[BinData(128, BEB165C000000000), BinData(128, BEB165FFFFFFFFFF)]"
],
"endDate": [
"[MinKey, MaxKey]"
],
"startDate": [
"[MinKey, MaxKey]"
],
"availableSubmitNumber": [
"[MinKey, MaxKey]"
],
"name": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"filter": {
"$and": [
{
"endDate": {
"$gt": ISODate(
"2019-03-01T01:02:00.000+0000"
)
}
},
{
"startDate": {
"$lt": ISODate(
"2019-03-01T01:02:00.000+0000"
)
}
},
{
"availableSubmitNumber": {
"$gt": 0.0
}
},
{
"name": {
"$in": ["Post1", "Post2"]
}
}
]
},
"keyPattern": {
"locationGeoPoint": "2d",
"endDate": 1.0,
"startDate": 1.0,
"availableSubmitNumber": 1.0,
"name": 1.0
},
"indexName": "locationGeoPoint_2d_endDate_1_startDate_1_availableSubmitNumber_1_name_1",
"isMultiKey": false,
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": 2.0,
"direction": "forward",
"indexBounds": {
"locationGeoPoint": [
"[BinData(128, BEB14BC000000000), BinData(128, BEB14BFFFFFFFFFF)]",
"[BinData(128, BEB14C0000000000), BinData(128, BEB14FFFFFFFFFFF)]",
"[BinData(128, BEB1580000000000), BinData(128, BEB15BFFFFFFFFFF)]",
"[BinData(128, BEB1600000000000), BinData(128, BEB163FFFFFFFFFF)]",
"[BinData(128, BEB1640000000000), BinData(128, BEB164FFFFFFFFFF)]",
"[BinData(128, BEB1650000000000), BinData(128, BEB1653FFFFFFFFF)]",
"[BinData(128, BEB1654000000000), BinData(128, BEB1657FFFFFFFFF)]",
"[BinData(128, BEB1680000000000), BinData(128, BEB16BFFFFFFFFFF)]"
],
"endDate": [
"[MinKey, MaxKey]"
],
"startDate": [
"[MinKey, MaxKey]"
],
"availableSubmitNumber": [
"[MinKey, MaxKey]"
],
"name": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"filter": {
"$and": [
{
"endDate": {
"$gt": ISODate(
"2019-03-01T01:02:00.000+0000"
)
}
},
{
"startDate": {
"$lt": ISODate(
"2019-03-01T01:02:00.000+0000"
)
}
},
{
"availableSubmitNumber": {
"$gt": 0.0
}
},
{
"name": {
"$in": ["Post1", "Post2"]
}
}
]
},
"keyPattern": {
"locationGeoPoint": "2d",
"endDate": 1.0,
"startDate": 1.0,
"availableSubmitNumber": 1.0,
"name": 1.0
},
"indexName": "locationGeoPoint_2d_endDate_1_startDate_1_availableSubmitNumber_1_name_1",
"isMultiKey": false,
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": 2.0,
"direction": "forward",
"indexBounds": {
"locationGeoPoint": [
"[BinData(128, BE9BE00000000000), BinData(128, BE9BEFFFFFFFFFFF)]",
"[BinData(128, BE9BF80000000000), BinData(128, BE9BFBFFFFFFFFFF)]",
"[BinData(128, BEB1100000000000), BinData(128, BEB11FFFFFFFFFFF)]",
"[BinData(128, BEB1300000000000), BinData(128, BEB13FFFFFFFFFFF)]",
"[BinData(128, BEB1400000000000), BinData(128, BEB143FFFFFFFFFF)]"
],
"endDate": [
"[MinKey, MaxKey]"
],
"startDate": [
"[MinKey, MaxKey]"
],
"availableSubmitNumber": [
"[MinKey, MaxKey]"
],
"name": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"filter": {
"$and": [
{
"endDate": {
"$gt": ISODate(
"2019-03-01T01:02:00.000+0000"
)
}
},
{
"startDate": {
"$lt": ISODate(
"2019-03-01T01:02:00.000+0000"
)
}
},
{
"availableSubmitNumber": {
"$gt": 0.0
}
},
{
"name": {
"$in": ["Post1", "Post2"]
}
}
]
},
"keyPattern": {
"locationGeoPoint": "2d",
"endDate": 1.0,
"startDate": 1.0,
"availableSubmitNumber": 1.0,
"name": 1.0
},
"indexName": "locationGeoPoint_2d_endDate_1_startDate_1_availableSubmitNumber_1_name_1",
"isMultiKey": false,
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": 2.0,
"direction": "forward",
"indexBounds": {
"locationGeoPoint": [
"[BinData(128, BE9B800000000000), BinData(128, BE9BBFFFFFFFFFFF)]",
"[BinData(128, BE9BC00000000000), BinData(128, BE9BCFFFFFFFFFFF)]"
],
"endDate": [
"[MinKey, MaxKey]"
],
"startDate": [
"[MinKey, MaxKey]"
],
"availableSubmitNumber": [
"[MinKey, MaxKey]"
],
"name": [
"[MinKey, MaxKey]"
]
}
}
}
]
}
}
},
"serverInfo": {
"port": 27017.0,
"version": "4.0.3",
"gitVersion": "7ea530946fa7880364d88c8d8b6026bbc9ffa48c"
},
"ok": 1.0,
"operationTime": Timestamp(1551940718,
4),
"$clusterTime": {
"clusterTime": Timestamp(1551940718,
4),
"signature": {
"hash": BinData(0,
"AAAAAAAAAAAAAAAAAAAAAAAAAAA="
),
"keyId": NumberLong(0)
}
}
}