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

shell should raise a useful error on mixed usage of $query document with .explain()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • 2.4.12
    • None
    • Shell
    • None
    • ALL
    • Hide

      db.test.find():
      {
          "_id" : ObjectId("54c158402f512862b58738c4"),
          "a" : 8,
          "b" : 3
      }
       
      /* 1 */
      {
          "_id" : ObjectId("54c158402f512862b58738c5"),
          "a" : 8,
          "b" : 9
      }
       
      /* 2 */
      {
          "_id" : ObjectId("54c158402f512862b58738c6"),
          "a" : 7,
          "b" : 4
      }
      ...
       
      db.test.getIndexes():
      {
          "0" : {
              "v" : 1,
              "name" : "_id_",
              "key" : {
                  "_id" : 1
              },
              "ns" : "test.test"
          },
          "1" : {
              "v" : 1,
              "name" : "b_1",
              "key" : {
                  "b" : 1
              },
              "ns" : "test.test"
          },
          "2" : {
              "v" : 1,
              "name" : "a_1",
              "key" : {
                  "a" : 1
              },
              "ns" : "test.test"
          }
      }

      Show
      db.test.find(): { "_id" : ObjectId("54c158402f512862b58738c4"), "a" : 8, "b" : 3 }   /* 1 */ { "_id" : ObjectId("54c158402f512862b58738c5"), "a" : 8, "b" : 9 }   /* 2 */ { "_id" : ObjectId("54c158402f512862b58738c6"), "a" : 7, "b" : 4 } ...   db.test.getIndexes(): { "0" : { "v" : 1, "name" : "_id_", "key" : { "_id" : 1 }, "ns" : "test.test" }, "1" : { "v" : 1, "name" : "b_1", "key" : { "b" : 1 }, "ns" : "test.test" }, "2" : { "v" : 1, "name" : "a_1", "key" : { "a" : 1 }, "ns" : "test.test" } }

    Description

      Consider the following code:

      t = db.t;
      t.drop();
      t.ensureIndex({a: 1});
      t.ensureIndex({b: 1});
      t.find({$query: {a: 1}, $orderby: {b: -1}}).explain()

      This should error with a useful message. a 2.4 server does not raise an error, whereas a 2.6 server raises an unhelpful error message. Instead, the shell could raise a useful error before sending the query to the server.

      Original Description

      I don't know if this is a bug, but the following two queries result in completely different outputs. The first output shows a full table scan whereas the second one claims to make use of the index. Which one is correct?

      query 1:

      db.java.find({ "$query" : { "a" : 1} , "$orderby" : { "b" : -1}}).explain()
      {
          "cursor" : "BasicCursor",
          "isMultiKey" : false,
          "n" : 0,
          "nscannedObjects" : 100,
          "nscanned" : 100,
          "nscannedObjectsAllPlans" : 100,
          "nscannedAllPlans" : 100,
          "scanAndOrder" : false,
          "indexOnly" : false,
          "nYields" : 0,
          "nChunkSkips" : 0,
          "millis" : 0,
          "indexBounds" : {},
          "server" : "XXXX"
      }

      query 2:

      db.java.find({ "$query" : { "a" : 1} , "$orderby" : { "b" : -1}, "$explain" : true})
      /* 0 */
      {
          "cursor" : "BtreeCursor a_1",
          "isMultiKey" : false,
          "n" : 6,
          "nscannedObjects" : 6,
          "nscanned" : 6,
          "nscannedObjectsAllPlans" : 19,
          "nscannedAllPlans" : 19,
          "scanAndOrder" : true,
          "indexOnly" : false,
          "nYields" : 0,
          "nChunkSkips" : 0,
          "millis" : 0,
          "indexBounds" : {
              "a" : [ 
                  [ 
                      1, 
                      1
                  ]
              ]
          },
          "allPlans" : [ 
              {
                  "cursor" : "BtreeCursor b_1 reverse",
                  "n" : 0,
                  "nscannedObjects" : 7,
                  "nscanned" : 7,
                  "indexBounds" : {
                      "b" : [ 
                          [ 
                              {
                                  "$maxElement" : 1
                              }, 
                              {
                                  "$minElement" : 1
                              }
                          ]
                      ]
                  }
              }, 
              {
                  "cursor" : "BtreeCursor a_1",
                  "n" : 6,
                  "nscannedObjects" : 6,
                  "nscanned" : 6,
                  "indexBounds" : {
                      "a" : [ 
                          [ 
                              1, 
                              1
                          ]
                      ]
                  }
              }, 
              {
                  "cursor" : "BasicCursor",
                  "n" : 0,
                  "nscannedObjects" : 6,
                  "nscanned" : 6,
                  "indexBounds" : {}
              }
          ],
          "oldPlan" : {
              "cursor" : "BtreeCursor a_1",
              "indexBounds" : {
                  "a" : [ 
                      [ 
                          1, 
                          1
                      ]
                  ]
              }
          },
          "server" : "nbwinviemg:27017"
      }

      Attachments

        Issue Links

          Activity

            People

              matt.kangas Matt Kangas
              mustiguel Musti
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: