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

StringBuilder prints doubles with only 6 digits of precision, can lead to misleading log lines for plan ranking

    • Fully Compatible
    • Query 2019-06-03, Query 2019-06-17

      We use StringBuilder and str::stream throughout the code base to produce log lines. When StringBuilder prints a double, it passes through the "%g" format specifier to snprintf(). The man pages for snprintf() indicate that without an explicit precision, this prints the double with 6 digits of precision.

      This behavior may be acceptable for most uses of StringBuilder, however, it leads to misleading log lines in the query subsystem. In particular, the PlanRanker generates log lines which provide information about how the system is scoring candidate plans during the plan selection process. Consider the following set of log lines, provided by christopher.harris:

      2018-01-08T11:18:41.411+0530 D QUERY    [conn1] Scoring query plan: IXSCAN { _id: 1 } planHitEOF=0
      2018-01-08T11:18:41.411+0530 D QUERY    [conn1] score(1) = baseScore(1) + productivity((0 advanced)/(3517483 works) = 0) + tieBreakers(2.84294e-08 noFetchBonus + 2.84294e-08 noSortBonus + 2.84294e-08 noIxisectBonus = 8.52883e-08)
      2018-01-08T11:18:41.411+0530 D QUERY    [conn1] score = 1 

      These log lines appear to suggest that the plan's score was 1, and that the tie-breakers were somehow discarded. However, the tie-breakers were not discarded. This is a symptom of the StringBuilder being unwilling to print more than 6 digits of precision. Unfortunately, this precision is important in query plan ranking due to our use of very small floating point numbers as tie-breakers.

      This may not be appropriate to fix in general for all log lines, but we can investigate producing a targeted fix to log plan scoring information with more precision.

            misha.ivkov@mongodb.com Mikhail Ivkov (Inactive)
            david.storch@mongodb.com David Storch
            0 Vote for this issue
            4 Start watching this issue