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

Plan scoring incorrectly applies noFetchBonus bonus to all plans when no projection is provided

    • Fully Compatible
    • ALL
    • v4.2, v4.0
    • Hide
      use ranktest
      db.score.drop()
      db.score.createIndexes([{x:1},{x:1,y:1}])
      db.setLogLevel(2,'query')
      db.score.find({x:1},{_id:0, y:1})
      db.score.find({x:1}) 

      Then check the log file

      Show
      use ranktest db.score.drop() db.score.createIndexes([{x:1},{x:1,y:1}]) db.setLogLevel(2,'query') db.score.find({x:1},{_id:0, y:1}) db.score.find({x:1}) Then check the log file
    • Query 2019-11-18, Query 2019-12-02
    • 0

      When a projection is applied to a query, the algorithm to score the plans correctly takes into consideration if a plan is covered or not.  This can be seen in the following log output ("query" component set to level 2) for the operation find({x:123},{_id:0, y:1})

      2019-01-28T21:58:09.666-0600 D QUERY    [conn12] Scoring query plan: IXSCAN { x: 1 } planHitEOF=1
      2019-01-28T21:58:09.666-0600 D QUERY    [conn12] score(1.0002) = baseScore(1) + productivity((0 advanced)/(1 works) = 0) + tieBreakers(0 noFetchBonus + 0.0001 noSortBonus + 0.0001 noIxisectBonus = 0.0002)
      2019-01-28T21:58:09.666-0600 D QUERY    [conn12] Scoring query plan: IXSCAN { x: 1, y: 1 } planHitEOF=1
      2019-01-28T21:58:09.666-0600 D QUERY    [conn12] score(1.0003) = baseScore(1) + productivity((0 advanced)/(1 works) = 0) + tieBreakers(0.0001 noFetchBonus + 0.0001 noSortBonus + 0.0001 noIxisectBonus = 0.0003)
      2019-01-28T21:58:09.667-0600 D QUERY    [conn12] Winning plan: IXSCAN { x: 1, y: 1 } 

      As expected, only the plan using the {x:1,y:1} index received a nonzero noFetchBonus value. 

      However, when the command is issued without a projection (eg find({x:123})), both of the plans receive the bonus despite the fact that they both contain FETCH stages:

      2019-01-28T22:00:04.415-0600 D QUERY    [conn12] Scoring query plan: IXSCAN { x: 1 } planHitEOF=1
      2019-01-28T22:00:04.415-0600 D QUERY    [conn12] score(1.0003) = baseScore(1) + productivity((0 advanced)/(1 works) = 0) + tieBreakers(0.0001 noFetchBonus + 0.0001 noSortBonus + 0.0001 noIxisectBonus = 0.0003)
      2019-01-28T22:00:04.415-0600 D QUERY    [conn12] Scoring query plan: IXSCAN { x: 1, y: 1 } planHitEOF=1
      2019-01-28T22:00:04.416-0600 D QUERY    [conn12] score(1.0003) = baseScore(1) + productivity((0 advanced)/(1 works) = 0) + tieBreakers(0.0001 noFetchBonus + 0.0001 noSortBonus + 0.0001 noIxisectBonus = 0.0003)
      2019-01-28T22:00:04.416-0600 D QUERY    [conn12] Winning plan: IXSCAN { x: 1 } 

       

            Assignee:
            david.percy@mongodb.com David Percy
            Reporter:
            christopher.harris@mongodb.com Chris Harris
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: