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

$or should use indexes

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.5.3
    • Affects Version/s: None
    • Component/s: Querying
    • None

      > db.foo.ensureIndex(

      { a : 1 }

      )
      true
      > db.foo.ensureIndex(

      { b : 1 }

      )
      true
      > db.foo.find(

      { a : 1 }

      ).explain()
      {"cursor" : "BtreeCursor a_1" , "startKey" :

      {"a" : 1}

      , "endKey" :

      {"a" : 1}

      , "nscanned" : 2 , "n" : 2 , "millis" : 0 , "allPlans" : [{"cursor" : "BtreeCursor a_1" , "startKey" :

      {"a" : 1}

      , "endKey" : {"a" : 1}}]}
      > db.foo.find( { $or : [

      { a : 1 }

      ,

      { b : 1 }

      } ).explain()
      Wed Jun 17 06:57:15 JS Error: SyntaxError: missing ] after element list (anon):2147
      > db.foo.find( { $or : [

      { a : 1 }

      ,

      { b : 1 }

      ] ).explain()
      Wed Jun 17 06:57:20 JS Error: SyntaxError: missing } after property list (anon):2147
      > db.foo.find( { $or : [

      { a : 1 }

      ,

      { b : 1 }

      ] } ).explain()
      {"cursor" : "BasicCursor" , "startKey" : {} , "endKey" : {} , "nscanned" : 3 , "n" : 0 , "millis" : 0 , "allPlans" : [{"cursor" : "BasicCursor" , "startKey" : {} , "endKey" : {}}]}
      > for ( i=0; i<2000; i++ ){ db.foo.save(

      { a : i }

      ); }
      > for ( i=0; i<2000; i++ ){ db.foo.save(

      { h : i }

      ); }
      > for ( i=0; i<2000; i++ ){ db.foo.save(

      { b : i }

      ); }
      > db.foo.find( { $or : [

      { a : 1 }

      ,

      { b : 1 }

      ] } ).explain()
      {"cursor" : "BasicCursor" , "startKey" : {} , "endKey" : {} , "nscanned" : 6003 , "n" : 0 , "millis" : 2 , "allPlans" : [{"cursor" : "BasicCursor" , "startKey" : {} , "endKey" : {}}]}

            Assignee:
            aaron Aaron Staple
            Reporter:
            eliot Eliot Horowitz (Inactive)
            Votes:
            9 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: