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

Use better bounds (like undefined) when matching empty array

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Fully Compatible
    • ALL

      When searching for an empty array if we match on "undefined" in the index we can use the index to find them. Also, searching for $size:0 could also be re-written to the empty array, and use the same bounds.

      Currently searching for an empty array with an index on the array does this:

      // 2.4.x
      find({a:[]}).explain()
      {
      	"cursor" : "BtreeCursor a_1 multi",
      	"isMultiKey" : false,
      	"n" : 1,
      	"nscannedObjects" : 1,
      	"nscanned" : 1,
      	"nscannedObjectsAllPlans" : 1,
      	"nscannedAllPlans" : 1,
      	"scanAndOrder" : false,
      	"indexOnly" : false,
      	"nYields" : 0,
      	"nChunkSkips" : 0,
      	"millis" : 0,
      	"indexBounds" : {
      		"a" : [
      			[ null, null ],
      			[ [], [] ]
      		]}}
      
      // 2.5.5--pre (12/11/13)
      {
      	"cursor" : "BtreeCursor a_1",
      	"isMultiKey" : false,
      	"n" : 1,
      	"nscannedObjects" : 2,
      	"nscanned" : 2,
      	"nscannedObjectsAllPlans" : 4,
      	"nscannedAllPlans" : 4,
      	"scanAndOrder" : false,
      	"indexOnly" : false,
      	"nYields" : 1,
      	"nChunkSkips" : 0,
      	"millis" : 2,
      	"indexBounds" : {
      		"a" : [[{
      					"$minElement" : 1
      				},
      				{
      					"$maxElement" : 1
      				}]]}}
      

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            scotthernandez Scott Hernandez (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: