无法获取MongoDB中分片集合的覆盖查询
集合是散列字段上的分片集合。 下面的查询应该是索引查询,但解释显示了其他查询无法获取MongoDB中分片集合的覆盖查询,mongodb,indexing,mongodb-query,sharding,Mongodb,Indexing,Mongodb Query,Sharding,集合是散列字段上的分片集合。 下面的查询应该是索引查询,但解释显示了其他查询 db.collection.ensureIndex({field : "hashed"}) db.collection.ensureIndex({field : 1, "field2" : 1, "field3" : 1}) db.collection.find( { field : 100 } ,{field : 1, _id : 0} ) //.hint({ "field" : 1, "fie
db.collection.ensureIndex({field : "hashed"})
db.collection.ensureIndex({field : 1, "field2" : 1, "field3" : 1})
db.collection.find(
{
field : 100
}
,{field : 1, _id : 0}
)
//.hint({ "field" : 1, "field2" : 1, "field3" : 1})
//.hint({ "field" : "hashed"})
.explain()
"cursor" : "BtreeCursor field_hashed",
"nscannedObjects" : 1,
"nscanned" : 1,
"indexOnly" : false,
我测试了这两个索引,但它们都没有生成覆盖查询。
如果有任何帮助或建议,我将不胜感激
解释():
与MongoDB 2.6一样,您不会得到完全覆盖的分片查询,因为有一个额外的查询来检查所讨论的分片是否拥有该文档(请参阅MongoDB问题跟踪程序中的)
mongos
路由器根据分片集群元数据过滤在分片上找到但不应存在的文档
在以下情况下,文档可以存在于多个碎片上:
- 有一个过程正在进行:文档从供体碎片复制到目标碎片,并且在区块迁移成功完成之前不会从供体碎片中删除
- 由于迁移失败或清理不完整,文档已在碎片上“孤立”。MongoDB 2.6中有一个可以针对分片的
运行以删除孤立文档的功能mongod
MongoDB文档的一节中提到了这一涵盖的查询限制,但也应该在关于的教程中强调。我提出这一点是为了让这一点更加明显。您能向我们展示完整的explain()吗?但是集合在索引中包含的(散列)字段上被切分。因此,索引返回的字段值应足以进行检查。这些检查所需的数据是否多于分片密钥?注意:SERVER-5022已在2.7.x开发周期内解决,因此在下一个MongoDB版本(即2.8.0或更高版本)中可以对分片集群进行涵盖的查询;这些变化太大,无法向后移植到早期版本。
{
"clusteredType" : "ParallelSort",
"shards" : {
"repset12" : [
{
"cursor" : "BtreeCursor field_hashed",
"isMultiKey" : false,
"n" : 1,
"nscannedObjects" : 1,
"nscanned" : 1,
"nscannedObjectsAllPlans" : 2,
"nscannedAllPlans" : 2,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" : {
"field" : [
[
NumberLong(5346856657151215906),
NumberLong(5346856657151215906)
]
]
},
"server" : "server",
"filterSet" : false,
"stats" : {
"type" : "PROJECTION",
"works" : 3,
"yields" : 0,
"unyields" : 0,
"invalidates" : 0,
"advanced" : 1,
"needTime" : 0,
"needFetch" : 0,
"isEOF" : 1,
"children" : [
{
"type" : "KEEP_MUTATIONS",
"works" : 3,
"yields" : 0,
"unyields" : 0,
"invalidates" : 0,
"advanced" : 1,
"needTime" : 0,
"needFetch" : 0,
"isEOF" : 1,
"children" : [
{
"type" : "SHARDING_FILTER",
"works" : 2,
"yields" : 0,
"unyields" : 0,
"invalidates" : 0,
"advanced" : 1,
"needTime" : 0,
"needFetch" : 0,
"isEOF" : 1,
"chunkSkips" : 0,
"children" : [
{
"type" : "FETCH",
"works" : 1,
"yields" : 0,
"unyields" : 0,
"invalidates" : 0,
"advanced" : 1,
"needTime" : 0,
"needFetch" : 0,
"isEOF" : 1,
"alreadyHasObj" : 0,
"forcedFetches" : 0,
"matchTested" : 1,
"children" : [
{
"type" : "IXSCAN",
"works" : 1,
"yields" : 0,
"unyields" : 0,
"invalidates" : 0,
"advanced" : 1,
"needTime" : 0,
"needFetch" : 0,
"isEOF" : 1,
"keyPattern" : "{ field: \"hashed\" }",
"boundsVerbose" : "field #0['field']: [5346856657151215906, 5346856657151215906]",
"isMultiKey" : 0,
"yieldMovedCursor" : 0,
"dupsTested" : 0,
"dupsDropped" : 0,
"seenInvalidated" : 0,
"matchTested" : 0,
"keysExamined" : 1,
"children" : []
}
]
}
]
}
]
}
]
}
}
]
},
"cursor" : "BtreeCursor field_hashed",
"n" : 1,
"nChunkSkips" : 0,
"nYields" : 0,
"nscanned" : 1,
"nscannedAllPlans" : 2,
"nscannedObjects" : 1,
"nscannedObjectsAllPlans" : 2,
"millisShardTotal" : 0,
"millisShardAvg" : 0,
"numQueries" : 1,
"numShards" : 1,
"indexBounds" : {
"field" : [
[
NumberLong(5346856657151215906),
NumberLong(5346856657151215906)
]
]
},
"millis" : 1
}