| Bug #69606 | Wasted work in method pretty_print_string() | ||
|---|---|---|---|
| Submitted: | 27 Jun 2013 19:11 | Modified: | 9 Jan 2015 16:23 |
| Reporter: | Po-Chun Chang (OCA) | Email Updates: | |
| Status: | Unsupported | Impact on me: | |
| Category: | MySQL Cluster: Cluster (NDB) storage engine | Severity: | S5 (Performance) |
| Version: | 5.6, 5.7 | OS: | Any |
| Assigned to: | CPU Architecture: | Any | |
| Tags: | patch, performance | ||
[27 Jun 2013 19:12]
Po-Chun Chang
Suggested patch (*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.
Contribution: patch.diff (text/plain), 502 bytes.
[28 Jun 2013 15:48]
MySQL Verification Team
Hello Chang, Thank you for the report and contribution. Thanks, Umesh
[14 Aug 2013 9:46]
Magnus Blåudd
The for loop in question is also used to count the length of the string to print(in the "len" variable) and thus performs useful work. Can the tool be updated to detect this?

Description: The problem appears in version 5.6 and in the revision 5216 in version 5.7. I attached a patch that fixes it. In method "pretty_print_string" in NdbDictionary.cpp, the loop on line 2968 should not be executed when "printable" becomes 0. When "printable" is 0, all the iterations do not perform any useful work. How to repeat: Once pretty_print_string() is executed. Suggested fix: Break the loop after "printable" becomes 0. === modified file 'storage/ndb/src/ndbapi/NdbDictionary.cpp' --- storage/ndb/src/ndbapi/NdbDictionary.cpp 2013-02-26 06:21:48 +0000 +++ storage/ndb/src/ndbapi/NdbDictionary.cpp 2013-06-27 19:06:28 +0000 @@ -2966,8 +2966,10 @@ if (sz == 0) return; // empty for (len=0; len < (int)sz && ref[i] != 0; len++) - if (printable && !isprint((int)ref[i])) + if (printable && !isprint((int)ref[i])) { printable= 0; + break; + } if (printable) out.print("%.*s", len, ref);