<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Handling big result sets</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/</link>
	<description>Everything about MySQL Performance</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:23:57 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Marc</title>
		<link>http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/comment-page-1/#comment-662640</link>
		<dc:creator>Marc</dc:creator>
		<pubDate>Wed, 07 Oct 2009 20:12:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/#comment-662640</guid>
		<description>When do I need MYSQLI_STORE_RESULT and $stmt-&gt;store_result()

Is there only a benefit if I receive many rows or are they useful for simple selects with LIMIT 10 or similar? 

What are the disadvantages?

regards</description>
		<content:encoded><![CDATA[<p>When do I need MYSQLI_STORE_RESULT and $stmt-&gt;store_result()</p>
<p>Is there only a benefit if I receive many rows or are they useful for simple selects with LIMIT 10 or similar? </p>
<p>What are the disadvantages?</p>
<p>regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cross Cable Network</title>
		<link>http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/comment-page-1/#comment-248647</link>
		<dc:creator>Cross Cable Network</dc:creator>
		<pubDate>Tue, 04 Mar 2008 13:37:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/#comment-248647</guid>
		<description>&lt;strong&gt;Dish Network Beats Cable&lt;/strong&gt;

Cable TV providers are fighting it out with Satellite TV providers to see who can deliver the best service, most cutting edge technology, and ultimately win over the majority of customers by doing so. Unfortunately for the cable companies, when you loo...</description>
		<content:encoded><![CDATA[<p><strong>Dish Network Beats Cable</strong></p>
<p>Cable TV providers are fighting it out with Satellite TV providers to see who can deliver the best service, most cutting edge technology, and ultimately win over the majority of customers by doing so. Unfortunately for the cable companies, when you loo&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vadim</title>
		<link>http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/comment-page-1/#comment-1052</link>
		<dc:creator>Vadim</dc:creator>
		<pubDate>Fri, 14 Jul 2006 14:43:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/#comment-1052</guid>
		<description>Robert,

I think you are right about congested networks - I&#039;d expect on connection with big latency the buffering makes sence. Maybe I will test it somehow :)</description>
		<content:encoded><![CDATA[<p>Robert,</p>
<p>I think you are right about congested networks &#8211; I&#8217;d expect on connection with big latency the buffering makes sence. Maybe I will test it somehow <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Hopson</title>
		<link>http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/comment-page-1/#comment-847</link>
		<dc:creator>Robert Hopson</dc:creator>
		<pubDate>Wed, 05 Jul 2006 17:31:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/#comment-847</guid>
		<description>I ran this code on my MySQL 4.1 server, connecting remotely.  Averages for several runs:

Initial Time: 73.3s
Unbuffered: 59.3s

Using MySQLi: 39.46
MySQLi w/o store_result(): 26.44

So it would seem that your findings hold true for remote servers.  Perhaps on a more congested network there would be a point when buffering would provide some benefit?

Thanks for taking the time to investigate this.</description>
		<content:encoded><![CDATA[<p>I ran this code on my MySQL 4.1 server, connecting remotely.  Averages for several runs:</p>
<p>Initial Time: 73.3s<br />
Unbuffered: 59.3s</p>
<p>Using MySQLi: 39.46<br />
MySQLi w/o store_result(): 26.44</p>
<p>So it would seem that your findings hold true for remote servers.  Perhaps on a more congested network there would be a point when buffering would provide some benefit?</p>
<p>Thanks for taking the time to investigate this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/comment-page-1/#comment-692</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Wed, 28 Jun 2006 07:17:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/#comment-692</guid>
		<description>Vadim,

This problem of mysql_use_result mainly applies to MyISAM tables as table locks will be held for long time. Also it only applies to the cases then temporary table is not used to store full result set before sending it.   For Innodb tables it is practically never problem due to onsistent reads for  MyISAM tables it can be worked around by using SQL_BUFFER_RESULT  option... It does buffering in temporary table.  It is likely to kill all speed benefit on mysql_use_result however :)</description>
		<content:encoded><![CDATA[<p>Vadim,</p>
<p>This problem of mysql_use_result mainly applies to MyISAM tables as table locks will be held for long time. Also it only applies to the cases then temporary table is not used to store full result set before sending it.   For Innodb tables it is practically never problem due to onsistent reads for  MyISAM tables it can be worked around by using SQL_BUFFER_RESULT  option&#8230; It does buffering in temporary table.  It is likely to kill all speed benefit on mysql_use_result however <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vadim</title>
		<link>http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/comment-page-1/#comment-691</link>
		<dc:creator>Vadim</dc:creator>
		<pubDate>Wed, 28 Jun 2006 05:14:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/#comment-691</guid>
		<description>Apachez,

mysql_use_result blocks other threads in next sense
(qoute from http://dev.mysql.com/doc/refman/5.0/en/mysql-use-result.html)
&lt;blockquote&gt;
On the other hand, you shouldn&#039;t use mysql_use_result() if you are doing a lot of processing for each row on the client side, or if the output is sent to a screen on which the user may type a ^S (stop scroll). This ties up the server and prevent other threads from updating any tables from which the data is being fetched. 
&lt;/blockquote&gt;

Also other drawbacks of mysql_use_result:
When using mysql_use_result(), you must execute mysql_fetch_row() until a NULL value is returned, otherwise, the unfetched rows are returned as part of the result set for your next query. The C API gives the error Commands out of sync; you can&#039;t run this command now if you forget to do this! 

You may not use mysql_data_seek(), mysql_row_seek(), mysql_row_tell(), mysql_num_rows(), or mysql_affected_rows() with a result returned from mysql_use_result(), nor may you issue other queries until mysql_use_result() has finished.</description>
		<content:encoded><![CDATA[<p>Apachez,</p>
<p>mysql_use_result blocks other threads in next sense<br />
(qoute from <a href="http://dev.mysql.com/doc/refman/5.0/en/mysql-use-result.html)" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/mysql-use-result.html)</a></p>
<blockquote><p>
On the other hand, you shouldn&#8217;t use mysql_use_result() if you are doing a lot of processing for each row on the client side, or if the output is sent to a screen on which the user may type a ^S (stop scroll). This ties up the server and prevent other threads from updating any tables from which the data is being fetched.
</p></blockquote>
<p>Also other drawbacks of mysql_use_result:<br />
When using mysql_use_result(), you must execute mysql_fetch_row() until a NULL value is returned, otherwise, the unfetched rows are returned as part of the result set for your next query. The C API gives the error Commands out of sync; you can&#8217;t run this command now if you forget to do this! </p>
<p>You may not use mysql_data_seek(), mysql_row_seek(), mysql_row_tell(), mysql_num_rows(), or mysql_affected_rows() with a result returned from mysql_use_result(), nor may you issue other queries until mysql_use_result() has finished.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vadim</title>
		<link>http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/comment-page-1/#comment-690</link>
		<dc:creator>Vadim</dc:creator>
		<pubDate>Wed, 28 Jun 2006 05:07:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/#comment-690</guid>
		<description>Peter Kuiper,

Thank you! Great results!

I think even better results you can get with native C API and prepared statements.
It looks like in PHP binded variables have additional processing, but in C they are mapped to native
C variables and result is fetched without overhead. 

About OO - no special reason. I just copy-pasted parts of code from PHP manual.
In common I also prefer procedural way, as historically OO works slow in PHP.</description>
		<content:encoded><![CDATA[<p>Peter Kuiper,</p>
<p>Thank you! Great results!</p>
<p>I think even better results you can get with native C API and prepared statements.<br />
It looks like in PHP binded variables have additional processing, but in C they are mapped to native<br />
C variables and result is fetched without overhead. </p>
<p>About OO &#8211; no special reason. I just copy-pasted parts of code from PHP manual.<br />
In common I also prefer procedural way, as historically OO works slow in PHP.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Apachez</title>
		<link>http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/comment-page-1/#comment-688</link>
		<dc:creator>Apachez</dc:creator>
		<pubDate>Wed, 28 Jun 2006 03:47:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/#comment-688</guid>
		<description>This does also exist in the perl api for mysql (dbi/dbd) and can be used as:

$dbh-&gt;{&#039;mysql_use_result&#039;}=0; #disable
$dbh-&gt;{&#039;mysql_use_result&#039;}=1; #enable

and since mysql 4.1 server based prepares can be used with:

$dbh-&gt;{&#039;mysql_server_prepare&#039;} = 1;

however the server based prepares will always use store_result instead of use_result for some reason according to some docs/forumposts.

One note, in the perl documentation it is said that use_result tends to block other processes. Is this also the case with php?

If Vadim has the possibility, could you please test the benchmark with say 10 och 100 concurrent runs of this testscript with use_result vs with store_result to see if some blocking migh occur which will make use_result slower than store_result for multiuser environments (like if you have more than 1 concurrent mysql query) ?</description>
		<content:encoded><![CDATA[<p>This does also exist in the perl api for mysql (dbi/dbd) and can be used as:</p>
<p>$dbh-&gt;{&#8217;mysql_use_result&#8217;}=0; #disable<br />
$dbh-&gt;{&#8217;mysql_use_result&#8217;}=1; #enable</p>
<p>and since mysql 4.1 server based prepares can be used with:</p>
<p>$dbh-&gt;{&#8217;mysql_server_prepare&#8217;} = 1;</p>
<p>however the server based prepares will always use store_result instead of use_result for some reason according to some docs/forumposts.</p>
<p>One note, in the perl documentation it is said that use_result tends to block other processes. Is this also the case with php?</p>
<p>If Vadim has the possibility, could you please test the benchmark with say 10 och 100 concurrent runs of this testscript with use_result vs with store_result to see if some blocking migh occur which will make use_result slower than store_result for multiuser environments (like if you have more than 1 concurrent mysql query) ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: P. Kuiper</title>
		<link>http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/comment-page-1/#comment-658</link>
		<dc:creator>P. Kuiper</dc:creator>
		<pubDate>Tue, 27 Jun 2006 17:59:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/#comment-658</guid>
		<description>Oh, my MySQL is connected to my webserver through a direct (cross) cable. So no connecting to localhost :)</description>
		<content:encoded><![CDATA[<p>Oh, my MySQL is connected to my webserver through a direct (cross) cable. So no connecting to localhost <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: P. Kuiper</title>
		<link>http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/comment-page-1/#comment-657</link>
		<dc:creator>P. Kuiper</dc:creator>
		<pubDate>Tue, 27 Jun 2006 17:58:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/06/26/handling-of-big-parts-of-data/#comment-657</guid>
		<description>Hi Vadim,

Thanks for pointing this out. I tried this on my database and I came up with the following results:

mysql_query:
Number of rows: 1000000. execution time: 24.53382897377 s

mysql_unbuffered_query: (same code, only changing mysql_query to mysql_unbuffered_query)
Number of rows: 1000000. execution time: 16.347587108612 s

I repeated this a few times and the above times seem to be persistent, ie almost the same for every run.

Now here is the kicker:

Using the new mysqli and prepared statement based on the code you provided:

Number of rows: 1000000. execution time: 1.9737339019775 s

BTW my table (InnoDB) has 10+ million records in there. The query I used:
SELECT * FROM `current` LIMIT 1000000;

I had to limit it to 1 million because it didn&#039;t really like the whole 10 million :) (The waiting on the result drove me nuts)

Though I have to admit, the first time I ran this code it took 14 seconds. After a rerun it was around 1.9 to 2.0 s. Does mysql cache these prepared statements perhaps? Either way the performance benefit is worthwhile :)

Thank you for pointing this out. The code used for the last test is actually a few lines more and has somewhat more complicated due to the statement preparing etc. This shows the shortest and easiest path sure isn&#039;t always the best :)

Is there any reason you used the OO style in your example instead of the procedural style? Myself, I used the procedural style.

Regards,

Peter</description>
		<content:encoded><![CDATA[<p>Hi Vadim,</p>
<p>Thanks for pointing this out. I tried this on my database and I came up with the following results:</p>
<p>mysql_query:<br />
Number of rows: 1000000. execution time: 24.53382897377 s</p>
<p>mysql_unbuffered_query: (same code, only changing mysql_query to mysql_unbuffered_query)<br />
Number of rows: 1000000. execution time: 16.347587108612 s</p>
<p>I repeated this a few times and the above times seem to be persistent, ie almost the same for every run.</p>
<p>Now here is the kicker:</p>
<p>Using the new mysqli and prepared statement based on the code you provided:</p>
<p>Number of rows: 1000000. execution time: 1.9737339019775 s</p>
<p>BTW my table (InnoDB) has 10+ million records in there. The query I used:<br />
SELECT * FROM `current` LIMIT 1000000;</p>
<p>I had to limit it to 1 million because it didn&#8217;t really like the whole 10 million <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  (The waiting on the result drove me nuts)</p>
<p>Though I have to admit, the first time I ran this code it took 14 seconds. After a rerun it was around 1.9 to 2.0 s. Does mysql cache these prepared statements perhaps? Either way the performance benefit is worthwhile <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Thank you for pointing this out. The code used for the last test is actually a few lines more and has somewhat more complicated due to the statement preparing etc. This shows the shortest and easiest path sure isn&#8217;t always the best <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Is there any reason you used the OO style in your example instead of the procedural style? Myself, I used the procedural style.</p>
<p>Regards,</p>
<p>Peter</p>
]]></content:encoded>
	</item>
</channel>
</rss>
