Correctly handle maxTimeMS for db.runCommand explain

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      As noted by christopher.harris@mongodb.com (see comments for full slack thread context):

      The top-level maxTimeMS is respected:

      db.runCommand({
        explain: { ... }, 
        maxTimeMS: 1000
      })

      Nested maxTimeMS in explain is not work:

      db.runCommand({ 
        explain: {
          ... ,
          maxTimeMS: 1000
        }
      })

      Two possible solutions:
      1. Augment explain to accept it as an argument

      2. Validate the command on server-side and reject it if there are extra options to explain

      Repro:

      print("Top level maxTimeMS");
      db.runCommand({
         explain: { find: "orders", filter: { $where: "sleep(1000) || true" } },
         maxTimeMS: 10
      }); // Should error with "MongoServerError: operation exceeded time limit"
      
      print("Explain nested maxTimeMS");
      db.runCommand({
         explain: { find: "orders", filter: { $where: "sleep(1000) || true" }, maxTimeMS: 10},
      }); // Runs to completion

            Assignee:
            Unassigned
            Reporter:
            Naafiyan Ahmed
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: