[SERVER-34200] Explain doesn't report stages which are above a MultiPlanStage Created: 29/Mar/18  Updated: 29/Oct/23  Resolved: 26/Feb/21

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 4.9.0

Type: Bug Priority: Major - P3
Reporter: Ian Boros Assignee: Timour Katchaounov
Resolution: Fixed Votes: 0
Labels: neweng, query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Query Optimization 2021-02-22, Query Optimization 2021-03-08
Participants:

 Description   

When we have a plan like this:

Count
    |
    |
MultiPlanStage
  |                   |
  |                   |
other stage    yet another stage

Running explain() on the plan will "forget" to report about any stage above the MultiPlanStage. The cause of this problem is this code which is used when trying to explain the winning plan here. The questionable code searches the entire plan tree for a MultiPlanStage, and then returns whichever child of it is considered the "winning plan," discarding any stages above.

I think the correct behavior would be to instead "replace" any MultiPlanStage with its best child.

Here's a way of reproducing this (notice the explain output doesn't have a "COUNT" stage).

(function() {
    "use strict";
 
    var coll = db.record_store_count;
    coll.drop();
 
    assert.writeOK(coll.insert({x: 0}));
    assert.writeOK(coll.insert({x: 1}));
 
    assert.commandWorked(coll.ensureIndex({x: 1}));
    assert.commandWorked(coll.ensureIndex({y: 1}));
 
    let explain = coll.explain("allPlansExecution").find({x: {$in: [1,3]}, y: {$in: [1, 3]}}).count();
    print("The full explain output is..." + tojson(explain));
})();

resmoke.py --suites=core count-bug.js

To see what the correct output would be, you can comment out one of the ensureIndex calls. This will mean only one plan is available, and so no MultiPlanStage will be used.



 Comments   
Comment by Githook User [ 01/Mar/21 ]

Author:

{'name': 'Timour Katchaounov', 'email': 'timour.katchaounov@mongodb.com'}

Message: SERVER-34200 Explain doesn't report stages which are above a MultiPlanStage

  • Change PlanExplainerImpl::getWinningPlanStats to not cut off the nodes
    on top of the MultiPlanStage.
  • Adapt all functions that process a tree of PlanStage or PlanStageStats
    for the purpose of Explain to skip the MultiPlan node, and jump to
    process its best plan child.
  • Pass the index of the multi-plan sub-plan that should be printed to
    various functions that print or linearize plans.
    Branch: master
    https://github.com/mongodb/mongo/commit/30a7024ffaf683f475ebfbbfcfeae15dc6b35eb9
Comment by Timour Katchaounov [ 01/Mar/21 ]

david.storch I got advice from Anton. The task got stuck on one test, unrelated. I'll rebase and repeat.

Comment by David Storch [ 01/Mar/21 ]

timour.katchaounov it looks like the githook didn't provide the github link to the commit?

Generated at Thu Feb 08 04:35:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.