Re: GetRows equivalent?
| From: | Michael Kimsal | Date: | Wed, 26 Jul 2000 18:11:45 +0000 |
| Subject: | Re: GetRows equivalent? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-8365@lists.php.net to get a copy of this message | ||
First off, we're not using MySQL. However, just to test
this theory, I've written a couple small benchmarks.
I created a 500 element array, and made a 500 line MySQL
table out of this. Also, I took that 500 element array,
serialized it, and stored it in another table as a blob.
Selecting the columns from the first table, looping thru
line by line (fetch_row, fetch_array, whatever), and echo
the results took .053 seconds.
Selecting the blob, unserializing it, and stepping thru that
array came up as .026 seconds. That's a big difference -
looks like 100% faster doing it the 'single grab' way.
I don't know enough about the innards of how the
specific drivers work to know if they indeed pull everything back,
or piece it together step by step. There does in fact seem
to be some overhead calling the fetch_array 500 times.
Whether that's simply the overhead of calling a function or
not, I don't know. Perhaps someone could shed a bit
more light on how the internals of PHP/Zend work
in this respect.
I realize .03 seconds doesn't mean much to some people,
but it's the percentage difference that interests us. We're
trying to optimize things as much as possible. Publishing
certain 'semi-static' data to a serialized structure rather
than pulling it back line by line seems to be faster,
and if we've got 300 people simultaneously banging on
this, .03 seconds can add up.
The only harm I can see is memory usage - pulling large result
sets back for multiple people may eat up RAM a lot quicker
than single file. Anyone have any thoughts/experience on this?
Soeren Staun-Pedersen wrote:
> > Is there anything in PHP db drivers that could be considered
> > the equivalent of GetRows from the ASP/ODBC world? In a nutshell,
> > rather than looping thru a result set one row at a time, you
> > can 'GetRows' and the entire result set will be returned as an
> > array that you can loop thru locally, rather than continually
> > pulling from the DB driver.
>
> As far as I know there isn't. I don't know if it is considered harmful,
> but I would. The result set you get from a, e.g. mysql_query(), call is
> gathered in one fell swoop. It is not gathered bit by bit from the server
> everytime you read a row from it.
>
> Doing what you suggest would mean moving one large datastructure into
> another large datastructure.. that cannot be a speed improvement.
>
> You can go an awful long way with this little construct:
>
> $query = mysql_query("some sql");
>
> while($row = mysql_fetch_array($query)
> {
> echo $row["some_column"];
> echo $row["some_other_column"];
> }
>
> Cheers,
>
> Soeren Staun-Pedersen - staun@netwarriors.org
> ------
> "The internet is full, beat it"
> - Me.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
==========================
Michael Kimsal
http://www.tapinternet.com
734-480-9961