Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

$sth->prepare_cached loop

by hmadhi (Acolyte)
on Mar 08, 2011 at 06:36 UTC ( [id://891955]=perlquestion: print w/replies, xml ) Need Help??

hmadhi has asked for the wisdom of the Perl Monks concerning the following question:

Will the following loop cause separate queries to the database?
my %kpi_thres = ( "PDP"=>80, "GAS"=>70, "RAU"=>75 ); $SQL=qq{select * from abc where date=?}; foreach $kpi (keys(%kpi_thres)) { my $sth_ne = $dbh->prepare_cached($SQL); $sth_ne->execute($currDateTime); }

Replies are listed 'Best First'.
Re: $sth->prepare_cached loop
by tilly (Archbishop) on Mar 08, 2011 at 07:17 UTC
    What will happen will vary depending on the database.

    With Oracle, you will prepare the query once. And then send 3 execute statements to it. Which saves you the effort of compiling the query. Since compilation is expensive in Oracle, this is a win.

    In MySQL the caching is done client side. So you wind up preparing and executing the query 3 times. Since MySQL makes preparing the query cheap, this doesn't cost very much.

      Thanks for the reply, I am using Oracle.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://891955]
Approved by NetWallah
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-25 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found