At 11:07 AM -0700 8/18/99, Thimble Smith wrote:
>At 11:35, 19990818, Dan Ray wrote:
>> Any opinons on whether it's more efficient to fetch rows all-at-once
>>or one-at-a-time? SHOULD I be using fetchall? Certainly it's trickier
>>to pull data out of the structure it returns. Given Perl's overhead
>>related to dereferencing nested references, is it better to use the
>>fetchrow_* methods? Anyone have an opinion about it?
>I often use fetchall_arrayref because I think the it's simpler to work
>with the data...but that's me being weird. I think that if you can
>use the data one row at a time (i.e., you don't ever need to go back
>and look at a previous row), then it's better to use fetchrow_*. If
>you need all the data anyway, go ahead and use fetchall_*.
Why is it better? I don't think you get any memory savings by fetching
a row at a time and working with your data that way. The MySQL DBD uses
mysql_store_result() by default, so it's fetching the entire result set
into memory anyway. And you're not making an extra copy by using
fetchall_arrayref() since all you're getting back is a reference.
This doesn't answer the original question, but for the row at a time
methods, they order like this for efficiency (best is first):
I assume from this that fetchall_arrayref() is reasonably efficient
unless you call it with a hash reference argument, in which case it's
As for *using* the returned values from these calls, I'm not sure what
the efficiency would be. I assume dereferencing hashes is least efficient.
Paul DuBois, paul@stripped