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

Indexed inequalities to arrays return incorrect results

    • Major Change
    • ALL
    • v4.2, v4.0, v3.6
    • Query 2020-01-27, Query 2020-02-10, Query 2020-02-24
    • 17

      > db.c.insert({a: [1, 2]})
      WriteResult({ "nInserted" : 1 })
      > db.c.find({a: {$lte: [0, 0]}})
      > db.c.find({a: {$lte: [2, 2]}})
      { "_id" : ObjectId("5dfa766b191cd168059aaf54"), "a" : [ 1, 2 ] }
      > db.c.createIndex({a: 1})
      {
      	"createdCollectionAutomatically" : false,
      	"numIndexesBefore" : 1,
      	"numIndexesAfter" : 2,
      	"ok" : 1
      }
      > db.c.find({a: {$lte: [2, 2]}})
      > 
      

      The bounds we build for this look wrong:

      {
      	"queryPlanner" : {
      		"plannerVersion" : 1,
      		"namespace" : "test.c",
      		"indexFilterSet" : false,
      		"parsedQuery" : {
      			"a" : {
      				"$lte" : [
      					2,
      					2
      				]
      			}
      		},
      		"queryHash" : "811451DD",
      		"planCacheKey" : "B859B02A",
      		"winningPlan" : {
      			"stage" : "FETCH",
      			"filter" : {
      				"a" : {
      					"$lte" : [
      						2,
      						2
      					]
      				}
      			},
      			"inputStage" : {
      				"stage" : "IXSCAN",
      				"keyPattern" : {
      					"a" : 1
      				},
      				"indexName" : "a_1",
      				"isMultiKey" : true,
      				"multiKeyPaths" : {
      					"a" : [
      						"a"
      					]
      				},
      				"isUnique" : false,
      				"isSparse" : false,
      				"isPartial" : false,
      				"indexVersion" : 2,
      				"direction" : "forward",
      				"indexBounds" : {
      					"a" : [
      						"[[], [ 2.0, 2.0 ]]"
      					]
      				}
      			}
      		},
      		"rejectedPlans" : [ ]
      	},
      	"serverInfo" : {
      		"host" : "borosaurus",
      		"port" : 30000,
      		"version" : "4.2.1",
      		"gitVersion" : "edf6d45851c0b9ee15548f0f847df141764a317e"
      	},
      	"ok" : 1
      }
      

      It only includes arrays! Since we index arrays element-wise, this will miss results.

            Assignee:
            ted.tuckman@mongodb.com Ted Tuckman
            Reporter:
            ian.boros@mongodb.com Ian Boros
            Votes:
            0 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved: