title: Mysql query date between in large table
body: <p>my query is running about 10 seconds and that's unacceptable.</p>
  
  <p>I am looking for a way to improve this speed but i'm out of options.
  I have to find the records between now and 30 days back in a table over 12 million rows.</p>
  
  <p>The following query:</p>
  
  <pre><code>SELECT DATE(DATE) AS FDATE,
         SUM(VIEW_COUNT) AS COUNT,
         COUNT(IP_ADDRESS) AS CLIENTS
  FROM VIEWS
  WHERE USERID = 'test'
    AND DATE BETWEEN ADDDATE(CURDATE(), INTERVAL -30 DAY) AND CURDATE()
  GROUP BY FDATE DESC
  </code></pre>
  
  <p>I also tried, but the same effect:</p>
  
  <pre><code>SELECT DATE(DATE) AS FDATE,
         SUM(VIEW_COUNT) AS COUNT,
         COUNT(IP_ADDRESS) AS CLIENTS
  FROM VIEWS
  WHERE USERID = 'test'
    AND DATE &gt;= (DATE(NOW() - INTERVAL 30 DAY) + INTERVAL 0 SECOND)
  GROUP BY FDATE DESC
  </code></pre>