<?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"
	>
<channel>
	<title>Comments on: Using GROUP BY WITH ROLLUP for Reporting Performance Optimization</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/</link>
	<description>Everything about MySQL Performance</description>
	<pubDate>Fri, 25 Jul 2008 12:29:37 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: richard</title>
		<link>http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-230943</link>
		<dc:creator>richard</dc:creator>
		<pubDate>Mon, 14 Jan 2008 15:12:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-230943</guid>
		<description>In MySQL 5 and up you could do the following.  Since you already have the counts, as long as you grouop by the same fields, using the sum function in the upper query does not change the counts, and you gain speed by using the limit in the subquery.

SELECT    grp
        , sum(cnt)
FROM    ( SELECT    grp
                  , count(*) cnt 
          FROM      dt 
          WHERE     slack LIKE "a%" 
          GROUP BY  grp
          ORDER BY  cnt DESC 
          LIMIT 10
        ) t1
GROUP BY  grp WITH rollup;

-richard</description>
		<content:encoded><![CDATA[<p>In MySQL 5 and up you could do the following.  Since you already have the counts, as long as you grouop by the same fields, using the sum function in the upper query does not change the counts, and you gain speed by using the limit in the subquery.</p>
<p>SELECT    grp<br />
        , sum(cnt)<br />
FROM    ( SELECT    grp<br />
                  , count(*) cnt<br />
          FROM      dt<br />
          WHERE     slack LIKE &#8220;a%&#8221;<br />
          GROUP BY  grp<br />
          ORDER BY  cnt DESC<br />
          LIMIT 10<br />
        ) t1<br />
GROUP BY  grp WITH rollup;</p>
<p>-richard</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: links for 2007-10-11 - smalls blogger</title>
		<link>http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-176437</link>
		<dc:creator>links for 2007-10-11 - smalls blogger</dc:creator>
		<pubDate>Thu, 11 Oct 2007 00:37:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-176437</guid>
		<description>[...] Using GROUP BY WITH ROLLUP for Reporting Performance Optimization &#124; MySQL Performance Blog Using GROUP BY WITH ROLLUP for Reporting Performance Optimization (tags: development performance mysql) [...]</description>
		<content:encoded><![CDATA[<p>[...] Using GROUP BY WITH ROLLUP for Reporting Performance Optimization | MySQL Performance Blog Using GROUP BY WITH ROLLUP for Reporting Performance Optimization (tags: development performance mysql) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-174598</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Wed, 03 Oct 2007 15:48:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-174598</guid>
		<description>Indeed. Your last name directly translates as "Hare" in Russian.  I guess it should be from some slavic country but probably not Russian directly as Russian last names usually formed using some apendix like "ov", "ev" etc.</description>
		<content:encoded><![CDATA[<p>Indeed. Your last name directly translates as &#8220;Hare&#8221; in Russian.  I guess it should be from some slavic country but probably not Russian directly as Russian last names usually formed using some apendix like &#8220;ov&#8221;, &#8220;ev&#8221; etc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Larry Zaetz</title>
		<link>http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-173968</link>
		<dc:creator>Larry Zaetz</dc:creator>
		<pubDate>Sun, 30 Sep 2007 23:14:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-173968</guid>
		<description>Hello Peter-
I was surprised to see a last name such as yours.
I was told that some of my family routes could have
had a similar name. Father was from a town that sounded
like "Chipchevitz". Relatives close by came from Sarne.</description>
		<content:encoded><![CDATA[<p>Hello Peter-<br />
I was surprised to see a last name such as yours.<br />
I was told that some of my family routes could have<br />
had a similar name. Father was from a town that sounded<br />
like &#8220;Chipchevitz&#8221;. Relatives close by came from Sarne.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-171974</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Tue, 25 Sep 2007 05:36:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-171974</guid>
		<description>Daniel,

Please compare the query I'm saying which can't be run and your query.  They are VERY different. 

Indeed you can get results sorted in any direction by columns you use for group by 
but if you're using group by with roll up you can't sort by value of aggregate function such as count(), avg() sum()  - hope it makes things a bit more clear.</description>
		<content:encoded><![CDATA[<p>Daniel,</p>
<p>Please compare the query I&#8217;m saying which can&#8217;t be run and your query.  They are VERY different. </p>
<p>Indeed you can get results sorted in any direction by columns you use for group by<br />
but if you&#8217;re using group by with roll up you can&#8217;t sort by value of aggregate function such as count(), avg() sum()  - hope it makes things a bit more clear.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Ciulinaru</title>
		<link>http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-170653</link>
		<dc:creator>Daniel Ciulinaru</dc:creator>
		<pubDate>Fri, 21 Sep 2007 19:37:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-170653</guid>
		<description>Hi Peter,

Looks like you CAN order the results the way you want in a GROUP BY ... WITH ROLLUP (at least in 5.1.11-beta - I haven't checked other versions).
The key word is DESC after immediately after GROUP BY:

mysql&#62; select IFNULL(date,'Total') as 'date_total', no_of_files, raw_size as 'raw_size', compressed_size as 'compressed_size', avg_ratio as 'avg_ratio' from (select date(log_datestamp) as date, count(log_instance) as no_of_files, sum(log_uncompressed_size) as raw_size, sum(log_compressed_size) as compressed_size, round(avg(log_compress_ratio_percentage),3) as avg_ratio from logs_stats group by date desc with rollup) as a;
+------------+-------------+--------------+-----------------+-----------+
&#124; date_total &#124; no_of_files &#124; raw_size     &#124; compressed_size &#124; avg_ratio &#124;
+------------+-------------+--------------+-----------------+-----------+
&#124; 2007-09-21 &#124;          16 &#124;   2605136552 &#124;       131024683 &#124;    94.988 &#124;
&#124; 2007-09-20 &#124;         171 &#124;  26946514751 &#124;      1724108146 &#124;    93.246 &#124;
&#124; 2007-09-19 &#124;         355 &#124;  53270319908 &#124;     11372204678 &#124;    79.300 &#124;
&#124; 2007-09-18 &#124;         375 &#124;  57924126151 &#124;     12854828516 &#124;    80.481 &#124;
.........................................................................
&#124; 2007-07-16 &#124;           1 &#124;    113834620 &#124;        82608679 &#124;    27.400 &#124;
&#124; 2007-06-08 &#124;           1 &#124;    132729275 &#124;        12107490 &#124;    90.900 &#124;
&#124; 2007-05-22 &#124;           1 &#124;    180724880 &#124;        16671364 &#124;    90.800 &#124;
&#124; 2007-05-03 &#124;           1 &#124;    180577870 &#124;        16670719 &#124;    90.800 &#124;
&#124; Total      &#124;        5641 &#124; 602786174381 &#124;    126053043926 &#124;    80.638 &#124;
+------------+-------------+--------------+-----------------+-----------+
37 rows in set (0.04 sec)

"Sure, trust the gurus. Just don't believe anything they say, especially when it comes to performance."
 - Steven Feuerstein

Cheers!</description>
		<content:encoded><![CDATA[<p>Hi Peter,</p>
<p>Looks like you CAN order the results the way you want in a GROUP BY &#8230; WITH ROLLUP (at least in 5.1.11-beta - I haven&#8217;t checked other versions).<br />
The key word is DESC after immediately after GROUP BY:</p>
<p>mysql&gt; select IFNULL(date,&#8217;Total&#8217;) as &#8216;date_total&#8217;, no_of_files, raw_size as &#8216;raw_size&#8217;, compressed_size as &#8216;compressed_size&#8217;, avg_ratio as &#8216;avg_ratio&#8217; from (select date(log_datestamp) as date, count(log_instance) as no_of_files, sum(log_uncompressed_size) as raw_size, sum(log_compressed_size) as compressed_size, round(avg(log_compress_ratio_percentage),3) as avg_ratio from logs_stats group by date desc with rollup) as a;<br />
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8211;+<br />
| date_total | no_of_files | raw_size     | compressed_size | avg_ratio |<br />
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8211;+<br />
| 2007-09-21 |          16 |   2605136552 |       131024683 |    94.988 |<br />
| 2007-09-20 |         171 |  26946514751 |      1724108146 |    93.246 |<br />
| 2007-09-19 |         355 |  53270319908 |     11372204678 |    79.300 |<br />
| 2007-09-18 |         375 |  57924126151 |     12854828516 |    80.481 |<br />
&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<br />
| 2007-07-16 |           1 |    113834620 |        82608679 |    27.400 |<br />
| 2007-06-08 |           1 |    132729275 |        12107490 |    90.900 |<br />
| 2007-05-22 |           1 |    180724880 |        16671364 |    90.800 |<br />
| 2007-05-03 |           1 |    180577870 |        16670719 |    90.800 |<br />
| Total      |        5641 | 602786174381 |    126053043926 |    80.638 |<br />
+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8211;+<br />
37 rows in set (0.04 sec)</p>
<p>&#8220;Sure, trust the gurus. Just don&#8217;t believe anything they say, especially when it comes to performance.&#8221;<br />
 - Steven Feuerstein</p>
<p>Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Data Management Today by Craig Mullins</title>
		<link>http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-170609</link>
		<dc:creator>Data Management Today by Craig Mullins</dc:creator>
		<pubDate>Fri, 21 Sep 2007 16:05:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-170609</guid>
		<description>&lt;strong&gt;Log Buffer #63: a Carnival of the Vanities for DBAs...&lt;/strong&gt;

Welcome to the 63rd edition of Log Buffer, the weekly review of database blogs. For those of you reading...</description>
		<content:encoded><![CDATA[<p><strong>Log Buffer #63: a Carnival of the Vanities for DBAs&#8230;</strong></p>
<p>Welcome to the 63rd edition of Log Buffer, the weekly review of database blogs. For those of you reading&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ThemePassion - Best stuff about design! &#187; Using GROUP BY WITH ROLLUP for Reporting Performance Optimization</title>
		<link>http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-170112</link>
		<dc:creator>ThemePassion - Best stuff about design! &#187; Using GROUP BY WITH ROLLUP for Reporting Performance Optimization</dc:creator>
		<pubDate>Thu, 20 Sep 2007 06:18:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-170112</guid>
		<description>[...] Frank Lion wrote an interesting post today!.Here&#8217;s a quick excerptThis allows us to get results in about 40 seconds and as we can see is pretty inefficient - almost half of the time is spent counting the rows which are already traversed and counted for group by operation. &#8230; [...]</description>
		<content:encoded><![CDATA[<p>[...] Frank Lion wrote an interesting post today!.Here&#8217;s a quick excerptThis allows us to get results in about 40 seconds and as we can see is pretty inefficient - almost half of the time is spent counting the rows which are already traversed and counted for group by operation. &#8230; [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
