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

Multikey index uses inefficient indexBounds

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 3.4.2
    • Component/s: None
    • None
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      > db.testcol.find().limit(7)
      { "_id" : "id1", "field" : [ { "age" : 23, "height" : 137 } ] }
      { "_id" : "id2", "field" : [ { "age" : 10, "height" : 137 }, { "age" : 24, "height" : 138 }, { "age" : 30, "height" : 141 }, { "age" : 10, "height" : 163 } ] }
      { "_id" : "id3", "field" : [ { "age" : 24, "height" : 163 }, { "age" : 26, "height" : 164 }, { "age" : 30, "height" : 130 }, { "age" : 10, "height" : 140 } ] }
      { "_id" : "id4", "field" : [ { "age" : 25, "height" : 163 } ] }
      { "_id" : "id5", "field" : [ { "age" : 10, "height" : 144 } ] }
      { "_id" : "id6", "field" : [ { "age" : 22, "height" : 169 }, { "age" : 26, "height" : 151 }, { "age" : 29, "height" : 171 } ] }
      { "_id" : "id7", "field" : [ { "age" : 30, "height" : 136 }, { "age" : 10, "height" : 142 }, { "age" : 27, "height" : 136 } ] }
      > db.testcol.getIndexes()
      [
      	{
      		"v" : 2,
      		"key" : {
      			"_id" : 1
      		},
      		"name" : "_id_",
      		"ns" : "testdb.testcol"
      	},
      	{
      		"v" : 2,
      		"key" : {
      			"field.age" : 1,
      			"field.height" : 1
      		},
      		"name" : "field.age_1_field.height_1",
      		"ns" : "testdb.testcol"
      	}
      ]
      > db.testcol.find({"field.age": 14, "field.height": 163}).explain()
      {
      	"queryPlanner" : {
      		"plannerVersion" : 1,
      		"namespace" : "testdb.testcol",
      		"indexFilterSet" : false,
      		"parsedQuery" : {
      			"$and" : [
      				{
      					"field.age" : {
      						"$eq" : 14
      					}
      				},
      				{
      					"field.height" : {
      						"$eq" : 163
      					}
      				}
      			]
      		},
      		"winningPlan" : {
      			"stage" : "FETCH",
      			"filter" : {
      				"field.height" : {
      					"$eq" : 163
      				}
      			},
      			"inputStage" : {
      				"stage" : "IXSCAN",
      				"keyPattern" : {
      					"field.age" : 1,
      					"field.height" : 1
      				},
      				"indexName" : "field.age_1_field.height_1",
      				"isMultiKey" : true,
      				"multiKeyPaths" : {
      					"field.age" : [
      						"field"
      					],
      					"field.height" : [
      						"field"
      					]
      				},
      				"isUnique" : false,
      				"isSparse" : false,
      				"isPartial" : false,
      				"indexVersion" : 2,
      				"direction" : "forward",
      				"indexBounds" : {
      					"field.age" : [
      						"[14.0, 14.0]"
      					],
      					"field.height" : [
      						"[MinKey, MaxKey]"
      					]
      				}
      			}
      		},
      		"rejectedPlans" : [ ]
      	},
      	"serverInfo" : {
      		"host" : "MacBook-Pro.local",
      		"port" : 27017,
      		"version" : "3.4.2",
      		"gitVersion" : "3f76e40c105fc223b3e5aac3e20dcd026b83b38b"
      	},
      	"ok" : 1
      }
      

      why is it using minkey maxkey on the second field? This seems to hurt performance.

            Assignee:
            mark.agarunov Mark Agarunov (Inactive)
            Reporter:
            thestick613 Tudor Aursulesei
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: