<?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: Derived Tables and Views Performance</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/</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: Vincent VAN HOLLEBEKE</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/comment-page-1/#comment-886323</link>
		<dc:creator>Vincent VAN HOLLEBEKE</dc:creator>
		<pubDate>Tue, 07 Feb 2012 18:53:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-886323</guid>
		<description>Hi,

Is the problem still existing in actual versions of MySQL, or is it solved ?

Thank you.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Is the problem still existing in actual versions of MySQL, or is it solved ?</p>
<p>Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Larsen</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/comment-page-1/#comment-446423</link>
		<dc:creator>John Larsen</dc:creator>
		<pubDate>Thu, 15 Jan 2009 16:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-446423</guid>
		<description>Baron: You know what your right. Somehow in the past I was able to get a view to do this, think it was for a aggregated value (view was an aggregate) which was then trimmed down in queries to the view to be pieces of the aggregate. Was able to get better performance at the time on multiple queries in a row (first query of a connection was slow later queries were instant) then a straight query to the table as the view was holding the aggregate data used for selection of its parts. Can&#039;t seem to figure out how I did it now as I didn&#039;t specify any special notation to it (like TEMPTABLE).</description>
		<content:encoded><![CDATA[<p>Baron: You know what your right. Somehow in the past I was able to get a view to do this, think it was for a aggregated value (view was an aggregate) which was then trimmed down in queries to the view to be pieces of the aggregate. Was able to get better performance at the time on multiple queries in a row (first query of a connection was slow later queries were instant) then a straight query to the table as the view was holding the aggregate data used for selection of its parts. Can&#8217;t seem to figure out how I did it now as I didn&#8217;t specify any special notation to it (like TEMPTABLE).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Baron Schwartz</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/comment-page-1/#comment-446407</link>
		<dc:creator>Baron Schwartz</dc:creator>
		<pubDate>Thu, 15 Jan 2009 14:37:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-446407</guid>
		<description>John, that is incorrect.  Views do not store their data.  You are mixing the TEMPTABLE algorithm (which creates an internal temp table for the duration of the query) and the query cache (which stores result sets until underlying tables change or other conditions require discarding them).  And views only permit usage of the underlying table&#039;s indexes if the MERGE algorithm is used.</description>
		<content:encoded><![CDATA[<p>John, that is incorrect.  Views do not store their data.  You are mixing the TEMPTABLE algorithm (which creates an internal temp table for the duration of the query) and the query cache (which stores result sets until underlying tables change or other conditions require discarding them).  And views only permit usage of the underlying table&#8217;s indexes if the MERGE algorithm is used.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Larsen</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/comment-page-1/#comment-446160</link>
		<dc:creator>John Larsen</dc:creator>
		<pubDate>Thu, 15 Jan 2009 04:33:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-446160</guid>
		<description>Ari:  Did you try immediently running it again with a different where this is where views shine. Yes unless specifically made not to a view will run the exact select stored in the view. But untill the table it is based upon changes relative to that view a temporary table will be stored containing the full view. As the view temp table won&#039;t need recreating a second run with where would be faster than the second run of a regular select because you have less columns to deal with. A view will generally retain it parents indexes.</description>
		<content:encoded><![CDATA[<p>Ari:  Did you try immediently running it again with a different where this is where views shine. Yes unless specifically made not to a view will run the exact select stored in the view. But untill the table it is based upon changes relative to that view a temporary table will be stored containing the full view. As the view temp table won&#8217;t need recreating a second run with where would be faster than the second run of a regular select because you have less columns to deal with. A view will generally retain it parents indexes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zblmw</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/comment-page-1/#comment-349989</link>
		<dc:creator>zblmw</dc:creator>
		<pubDate>Fri, 29 Aug 2008 03:17:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-349989</guid>
		<description>ç å®è”ç›Ÿç½‘

     ä¸­å›½ç å®è”ç›Ÿç½‘(zblmw.com)æ˜¯ä¸€å®¶æœåŠ¡äºŽä¸­å›½å¤§é™†åŠå…¨çƒåŽäººç¤¾ç¾¤çš„é¢†å…ˆåœ¨çº¿ç å®åª’ä½“åŠå¢žå€¼èµ„è®¯æœåŠ¡æä¾›å•†ã€‚ä¸­å›½ç å®ç½‘ç«™æ‹¥æœ‰å¤šå®¶åœ°åŒºæ€§ç½‘ç«™ï¼Œä»¥æœåŠ¡å¤§ä¸­åŽåœ°åŒºä¸Žæµ·å¤–åŽäººä»¥åŠç å®ä¼ä¸šä¸ºå·±ä»»ï¼Œé€šè¿‡ä¸ºå¹¿å¤§ç½‘æ°‘å’Œæ”¿åºœä¼ä¸šç”¨æˆ·æä¾›ç½‘ç»œåª’ä½“åŠå¨±ä¹ã€åœ¨çº¿ç”¨æˆ·ä»˜è´¹å¢žå€¼/æ— çº¿å¢žå€¼æœåŠ¡å’Œç”µå­æ”¿åŠ¡è§£å†³æ–¹æ¡ˆç­‰åœ¨å†…çš„ä¸€ç³»åˆ—æœåŠ¡ã€‚
  
     ä¸“ä¸šç å®é—¨æˆ·â€”â€”ä¸­å›½ç å®ç½‘ç«™é¢„è®¡2008å¹´åœ¨å…¨çƒèŒƒå›´å†…æ³¨å†Œç”¨æˆ·è¶…è¿‡500ä¸‡ï¼Œæ—¥æµè§ˆé‡èƒ½æœ€é«˜çªç ´8000ä¸‡æ¬¡ï¼Œå°†æˆä¸ºä¸­å›½å¤§é™†åŠå…¨çƒåŽäººç¤¾ç¾¤ä¸­æœ€å—æŽ¨å´‡çš„è¡Œä¸šäº’è”ç½‘å“ç‰Œã€‚  

     é«˜æ•ˆçš„æ•´åˆè¥é”€æœåŠ¡â€”â€”å‡­å€Ÿé¢†å…ˆçš„æŠ€æœ¯å’Œä¼˜è´¨çš„æœåŠ¡ï¼Œä¸­å›½ç å®ç½‘ç«™ä¼šæ·±å—å¹¿å¤§ç½‘æ°‘çš„æ¬¢è¿Žå¹¶èƒ½äº«æœ‰æžé«˜çš„å£°èª‰ã€‚  
     
     
 http://www.zblmw.com</description>
		<content:encoded><![CDATA[<p>ç å®è”ç›Ÿç½‘</p>
<p>     ä¸­å›½ç å®è”ç›Ÿç½‘(zblmw.com)æ˜¯ä¸€å®¶æœåŠ¡äºŽä¸­å›½å¤§é™†åŠå…¨çƒåŽäººç¤¾ç¾¤çš„é¢†å…ˆåœ¨çº¿ç å®åª’ä½“åŠå¢žå€¼èµ„è®¯æœåŠ¡æä¾›å•†ã€‚ä¸­å›½ç å®ç½‘ç«™æ‹¥æœ‰å¤šå®¶åœ°åŒºæ€§ç½‘ç«™ï¼Œä»¥æœåŠ¡å¤§ä¸­åŽåœ°åŒºä¸Žæµ·å¤–åŽäººä»¥åŠç å®ä¼ä¸šä¸ºå·±ä»»ï¼Œé€šè¿‡ä¸ºå¹¿å¤§ç½‘æ°‘å’Œæ”¿åºœä¼ä¸šç”¨æˆ·æä¾›ç½‘ç»œåª’ä½“åŠå¨±ä¹ã€åœ¨çº¿ç”¨æˆ·ä»˜è´¹å¢žå€¼/æ— çº¿å¢žå€¼æœåŠ¡å’Œç”µå­æ”¿åŠ¡è§£å†³æ–¹æ¡ˆç­‰åœ¨å†…çš„ä¸€ç³»åˆ—æœåŠ¡ã€‚</p>
<p>     ä¸“ä¸šç å®é—¨æˆ·â€”â€”ä¸­å›½ç å®ç½‘ç«™é¢„è®¡2008å¹´åœ¨å…¨çƒèŒƒå›´å†…æ³¨å†Œç”¨æˆ·è¶…è¿‡500ä¸‡ï¼Œæ—¥æµè§ˆé‡èƒ½æœ€é«˜çªç ´8000ä¸‡æ¬¡ï¼Œå°†æˆä¸ºä¸­å›½å¤§é™†åŠå…¨çƒåŽäººç¤¾ç¾¤ä¸­æœ€å—æŽ¨å´‡çš„è¡Œä¸šäº’è”ç½‘å“ç‰Œã€‚  </p>
<p>     é«˜æ•ˆçš„æ•´åˆè¥é”€æœåŠ¡â€”â€”å‡­å€Ÿé¢†å…ˆçš„æŠ€æœ¯å’Œä¼˜è´¨çš„æœåŠ¡ï¼Œä¸­å›½ç å®ç½‘ç«™ä¼šæ·±å—å¹¿å¤§ç½‘æ°‘çš„æ¬¢è¿Žå¹¶èƒ½äº«æœ‰æžé«˜çš„å£°èª‰ã€‚  </p>
<p> <a href="http://www.zblmw.com" rel="nofollow">http://www.zblmw.com</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: javatopia</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/comment-page-1/#comment-217722</link>
		<dc:creator>javatopia</dc:creator>
		<pubDate>Fri, 14 Dec 2007 22:18:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-217722</guid>
		<description>We ran into this problem just recently on a real world query. In this case the query was of this form:

select * from (big inner query) foo order by a, b, c

The choice to use this query syntax was for programming brevity - it&#039;s easier to rename the output columns from the big inner query using the outer query instead. Alas, though, the nasty version of this query took over 2.5 minutes to run on 53,000 record scans. The version without the outer select ran in 9/10th of a second on the same record space.

The EXPLAIN clearly showed that the outer select was doing a full table scan on the results instead of using the indices.

Unbelievable. I ran the exact same nasty query in Microsoft SQL Server 2000 and it performed as expectd - lightning fast execution. The execution plan showed the effective use of table indices and much smarter insertion of the sub-query&#039;s grouping clauses.

MySQL needs quite a bit of real-world tuning to make it a believable enterprise database. You get what you pay for, right?</description>
		<content:encoded><![CDATA[<p>We ran into this problem just recently on a real world query. In this case the query was of this form:</p>
<p>select * from (big inner query) foo order by a, b, c</p>
<p>The choice to use this query syntax was for programming brevity &#8211; it&#8217;s easier to rename the output columns from the big inner query using the outer query instead. Alas, though, the nasty version of this query took over 2.5 minutes to run on 53,000 record scans. The version without the outer select ran in 9/10th of a second on the same record space.</p>
<p>The EXPLAIN clearly showed that the outer select was doing a full table scan on the results instead of using the indices.</p>
<p>Unbelievable. I ran the exact same nasty query in Microsoft SQL Server 2000 and it performed as expectd &#8211; lightning fast execution. The execution plan showed the effective use of table indices and much smarter insertion of the sub-query&#8217;s grouping clauses.</p>
<p>MySQL needs quite a bit of real-world tuning to make it a believable enterprise database. You get what you pay for, right?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ari</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/comment-page-1/#comment-127215</link>
		<dc:creator>ari</dc:creator>
		<pubDate>Fri, 18 May 2007 05:48:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-127215</guid>
		<description>we are currently using mysql 5.037(27)
it looks like when you create a view on a table and then use this view in query with a join or where statement with another table indexes 
from a view(first original table) are not used.Run the same query replacing view with a table it is based and result is in several times faster.</description>
		<content:encoded><![CDATA[<p>we are currently using mysql 5.037(27)<br />
it looks like when you create a view on a table and then use this view in query with a join or where statement with another table indexes<br />
from a view(first original table) are not used.Run the same query replacing view with a table it is based and result is in several times faster.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: æ´¾ç”Ÿè¡¨å’Œè§†å›¾çš„æ€§èƒ½ at å‘¨ä¿­ Blog</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/comment-page-1/#comment-2585</link>
		<dc:creator>æ´¾ç”Ÿè¡¨å’Œè§†å›¾çš„æ€§èƒ½ at å‘¨ä¿­ Blog</dc:creator>
		<pubDate>Sat, 16 Sep 2006 14:03:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-2585</guid>
		<description>[...] åŽŸæ–‡ä½œè€…ï¼š Peter ZaitsevåŽŸæ–‡æ¥æºï¼š http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performanceè¯‘è€…ï¼šå¶é‡‘è£ï¼ˆEmail:ï¼‰ï¼Œè½¬è½½è¯·æ³¨æ˜Žè¯‘è€…å’Œå‡ºå¤„ï¼Œå¹¶ä¸”ä¸èƒ½ç”¨äºŽå•†ä¸šç”¨é€”ï¼Œè¿è€…å¿…ç©¶ã€‚ [...]</description>
		<content:encoded><![CDATA[<p>[...] åŽŸæ–‡ä½œè€…ï¼š Peter ZaitsevåŽŸæ–‡æ¥æºï¼š <a href="http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performanceè¯‘è€…ï¼šå¶é‡‘è£ï¼ˆEmail:ï¼‰ï¼Œè½¬è½½è¯·æ³¨æ˜Žè¯‘è€…å’Œå‡ºå¤„ï¼Œå¹¶ä¸”ä¸èƒ½ç”¨äºŽå•†ä¸šç”¨é€”ï¼Œè¿è€…å¿…ç©¶ã€‚" rel="nofollow">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performanceè¯‘è€…ï¼šå¶é‡‘è£ï¼ˆEmail:ï¼‰ï¼Œè½¬è½½è¯·æ³¨æ˜Žè¯‘è€…å’Œå‡ºå¤„ï¼Œå¹¶ä¸”ä¸èƒ½ç”¨äºŽå•†ä¸šç”¨é€”ï¼Œè¿è€…å¿…ç©¶ã€‚</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martijn Tonies</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/comment-page-1/#comment-2220</link>
		<dc:creator>Martijn Tonies</dc:creator>
		<pubDate>Mon, 04 Sep 2006 10:01:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-2220</guid>
		<description>Interesting, thanks for trying.

--
Martijn Tonies
Upscene Productions</description>
		<content:encoded><![CDATA[<p>Interesting, thanks for trying.</p>
<p>&#8211;<br />
Martijn Tonies<br />
Upscene Productions</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/comment-page-1/#comment-2158</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Fri, 01 Sep 2006 20:14:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-2158</guid>
		<description>Martijn,

First - you&#039;re right. There is no reason for derived tables to be materialized. It is design deficiency in MySQL 5.0.

Speaking about Views with group by - good question.     MySQL is currently able to execute via query merge only simple views,  more complicated views as ones with group by require temporary table even if it is possible to avoid it.   Hopefully it will be improved in the future:

mysql&gt; create view v1 as select count(*) cnt, k from test group by k;
Query OK, 0 rows affected (0.03 sec)

mysql&gt; explain select * from v2 where k=7 limit 5;
+----+-------------+------------+-------+---------------+------+---------+------+---------+-------------+
&#124; id &#124; select_type &#124; table      &#124; type  &#124; possible_keys &#124; key  &#124; key_len &#124; ref  &#124; rows    &#124; Extra       &#124;
+----+-------------+------------+-------+---------------+------+---------+------+---------+-------------+
&#124;  1 &#124; PRIMARY     &#124; &lt;derived2&gt; &#124; ALL   &#124; NULL          &#124; NULL &#124; NULL    &#124; NULL &#124; 1638400 &#124; Using where &#124;
&#124;  2 &#124; DERIVED     &#124; test       &#124; index &#124; NULL          &#124; k    &#124; 772     &#124; NULL &#124; 1638400 &#124; Using index &#124;
+----+-------------+------------+-------+---------------+------+---------+------+---------+-------------+
2 rows in set (6.88 sec)

As you see full temporary table is used, there is index on k but it only allows to do index scan instead of full table scan.</description>
		<content:encoded><![CDATA[<p>Martijn,</p>
<p>First &#8211; you&#8217;re right. There is no reason for derived tables to be materialized. It is design deficiency in MySQL 5.0.</p>
<p>Speaking about Views with group by &#8211; good question.     MySQL is currently able to execute via query merge only simple views,  more complicated views as ones with group by require temporary table even if it is possible to avoid it.   Hopefully it will be improved in the future:</p>
<p>mysql> create view v1 as select count(*) cnt, k from test group by k;<br />
Query OK, 0 rows affected (0.03 sec)</p>
<p>mysql> explain select * from v2 where k=7 limit 5;<br />
+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| id | select_type | table      | type  | possible_keys | key  | key_len | ref  | rows    | Extra       |<br />
+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
|  1 | PRIMARY     | <derived2> | ALL   | NULL          | NULL | NULL    | NULL | 1638400 | Using where |<br />
|  2 | DERIVED     | test       | index | NULL          | k    | 772     | NULL | 1638400 | Using index |<br />
+&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
2 rows in set (6.88 sec)</p>
<p>As you see full temporary table is used, there is index on k but it only allows to do index scan instead of full table scan.</derived2></p>
]]></content:encoded>
	</item>
</channel>
</rss>

