From: Jon Molin <[EMAIL PROTECTED]> > Jenda Krynicky wrote: > [snip] > > > > You could use fetchall_arrayref(), but I would not recomend doing > > that unless you are really sure the resultset is small enough. That > > would slurp all the data to memory of YOUR process with quite some > > overhead. > > > > Are there any benchmarks on this? Becouse i guess you make the db > server work alot more, or at least for a longer time. > > Consider you have a www server and a db server, then i don't think > it's fully obvious wether you'd want to fetch all the rows, so the db > can close down the connection and be ready for the next user. On the > other hand, as you say the process will eat memory...so does anyone > has THE ANSWER(TM)?
No I did not do any benchmarks. But if you look into DBI.pm you'll find out that fetchall_arrayref() is implemented on top of fetchrow_hashref(). So basicaly the only difference between having a loop that fetches one row, does some computations and prints a result versus fetching all rows and then looping through them is that in the second case your scripts uses more memory, but closes the resultset a litle bit later. Keep in mind that most usualy you don't do anything heavy with the rows, you don't wait for anything. So it doesn't take longer to make the things you need and print results than to add the data to a structure. And since you may end up useing a lot of memory you may actualy spend more time allocating memory and swaping than you would processing the data. I'd say ... if the processing doesn't take long ... don't play tricks, fetch and process rows one by one. If processing one row takes long (like if you need to fetch a page for each row) you micht consider reading all the data beforehand and processing them later. But even in this case if I cared for efficiency I would not use fetchall_arrayref(). Keep in mind that it uses fetchrow_hashref() which has to construct a hash for every row. It's much more efficient to fetch into an array or into bound variables and store the data in an array of arrays. In either case the number of fetches, the number of "calls" to the database will be exactly the same. Jenda =========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ========== There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain. I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]