Don't I get a performance benefit from using prepare_cached?

It depends. Not on any statements that are executed only once. Have you read the DBI docs on how prepare_cached actually works? It stores the actual SQL statement (and any attributes) as a hash key whose value is the statement handle. If your program happens to prepare the same SQL statement twice within the same invocation of your program, you will get back the same statement handle. So its actually useless for statements that are only executed once. And I usually prefer to organize my logic so that statements only get prepared once anyway, so I normally have little use for prepare_cached (even though I'm the one that came up with the insert_hash example in the DBI docs). But even in this case I still don't think the performance benefit justifies caching up to 1000 handles for this one bit of code even if its running under mod_perl (meaning every child process would be caching up to 1000 statement handles).

And you still haven't answered whether this is under CGI or under something like mod_perl. Nor how many times will that statement be prepared in one run of the program?


In reply to Re: Re(4): DBI question with placeholders and IN by runrig
in thread DBI question with placeholders and IN by dragonchild

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.