Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: DBI speed up needed on MySQL

by bart (Canon)
on May 08, 2005 at 09:42 UTC ( #454990=note: print w/ replies, xml ) Need Help??


in reply to Re^3: DBI speed up needed on MySQL
in thread DBI speed up needed on MySQL

Well, then you'll probably want to get the list of column names via a separate query, store those in an array (e.g. "@colnames")...
No you don't. Check out the property NAME of the statement handles in the DBI docs. It fetches and stores those column names into an array, when you execute the query. This property contains an array ref to it.
my $sth = $dbh->prepare("SELECT * FROM sometable"); my $colnames = $sth->{NAME}; while (my $rowref = $sth->fetchrow_arrayref ) { @rowhash{@$colnames} = @$rowref; ... }

However, DBI being highly optimized as it is, I don't expect any speed improvement over fetching the hashref.

Why the need for a hash anyway? It's not ordered. So, keeping the names and data as two arrays, holds more information for you, than just the hash on its own does: the column order. I would believe that for printing, the order is very important. To loop through the arrays side by side, loop through the array index (for either array, they're the same size).

You can always still map the field names to column numbers, the inverse of the array @$colnames, in a separate hash — and you need to do that only once:

my %colcolumn; @colcolumn{@$colnames} = 0 .. $#$colnames;

Stil, I don't expect all this mucking about to perform any miracles. Otherwise, Tim Bunce and co. would really have had to have been messing about. I don't think so.


Comment on Re^4: DBI speed up needed on MySQL
Select or Download Code
Re^5: DBI speed up needed on MySQL
by jacques (Priest) on May 09, 2005 at 00:20 UTC
    However, DBI being highly optimized as it is, I don't expect any speed improvement over fetching the hashref.

    It is highly optimized, but the docs point out that using fetchrow_hashref is slower than using other methods.

    Why the need for a hash anyway?

    That's the spec I have been given. I need a hash ref. (Another application uses it.)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://454990]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (13)
As of 2014-08-20 19:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (122 votes), past polls