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

Unexpected query plan for a $or condition

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 2.4.1
    • Querying
    • ALL
    • Hide

      Reproduce:

      db.files.drop();
       
      db.files.insert({ _id:"foo.txt", attr: [ { type: "text" },   { size: 64 } ] } )
      db.files.insert({ _id:"bar.txt", attr: [ { type: "text" },   { size: 128 }, { created: ISODate("2013-01-01T18:13:42.689Z") } ] } )
      db.files.insert({ _id:"foobar",  attr: [ { type: "binary" }, { size: 256 }, { created: ISODate("2013-04-01T18:13:42.689Z") } ] } )
       
      db.files.ensureIndex({attr: 1})
       
      db.files.find( { $or: [ { attr: { $gte: { created: ISODate("2013-02-01T00:00:01.689Z") } } },  
                              { attr: { $gt: { size:128 }, $lte: { size: 16384 } } }
                             ] } ).explain()

      Show
      Reproduce: db.files.drop();   db.files.insert({ _id:"foo.txt", attr: [ { type: "text" }, { size: 64 } ] } ) db.files.insert({ _id:"bar.txt", attr: [ { type: "text" }, { size: 128 }, { created: ISODate("2013-01-01T18:13:42.689Z") } ] } ) db.files.insert({ _id:"foobar", attr: [ { type: "binary" }, { size: 256 }, { created: ISODate("2013-04-01T18:13:42.689Z") } ] } )   db.files.ensureIndex({attr: 1})   db.files.find( { $or: [ { attr: { $gte: { created: ISODate("2013-02-01T00:00:01.689Z") } } }, { attr: { $gt: { size:128 }, $lte: { size: 16384 } } } ] } ).explain()

    Description

      Problem:
      Seeing the index bounds for a single element of a $or reference items in another element of the $or.

      Example:
      See the second element of the query plan, where bounds are "size" and "created" (lines 46 and 49 below)

      {
      	"clauses" : [
      		{
      			"cursor" : "BtreeCursor attr_1",
      			"isMultiKey" : true,
      			"n" : 1,
      			"nscannedObjects" : 1,
      			"nscanned" : 1,
      			"nscannedObjectsAllPlans" : 1,
      			"nscannedAllPlans" : 1,
      			"scanAndOrder" : false,
      			"indexOnly" : false,
      			"nYields" : 0,
      			"nChunkSkips" : 0,
      			"millis" : 0,
      			"indexBounds" : {
      				"attr" : [
      					[
      						{
      							"created" : ISODate("2013-02-01T00:00:01.689Z")
      						},
      						{
      							"$maxElement" : 1
      						}
      					]
      				]
      			}
      		},
      		{
      			"cursor" : "BtreeCursor attr_1",
      			"isMultiKey" : true,
      			"n" : 2,
      			"nscannedObjects" : 5,
      			"nscanned" : 5,
      			"nscannedObjectsAllPlans" : 5,
      			"nscannedAllPlans" : 5,
      			"scanAndOrder" : false,
      			"indexOnly" : false,
      			"nYields" : 0,
      			"nChunkSkips" : 0,
      			"millis" : 0,
      			"indexBounds" : {
      				"attr" : [
      					[
      						{
      							"size" : 128
      						},
      						{
      							"created" : ISODate("2013-02-01T00:00:01.689Z")
      						}
      					]
      				]
      			}
      		}
      	],
      	"n" : 3,
      	"nscannedObjects" : 6,
      	"nscanned" : 6,
      	"nscannedObjectsAllPlans" : 6,
      	"nscannedAllPlans" : 6,
      	"millis" : 0,
      	"server" : "vero:27017"
      }

      Attachments

        Activity

          People

            david.storch@mongodb.com David Storch
            alvin Alvin Richards (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: