Skip to main content
EU.EDGE
  • Services
  • Clients
  • Case Studies
    • FreshDirect
    • Dragontape
  • About Us
    • The Team
    • Sponsorship
  • Blog
  • Careers
    • Open Positions
    • Training
  • Contact

You are here

Home ‣ Blog ‣ Prepared statement performance in MySQL
  • News
  • Technology
    • Java
    • Android
    • Open Source

Latest Posts

  • May

    08

    2013

    RIPE Atlas probes hosted by EU Edge

    EU is proud to participate in a huge measurment project by RIPE NCC hosting RIPE Atlas probes. RIPE Atlas employs a global network of probes that measure Internet connectivity and reachability, Continue...
  • May

    08

    2013

    We are Atlassian experts

    It's not that we need the positive reinforcement to feel like experts, but it's nice to have an official certificate: EU Edge is now expert for Atlassian We can help you develop customized Continue...

Free Developer Training

HTML, CSS and Javascript

Careers

  • Senior Back-End Developer
  • Senior Mobile (iPhone/Android) Software Developer
  • Senior Web Front-End Developer
  • Senior Web Front-End Tester

We are constantly looking for great minds to join and enrich our team. Please upload your CV to let us know about your talents.

Upload your CV

Sponsorship

Viktor

Nov

11

2007

Prepared statement performance in MySQL

Share on Facebook
Tweet this
  • Research

While working on performance tuning for one of our clients, we have performed some benchmarks on the various statement types and JDBC options for MySQL. The results turned out to be somewhat interesting, so we are sharing it here :)

Type Reused Server-side Cached Duration Relative
Plain n/a n/a n/a 283 100%
Prepared - - - 328 116%
Prepared Y - - 267 94%
Prepared - - Y 302 107%
Prepared - Y - 433 153%
Prepared - Y Y 243 86%
Prepared Y Y Y 216 76%

Definitions

Reused:
The prepared statement was reused in a loop (as opposed to opening/closing a new one for each query).
Server-side:
The JDBC option useServerPrepStmts was set to true.
Cached:
The JDBC option cachePrepStmts was set to true.
Duration:
Time to complete test in seconds.
Relative:
Elapsed time relative to the base-case (plain-statements). Lower is better.

The benchmark issued simple select queries, with randomized parameters that return no results. Tests were performed on MySQL 5.0.44, using MySQL Connector/J 5.0.7.

General conclusions

Plain statements are not worth the hassle or the potential SQL-injection security holes. Prepared statements perform significantly better with a combination of useServerPrepStmts=true and cachePrepStmts=true. And the conventional wisdom of reusing JDBC statements still applies.


Comments

Submitted by sus (not verified) on Wed, 04/23/2008 - 06:33

very helpful information to campare whether to use prepared statements or not

  • reply

Submitted by Loudacris (not verified) on Mon, 10/06/2008 - 22:11

Perfect, just what I was looking for, thanks.

  • reply

Submitted by Christian Vest ... (not verified) on Tue, 11/18/2008 - 12:13

Nice round-up, but I'd like to see a lot more variation in your queries. How does it fair with insert, update, delete, etc. statements? Also, how many times did you execute your queries? That sort of stuff...

  • reply

Submitted by Binod Suman (not verified) on Wed, 06/08/2011 - 07:31

Hi,

I know my comment is very old as you have posted this blog long back. Just I want to say it is very useful tips to get better performance in project. Many developer used to use PreparedStatment without knowing complete things behind it.
Thanks for your compare table.

Thanks again for your this blog.

Binod Suman

  • reply

Add new comment

More information about text formats

Filtered HTML

  • Email addresses will be obfuscated in the page source to reduce the chances of being harvested by spammers.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Services
  • Clients
  • Case Studies
  • About Us
  • Blog
  • Careers
  • Contact
  • Home
  • News
  • Contributions
  • Sponsorship
  • Training

join us on facebookfollow us on twitter

Copyright ©2011
Powered  by EU Edge LLC

EU Edge LLC
24 Tölgyfa street
1027 Budapest, Hungary

Tel.: +36 1 438 6337
Fax: +36 1 438 6336
email: