I have folowwing SQL query
SELECT CustomerID FROM sales WHERE `Date` <= '2012-01-01' GROUP BY CustomerID
The query runs on 11,400,000 rows and runs very slowly. It takes more than 3 minutes. If I delete the group part, it runs below 1 second. Why is this?
MySQL server version is "5.0.21-community-nt"
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
performance mysql group-by
Treach
source share