List:MySQL and Perl« Previous MessageNext Message »
From:Jochen Wiedmann Date:June 8 2001 3:54pm
Subject:Re: Maintaining State/Cached Connections
View as plain text  

Todd Finney wrote:

> >Someone else said this would work but I believe they are
> >incorrect.  Your
> >startup file (presumably loaded via PerlRequire startup.pl) will be
> >executed in the parent Apache process _before_
> >forking.  Unfortunately,
> >DBI database handles become invalid after a fork.
> 
> You presumably mean 'statement handles' there.  Doing a connect_on_init
> via startup.pl is standard operating procedure, and it works just
> fine.  But you know that.

It may be a standard operating procedure, but it cannot work
with DBD::mysql. The precise statement is:

  - A created database handle may be shared by different
    threads and/or processes,
    but *only* if they serialize using the database handle.
    Serialization can be done, for example, if Apache is using
    threads. With fork() serialization is *very* hard.

    Also, if one thread/process closes the database handle,
    the others cannot use the handle anymore.

  - The same holds true for a statement handle.


> http://perl.apache.org/guide/performance.html#Eliminating_SQL_Statement_Parsin
> 
> Am I reading that incorrectly?

I don't know this page, but I assume that it recommends
using placeholders, which is not only good style, but
indeed recommendable in terms of performance.

If this page recommends sharing statement handles, I strongly
discourage this, considering the above.

In the case of DBD::mysql, it is possible to share an *inactive*
statement handle: An inactive statement handle is a handle,
where you either did not do an execute() upon or where you
did a finish() or you have read all the result rows.

However, this may *very* easily change in the future: The
above works, because the driver DBD::mysql emulates placeholders.
As soon as the MySQL client library supports them, the
above statement will almost definitely break.


Yours,

Jochen
Thread
DBD::mysql ProblemsJason Allocco6 Jun
  • Re: DBD::mysql ProblemsJeremy Zawodny6 Jun
  • Re: DBD::mysql Problemsed phillips6 Jun
  • Maintaining State/Cached ConnectionsDodger6 Jun
    • Re: Maintaining State/Cached ConnectionsTodd Finney7 Jun
    • Re: Maintaining State/Cached ConnectionsDave Rolsky8 Jun
      • Re: Maintaining State/Cached ConnectionsJochen Wiedmann8 Jun
      • Re: Maintaining State/Cached ConnectionsTodd Finney8 Jun
    • Re: Maintaining State/Cached ConnectionsJochen Wiedmann8 Jun
      • Re: Maintaining State/Cached ConnectionsTodd Finney8 Jun
        • Re: Maintaining State/Cached ConnectionsJochen Wiedmann9 Jun
          • Re: Maintaining State/Cached ConnectionsStas Bekman9 Jun
            • Re: Maintaining State/Cached ConnectionsJochen Wiedmann10 Jun
              • Re: Maintaining State/Cached ConnectionsStas Bekman10 Jun