title: MySQL query performance with calculated where clause
body: <p>Using MySQL, 1M record table, index exists for 'some_timestamp'.</p>
  
  <p>WHERE clause is using a calculation so that records can be counted for different time buckets.</p>
  
  <p>Takes way to long to execute.</p>
  
  <p>Is there a better, faster approach???</p>
  
  <p>Here is the current code:</p>
  
  <pre><code>set @now = now();
  
  (SELECT 
      "45 Days" as "interval", count(*) as "thecount"
      FROM blah.yada
      where TIMESTAMPDIFF(day,some_timestamp,@now) &lt;= 45
          )
  
  UNION
  (SELECT 
      "90 Days" as "interval", count(*) as "thecount"
      FROM blah.yada
      where TIMESTAMPDIFF(day,some_timestamp,@now) &gt; 45 and TIMESTAMPDIFF(day,event_timestamp,@now) &lt;=90
          )
  
  UNION
  (SELECT 
      "the rest" as "interval", count(*) as "thecount"
      FROM blah.yada
      where TIMESTAMPDIFF(day,some_timestamp,@now) &gt; 90 
          )
  </code></pre>