<?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: 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>Percona&#039;s MySQL &#38; InnoDB performance and scalability blog</description>
	<lastBuildDate>Sat, 11 Feb 2012 16:45:54 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: sqlMontreal</title>
		<link>http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/comment-page-1/#comment-785835</link>
		<dc:creator>sqlMontreal</dc:creator>
		<pubDate>Wed, 08 Dec 2010 16:01:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-785835</guid>
		<description>Excellent article!!! Thank you ! It solved my issues with ORDER BY and GROUP BY ..WITH ROLLUP in a great way. I also noticed that this is significant faster than the regular WITH ROLLUP</description>
		<content:encoded><![CDATA[<p>Excellent article!!! Thank you ! It solved my issues with ORDER BY and GROUP BY ..WITH ROLLUP in a great way. I also noticed that this is significant faster than the regular WITH ROLLUP</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dasher</title>
		<link>http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/comment-page-1/#comment-349559</link>
		<dc:creator>Dasher</dc:creator>
		<pubDate>Wed, 27 Aug 2008 10:46:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-349559</guid>
		<description>The Tag Cloud only changes when an article is added or changed.

So geneate a normalised value tag information and store the information in a table.
Then when needed update the tag table with the tags used for the post.

Each day - re-normalise the tag table.

You&#039;ll need to normalise the values otherwise you&#039;ll end up with very large values over time - when what&#039;s important is the relative values for the tags.

For optimum performance:
If you&#039;re using PHP for the site - you can also use APC to store the site-wide TAG data (the HTML will be enough) - and then the code that updates the tag table - also updates the APC tag data.</description>
		<content:encoded><![CDATA[<p>The Tag Cloud only changes when an article is added or changed.</p>
<p>So geneate a normalised value tag information and store the information in a table.<br />
Then when needed update the tag table with the tags used for the post.</p>
<p>Each day &#8211; re-normalise the tag table.</p>
<p>You&#8217;ll need to normalise the values otherwise you&#8217;ll end up with very large values over time &#8211; when what&#8217;s important is the relative values for the tags.</p>
<p>For optimum performance:<br />
If you&#8217;re using PHP for the site &#8211; you can also use APC to store the site-wide TAG data (the HTML will be enough) &#8211; and then the code that updates the tag table &#8211; also updates the APC tag data.</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-page-1/#comment-343608</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Mon, 11 Aug 2008 15:51:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-343608</guid>
		<description>vepa,

This may be long (though can be OK if the load is IO bound) - the first thing you should not run such complex queries in real time :)</description>
		<content:encoded><![CDATA[<p>vepa,</p>
<p>This may be long (though can be OK if the load is IO bound) &#8211; the first thing you should not run such complex queries in real time <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vepa</title>
		<link>http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/comment-page-1/#comment-343571</link>
		<dc:creator>vepa</dc:creator>
		<pubDate>Mon, 11 Aug 2008 13:39:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/#comment-343571</guid>
		<description>Having same problem with count() for tagcloud generation. have 300.000 different tags (groups) and 1.5 mil records. takes 120 sec. to populate a tagcloud. Do you know any optimal ways to do tagclouds for huge websites? 

I wanted to store total numebers and update time on each tag but I am using same tagcloud for different things. so I need to store several totals for each tag which will be 20 extra columns for each record.</description>
		<content:encoded><![CDATA[<p>Having same problem with count() for tagcloud generation. have 300.000 different tags (groups) and 1.5 mil records. takes 120 sec. to populate a tagcloud. Do you know any optimal ways to do tagclouds for huge websites? </p>
<p>I wanted to store total numebers and update time on each tag but I am using same tagcloud for different things. so I need to store several totals for each tag which will be 20 extra columns for each record.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: richard</title>
		<link>http://www.mysqlperformanceblog.com/2007/09/17/using-group-by-with-rollup-for-reporting-performance-optimization/comment-page-1/#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 &quot;a%&quot; 
          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-page-1/#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-page-1/#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 &quot;Hare&quot; 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 &quot;ov&quot;, &quot;ev&quot; 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-page-1/#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 &quot;Chipchevitz&quot;. 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-page-1/#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&#039;m saying which can&#039;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&#039;re using group by with roll up you can&#039;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()  &#8211; 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-page-1/#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&#039;t checked other versions).
The key word is DESC after immediately after GROUP BY:

mysql&gt; select IFNULL(date,&#039;Total&#039;) as &#039;date_total&#039;, no_of_files, raw_size as &#039;raw_size&#039;, compressed_size as &#039;compressed_size&#039;, avg_ratio as &#039;avg_ratio&#039; 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)

&quot;Sure, trust the gurus. Just don&#039;t believe anything they say, especially when it comes to performance.&quot;
 - 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 &#8211; 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 />
 &#8211; Steven Feuerstein</p>
<p>Cheers!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

