Add full maxTimeMS support to the explain command

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Gone away
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying, Sharding
    • Query 2021-01-11
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      The explain command does not fully support the maxTimeMS option due to the two following issues.

      The first is that the explain shell helpers generate an explain command with the maxTimeMS parameter in the wrong location. The shell command

      db.c.find().maxTimeMS(100).explain("executionStats");
      

      generates the command:

      { explain: { find: "c", filter: {}, maxTimeMS: 100.0 }, verbosity: "executionStats" }
      

      Instead it should place maxTimeMS as a top-level parameter:

      { explain: { find: "c", filter: {} }, verbosity: "executionStats", maxTimeMS: 100.0 }
      

      The second issue is that mongos strips out the maxTimeMS before forwarding it to the shards. I can reproduce by starting a one-shard cluster and running the following against the mongos:

      db.c.drop()
      for (var i = 0; i < 10; i++) { db.c.insert({_id: i}); }
      db.runCommand({explain: {find: "c", filter: {$where: "sleep(100)"}}, verbosity: "executionStats", maxTimeMS: 1});
      

      When I run this directly against a mongod, it results in ErrorCodes::ExceededTimeLimit. But it does not time out when I run it against a mongos.

            Assignee:
            David Storch
            Reporter:
            David Storch
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: