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

incorrect elemMatch bounds for multi key compound index

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.0-rc0
    • Affects Version/s: 2.4.3
    • Component/s: Querying
    • Environment:
      Linux 64bit
    • ALL
    • Hide

      create index on aH.uid

      > db.testing_ah_array_path_new.find({'aH.sm':'dominik','aH.uid':{'$gte':1, '$lte':1000}}).explain()
      {
      "cursor" : "BtreeCursor aH_uid_1",
      "isMultiKey" : true,
      "n" : 276,
      "nscannedObjects" : 124565,
      "nscanned" : 124565,
      "nscannedObjectsAllPlans" : 124667,
      "nscannedAllPlans" : 124667,
      "scanAndOrder" : false,
      "indexOnly" : false,
      "nYields" : 1,
      "nChunkSkips" : 0,
      "millis" : 809,
      "indexBounds" :

      { "aH.uid" : [ [ 1, 1.7976931348623157e+308 ] ] }

      ,
      }

      On the other hand, when changing the '$lte' and '$gte' order

      > db.testing_ah_array_path_new.find({'aH.sm':'dominik','aH.uid':{'$lte':1000,'$gte':1}}).explain()
      {
      "cursor" : "BtreeCursor aH_uid_1",
      "isMultiKey" : true,
      "n" : 276,
      "nscannedObjects" : 276,
      "nscanned" : 276,
      "nscannedObjectsAllPlans" : 378,
      "nscannedAllPlans" : 378,
      "scanAndOrder" : false,
      "indexOnly" : false,
      "nYields" : 0,
      "nChunkSkips" : 0,
      "millis" : 2,
      "indexBounds" :

      { "aH.uid" : [ [ -1.7976931348623157e+308, 1000 ] ] }

      ,
      }

      In both cases, upper and lower bound should be shown as set to 1 and 1000 respectively by explain()

      Show
      create index on aH.uid > db.testing_ah_array_path_new.find({'aH.sm':'dominik','aH.uid':{'$gte':1, '$lte':1000}}).explain() { "cursor" : "BtreeCursor aH_uid_1", "isMultiKey" : true, "n" : 276, "nscannedObjects" : 124565, "nscanned" : 124565, "nscannedObjectsAllPlans" : 124667, "nscannedAllPlans" : 124667, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 1, "nChunkSkips" : 0, "millis" : 809, "indexBounds" : { "aH.uid" : [ [ 1, 1.7976931348623157e+308 ] ] } , } On the other hand, when changing the '$lte' and '$gte' order > db.testing_ah_array_path_new.find({'aH.sm':'dominik','aH.uid':{'$lte':1000,'$gte':1}}).explain() { "cursor" : "BtreeCursor aH_uid_1", "isMultiKey" : true, "n" : 276, "nscannedObjects" : 276, "nscanned" : 276, "nscannedObjectsAllPlans" : 378, "nscannedAllPlans" : 378, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 2, "indexBounds" : { "aH.uid" : [ [ -1.7976931348623157e+308, 1000 ] ] } , } In both cases, upper and lower bound should be shown as set to 1 and 1000 respectively by explain()

      only the first of the '$lte' and '$gte' boundaries is actually used by the query optimizer. Order of '$lte' and '$gte therefore becomes crucial

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            dominik Dominik Gehl
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: