title: SQL query performance - same calculation in SELECT and WHERE
body: <p>I'm working with MySQL. Let's assume I have a table <code>test(id, x)</code> -- the data types are not important --and the following query</p>
  
  <pre><code>SELECT id
  FROM test
  WHERE F(x) &lt;= 1000;
  </code></pre>
  
  <p>Further, let's assume <code>F</code> is a "more or less complex" function. Now, what is the effect if I change the query to:</p>
  
  <pre><code>SELECT id, F(x)
  FROM test
  WHERE F(x) &lt;= 1000;
  </code></pre>
  
  <p>That is, I need the result of F(x) not only for the WHERE condition but also as output in the SELECT clause. Can I safely assume that MySQL is clever enough to calculate only once for each row?</p>
  
  <p>(If the information is needed, in my specific case I handle geo-coordinates using MySQL spatial functions ST_WITHIN, ST_GEOMFROMTEXT, etc.)</p>