[SERVER-7945] use plan ordering when reporting "winning" plan at the top of explain Created: 14/Dec/12  Updated: 11/Jul/16  Resolved: 13/Feb/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 2.6.0-rc0

Type: Bug Priority: Major - P3
Reporter: Aaron Staple Assignee: Benety Goh
Resolution: Done Votes: 1
Labels: query_triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-7950 MongoDB not using the most optimal in... Closed
Related
related to SERVER-8747 In explain output, per plan 'n' count... Closed
is related to SERVER-10026 New query system Closed
is related to SERVER-10565 Re-implement explain() for new execut... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

In cases where there is no "winning" query plan, one query plan with the highest match count is reported in the explain output (see discussion in SERVER-4150). However, in cases where some query plans are ordered and others are unordered, and a small limit is applied, this may result in an unordered plan being incorrectly reported at the top of explain when the results actually came from an ordered plan. We should take plan ordering and limit completion into account when choosing a plan to report at the top of explain (ExplainClauseInfo::virtualPickedPlan).



 Comments   
Comment by Benety Goh [ 13/Feb/14 ]

plans are now ordered by ranking score computed in src/mongo/db/query/plan_ranker.cpp.

Comment by Aaron Staple [ 15/Dec/12 ]

Test

c = db.c;
c.drop();
for( i = 0; i < 100; ++i ) {
    c.save( { a:1, b:1, c:i, d:1 } );
}
 
c.ensureIndex( { a:1, b:1, c:1, d:-1 } );
c.ensureIndex( { a:1, d:-1, b:1 } );
explain = c.find( { b:1, a:1 } ).sort( { d:-1 } ).limit( 1 ).explain( true );
printjson( explain );
 
assert.eq( 'BtreeCursor a_1_d_-1_b_1', explain.cursor );

Generated at Thu Feb 08 03:16:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.