<?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: Optimizing repeated subexpressions in MySQL</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2009/01/23/optimizing-repeated-subexpressions-in-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2009/01/23/optimizing-repeated-subexpressions-in-mysql/</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: Sergei Golubchik</title>
		<link>http://www.mysqlperformanceblog.com/2009/01/23/optimizing-repeated-subexpressions-in-mysql/comment-page-1/#comment-455143</link>
		<dc:creator>Sergei Golubchik</dc:creator>
		<pubDate>Sun, 25 Jan 2009 20:23:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=596#comment-455143</guid>
		<description>To recognize common subexpressions ? No, I don&#039;t know.</description>
		<content:encoded><![CDATA[<p>To recognize common subexpressions ? No, I don&#8217;t know.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2009/01/23/optimizing-repeated-subexpressions-in-mysql/comment-page-1/#comment-455138</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Sun, 25 Jan 2009 19:18:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=596#comment-455138</guid>
		<description>Sergei,

Do you know if this is on the roadmap to be fixed natively by the way ?</description>
		<content:encoded><![CDATA[<p>Sergei,</p>
<p>Do you know if this is on the roadmap to be fixed natively by the way ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lukas</title>
		<link>http://www.mysqlperformanceblog.com/2009/01/23/optimizing-repeated-subexpressions-in-mysql/comment-page-1/#comment-454975</link>
		<dc:creator>Lukas</dc:creator>
		<pubDate>Sun, 25 Jan 2009 14:26:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=596#comment-454975</guid>
		<description>@Sergei: thats exactly the approach I meant in my original approach.

@Ms. Anthrope: right .. then again in some cases its nicer for the eyes to still do this subquery if the expression is very long.</description>
		<content:encoded><![CDATA[<p>@Sergei: thats exactly the approach I meant in my original approach.</p>
<p>@Ms. Anthrope: right .. then again in some cases its nicer for the eyes to still do this subquery if the expression is very long.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ms. Anthrope</title>
		<link>http://www.mysqlperformanceblog.com/2009/01/23/optimizing-repeated-subexpressions-in-mysql/comment-page-1/#comment-454849</link>
		<dc:creator>Ms. Anthrope</dc:creator>
		<pubDate>Sun, 25 Jan 2009 11:11:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=596#comment-454849</guid>
		<description>Notably, Postgres does not have this particular deficiency.  I often run into optimizer deficiencies in MySQL with my clients (this being one of the more minor sorts) and find myself longing for my younger days with the PGSQL.</description>
		<content:encoded><![CDATA[<p>Notably, Postgres does not have this particular deficiency.  I often run into optimizer deficiencies in MySQL with my clients (this being one of the more minor sorts) and find myself longing for my younger days with the PGSQL.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sergei Golubchik</title>
		<link>http://www.mysqlperformanceblog.com/2009/01/23/optimizing-repeated-subexpressions-in-mysql/comment-page-1/#comment-454839</link>
		<dc:creator>Sergei Golubchik</dc:creator>
		<pubDate>Sun, 25 Jan 2009 10:21:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=596#comment-454839</guid>
		<description>You don&#039;t need a user variable in your solution:

SELECT
pow(sum, 1),
pow(sum, 2),
pow(sum, 3),
pow(sum, 4),
pow(sum, 5),
pow(sum, 6),
pow(sum, 7),
pow(sum, 8),
pow(sum, 10),
pow(sum, 11),
pow(sum, 12),
pow(sum, 13),
pow(sum, 14),
pow(sum, 15),
pow(sum, 16),
pow(sum, 17),
pow(sum, 18)
FROM (SELECT sum(rental_id) as sum FROM sakila.rental) a

you can even write &quot;

  ...
  SELECT sum(rental_id) as sum FROM sakila.rental GROUP BY customer_id
  ...

which isn&#039;t possible with user variables.</description>
		<content:encoded><![CDATA[<p>You don&#8217;t need a user variable in your solution:</p>
<p>SELECT<br />
pow(sum, 1),<br />
pow(sum, 2),<br />
pow(sum, 3),<br />
pow(sum, 4),<br />
pow(sum, 5),<br />
pow(sum, 6),<br />
pow(sum, 7),<br />
pow(sum, 8),<br />
pow(sum, 10),<br />
pow(sum, 11),<br />
pow(sum, 12),<br />
pow(sum, 13),<br />
pow(sum, 14),<br />
pow(sum, 15),<br />
pow(sum, 16),<br />
pow(sum, 17),<br />
pow(sum, 18)<br />
FROM (SELECT sum(rental_id) as sum FROM sakila.rental) a</p>
<p>you can even write &#8221;</p>
<p>  &#8230;<br />
  SELECT sum(rental_id) as sum FROM sakila.rental GROUP BY customer_id<br />
  &#8230;</p>
<p>which isn&#8217;t possible with user variables.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shlomi Noach</title>
		<link>http://www.mysqlperformanceblog.com/2009/01/23/optimizing-repeated-subexpressions-in-mysql/comment-page-1/#comment-454666</link>
		<dc:creator>Shlomi Noach</dc:creator>
		<pubDate>Sun, 25 Jan 2009 06:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=596#comment-454666</guid>
		<description>Hi,

To solve the issue of whether @sum is calculated first, the query can be rewritten as:
SELECT sql_no_cache
   pow(@sum, 1),
   pow(@sum, 2),
   pow(@sum, 3),
   pow(@sum, 4),
   pow(@sum, 5),
   pow(@sum, 6),
   pow(@sum, 7),
   pow(@sum, 8),
   pow(@sum, 10),
   pow(@sum, 11),
   pow(@sum, 12),
   pow(@sum, 13),
   pow(@sum, 14),
   pow(@sum, 15),
   pow(@sum, 16),
   pow(@sum, 17),
   pow(@sum, 18)
FROM
   (SELECT @sum := (SELECT sum(rental_id) FROM sakila.rental)) a

In this query @sum is guaranteed to be calculated before all the pow(...) take place.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>To solve the issue of whether @sum is calculated first, the query can be rewritten as:<br />
SELECT sql_no_cache<br />
   pow(@sum, 1),<br />
   pow(@sum, 2),<br />
   pow(@sum, 3),<br />
   pow(@sum, 4),<br />
   pow(@sum, 5),<br />
   pow(@sum, 6),<br />
   pow(@sum, 7),<br />
   pow(@sum, 8),<br />
   pow(@sum, 10),<br />
   pow(@sum, 11),<br />
   pow(@sum, 12),<br />
   pow(@sum, 13),<br />
   pow(@sum, 14),<br />
   pow(@sum, 15),<br />
   pow(@sum, 16),<br />
   pow(@sum, 17),<br />
   pow(@sum, 18)<br />
FROM<br />
   (SELECT @sum := (SELECT sum(rental_id) FROM sakila.rental)) a</p>
<p>In this query @sum is guaranteed to be calculated before all the pow(&#8230;) take place.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sergei Golubchik</title>
		<link>http://www.mysqlperformanceblog.com/2009/01/23/optimizing-repeated-subexpressions-in-mysql/comment-page-1/#comment-453952</link>
		<dc:creator>Sergei Golubchik</dc:creator>
		<pubDate>Sat, 24 Jan 2009 11:40:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=596#comment-453952</guid>
		<description>sorry, bad timing :) we were commenting at the same time, apparently, at least, your comment wasn&#039;t here when I was writing mine.

I mean that Baron&#039;s workaround relies on the order in which SELECT expressions are evaluated. And this order is undefined, afaik.</description>
		<content:encoded><![CDATA[<p>sorry, bad timing <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  we were commenting at the same time, apparently, at least, your comment wasn&#8217;t here when I was writing mine.</p>
<p>I mean that Baron&#8217;s workaround relies on the order in which SELECT expressions are evaluated. And this order is undefined, afaik.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Baron Schwartz</title>
		<link>http://www.mysqlperformanceblog.com/2009/01/23/optimizing-repeated-subexpressions-in-mysql/comment-page-1/#comment-453940</link>
		<dc:creator>Baron Schwartz</dc:creator>
		<pubDate>Sat, 24 Jan 2009 11:33:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=596#comment-453940</guid>
		<description>Sergei, indeed: in cases where it matters, such as in mk-table-checksum, I run test queries to find out which place the &quot;real&quot; expression needs to go and where the user variables can be substituted.  The result is often that the real expression goes LAST, not first!  It looks odd but it&#039;s true -- you end up using @variable apparently before it&#039;s assigned to.  In this case it needed to be first.</description>
		<content:encoded><![CDATA[<p>Sergei, indeed: in cases where it matters, such as in mk-table-checksum, I run test queries to find out which place the &#8220;real&#8221; expression needs to go and where the user variables can be substituted.  The result is often that the real expression goes LAST, not first!  It looks odd but it&#8217;s true &#8212; you end up using @variable apparently before it&#8217;s assigned to.  In this case it needed to be first.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lukas</title>
		<link>http://www.mysqlperformanceblog.com/2009/01/23/optimizing-repeated-subexpressions-in-mysql/comment-page-1/#comment-453847</link>
		<dc:creator>Lukas</dc:creator>
		<pubDate>Sat, 24 Jan 2009 10:22:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=596#comment-453847</guid>
		<description>@Sergei: So the subquery solution is safer?</description>
		<content:encoded><![CDATA[<p>@Sergei: So the subquery solution is safer?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sergei Golubchik</title>
		<link>http://www.mysqlperformanceblog.com/2009/01/23/optimizing-repeated-subexpressions-in-mysql/comment-page-1/#comment-453845</link>
		<dc:creator>Sergei Golubchik</dc:creator>
		<pubDate>Sat, 24 Jan 2009 10:20:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=596#comment-453845</guid>
		<description>Just to say that your workaround isn&#039;t guaranteed to work. The server is not required to evaluate expressions in the SELECT clause in the order they are listed. The fact that it does is an implementation detail that may change any time.</description>
		<content:encoded><![CDATA[<p>Just to say that your workaround isn&#8217;t guaranteed to work. The server is not required to evaluate expressions in the SELECT clause in the order they are listed. The fact that it does is an implementation detail that may change any time.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
