title: Doing SUM() and GROUP BY over millions of rows on mysql
body: <p>I have this query which only runs once per request.</p>
  
  <pre><code>SELECT SUM(numberColumn) AS total, groupColumn
  FROM myTable
  WHERE dateColumn &lt; ? AND categoryColumn = ?
  GROUP BY groupColumn
  HAVING total &gt; 0
  </code></pre>
  
  <p><code>myTable</code> has less than a dozen columns and can grow up to 5 millions of rows, but more likely about 2 millions in production. All columns used in the query are numbers, except for <code>dateColumn</code>, and there are indexes on <code>dateColumn</code> and <code>categoryColumn</code>. </p>
  
  <p>Would it be reasonble to expect this query to run in under 5 seconds with 5 million rows on most modern servers if the database is properly optimized?</p>
  
  <p>The reason I'm asking is that we don't have 5 millions of data and we won't even hit 2 millions within the next few years, if the query doesn't run in under 5 seconds then, it's hard to know where the problem lies. Would it be because the query is not suitable for a large table, or the database isn't optimized, or the server isn't powerful enough? Basically, I'd like to know whether using <code>SUM()</code> and <code>GROUP BY</code> over a large table is reasonable.</p>
  
  <p>Thanks.</p>