PreparedStatements and performance

The notion that prepared statements are primarily about performance is something of a misconception, although it’s quite a common one.

Another poster mentioned that he noted a speed improvement of about 20% in Oracle and SQL Server. I’ve noted a similar figure with MySQL. It turns out that parsing the query just isn’t such a significant part of the work involved. On a very busy database system, it’s also not clear that query parsing will affect overall throughput: overall, it’ll probably just be using up CPU time that would otherwise be idle while data was coming back from the disk.

So as a reason for using prepared statements, the protection against SQL injection attacks far outweighs the performance improvement. And if you’re not worried about SQL injection attacks, you probably should be…

Leave a Comment