title: MySQL group-by very slow
body: <p>I have the folowwing SQL query</p>
  
  <pre><code>SELECT CustomerID FROM sales WHERE `Date` &lt;= '2012-01-01' GROUP BY CustomerID
  </code></pre>
  
  <p>The query is executed over 11400000 rows and runs very slow. It takes over 3 minutes to execute. If I remove the group-by part, this runs below 1 second. Why is that?</p>
  
  <p>MySQL Server version is '5.0.21-community-nt'</p>
  
  <pre><code>Here is the table schema:
  CREATE TABLE `sales` (
    `ID` int(11) NOT NULL auto_increment,
    `DocNo` int(11) default '0',
    `CustomerID` int(11) default '0',
    `OperatorID` int(11) default '0',
    PRIMARY KEY  (`ID`),
    KEY `ID` (`ID`),
    KEY `DocNo` (`DocNo`),
    KEY `CustomerID` (`CustomerID`),
    KEY `Date` (`Date`)
  ) ENGINE=MyISAM AUTO_INCREMENT=14946509 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  </code></pre>