MongoDB 2d index query with an additional sorting field - performance issue
I have a compound index in a 2d and normal field:
"key" : {
"_meta.loc.coordinates" : "2d",
"_meta.unifiedAt" : 1
},
Then I want to execute the following query with sorting:
db.static_booking
.find({ "_meta.loc.coordinates": { "$geoWithin": { "$box": [ [ -0.70724367, 51.13817111 ], [ 0.45524367, 51.86182889 ] ] } } }, {itemId: 1})
.sort({'_meta.unifiedAt': 1})
.limit(100)
The problem I have is that it takes a very long time to return the results. Checking the explain, I see that it does not use the compound index created:
> db.static_booking.find({ "_meta.loc.coordinates": { "$geoWithin": { "$box": [ [ -0.70724367, 51.13817111 ], [ 0.45524367, 51.86182889 ] ] } } }, {itemId: 1}).sort({'_meta.unifiedAt': 1}).limit(100).explain()
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "seetransparent.static_booking",
"indexFilterSet" : false,
"parsedQuery" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"winningPlan" : {
"stage" : "LIMIT",
"limitAmount" : 100,
"inputStage" : {
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.unifiedAt" : 1
},
"indexName" : "_meta.unifiedAt_1",
"isMultiKey" : false,
"multiKeyPaths" : {
"_meta.unifiedAt" : [ ]
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.unifiedAt" : [
"[MinKey, MaxKey]"
]
}
}
}
}
},
"rejectedPlans" : [
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d"
},
"indexName" : "_meta.loc.coordinates_2d",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
]
}
}
}
}
}
},
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d",
"_meta.delisted" : 1
},
"indexName" : "_meta.loc.coordinates_2d__meta.delisted_1",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
],
"_meta.delisted" : [
"[MinKey, MaxKey]"
]
}
}
}
}
}
},
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d",
"_meta.delisted" : 1,
"_id" : 1
},
"indexName" : "_meta.loc.coordinates_2d__meta.delisted_1__id_1",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
],
"_meta.delisted" : [
"[MinKey, MaxKey]"
],
"_id" : [
"[MinKey, MaxKey]"
]
}
}
}
}
}
},
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d",
"_meta.unifiedAt" : 1
},
"indexName" : "_meta.loc.coordinates_2d__meta.unifiedAt_1",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
],
"_meta.unifiedAt" : [
"[MinKey, MaxKey]"
]
}
}
}
}
}
}
]
},
"serverInfo" : {
"host" : "production",
"port" : 27017,
"version" : "3.4.3",
"gitVersion" : "f07437fb5a6cca07c10bafa78365456eb1d6d5e1"
},
"ok" : 1
}
As it is not using the index that I created, I try to use the hint method to force the index, but then I get an error in the result:
> db.static_booking.find({ "_meta.loc.coordinates": { "$geoWithin": { "$box": [ [ -0.70724367, 51.13817111 ], [ 0.45524367, 51.86182889 ] ] } } }, {itemId: 1}).sort({'_meta.unifiedAt': 1}).limit(100).hint({'_meta.loc.coordinates': '2d', '_meta.unifiedAt': 1})
Error: error: {
"ok" : 0,
"errmsg" : "Executor error during find command: OperationFailed: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit.",
"code" : 96,
"codeName" : "OperationFailed"
}
As long as I use a limit larger than 2, then the error will appear. How can I solve this issue? Thanks.
performance index mongodb
bumped to the homepage by Community♦ 12 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I have a compound index in a 2d and normal field:
"key" : {
"_meta.loc.coordinates" : "2d",
"_meta.unifiedAt" : 1
},
Then I want to execute the following query with sorting:
db.static_booking
.find({ "_meta.loc.coordinates": { "$geoWithin": { "$box": [ [ -0.70724367, 51.13817111 ], [ 0.45524367, 51.86182889 ] ] } } }, {itemId: 1})
.sort({'_meta.unifiedAt': 1})
.limit(100)
The problem I have is that it takes a very long time to return the results. Checking the explain, I see that it does not use the compound index created:
> db.static_booking.find({ "_meta.loc.coordinates": { "$geoWithin": { "$box": [ [ -0.70724367, 51.13817111 ], [ 0.45524367, 51.86182889 ] ] } } }, {itemId: 1}).sort({'_meta.unifiedAt': 1}).limit(100).explain()
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "seetransparent.static_booking",
"indexFilterSet" : false,
"parsedQuery" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"winningPlan" : {
"stage" : "LIMIT",
"limitAmount" : 100,
"inputStage" : {
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.unifiedAt" : 1
},
"indexName" : "_meta.unifiedAt_1",
"isMultiKey" : false,
"multiKeyPaths" : {
"_meta.unifiedAt" : [ ]
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.unifiedAt" : [
"[MinKey, MaxKey]"
]
}
}
}
}
},
"rejectedPlans" : [
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d"
},
"indexName" : "_meta.loc.coordinates_2d",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
]
}
}
}
}
}
},
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d",
"_meta.delisted" : 1
},
"indexName" : "_meta.loc.coordinates_2d__meta.delisted_1",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
],
"_meta.delisted" : [
"[MinKey, MaxKey]"
]
}
}
}
}
}
},
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d",
"_meta.delisted" : 1,
"_id" : 1
},
"indexName" : "_meta.loc.coordinates_2d__meta.delisted_1__id_1",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
],
"_meta.delisted" : [
"[MinKey, MaxKey]"
],
"_id" : [
"[MinKey, MaxKey]"
]
}
}
}
}
}
},
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d",
"_meta.unifiedAt" : 1
},
"indexName" : "_meta.loc.coordinates_2d__meta.unifiedAt_1",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
],
"_meta.unifiedAt" : [
"[MinKey, MaxKey]"
]
}
}
}
}
}
}
]
},
"serverInfo" : {
"host" : "production",
"port" : 27017,
"version" : "3.4.3",
"gitVersion" : "f07437fb5a6cca07c10bafa78365456eb1d6d5e1"
},
"ok" : 1
}
As it is not using the index that I created, I try to use the hint method to force the index, but then I get an error in the result:
> db.static_booking.find({ "_meta.loc.coordinates": { "$geoWithin": { "$box": [ [ -0.70724367, 51.13817111 ], [ 0.45524367, 51.86182889 ] ] } } }, {itemId: 1}).sort({'_meta.unifiedAt': 1}).limit(100).hint({'_meta.loc.coordinates': '2d', '_meta.unifiedAt': 1})
Error: error: {
"ok" : 0,
"errmsg" : "Executor error during find command: OperationFailed: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit.",
"code" : 96,
"codeName" : "OperationFailed"
}
As long as I use a limit larger than 2, then the error will appear. How can I solve this issue? Thanks.
performance index mongodb
bumped to the homepage by Community♦ 12 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
The last plan in the rejectedPlans section is the one which uses your compound index as you were hoping, but it doesn't explain why that plan was rejected. Could you try asking it to explain, but with the verbosity mode set to "allPlansExecution", to see if that tells you any more?
– Vince Bowdren
Apr 24 '17 at 9:19
add a comment |
I have a compound index in a 2d and normal field:
"key" : {
"_meta.loc.coordinates" : "2d",
"_meta.unifiedAt" : 1
},
Then I want to execute the following query with sorting:
db.static_booking
.find({ "_meta.loc.coordinates": { "$geoWithin": { "$box": [ [ -0.70724367, 51.13817111 ], [ 0.45524367, 51.86182889 ] ] } } }, {itemId: 1})
.sort({'_meta.unifiedAt': 1})
.limit(100)
The problem I have is that it takes a very long time to return the results. Checking the explain, I see that it does not use the compound index created:
> db.static_booking.find({ "_meta.loc.coordinates": { "$geoWithin": { "$box": [ [ -0.70724367, 51.13817111 ], [ 0.45524367, 51.86182889 ] ] } } }, {itemId: 1}).sort({'_meta.unifiedAt': 1}).limit(100).explain()
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "seetransparent.static_booking",
"indexFilterSet" : false,
"parsedQuery" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"winningPlan" : {
"stage" : "LIMIT",
"limitAmount" : 100,
"inputStage" : {
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.unifiedAt" : 1
},
"indexName" : "_meta.unifiedAt_1",
"isMultiKey" : false,
"multiKeyPaths" : {
"_meta.unifiedAt" : [ ]
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.unifiedAt" : [
"[MinKey, MaxKey]"
]
}
}
}
}
},
"rejectedPlans" : [
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d"
},
"indexName" : "_meta.loc.coordinates_2d",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
]
}
}
}
}
}
},
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d",
"_meta.delisted" : 1
},
"indexName" : "_meta.loc.coordinates_2d__meta.delisted_1",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
],
"_meta.delisted" : [
"[MinKey, MaxKey]"
]
}
}
}
}
}
},
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d",
"_meta.delisted" : 1,
"_id" : 1
},
"indexName" : "_meta.loc.coordinates_2d__meta.delisted_1__id_1",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
],
"_meta.delisted" : [
"[MinKey, MaxKey]"
],
"_id" : [
"[MinKey, MaxKey]"
]
}
}
}
}
}
},
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d",
"_meta.unifiedAt" : 1
},
"indexName" : "_meta.loc.coordinates_2d__meta.unifiedAt_1",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
],
"_meta.unifiedAt" : [
"[MinKey, MaxKey]"
]
}
}
}
}
}
}
]
},
"serverInfo" : {
"host" : "production",
"port" : 27017,
"version" : "3.4.3",
"gitVersion" : "f07437fb5a6cca07c10bafa78365456eb1d6d5e1"
},
"ok" : 1
}
As it is not using the index that I created, I try to use the hint method to force the index, but then I get an error in the result:
> db.static_booking.find({ "_meta.loc.coordinates": { "$geoWithin": { "$box": [ [ -0.70724367, 51.13817111 ], [ 0.45524367, 51.86182889 ] ] } } }, {itemId: 1}).sort({'_meta.unifiedAt': 1}).limit(100).hint({'_meta.loc.coordinates': '2d', '_meta.unifiedAt': 1})
Error: error: {
"ok" : 0,
"errmsg" : "Executor error during find command: OperationFailed: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit.",
"code" : 96,
"codeName" : "OperationFailed"
}
As long as I use a limit larger than 2, then the error will appear. How can I solve this issue? Thanks.
performance index mongodb
I have a compound index in a 2d and normal field:
"key" : {
"_meta.loc.coordinates" : "2d",
"_meta.unifiedAt" : 1
},
Then I want to execute the following query with sorting:
db.static_booking
.find({ "_meta.loc.coordinates": { "$geoWithin": { "$box": [ [ -0.70724367, 51.13817111 ], [ 0.45524367, 51.86182889 ] ] } } }, {itemId: 1})
.sort({'_meta.unifiedAt': 1})
.limit(100)
The problem I have is that it takes a very long time to return the results. Checking the explain, I see that it does not use the compound index created:
> db.static_booking.find({ "_meta.loc.coordinates": { "$geoWithin": { "$box": [ [ -0.70724367, 51.13817111 ], [ 0.45524367, 51.86182889 ] ] } } }, {itemId: 1}).sort({'_meta.unifiedAt': 1}).limit(100).explain()
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "seetransparent.static_booking",
"indexFilterSet" : false,
"parsedQuery" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"winningPlan" : {
"stage" : "LIMIT",
"limitAmount" : 100,
"inputStage" : {
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.unifiedAt" : 1
},
"indexName" : "_meta.unifiedAt_1",
"isMultiKey" : false,
"multiKeyPaths" : {
"_meta.unifiedAt" : [ ]
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.unifiedAt" : [
"[MinKey, MaxKey]"
]
}
}
}
}
},
"rejectedPlans" : [
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d"
},
"indexName" : "_meta.loc.coordinates_2d",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
]
}
}
}
}
}
},
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d",
"_meta.delisted" : 1
},
"indexName" : "_meta.loc.coordinates_2d__meta.delisted_1",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
],
"_meta.delisted" : [
"[MinKey, MaxKey]"
]
}
}
}
}
}
},
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d",
"_meta.delisted" : 1,
"_id" : 1
},
"indexName" : "_meta.loc.coordinates_2d__meta.delisted_1__id_1",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
],
"_meta.delisted" : [
"[MinKey, MaxKey]"
],
"_id" : [
"[MinKey, MaxKey]"
]
}
}
}
}
}
},
{
"stage" : "PROJECTION",
"transformBy" : {
"itemId" : 1
},
"inputStage" : {
"stage" : "SORT",
"sortPattern" : {
"_meta.unifiedAt" : 1
},
"limitAmount" : 100,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"_meta.loc.coordinates" : {
"$geoWithin" : {
"$box" : [
[
-0.70724367,
51.13817111
],
[
0.45524367,
51.86182889
]
]
}
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"_meta.loc.coordinates" : "2d",
"_meta.unifiedAt" : 1
},
"indexName" : "_meta.loc.coordinates_2d__meta.unifiedAt_1",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_meta.loc.coordinates" : [
"[BinData(128, 6EBA300000000000), BinData(128, 6EBA3FFFFFFFFFFF)]",
"[BinData(128, 6EBA680000000000), BinData(128, 6EBA6BFFFFFFFFFF)]",
"[BinData(128, 6EBA6C0000000000), BinData(128, 6EBA6FFFFFFFFFFF)]",
"[BinData(128, 6EBA700000000000), BinData(128, 6EBA7FFFFFFFFFFF)]",
"[BinData(128, 6EBA900000000000), BinData(128, 6EBA9FFFFFFFFFFF)]",
"[BinData(128, 6EBAB00000000000), BinData(128, 6EBABFFFFFFFFFFF)]",
"[BinData(128, 6EBAC00000000000), BinData(128, 6EBACFFFFFFFFFFF)]",
"[BinData(128, 6EBAD00000000000), BinData(128, 6EBADFFFFFFFFFFF)]",
"[BinData(128, 6EBAE00000000000), BinData(128, 6EBAEFFFFFFFFFFF)]",
"[BinData(128, 6EBAF00000000000), BinData(128, 6EBAFFFFFFFFFFFF)]",
"[BinData(128, C410100000000000), BinData(128, C4101FFFFFFFFFFF)]",
"[BinData(128, C410300000000000), BinData(128, C4103FFFFFFFFFFF)]",
"[BinData(128, C410400000000000), BinData(128, C4104FFFFFFFFFFF)]",
"[BinData(128, C410500000000000), BinData(128, C4105FFFFFFFFFFF)]",
"[BinData(128, C410600000000000), BinData(128, C4106FFFFFFFFFFF)]",
"[BinData(128, C410700000000000), BinData(128, C4107FFFFFFFFFFF)]"
],
"_meta.unifiedAt" : [
"[MinKey, MaxKey]"
]
}
}
}
}
}
}
]
},
"serverInfo" : {
"host" : "production",
"port" : 27017,
"version" : "3.4.3",
"gitVersion" : "f07437fb5a6cca07c10bafa78365456eb1d6d5e1"
},
"ok" : 1
}
As it is not using the index that I created, I try to use the hint method to force the index, but then I get an error in the result:
> db.static_booking.find({ "_meta.loc.coordinates": { "$geoWithin": { "$box": [ [ -0.70724367, 51.13817111 ], [ 0.45524367, 51.86182889 ] ] } } }, {itemId: 1}).sort({'_meta.unifiedAt': 1}).limit(100).hint({'_meta.loc.coordinates': '2d', '_meta.unifiedAt': 1})
Error: error: {
"ok" : 0,
"errmsg" : "Executor error during find command: OperationFailed: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit.",
"code" : 96,
"codeName" : "OperationFailed"
}
As long as I use a limit larger than 2, then the error will appear. How can I solve this issue? Thanks.
performance index mongodb
performance index mongodb
asked Apr 21 '17 at 19:47
nsbleninnsblenin
61
61
bumped to the homepage by Community♦ 12 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 12 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
The last plan in the rejectedPlans section is the one which uses your compound index as you were hoping, but it doesn't explain why that plan was rejected. Could you try asking it to explain, but with the verbosity mode set to "allPlansExecution", to see if that tells you any more?
– Vince Bowdren
Apr 24 '17 at 9:19
add a comment |
The last plan in the rejectedPlans section is the one which uses your compound index as you were hoping, but it doesn't explain why that plan was rejected. Could you try asking it to explain, but with the verbosity mode set to "allPlansExecution", to see if that tells you any more?
– Vince Bowdren
Apr 24 '17 at 9:19
The last plan in the rejectedPlans section is the one which uses your compound index as you were hoping, but it doesn't explain why that plan was rejected. Could you try asking it to explain, but with the verbosity mode set to "allPlansExecution", to see if that tells you any more?
– Vince Bowdren
Apr 24 '17 at 9:19
The last plan in the rejectedPlans section is the one which uses your compound index as you were hoping, but it doesn't explain why that plan was rejected. Could you try asking it to explain, but with the verbosity mode set to "allPlansExecution", to see if that tells you any more?
– Vince Bowdren
Apr 24 '17 at 9:19
add a comment |
1 Answer
1
active
oldest
votes
You are hitting the limit of in memory sort which is 32MB.
Sort Operations
If MongoDB cannot use an index to get documents in the requested sort
order, the combined size of all documents in the sort operation, plus
a small overhead, must be less than 32 megabytes.
You can add an index with leading column _meta.unifiedAt
.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f171684%2fmongodb-2d-index-query-with-an-additional-sorting-field-performance-issue%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are hitting the limit of in memory sort which is 32MB.
Sort Operations
If MongoDB cannot use an index to get documents in the requested sort
order, the combined size of all documents in the sort operation, plus
a small overhead, must be less than 32 megabytes.
You can add an index with leading column _meta.unifiedAt
.
add a comment |
You are hitting the limit of in memory sort which is 32MB.
Sort Operations
If MongoDB cannot use an index to get documents in the requested sort
order, the combined size of all documents in the sort operation, plus
a small overhead, must be less than 32 megabytes.
You can add an index with leading column _meta.unifiedAt
.
add a comment |
You are hitting the limit of in memory sort which is 32MB.
Sort Operations
If MongoDB cannot use an index to get documents in the requested sort
order, the combined size of all documents in the sort operation, plus
a small overhead, must be less than 32 megabytes.
You can add an index with leading column _meta.unifiedAt
.
You are hitting the limit of in memory sort which is 32MB.
Sort Operations
If MongoDB cannot use an index to get documents in the requested sort
order, the combined size of all documents in the sort operation, plus
a small overhead, must be less than 32 megabytes.
You can add an index with leading column _meta.unifiedAt
.
edited Apr 23 '17 at 21:56
answered Apr 23 '17 at 14:07
SqlWorldWideSqlWorldWide
8,14521335
8,14521335
add a comment |
add a comment |
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f171684%2fmongodb-2d-index-query-with-an-additional-sorting-field-performance-issue%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The last plan in the rejectedPlans section is the one which uses your compound index as you were hoping, but it doesn't explain why that plan was rejected. Could you try asking it to explain, but with the verbosity mode set to "allPlansExecution", to see if that tells you any more?
– Vince Bowdren
Apr 24 '17 at 9:19