Practical mod_perl / HTML Version / books


previous page: 20.2.5. Running Two or More Relational Databasespage up: HTML Version of the booknext page: 20.3. DBI Debug Techniques

20.2.6. Caching prepare( ) Statements


Search







modperlbook.org


 HTML Version


 PDF Version


 Download Code


 Table of Contents


 Errata


 mod_perl2 User's Guide


 Sitemap





Add to Google



Creative Commons License


Written by
Eric Cholet (Logilune)
and Stas Bekman (StasoSphere).

Hosted by ibiblio.org.




























You can also benefit from persistent connections by replacing prepare( ) with prepare_cached( ). That way you will always be sure that you have a good statement handle and you will get some caching benefit. The downside is that you are going to pay for DBI to parse your SQL and do a cache lookup every time you call prepare_cached( ). This will give a big performance boost to database servers that execute prepare( ) quite slowly (e.g., Oracle), but it might add an unnecessary overhead with servers such as MySQL that do this operation very quickly.

Be warned that some databases (e.g., PostgreSQL and Sybase) don't support caches of prepared plans. With Sybase you could open multiple connections to achieve the same result, but this is at the risk of getting deadlocks, depending on what you are trying to do!

Another pitfall to watch out for lies in the fact that prepare_cached( ) actually gives you a reference to the same cached statement handle, not just a similar copy. So you can't do this:

my $sth1 = $dbh->prepare_cached('SELECT name FROM table WHERE id=?');
my $sth2 = $dbh->prepare_cached('SELECT name FROM table WHERE id=?');

because $sth1 and $sth2 are now the same object! If you try to use them independently, your code will fail.

Make sure to read the DBI manpage for the complete documentation of this method and the latest updates.

 

Continue to:

  • prev: 20.2.5. Running Two or More Relational Databases
  • Table of Contents
  • next: 20.3. DBI Debug Techniques

Tags

mod_perl, modperl, Apache, perl, cgi, html, mod_perl, e-commerce, scalability, free, open source, OSS, apache, squid, high availability, modperl, linux, unix, Web, www, mod_perl, webserver, admin, apache, book, webmaster, tools, modperl, guide, docs, documentation, help, mod_perl, perl, information, apache, script, errata, eric cholet, perl, apache, mod-perl, stas bekman, mod_perl, cool, perl, Apache, performance, speed, choice




Other projects to check out: meta-religion.com is for those interested in Religious, Spiritual and Esoteric Phenomena. i-want-a-better.com is a community of people discussing what they would like to be improved in their lives and things they use and interact with. You may also want to find a healer in your area or read articles on variety of topics.






TOP
previous page: 20.2.5. Running Two or More Relational Databasespage up: HTML Version of the booknext page: 20.3. DBI Debug Techniques

© 2007 StasoSphere

[ Privacy Policy ] [ Terms of Use ] [ About Authors ] [ Search ]

Last modified Wed May 7 06:27:43 2008