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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.2.6, 4.3.2, 4.0.19
    • Component/s: None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Backport Requested:
      v4.2, v4.0
    • Steps To Reproduce:
      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
    • Sprint:
      Query 2019-11-18, Query 2019-12-02
    • Case:
    • Linked BF Score:
      0

      Description

      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 } 

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              david.percy David Percy
              Reporter:
              christopher.harris Christopher Harris
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              12 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: