Stephane’s thoughts corner…
Stephane Bailliez's thoughts on everything

«« Feeling like using a Music API to operate a nuclear facility ? | MongoDB : schema-free document-oriented datastore »»

March 8, 2009

mysql jdbc driver 5.1.7 – avoid

Filed under: OpenSource,Software — stephane @ 12:36 am

If you happen to use java and mysql do yourself a favor and don’t take the 5.1.7 jdbc driver.

I recently opened bug 42970 following a quick profiling to find the reason why 100 test calls of a 3.5KB-long sql query increased from 4.5s to 50s by upgrading the driver from 5.1.6 to 5.1.7.

There is a subtle piece of code in 5.1.7 which tries to find the string ‘ ON DUPLICATE KEY UPDATE ‘ in every statement in a very peculiar way

In my case, as can be seen from the call tree below, 4 PreparedStatement, means 4 calls to containsOnDuplicateKeyInString() and generates more than 12M calls to String.charAt() , 9M calls to Characters.toUpperCase, 4.5M calls to Characters.toLowercase().

  99,9% - 386 s - 4 inv. com.mysql.jdbc.JDBC4PreparedStatement.
    99,9% - 386 s - 4 inv. com.mysql.jdbc.PreparedStatement. (line: 47)
      99,9% - 386 s - 4 inv. com.mysql.jdbc.PreparedStatement$ParseInfo. (line:635)
        99,9% - 386 s - 4 inv. com.mysql.jdbc.PreparedStatement.containsOnDuplicateKeyInString (line: 202)
          99,9% - 386 s - 4 inv. com.mysql.jdbc.StringUtils.indexOfIgnoreCaseRespectMarker(line: 5193)
            99,7% - 386 s - 3 002 inv. com.mysql.jdbc.StringUtils.indexOfIgnoreCase (line:1023)
              18,0% - 69 578 ms - 9 530 899 inv. java.lang.String.charAt (line: 946)
              10,3% - 40 015 ms - 5 506 413 inv. java.lang.Character.toUpperCase (line:946)
              7,4% - 28 716 ms - 4 024 486 inv. java.lang.Character.toLowerCase (line:946)
              6,4% - 24 725 ms - 3 420 156 inv. java.lang.Character.toUpperCase (line:963)
              6,2% - 23 975 ms - 3 420 156 inv. java.lang.String.charAt (line: 963)
              0,8% - 3 228 ms - 450 342 inv. java.lang.Character.toLowerCase (line: 974)
              0,8% - 2 932 ms - 450 342 inv. java.lang.String.charAt (line: 974)

5.1.6 works fine (at least for what we do)…

1 Comment »

  1. woah! we were *just* about to update to 5.1.7 and i’m glad i found this posting. thanks stephane!

    Comment by jon — March 10, 2009 @ 1:46 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress