LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] MySQL DBI utility functions

[ILUG] MySQL DBI utility functions

Niall O Broin niall at linux.ie
Thu Sep 13 16:57:37 IST 2001


On Thu, Sep 13, 2001 at 11:47:40AM +0100, Fergal Daly wrote:

> If you moved the prepare to outside the first loop it might make a
> difference, the whole point of a prepare is that the DB only has to parse
> the statement once and you can reuse it without reparsing. I think this may
> not work very well for MySQL but even still moving it outside might help.
> It's possible that you'd see a bigger difference with Oracle where the
> prepares can have much bigger effects, especially with complex queries.

Yes, but then I wouldn't be comparing like with like. The repetition was
only to take sufficient time to benchmark.

> [ @$row ] creates an anonymous ref to an array that has the same entries as
> @$row. Basically it makes a copy of the array. Possibly the array pointed to
> by $row is permanently associated with that prepared statement and is used
> to pass values from C code to perl code. That would mean it gets altered
> every time a new row is read from the DB and fetch always returns the same
> ref. You could end up with
> 
> push @rows, $row while($row = $sth->fetch);
> 
> filling @rows with n references to the same array

That's exactly it ! The DBI code says that fetch always returns the same
array ref, so this copying is because of that. I think this points to the
speed difference too - I believe I do a little less data copying by calling
fetch (fetchrow_arrayref) myself repeatedly in a loop than the utility
functions do. Full marks to Fergal !



Niall




More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell