MySQL Forums
Forum List  »  Perl

Is it possible to use several statement handlers with only one database handler ?
Posted by: Apachez
Date: April 28, 2006 04:05PM

I have built myself an indexer for my search-engine (which uses perl and mysql backend) where I wonder if it is possible to setup several statement handlers for a single database handler/single connection ?

The statements are executed one after each other.

The workflow is that I connect to the database which has the tables I will index and at the same time connect to the database where I will store my indexed result. No problem so far... However I am then using one connection for each query for the inner loop towards the database where I store the results.

It looks something like:

dbh1 = connect(db1);
dbh2 = connect(db2);
dbh3 = connect(db2);
dbh4 = connect(db2);

sth1 = dbh1->prepare(select from t1 in db1);
sth2 = dbh2->prepare(select from t1 in db2);
sth3 = dbh3->prepare(select something else from t1 in db2);
sth4 = dbh4->prepare(insert into t1 in db2);

sth1->execute();

while(sth1->fetchrow_arrayref)
{

sth2->execute;
sth2->bind_columns();
...
sth3->execute;
sth3->bind_columns();
...
sth4->execute(data);

}

The above idea is to do the prepare outside the "inner loop" and inside this loop only fire the execute/bind_columns function in order to gain performance (avoiding running prepare all the time).

However I have a slight feeling that I wont need 4 connections against the mysql server while I do this when I could get around with only 2 connections (one against db1 and one against db2).

The statement handlers for sth2, sth3 and sth4 are never used concurrently. The only concurrent execution is versus the sth1 handler (that is why I need at least 2 connections towards the mysql server).

I have tried to read through the documentation for DBD::mysql but I have not found any words for if it is recommended or not to do what I want to do with having several statement handlers sharing a single connection.

The idea would be that it would look something like:

dbh1 = connect(db1);
dbh2 = connect(db2);

sth1 = dbh1->prepare(select from t1 in db1);
sth2 = dbh2->prepare(select from t1 in db2);
sth3 = dbh2->prepare(select something else from t1 in db2);
sth4 = dbh2->prepare(insert into t1 in db2);

However would the prepares then somehow be broken ?

I mean are the statement handler saving the prepared statement against the database handler (which would spoil my idea of shrinking down to a single connection) or are the prepared statement saved against the statement handler ?

And if they are stored in the database handler, can the database handler only have one prepared statement at a time (yeah I know they can be cached but I want to avoid running prepare/prepare_cached inside this "inner loop") ?

Or is my only option to use a single connection for each statement handler because I dont want to call prepare inside this "inner loop" ?

Options: ReplyQuote


Subject
Written By
Posted
Is it possible to use several statement handlers with only one database handler ?
April 28, 2006 04:05PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.