MongoDB一直运行备用查询计划

时间:2013-03-03 17:16:06

标签: mongodb indexing

MongoDB文档says

  

...查询优化器通过偶尔运行备用查询计划并选择每个查询类型具有最佳响应时间的计划来凭经验选择索引...

我遇到的MongoDB 2.0.2问题是,Mongo似乎一直在为某些查询运行备用查询计划。

不仅如此,整个过程非常缓慢(explain({verbose:true})在'allPlans'数组中显示10-15个额外的测试),Mongo也没有选择最佳索引。提供一个提示命令,其中包含我为该查询创建的索引,可以获得更快的结果。

以下是一个例子:

> db.posts.find({"project.id" : 2, "project.sections" : 1, "reading" : {"$in" : [0,1]}, "publicate" : 1}).sort({"date":-1}).explain()

"cursor" : "BtreeCursor project.id_1_reading_1_publicate_1_public_1_last_comment_time_1 multi",
"nscanned" : 13347,
"nscannedObjects" : 13346,
"n" : 7619,
"millis" : 2371,
"nYields" : 7,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,

使用verbose:true的相同查询在'allPlans'数组中显示这些索引:

"BtreeCursor reading_1_publicate_1_last_comment_time_1 multi",
"BtreeCursor date_-1_community_id_1",
"BtreeCursor project.id_1_reading_1_publicate_1_public_1_last_comment_time_1 multi",
"BtreeCursor project.id_1_reading_1_publicate_1_last_comment_time_1 multi",
"BtreeCursor project.id_1_project.sections_1_reading_1_publicate_1_public_1_date_-1 multi",
"BtreeCursor timeline_main_liked_all",
"BtreeCursor timeline_main_liked_user",
"BtreeCursor timeline_main_commented_all",
"BtreeCursor timeline_main_commented_user",
"BtreeCursor project.id_1_reading_1_publicate_1_public_1_project.sections_1 multi",
"BtreeCursor publicate_1_public_1_date_-1_reading_1_type_1 multi",
"BtreeCursor publicate_1_timeline_visibility_all_1_short.formatted_1_short.show_1_short.commercial_1_date_-1",
"BtreeCursor publicate_1_timeline_visibility_user_1_short.formatted_1_short.show_1_short.commercial_1_date_-1",
"BasicCursor",
  1. 如何让Mongo一直停止运行这些索引检查?
  2. 如何让Mongo使用并坚持实际的最佳指数?

0 个答案:

没有答案