Respect your server's SQL cache
Optimised Access Plan and related data
- is cached within the server (for Oracle etc, but not MySQL etc)
- keyed by the exact original SQL string used
-
Compare do("insert … $id");
with do("insert … ?", undef, $id);
Without placeholders, SQL string varies each time
- so cached one is not reused
- so time is wasted creating a new access plan
- the new statement and access plan are added to cache
- so the cache fills and other statements get pushed out
- on a busy system this can lead to ‘thrashing’
-
Oracle now has a way to avoid/reduce this problem
- it can effectively replace literal constants with placeholders
- but the quality of query execution plans can suffer