<?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: 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>
	<pubDate>Tue, 02 Dec 2008 12:21:08 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: zblmw</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#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-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'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'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 - 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 - 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-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-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" rel="nofollow">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance</a>译者：叶金荣（Email:），转载请注明译者和出处，并且不能用于商业用途，违者必究。 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martijn Tonies</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#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-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'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 - 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 - 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-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 "select * from view where summed_column = 50" 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>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-2140</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Fri, 01 Sep 2006 08:47:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-2140</guid>
		<description>I would not call it  Views Inherit indexes because views are not physical - they have no real data or indexes, they however describe a way to access data.   

The difference is not inheriting indexes but as I wrote different method of execution - Views are executed (in this case) by query rewriting, so effectively query becomes same as on base table.  Inline views/derived tables however can't do it they always have to materialize table. 

Creating view you can also force it to use TEMPTABLE for query execution. See

http://dev.mysql.com/doc/refman/5.0/en/create-view.html

Regarding behavior in real cases - this is simplification based on real production cases. 

Note: It applies to subselects in FROM clause only.  Other kind of subselects is very different story.</description>
		<content:encoded><![CDATA[<p>I would not call it  Views Inherit indexes because views are not physical - they have no real data or indexes, they however describe a way to access data.   </p>
<p>The difference is not inheriting indexes but as I wrote different method of execution - Views are executed (in this case) by query rewriting, so effectively query becomes same as on base table.  Inline views/derived tables however can&#8217;t do it they always have to materialize table. </p>
<p>Creating view you can also force it to use TEMPTABLE for query execution. See</p>
<p><a href="http://dev.mysql.com/doc/refman/5.0/en/create-view.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/create-view.html</a></p>
<p>Regarding behavior in real cases - this is simplification based on real production cases. </p>
<p>Note: It applies to subselects in FROM clause only.  Other kind of subselects is very different story.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raven</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-2131</link>
		<dc:creator>Raven</dc:creator>
		<pubDate>Fri, 01 Sep 2006 00:51:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-2131</guid>
		<description>Based on your EXPLAIN output, it looks like Views inherit indices from the underlying tables (which would explain the speed difference).  Probably the execution of the subselect is faster/less of a memory hog than creating the view, so I can see that you might want the two options to maximize performance in specific situations.

Do you get similar results in less contrived (more realistic) scenarios?</description>
		<content:encoded><![CDATA[<p>Based on your EXPLAIN output, it looks like Views inherit indices from the underlying tables (which would explain the speed difference).  Probably the execution of the subselect is faster/less of a memory hog than creating the view, so I can see that you might want the two options to maximize performance in specific situations.</p>
<p>Do you get similar results in less contrived (more realistic) scenarios?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pabloj</title>
		<link>http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-2121</link>
		<dc:creator>pabloj</dc:creator>
		<pubDate>Thu, 31 Aug 2006 15:37:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/2006/08/31/derived-tables-and-views-performance/#comment-2121</guid>
		<description>Well probably v 5.2 will be used to make all the new features stable and well integrated ;-)</description>
		<content:encoded><![CDATA[<p>Well probably v 5.2 will be used to make all the new features stable and well integrated <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
</channel>
</rss>
