in reply to Re: fastest method to use DBI
in thread fastest method to use DBI
Yes, bind_columns/->fetchrow_arrayref (or its alias, ->fetch) is the fastest way to retrieve data, per the DBI docs:
[fetchrow_arrayref] Fetches the next row of data and returns a reference to an array holding the field values. Null fields are returned as undef values in the array. This is the fastest way to fetch data, particularly if used with $sth->bind_columns.Perhaps the OP misread this as saying that the fastest option was fetchall_arrayref rather than fetchrow_arrayref?
The recommended technique, then, would be:
my $sth = $dbn->prepare("select number,id,start_dat,end_dat from SUBSC +RIBERSLIST"); $sth->execute(); $sth->bind_columns(\$number, \$id, \$start_dat, \$end_dat); my %hash =(); while ($sth->fetch) { # ->fetch populates the variables from ->bind_columns push @{$hash{$number}}, [$id, $start_dat, $end_dat]; }; $sth->finish(); $dbn->disconnect;
But, as already noted, you should also SELECT only the rows you need and do your processing line-by-line instead of sucking in the whole table at once if possible. I've only addressed the mechanics of how the OP is pulling the SELECTed rows.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: fastest method to use DBI
by perrin (Chancellor) on Jul 07, 2009 at 15:34 UTC | |
by zwon (Abbot) on Jul 07, 2009 at 18:54 UTC | |
by perrin (Chancellor) on Jul 07, 2009 at 19:25 UTC |
In Section
Seekers of Perl Wisdom