On Thu, 14 Jun 2007, Greg Sabino Mullane wrote:
I have a bunch of queries which are not extremely performance sensitive.
What is the trade-off between prepare and prepare_cached? Is
prepare_cached basically free and I should use it all the time? Or is
there a significant memory cost and I should only use it for the most
time-critical queries?
No significant memory or computation cost. It's a fairly cheap optimization.
It's probably fine to use it all you want. Personally, I rarely use it myself,
as my apps prepare things only once and keep pretty good track of what's
already been prepared or not.
That depends, I can think of some instances were you would not want to use it:
for (1..100_000_000) {
eval {
my $sth = $dbh->prepare_cached(q{
INSERT INTO mytable (number) VALUES ($_);
});
$sth->excute();
}; if (my $e = $@) {
die "Hmm there was an error... Did you forget to create mytable? $e";
}
}
Or in general, any time you have something that will generate a large set of
different statements....
-r