There's more than one way to do things | |
PerlMonks |
Re^5: Dynamic SQL (prepare)by tye (Sage) |
on Apr 07, 2015 at 03:47 UTC ( [id://1122654]=note: print w/replies, xml ) | Need Help?? |
prepared statements with placeholders will likely be faster than constructing queries on the flyI rather doubt this is generally true. It would be nice to see it demonstrated. Running a ton of nearly identical queries can get a rather slight performance improvement from only having to prepare the statement once. But this is not particularly significant in the most extreme case and is of no significance at all if your queries are not rather trivial. On the other hand, in all 3 of my most recent jobs I've had to basically disable the "prepare" step as the poor query optimization that is done in the absence of the actual values is often horrible and can result in queries taking several orders of magnitude longer. So I've heard that newer versions of databases that I haven't used recently end up doing query planning twice, once at "prepare" time and then again once the values are known. I don't know how much that impacts the oft-touted "efficiency" of separate prepare/execute, but it surely means it has become even more insignificant. But the documentation says that it is faster so everybody repeats that, usually with much more emphasis than is warranted (and completely ignoring the much, much worse performance problems that can result). - tye
In Section
Seekers of Perl Wisdom
|
|