Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-28039

Add full maxTimeMS support to the explain command

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

      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@mongodb.com David Storch
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: