Note that there are some explanatory texts on larger screens.

plurals
  1. POMongoDB runs alternate query plans all the time
    primarykey
    data
    text
    <p>The MongoDB documentation <a href="http://docs.mongodb.org/manual/core/indexes/" rel="nofollow">says</a>:</p> <blockquote> <p>... The query optimizer selects the index empirically by occasionally running alternate query plans and by selecting the plan with the best response time for each query type...</p> </blockquote> <p>The problem I'm experiencing with MongoDB 2.0.2 is that it seems like Mongo runs alternate query plans all the time for certain queries. </p> <p>Not only that makes the whole process very slow (explain({verbose:true}) shows 10-15 additional tests in 'allPlans' array), Mongo also doesn't choose the best index. Providing a hint command with the index I created exactly for that query results in much faster result.</p> <p>Here is an example:</p> <pre><code>&gt; 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, </code></pre> <p>Same query with verbose:true shows these indexes in 'allPlans' array:</p> <pre><code>"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", </code></pre> <ol> <li>How do I make Mongo stop running those index checks all the time?</li> <li>How do I make Mongo use and stick to the actual optimal index?</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload