<?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>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: 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>
	<item>
		<title>By: Martijn Tonies</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/comment-page-1/#comment-2152</link>
		<dc:creator>Martijn Tonies</dc:creator>
		<pubDate>Fri, 01 Sep 2006 18:26:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-2152</guid>
		<description>I wonder what happens if you use a view that cannot be easily rewritten.

eg: GROUP BY or have a SUM in it. 

Now, do a &quot;select * from view where summed_column = 50&quot; or something.

Will this be re-written? And if so, what IS the final result of the re-written query?

Besides, why DO derived tables get materialized anyway? The optimizer is free to re-write queries including these as well, right?

--
Martijn Tonies
Upscene Productions</description>
		<content:encoded><![CDATA[<p>I wonder what happens if you use a view that cannot be easily rewritten.</p>
<p>eg: GROUP BY or have a SUM in it. </p>
<p>Now, do a &#8220;select * from view where summed_column = 50&#8243; or something.</p>
<p>Will this be re-written? And if so, what IS the final result of the re-written query?</p>
<p>Besides, why DO derived tables get materialized anyway? The optimizer is free to re-write queries including these as well, right?</p>
<p>&#8211;<br />
Martijn Tonies<br />
Upscene Productions</p>
]]></content:encoded>
	</item>
</channel>
</rss>
