1,799
社区成员




这是 Mongo 慢日志 记录的其中一条日志. 这个集合中大概有500W条数据
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 833,
"executionTimeMillis" : 956,
"totalKeysExamined" : 131050,
"totalDocsExamined" : 131050,
"executionStages" : {
"stage" : "FETCH",
"filter" : {
"$and" : [
{
"name" : {
"$eq" : "b334085"
}
},
{
"state" : {
"$eq" : 1
}
}
]
},
"nReturned" : 833,
"executionTimeMillisEstimate" : 616,
"works" : 131051,
"advanced" : 833,
"needTime" : 130217,
"needYield" : 0,
"saveState" : 198,
"restoreState" : 198,
"isEOF" : 1,
"docsExamined" : 131050,
"alreadyHasObj" : 0,
"inputStage" : {
"stage" : "IXSCAN",
"nReturned" : 131050,
"executionTimeMillisEstimate" : 177,
"works" : 131051,
"advanced" : 131050,
"needTime" : 0,
"needYield" : 0,
"saveState" : 198,
"restoreState" : 198,
"isEOF" : 1,
"keyPattern" : {
"_id" : 1
},
"indexName" : "_id_",
"isMultiKey" : false,
"multiKeyPaths" : {
"_id" : [ ]
},
"isUnique" : true,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"_id" : [
"[ObjectId('630105000000000000000000'), ObjectId('6301c2ee0000000000000000')]"
]
},
"keysExamined" : 131050,
"seeks" : 1,
"dupsTested" : 0,
"dupsDropped" : 0
}
}
},
看日志,索引都有命中.
name 字段有索引.默认_id 肯定也 有索引.
这2个字段,是都是单条索引.... 查询时间 956ms,,这个有点慢.
请教这个如何优化比较好....能将2个字段,建立一个复合索引吗......
主要是有 _id这个 字段.
这个一直没搞懂,,mongodb中,,_id这个字段,是自动生成的对象,不是整数 ,能与其他字段一起创建复合字段么.
或者说一个整数字段,搜索的时候,会带上 范围搜索,,这个能建立复合字段吗......先去尝试一下看看.