[SERVER-41271] StringBuilder prints doubles with only 6 digits of precision, can lead to misleading log lines for plan ranking Created: 22/May/19  Updated: 29/Oct/23  Resolved: 11/Jun/19

Status: Closed
Project: Core Server
Component/s: Diagnostics, Logging, Querying
Affects Version/s: 4.1.11
Fix Version/s: 4.3.1

Type: Improvement Priority: Major - P3
Reporter: David Storch Assignee: Mikhail Ivkov (Inactive)
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Query 2019-06-03, Query 2019-06-17
Participants:

 Description   

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.



 Comments   
Comment by Githook User [ 11/Jun/19 ]

Author:

{'name': 'Misha Ivkov', 'email': 'misha.ivkov@10gen.com'}

Message: SERVER-41271 allow logging doubles with arbitrary precision
Branch: master
https://github.com/mongodb/mongo/commit/cad3a84e198e0851c7a8dd49d365ea1ce5cada50

Generated at Thu Feb 08 04:57:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.