Bug #51149 Command.TrimSemicolons uses a lot of memory
Submitted: 12 Feb 2010 15:21 Modified: 17 Feb 2010 16:06
Reporter: Simen Endsjø Haugen Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S5 (Performance)
Version:6.2.2 (and 61.2,3 at least) OS:Any
Assigned to: Reggie Burnett CPU Architecture:Any
Tags: out of memory, StringBuilder, TrimSemicolons

[12 Feb 2010 15:21] Simen Endsjø Haugen
Description:
TrimSemicolons uses StringBuilder, and therefore always allocates space for the query even if it doesn't need to be trimmed. This leads to a major resource hog when executing many large queries.

How to repeat:
Profile the memory use when running queries.

Suggested fix:
561d560
< 			System.Text.StringBuilder sb = new System.Text.StringBuilder(sql);
563c562
< 			while (sb[start] == ';')
---
>             while (sql[start] == ';')
566,567c565,566
< 			int end = sb.Length - 1;
< 			while (sb[end] == ';')
---
>             int end = sql.Length - 1;
>             while (sql[end] == ';')
569c568,569
< 			return sb.ToString(start, end - start + 1);
---
> 
>             return sql.Substring(start, end - start + 1);
[12 Feb 2010 17:16] Tonci Grgin
Hi Simen and thanks for your report.

Verified as described by looking into latest sources.
[15 Feb 2010 20:36] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/100438

792 Reggie Burnett	2010-02-15
      - small performance fix (bug #51149)
[15 Feb 2010 20:37] Reggie Burnett
fixed in 6.0.6, 6.1.4, 6.2.3, and 6.3.1+
[17 Feb 2010 16:06] Tony Bedford
An entry has been added to changelogs for 6.0.6, 6.1.4, 6.2.3, 6.3.1:

The method Command.TrimSemicolons used StringBuilder, and therefore allocated memory for the query even if it did not need to be trimmed. This led to excessive memory consumption when executing a number of large queries.