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

Wrong index bounds when using "hint"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 2.6.3
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      I have the following two indexes:

      {Groups: 1, Duplicate: 1, NotFound: 1, DontShow: 1, TSCreated: 1, FacebookShares: -1}, {name: 'DateGroupIndex-FacebookShares'}
      {Groups: 1, Duplicate: 1, NotFound: 1, DontShow: 1, TSCreated: 1, TwitterShares: -1}, {name: 'DateGroupIndex-TwitterShares'}

      A) When I run the following query:

      .find({Groups:1,Duplicate:0,NotFound:0,DontShow:0,TSCreated:{$lt:1405695600,$gt:1405609200}}).hint("DateGroupIndex-FacebookShares").limit(10).sort({FacebookShares: -1}).explain()
       
      "cursor" : "BtreeCursor DateGroupIndex-FacebookShares"
      ...
      "indexBounds": {
      ...
      "TSCreated" : [
      		[
      				-Infinity,
      				1405695600
      		]
      ],
      ...}

      B) And when I run same query without calling "hint", the index bounds for TSCreated is properly computed, although it's not the proper index which is picked up:

      "cursor" : "BtreeCursor DateBasicIndex-TwitterShares"
      ...
      "indexBounds": {
      ...
      "TSCreated" : [
      		[
      				1405609200,
      				1405695600
      		]
      ],
      ...}
       

      Show
      I have the following two indexes: {Groups: 1, Duplicate: 1, NotFound: 1, DontShow: 1, TSCreated: 1, FacebookShares: -1}, {name: 'DateGroupIndex-FacebookShares'} {Groups: 1, Duplicate: 1, NotFound: 1, DontShow: 1, TSCreated: 1, TwitterShares: -1}, {name: 'DateGroupIndex-TwitterShares'} A) When I run the following query: .find({Groups:1,Duplicate:0,NotFound:0,DontShow:0,TSCreated:{$lt:1405695600,$gt:1405609200}}).hint("DateGroupIndex-FacebookShares").limit(10).sort({FacebookShares: -1}).explain()   "cursor" : "BtreeCursor DateGroupIndex-FacebookShares" ... "indexBounds": { ... "TSCreated" : [ [ -Infinity, 1405695600 ] ], ...} B) And when I run same query without calling "hint", the index bounds for TSCreated is properly computed, although it's not the proper index which is picked up: "cursor" : "BtreeCursor DateBasicIndex-TwitterShares" ... "indexBounds": { ... "TSCreated" : [ [ 1405609200, 1405695600 ] ], ...}  

      Description

      It seems like than when using a range matching {$gt: XX, $lt YY} and forcing an index with "hint", the parser can properly parse the lower bound value. I've tried switching $gt and $lt places, it's all the same.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: