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

Index scan uses incorrect bounds for MinKey and MaxKey

    • Minor Change
    • ALL
    • v4.2, v4.0
    • Query 2019-08-12
    • 49

      The document {a: MinKey} should not match the query {a: { $gt: MinKey }}. However when there is an index present, MinKey is considered in the bounds for the index scan.

      > db.test_min_max.find()
      { "_id" : "a_max_key", "a" : { "$maxKey" : 1 } }
      { "_id" : "a_min_key", "a" : { "$minKey" : 1 } }
      { "_id" : "a_null", "a" : null }
      { "_id" : "a_number", "a" : 4 }
      { "_id" : "a_subobject", "a" : { "b" : "hi" } }
      { "_id" : "a_undefined", "a" : undefined }
      { "_id" : "a_string", "a" : "hello" }
      > db.test_min_max.find({a: {$gt: MinKey}})
      { "_id" : "a_min_key", "a" : { "$minKey" : 1 } } . // THIS IS WRONG
      { "_id" : "a_undefined", "a" : undefined }
      { "_id" : "a_null", "a" : null }
      { "_id" : "a_number", "a" : 4 }
      { "_id" : "a_string", "a" : "hello" }
      { "_id" : "a_subobject", "a" : { "b" : "hi" } }
      { "_id" : "a_max_key", "a" : { "$maxKey" : 1 } }
      > db.test_min_max.find({a: {$gt: MinKey}}).explain()
      {
      	"queryPlanner" : {
      		"plannerVersion" : 1,
      		"namespace" : "test.test_min_max",
      		"indexFilterSet" : false,
      		"parsedQuery" : {
      			"a" : {
      				"$gt" : { "$minKey" : 1 }
      			}
      		},
      		"winningPlan" : {
      			"stage" : "FETCH",
      			"inputStage" : {
      				"stage" : "IXSCAN",
      				"keyPattern" : {
      					"a" : 4
      				},
      				"indexName" : "a_4",
      				"isMultiKey" : false,
      				"multiKeyPaths" : {
      					"a" : [ ]
      				},
      				"isUnique" : false,
      				"isSparse" : false,
      				"isPartial" : false,
      				"indexVersion" : 2,
      				"direction" : "forward",
      				"indexBounds" : {
      					"a" : [
      						"[MinKey, MaxKey]" . // THIS IS WRONG
      					]
      				}
      			}
      		},
      		"rejectedPlans" : [ ]
      	},
      	"serverInfo" : {
      		"host" : "franklinia",
      		"port" : 27017,
      		"version" : "0.0.0",
      		"gitVersion" : "unknown"
      	},
      	"ok" : 1
      }
      

            Assignee:
            misha.ivkov@mongodb.com Mikhail Ivkov (Inactive)
            Reporter:
            minji.kim Minji Kim
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: