Uploaded image for project: 'Drivers'
  1. Drivers
  2. DRIVERS-653

Require hint for min/max find options

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • $i18n.getText("admin.common.words.hide")
      Key Status/Resolution FixVersion
      CDRIVER-3099 Fixed 1.15.0, 1.14.1
      PYTHON-1811 Fixed 3.8
      $i18n.getText("admin.common.words.show")
      #scriptField, #scriptField *{ border: 1px solid black; } #scriptField{ border-collapse: collapse; } #scriptField td { text-align: center; /* Center-align text in table cells */ } #scriptField td.key { text-align: left; /* Left-align text in the Key column */ } #scriptField a { text-decoration: none; /* Remove underlines from links */ border: none; /* Remove border from links */ } /* Add green background color to cells with FixVersion */ #scriptField td.hasFixVersion { background-color: #00FF00; /* Green color code */ } /* Center-align the first row headers */ #scriptField th { text-align: center; } Key Status/Resolution FixVersion CDRIVER-3099 Fixed 1.15.0, 1.14.1 PYTHON-1811 Fixed 3.8

    Description

      Issue

      Query with min/max modifier uses first index with related fields.

      On fresh MongoDB secondary startup `id` index became last in order (this looks like a bug) and `find` operation with `min`/`max` modifier starts using first hashed index by `_id`.

      When this secondary became primary, this shard returns incomplete results on query.

      user:PRIMARY> db.socialTopics.getIndices()
      [
      	{
      		"v" : 2,
      		"key" : {
      			"_id" : "hashed"
      		},
      		"name" : "_id_hashed",
      		"background" : true,
      		"ns" : "user.socialTopics"
      	},
      	{
      		"v" : 2,
      		"key" : {
      			"_id" : 1
      		},
      		"name" : "_id_",
      		"ns" : "user.socialTopics"
      	}
      ]
      user:PRIMARY> db.socialTopics.find({}, {_id: 1}).min({_id: ObjectId("5bb74d8cefa37173fe2cf692")}).sort({_id: 1}).limit(5).explain()
      {
      	"queryPlanner" : {
      		"plannerVersion" : 1,
      		"namespace" : "user.socialTopics",
      		"indexFilterSet" : false,
      		"parsedQuery" : {
      			
      		},
      		"winningPlan" : {
      			"stage" : "PROJECTION",
      			"transformBy" : {
      				"_id" : 1
      			},
      			"inputStage" : {
      				"stage" : "SORT",
      				"sortPattern" : {
      					"_id" : 1
      				},
      				"limitAmount" : 5,
      				"inputStage" : {
      					"stage" : "SORT_KEY_GENERATOR",
      					"inputStage" : {
      						"stage" : "FETCH",
      						"inputStage" : {
      							"stage" : "IXSCAN",
      							"keyPattern" : {
      								"_id" : "hashed"
      							},
      							"indexName" : "_id_hashed",
      							"isMultiKey" : false,
      							"isUnique" : false,
      							"isSparse" : false,
      							"isPartial" : false,
      							"indexVersion" : 2,
      							"direction" : "forward",
      							"indexBounds" : {
      								
      							}
      						}
      					}
      				}
      			}
      		},
      		"rejectedPlans" : [ ]
      	},
      	...
      } 

      Why we use min/max modifier

      We use min/max modifier for iterating over collections, because MongoDB don't have operation like `after` or `before`.

      We can't use `$gt`/`$gte`/`$lt`/`$lte` because:

      1. this operations always false for values with differ types;
      2. it's not trivial to make query with multiple field bounds.

      Workaround

      Looks like with `hint` we can set correct index directly.

      Attachments

        Activity

          People

            Unassigned Unassigned
            rathi.gnanasekaran Rathi Gnanasekaran
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: