Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-1826

Explain does not respect maxTimeMS

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Developer Tools

      Problem Statement/Rationale

      When the user wants to run an Explain command with the allPlansExecution verbosity level, but enforcing a maximum time of computation, the only place where the maxTimeMS option can be specified is inside the command to be explained.

      However, as documented in SERVER-28039 and SERVER-46686, such option is not taken into consideration, as it should be specified inside the Explain command.

      Steps to Reproduce

       

      use tempdb;
      let documents = [];
      for (let i = 1; i <= 100000; i++) {
        documents.push({ _id: i, name: `Document ${i}`, value: Math.random() * 100 });
      }
      db.test.insertMany(documents);
      // run win explain
      db.test.aggregate([ 
          { $match: { "name": "1" } }, 
          { $count: "count" } ], 
          { maxTimeMS: 5 }).explain("allPlansExecution");
      // my result the explain took 58ms, should have been stopped with 5
      // run without explain
      db.test.aggregate([ 
          { $match: { "name": "1" } }, 
          { $count: "count" } ],
          { maxTimeMS: 5 });
      //MongoServerError: PlanExecutor error during aggregation :: caused by :: operation exceeded time limit
      

       

      Expected Results

      The explain command should have stopped after the timeout expires

      Actual Results

      The explain runs all the possible plans until they are finished, taking potentially a long time if such plans contain an inefficient COLLSCAN

      Additional Notes

      The fix in SERVER-46686 modified the MongoDB shell client so that an Explain command copies the maxTimeMS setting from the inner command into the wrapper Explain command. The same change could be done in the mongosh client; in alternative the maxTimeMS property could be added as a property of the Explainable type

            Assignee:
            Unassigned Unassigned
            Reporter:
            alberto.massari@mongodb.com Alberto Massari
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: