Davin Flatten wrote:
> 
> Hello everyone,
> 
> I have a quick question of performance.  Which is
> faster with the Perl DBI:
> 
> 1. One SQL query that retrieves a large amount of data
> and then lets Perl decide what to do with each row.
> i.e. this row is a "foo1" do this, this row is a
> "foo2" do this.
> 
> 2. Several SQL queries that segement the larger query
> into several small queries.  i.e. Perl does this to
> all "foo1" from query #1. Perl does this to all "foo2"
> from query #2. Etc...
> 

If there's a chance that in #2 you might end up operating
on a smaller dataset than in #1, you may get better 
performance out of #2, if you end up fetching
fewer (rows X columns) worth of data.

But if its the same data set size no matter what, 
and you are just going to do different things to it,
then as long are you are not building up large @arrays
to hold the data in some post processing stage, it
shouldn't matter.  If you are aggregating the data
in large arrays, then it may again help to go with #2.

Generally, its more efficient for LARGE (10,000's+ of rows) 
data sets to:

while(my $row = $sth->fetchrow_arrayref) {
   ... do something to $row, then output, move on ...
}

than it is to:

my $rows = $dbh->selectall_arrayref();
for my $row ( @$rows ) {
  ... do something ...
}

--Josh

_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks >> free web link monitoring   Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to